import XenAPI
session=XenAPI.Session("http://172.20.25.172")
session.xenapi.login_with_password("root","123")
hh=session.xenapi.host.get_by_name_label("xenserver2")
record_hh=session.xenapi.host.get_record(hh[0])
pbds=record_hh["PBDs"]
for p in pbds:
aa=session.xenapi.SR.get_by_name_label("Local storage")
for a in aa:
record=session.xenapi.SR.get_record(a)
pp=record["PBDs"]
for px in pp:
if p==px:
vdisk={\'name_label\':"Disco",
\'name_description\':"",
\'SR\':aa[1],
\'virtual_size\':"2555555555",
\'type\':"user",
\'sharable\':True,
\'read_only\':True,
\'other_config\':{}}
vdi_ref=session.xenapi.VDI.create(vdisk)
platfrm={}
vmprop={\'name_label\':"testVM",
\'name_description\':"",
\'user_version\':"1",
\'affinity\':"",
\'is_a_template\':False,
\'auto_power_on\':False,
\'memory_static_max\':"268435456",
\'memory_static_min\':"268435456",
\'memory_dynamic_max\':"268435456",
\'memory_dynamic_min\':"268435456",
\'VCPUs_max\':"1",
\'VCPUs_at_startup\':"1",
\'VCPUs_params\':{},
\'actions_after_shutdown\':"destroy",
\'actions_after_reboot\':"restart",
\'actions_after_crash\':"restart",
\'PV_kernel\':"",
\'PV_ramdisk\':"",
\'PV_bootloader\':"",
\'PV_bootloader_args\':"",
\'PV_legacy_args\':"",
\'HVM_boot_policy\':"BIOS order",
\'HVM_boot_params\':{\'order\':\'dc\'},
\'platform\':platfrm,
\'PCI_bus\':"",
\'other_config\':{},
\'recommendations\':"",
\'PV_args\':""}
VM_ref=session.xenapi.VM.create(vmprop)
vbdconnect={\'VDI\':vdi_ref,
\'VM\':VM_ref,
\'userdevice\':"0",
\'mode\':"RW",
\'type\':"Disk",
\'bootable\':True,
\'unpluggable\':True,
\'empty\':False,
\'other_config\':{},
\'qos_algorithm_type\':\'\',
\'qos_algorithm_params\':{}}
vbdref=session.xenapi.VBD.create(vbdconnect)