How to add disk to SATA controller

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
Dmouha
Posts: 11
Joined: 12. Aug 2015, 11:04

How to add disk to SATA controller

Post by Dmouha »

Hello Team,
I'm having a hard time to ass a disk to a SATA controller with virtualbox API when using a SAS controller everything works great but here I have a huge traceback that I do not understand.
Do I have to do something special with the SATA controller first (like creating a port range) why is it working when I do this on a SAS or SCSI controller? Thanks for helping
cheers,

Code: Select all

import time
import os
import virtualbox
from virtualbox.library import StorageBus, IMachine
from virtualbox.library import IStorageController, LockType
from virtualbox.library import DeviceType, MediumVariant
from virtualbox.library import VBoxErrorObjectNotFound
from virtualbox.library import IStorageController, LockType, IVirtualBox
from virtualbox.library import IVirtualBox, AccessMode

session = virtualbox.Session()
sup = virtualbox.VirtualBox().find_machine("test_machine")
sup.lock_machine(session,LockType.write)
current_interface = IVirtualBox()
medium = current_interface.create_hard_disk("VDI", "/home/luffy/mine.vdi")
progress = medium.create_base_storage(1024*1024, [MediumVariant.fixed])
progress.wait_for_completion()
opened_medium = current_interface.open_medium("/home/luffy/mine.vdi", DeviceType.hard_disk, AccessMode.read_write,False)
session.machine.attach_device("SAS",2, 0, DeviceType.hard_disk,opened_medium) # This one works
session.machine.attach_device("SATA",2 ,0 ,DeviceType.hard_disk,opened_medium)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/virtualbox/library.py", line 10264, in attach_device
    in_p=[name, controller_port, device, type_p, medium])
  File "/usr/local/lib/python2.7/dist-packages/virtualbox/library_base.py", line 173, in _call
    return self._call_method(method, in_p=in_p)
  File "/usr/local/lib/python2.7/dist-packages/virtualbox/library_base.py", line 199, in _call_method
    raise errobj
virtualbox.library.OleErrorInvalidarg: 0x80070057 (The port and/or device parameter are out of range: port=2 (must be in range [0, 0]), device=0 (must be in range [0, 0]))
#session.machine.save_settings()
session.unlock_machine()
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: How to add disk to SATA controller

Post by noteirak »

By default, the SATA controller has only one port enabled, which means you can only use "0, 0" to add a disk.
If you want to use port ID 2, you'll need to set the amount of ports to minimum 3 with IStorageController::portCount
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Dmouha
Posts: 11
Joined: 12. Aug 2015, 11:04

Re: How to add disk to SATA controller

Post by Dmouha »

How can I set the amount of port to the maximum ?
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: How to add disk to SATA controller

Post by noteirak »

You can use IStorageController::maxPortCount to get the maxium allowed value.
In Java you would have something like this :

Code: Select all

IStorageController sc = machine.getStorageControllerByName("SATA");
sc.setPortCount(sc.getMaxPortCount());
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Dmouha
Posts: 11
Joined: 12. Aug 2015, 11:04

Re: How to add disk to SATA controller

Post by Dmouha »

awsome thx a lot
michaln
Oracle Corporation
Posts: 2973
Joined: 19. Dec 2007, 15:45
Primary OS: MS Windows 7
VBox Version: PUEL
Guest OSses: Any and all
Contact:

Re: How to add disk to SATA controller

Post by michaln »

Dmouha wrote:How can I set the amount of port to the maximum ?
Only do that if you like problems. Some guest OSes will take a long time enumerating the non-present disks, and some will crash.

There is a reason why the VirtualBox GUI only sets the SATA port count to match the number of attached devices, not the maximum possible.
Dmouha
Posts: 11
Joined: 12. Aug 2015, 11:04

Re: How to add disk to SATA controller

Post by Dmouha »

Roger that will pay attention
Dmouha
Posts: 11
Joined: 12. Aug 2015, 11:04

Re: How to add disk to SATA controller

Post by Dmouha »

Got an issue since I upgraded to virtualbox 5.0 I cannot create HDD anymore getting the error

Code: Select all

>>>
medium = current_interface.create_hard_disk("VDI", "/home/luffy/mine.vdi")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/virtualbox/library.py", line 6633, in create_hard_disk
    in_p=[format_p, location])
  File "/usr/local/lib/python2.7/dist-packages/virtualbox/library_base.py", line 171, in _call
    method = self._search_attr(name)
  File "/usr/local/lib/python2.7/dist-packages/virtualbox/library_base.py", line 152, in _search_attr
    raise AttributeError("Failed to find attribute %s in %s" % (name, self))
AttributeError: Failed to find attribute createHardDisk in <virtualbox.library_ext.vbox.IVirtualBox object at 0x7f87aa899210>
>>> 
any idea why it is not supported anymore? I used the same code sample as above and it worked on previous version
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: How to add disk to SATA controller

Post by noteirak »

Could you try again using the 5.0.4 SDK and binding?
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Post Reply