I want to add a DVD drive to VM on xenserver using Python. I created a VM using Python and now I want to add the DVD Drive attached to host to be accessible in VM also. So I need to create a VBD for the DVD Drive as well. But I am unable to get which prop开发者_JS百科erty I need to set in VBD.Record as in attaching disk, I set up the VDI property and it got attached. But for the DVD Drive, I am unable to figure out which property I need to set to attach that CD Drive to the XenServer. Do help me regarding this.....
I can't help you directly with the Python part, but I'll try to give the you the correct command line statements.
Assuming the VM already has a DVD drive, you can just issue these commands
xe cd-list
xe vm-cd-insert uuid=... cd-name="xs-tools.iso"
xe vm-cd-eject uuid=...
. .
If your interested in the the vbd stuff, the following commands can get you the uuid of the vbd for the DVD drive:
Start with a single VM. From XenCenter eject the DVD. Now connect to the XenServer host on the command line, and run:
xe vbd-list vm-uuid=...
If the VM has an empty DVD drive it's vdi-uuid will be listed as <not in database>. This will allow you to pinpoint the uuid of the vbd your after!
For more information, check out this link:
http://docs.vmd.citrix.com/XenServer/5.0.0/1.0/en_gb/guest.html
I have written about this on my blog:
sr=session.xenapi.SR.get_by_name_label("DVD drives") record_dvd=session.xenapi.SR.get_record(sr[0]) VDI_dvd=record_dvd["VDIs"] vbdconnectcd={'VDI':VDI_dvd[0], 'VM':VM_ref, 'userdevice':"1", 'mode':"RO", 'type':"cd", 'bootable':True, 'unpluggable':True, 'empty':False, 'other_config':{}, 'qos_algorithm_type':'', 'qos_algorithm_params':{}} vbdref1=session.xenapi.VBD.create(vbdconnectcd)
Here,
VM_ref
refers to theuuid
of newly created VM to which we want to add the DVD Drive. Every physical DVD Drive has its VDI which is stored in its properties and one can get it and pass it as one of the parameters to create a VBD linking DVD Drive with the VM.
Add CD Drive to XenServer VM using Java
First you have to Connect with xenserver and get the connection variable.
public VBD makeCDDrive(VM vm) throws Exception {
VBD.Record vbdrecord = new VBD.Record();
vbdrecord.VM = vm;
vbdrecord.VDI = null;
vbdrecord.userdevice = "3";
vbdrecord.mode = Types.VbdMode.RO;
vbdrecord.type = Types.VbdType.CD;
vbdrecord.empty = true;
return VBD.create(connection, vbdrecord);
}
精彩评论