def create_basic_vm(stub_config, placement_spec, standard_network): """ Create a basic VM. Using the provided PlacementSpec, create a VM with a selected Guest OS and provided name. Create a VM with the following configuration: * Create 2 disks and specify one of them on scsi0:0 since it's the boot disk * Specify 1 ethernet adapter using a Standard Portgroup backing * Setup for PXE install by selecting network as first boot device Use guest and system provided defaults for most configuration settings. """ guest_os = testbed.config['VM_GUESTOS'] boot_disk = Disk.CreateSpec(type=Disk.HostBusAdapterType.SCSI, scsi=ScsiAddressSpec(bus=0, unit=0), new_vmdk=Disk.VmdkCreateSpec()) data_disk = Disk.CreateSpec(new_vmdk=Disk.VmdkCreateSpec()) nic = Ethernet.CreateSpec(start_connected=True, backing=Ethernet.BackingSpec( type=Ethernet.BackingType.STANDARD_PORTGROUP, network=standard_network)) # TODO Should DISK be put before ETHERNET? Does the BIOS automatically try # the next device if the DISK is empty? boot_device_order = [ BootDevice.EntryCreateSpec(BootDevice.Type.ETHERNET), BootDevice.EntryCreateSpec(BootDevice.Type.DISK) ] vm_create_spec = VM.CreateSpec(name=vm_name, guest_os=guest_os, placement=placement_spec, disks=[boot_disk, data_disk], nics=[nic], boot_devices=boot_device_order) print('\n# Example: create_basic_vm: Creating a VM using spec\n-----') print(pp(vm_create_spec)) print('-----') vm_svc = VM(stub_config) vm = vm_svc.create(vm_create_spec) print("create_basic_vm: Created VM '{}' ({})".format(vm_name, vm)) vm_info = vm_svc.get(vm) print('vm.get({}) -> {}'.format(vm, pp(vm_info))) return vm
def create_vm_api(request): datacenter_name = 'BlueKing' vm_folder_name = 'test' datastore_name = 'esxi-1-hdd' # session = get_unverified_session() session = requests.session() session.verify = False urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) client = create_vsphere_client(server='10.12.33.9', username='******', password='******', session=session) # client = create_vsphere_client(server='10.12.0.3', # username=r'*****@*****.**', # password=r'p@ssw0rd', # session=session) placement_spec = get_placement_spec_for_resource_pool( client, datacenter_name, vm_folder_name, datastore_name) rec_data = json.loads(request.body.decode('utf-8'), strict=False) guest_os = "WINDOWS_9" vm_name = rec_data['name'] memory = Memory.UpdateSpec(size_mib=int(rec_data['memory']) * 1024) disk = Disk.CreateSpec(new_vmdk=Disk.VmdkCreateSpec( capacity=int(rec_data['disk']) * 1024 * 1024 * 1024)) vm_create_spec = VM.CreateSpec(name=vm_name, guest_os=guest_os, memory=memory, disks=[disk], placement=placement_spec) vm = client.vcenter.VM.create(vm_create_spec) print("create_default_vm: Created VM '{}' ({})".format(vm_name, vm)) vm_info = client.vcenter.VM.get(vm) if (vm_info): return JsonResponse({ 'code': 200, 'data': "create_default_vm: Created VM '{}' ({})".format(vm_name, vm) }) else: return JsonResponse({'code': 500, 'message': "error"})
def run(self): # Get a placement spec datacenter_name = testbed.config['VM_DATACENTER_NAME'] vm_folder_name = testbed.config['VM_FOLDER2_NAME'] datastore_name = testbed.config['VM_DATASTORE_NAME'] std_portgroup_name = testbed.config['STDPORTGROUP_NAME'] dv_portgroup_name = testbed.config['VDPORTGROUP1_NAME'] if not self.placement_spec: self.placement_spec = vm_placement_helper.get_placement_spec_for_resource_pool( self.client, datacenter_name, vm_folder_name, datastore_name) # Get a standard network backing if not self.standard_network: self.standard_network = network_helper.get_network_backing( self.client, std_portgroup_name, datacenter_name, Network.Type.STANDARD_PORTGROUP) # Get a distributed network backing if not self.distributed_network: self.distributed_network = network_helper.get_network_backing( self.client, dv_portgroup_name, datacenter_name, Network.Type.DISTRIBUTED_PORTGROUP) """ Create an exhaustive VM. Using the provided PlacementSpec, create a VM with a selected Guest OS and provided name. Create a VM with the following configuration: * Hardware Version = VMX_11 (for 6.0) * CPU (count = 2, coresPerSocket = 2, hotAddEnabled = false, hotRemoveEnabled = false) * Memory (size_mib = 2 GB, hotAddEnabled = false) * 3 Disks and specify each of the HBAs and the unit numbers * (capacity=40 GB, name=<some value>, spaceEfficient=true) * Specify 2 ethernet adapters, one using a Standard Portgroup backing and the other using a DISTRIBUTED_PORTGROUP networking backing. * nic1: Specify Ethernet (macType=MANUAL, macAddress=<some value>) * nic2: Specify Ethernet (macType=GENERATED) * 1 CDROM (type=ISO_FILE, file="os.iso", startConnected=true) * 1 Serial Port (type=NETWORK_SERVER, file="tcp://localhost/16000", startConnected=true) * 1 Parallel Port (type=HOST_DEVICE, startConnected=false) * 1 Floppy Drive (type=CLIENT_DEVICE) * Boot, type=BIOS * BootDevice order: CDROM, DISK, ETHERNET Use guest and system provided defaults for remaining configuration settings. """ guest_os = testbed.config['VM_GUESTOS'] iso_datastore_path = testbed.config['ISO_DATASTORE_PATH'] serial_port_network_location = \ testbed.config['SERIAL_PORT_NETWORK_SERVER_LOCATION'] GiB = 1024 * 1024 * 1024 GiBMemory = 1024 vm_create_spec = VM.CreateSpec( guest_os=guest_os, name=self.vm_name, placement=self.placement_spec, hardware_version=Hardware.Version.VMX_11, cpu=Cpu.UpdateSpec(count=2, cores_per_socket=1, hot_add_enabled=False, hot_remove_enabled=False), memory=Memory.UpdateSpec(size_mib=2 * GiBMemory, hot_add_enabled=False), disks=[ Disk.CreateSpec(type=Disk.HostBusAdapterType.SCSI, scsi=ScsiAddressSpec(bus=0, unit=0), new_vmdk=Disk.VmdkCreateSpec(name='boot', capacity=40 * GiB)), Disk.CreateSpec(new_vmdk=Disk.VmdkCreateSpec( name='data1', capacity=10 * GiB)), Disk.CreateSpec(new_vmdk=Disk.VmdkCreateSpec( name='data2', capacity=10 * GiB)) ], nics=[ Ethernet.CreateSpec( start_connected=True, mac_type=Ethernet.MacAddressType.MANUAL, mac_address='11:23:58:13:21:34', backing=Ethernet.BackingSpec( type=Ethernet.BackingType.STANDARD_PORTGROUP, network=self.standard_network)), Ethernet.CreateSpec( start_connected=True, mac_type=Ethernet.MacAddressType.GENERATED, backing=Ethernet.BackingSpec( type=Ethernet.BackingType.DISTRIBUTED_PORTGROUP, network=self.distributed_network)), ], cdroms=[ Cdrom.CreateSpec(start_connected=True, backing=Cdrom.BackingSpec( type=Cdrom.BackingType.ISO_FILE, iso_file=iso_datastore_path)) ], serial_ports=[ Serial.CreateSpec( start_connected=False, backing=Serial.BackingSpec( type=Serial.BackingType.NETWORK_SERVER, network_location=serial_port_network_location)) ], parallel_ports=[ Parallel.CreateSpec(start_connected=False, backing=Parallel.BackingSpec( type=Parallel.BackingType.HOST_DEVICE)) ], floppies=[ Floppy.CreateSpec(backing=Floppy.BackingSpec( type=Floppy.BackingType.CLIENT_DEVICE)) ], boot=Boot.CreateSpec(type=Boot.Type.BIOS, delay=0, enter_setup_mode=False), # TODO Should DISK be put before CDROM and ETHERNET? Does the BIOS # automatically try the next device if the DISK is empty? boot_devices=[ BootDevice.EntryCreateSpec(BootDevice.Type.CDROM), BootDevice.EntryCreateSpec(BootDevice.Type.DISK), BootDevice.EntryCreateSpec(BootDevice.Type.ETHERNET) ]) print( '# Example: create_exhaustive_vm: Creating a VM using spec\n-----') print(pp(vm_create_spec)) print('-----') vm = self.client.vcenter.VM.create(vm_create_spec) print("create_exhaustive_vm: Created VM '{}' ({})".format( self.vm_name, vm)) vm_info = self.client.vcenter.VM.get(vm) print('vm.get({}) -> {}'.format(vm, pp(vm_info))) return vm
print(network2) placement_spec = VM.PlacementSpec(folder=folder, #resource_pool=resource_pool, #host='esxi-1.prod.vmware.haf', host=host.host, datastore=datastore.datastore) scsi_create_spec0 = Scsi.CreateSpec(bus=0, pci_slot_number=160, sharing=Scsi.Sharing.NONE) scsi_create_spec1 = Scsi.CreateSpec(bus=1, pci_slot_number=256, sharing=Scsi.Sharing.PHYSICAL) #scsi_create_spec2 = Scsi.CreateSpec(bus=2, pci_slot_number=256, sharing=Scsi.Sharing.PHYSICAL) disk_create_spec0 = Disk.CreateSpec(type=Disk.HostBusAdapterType.SCSI, scsi=ScsiAddressSpec(bus=0, unit=0), new_vmdk=Disk.VmdkCreateSpec(name='disk-0', capacity=10 * GiB)) disk_create_spec1 = Disk.CreateSpec(type=Disk.HostBusAdapterType.SCSI, scsi=ScsiAddressSpec(bus=0, unit=1), new_vmdk=Disk.VmdkCreateSpec(name='disk-1', capacity=10 * GiB)) disk_create_spec2 = Disk.CreateSpec(type=Disk.HostBusAdapterType.SCSI, scsi=ScsiAddressSpec(bus=2, unit=0), new_vmdk=Disk.VmdkCreateSpec(name='disk-shared-0', capacity=4 * GiB)) #[Kingston120G] SHARED/RAC_SSD_1.vm vm_create_spec = VM.CreateSpec( guest_os='CENTOS_7_64', name='TESTVM', placement=placement_spec, hardware_version=Hardware.Version.VMX_13,
def run(self): # Get a placement spec datacenter_name = testbed.config['VM_DATACENTER_NAME'] vm_folder_name = testbed.config['VM_FOLDER2_NAME'] datastore_name = testbed.config['VM_DATASTORE_NAME'] std_portgroup_name = testbed.config['STDPORTGROUP_NAME'] if not self.placement_spec: self.placement_spec = vm_placement_helper.get_placement_spec_for_resource_pool( self.stub_config, datacenter_name, vm_folder_name, datastore_name) # Get a standard network backing standard_network = network_helper.get_standard_network_backing( self.stub_config, std_portgroup_name, datacenter_name) """ Create a basic VM. Using the provided PlacementSpec, create a VM with a selected Guest OS and provided name. Create a VM with the following configuration: * Create 2 disks and specify one of them on scsi0:0 since it's the boot disk * Specify 1 ethernet adapter using a Standard Portgroup backing * Setup for PXE install by selecting network as first boot device Use guest and system provided defaults for most configuration settings. """ guest_os = testbed.config['VM_GUESTOS'] boot_disk = Disk.CreateSpec(type=Disk.HostBusAdapterType.SCSI, scsi=ScsiAddressSpec(bus=0, unit=0), new_vmdk=Disk.VmdkCreateSpec()) data_disk = Disk.CreateSpec(new_vmdk=Disk.VmdkCreateSpec()) nic = Ethernet.CreateSpec( start_connected=True, backing=Ethernet.BackingSpec( type=Ethernet.BackingType.STANDARD_PORTGROUP, network=standard_network)) boot_device_order = [ BootDevice.EntryCreateSpec(BootDevice.Type.ETHERNET), BootDevice.EntryCreateSpec(BootDevice.Type.DISK) ] vm_create_spec = VM.CreateSpec(name=self.vm_name, guest_os=guest_os, placement=self.placement_spec, disks=[boot_disk, data_disk], nics=[nic], boot_devices=boot_device_order) print('\n# Example: create_basic_vm: Creating a VM using spec\n-----') print(pp(vm_create_spec)) print('-----') vm_svc = VM(self.stub_config) vm = vm_svc.create(vm_create_spec) print("create_basic_vm: Created VM '{}' ({})".format(self.vm_name, vm)) vm_info = vm_svc.get(vm) print('vm.get({}) -> {}'.format(vm, pp(vm_info))) return vm
def run(): GiB = 1024 * 1024 * 1024 print('\n# Example: List all Disks for a VM') disk_summaries = client.vcenter.vm.hardware.Disk.list(vm=vm) print('vm.hardware.Disk.list({}) -> {}'.format(vm, disk_summaries)) # Save current list of disks to verify that we have cleaned up properly global orig_disk_summaries orig_disk_summaries = disk_summaries # Get information for each Disk on the VM for disk_summary in disk_summaries: disk = disk_summary.disk disk_info = client.vcenter.vm.hardware.Disk.get(vm=vm, disk=disk) print('vm.hardware.Disk.get({}, {}) -> {}'.format( vm, disk, pp(disk_info))) print('\n# Example: Create a new Disk using default settings') disk_create_spec = Disk.CreateSpec(new_vmdk=Disk.VmdkCreateSpec()) disk = client.vcenter.vm.hardware.Disk.create(vm=vm, spec=disk_create_spec) print('vm.hardware.Disk.create({}, {}) -> {}'.format( vm, disk_create_spec, disk)) global disks_to_delete disks_to_delete.append(disk) disk_info = client.vcenter.vm.hardware.Disk.get(vm, disk) print('vm.hardware.Disk.get({}, {}) -> {}'.format(vm, disk, pp(disk_info))) print( '\n# Example: Create a new Disk specifying the capacity in bytes \n' + '# and that the flat format (ie. SeSparse format) should be used.') disk_create_spec = Disk.CreateSpec(new_vmdk=Disk.VmdkCreateSpec( capacity=10 * GiB)) disk = client.vcenter.vm.hardware.Disk.create(vm=vm, spec=disk_create_spec) print('vm.hardware.Disk.create({}, {}) -> {}'.format( vm, disk_create_spec, disk)) disks_to_delete.append(disk) disk_info = client.vcenter.vm.hardware.Disk.get(vm, disk) print('vm.hardware.Disk.get({}, {}) -> {}'.format(vm, disk, pp(disk_info))) print('\n# Example: Create a new SCSI Disk') disk_create_spec = Disk.CreateSpec( type=Disk.HostBusAdapterType.SCSI, new_vmdk=Disk.VmdkCreateSpec(capacity=10 * GiB)) disk = client.vcenter.vm.hardware.Disk.create(vm=vm, spec=disk_create_spec) print('vm.hardware.Disk.create({}, {}) -> {}'.format( vm, disk_create_spec, disk)) disks_to_delete.append(disk) disk_info = client.vcenter.vm.hardware.Disk.get(vm, disk) print('vm.hardware.Disk.get({}, {}) -> {}'.format(vm, disk, pp(disk_info))) print('\n# Example: Create a new SCSI Disk on a specific bus') disk_create_spec = Disk.CreateSpec( type=Disk.HostBusAdapterType.SCSI, scsi=ScsiAddressSpec(bus=0), new_vmdk=Disk.VmdkCreateSpec(capacity=10 * GiB)) disk = client.vcenter.vm.hardware.Disk.create(vm=vm, spec=disk_create_spec) print('vm.hardware.Disk.create({}, {}) -> {}'.format( vm, disk_create_spec, disk)) disks_to_delete.append(disk) disk_info = client.vcenter.vm.hardware.Disk.get(vm, disk) print('vm.hardware.Disk.get({}, {}) -> {}'.format(vm, disk, pp(disk_info))) print( '\n# Example: Create a new SCSI Disk on a specific bus and unit number' ) disk_create_spec = Disk.CreateSpec( type=Disk.HostBusAdapterType.SCSI, scsi=ScsiAddressSpec(bus=0, unit=10), new_vmdk=Disk.VmdkCreateSpec(capacity=10 * GiB)) disk = client.vcenter.vm.hardware.Disk.create(vm=vm, spec=disk_create_spec) print('vm.hardware.Disk.create({}, {}) -> {}'.format( vm, disk_create_spec, disk)) disks_to_delete.append(disk) disk_info = client.vcenter.vm.hardware.Disk.get(vm, disk) print('vm.hardware.Disk.get({}, {}) -> {}'.format(vm, disk, pp(disk_info))) print('\n# Example: Create a SATA controller') sata_create_spec = Sata.CreateSpec() print('# Adding SATA controller for SATA Disk') global sata sata = client.vcenter.vm.hardware.adapter.Sata.create(vm, sata_create_spec) print('vm.hardware.adapter.Sata.create({}, {}) -> {}'.format( vm, sata_create_spec, sata)) print('\n# Example: Create a new SATA disk') disk_create_spec = Disk.CreateSpec( type=Disk.HostBusAdapterType.SATA, new_vmdk=Disk.VmdkCreateSpec(capacity=10 * GiB)) disk = client.vcenter.vm.hardware.Disk.create(vm=vm, spec=disk_create_spec) print('vm.hardware.Disk.create({}, {}) -> {}'.format( vm, disk_create_spec, disk)) disks_to_delete.append(disk) disk_info = client.vcenter.vm.hardware.Disk.get(vm, disk) print('vm.hardware.Disk.get({}, {}) -> {}'.format(vm, disk, pp(disk_info))) print('\n# Example: Create a new SATA disk on a specific bus') disk_create_spec = Disk.CreateSpec( type=Disk.HostBusAdapterType.SATA, sata=SataAddressSpec(bus=0), new_vmdk=Disk.VmdkCreateSpec(capacity=10 * GiB)) disk = client.vcenter.vm.hardware.Disk.create(vm=vm, spec=disk_create_spec) print('vm.hardware.Disk.create({}, {}) -> {}'.format( vm, disk_create_spec, disk)) disks_to_delete.append(disk) disk_info = client.vcenter.vm.hardware.Disk.get(vm, disk) print('vm.hardware.Disk.get({}, {}) -> {}'.format(vm, disk, pp(disk_info))) print('\n# Example: Create a new SATA disk on a specific bus and specific ' 'unit') disk_create_spec = Disk.CreateSpec( type=Disk.HostBusAdapterType.SATA, sata=SataAddressSpec(bus=0, unit=20), new_vmdk=Disk.VmdkCreateSpec(capacity=10 * GiB)) disk = client.vcenter.vm.hardware.Disk.create(vm=vm, spec=disk_create_spec) print('vm.hardware.Disk.create({}, {}) -> {}'.format( vm, disk_create_spec, disk)) disks_to_delete.append(disk) disk_info = client.vcenter.vm.hardware.Disk.get(vm, disk) print('vm.hardware.Disk.get({}, {}) -> {}'.format(vm, disk, pp(disk_info))) print('\n# Example: Create a new IDE disk') disk_create_spec = Disk.CreateSpec( type=Disk.HostBusAdapterType.IDE, new_vmdk=Disk.VmdkCreateSpec(capacity=10 * GiB)) disk = client.vcenter.vm.hardware.Disk.create(vm=vm, spec=disk_create_spec) print('vm.hardware.Disk.create({}, {}) -> {}'.format( vm, disk_create_spec, disk)) disks_to_delete.append(disk) disk_info = client.vcenter.vm.hardware.Disk.get(vm, disk) print('vm.hardware.Disk.get({}, {}) -> {}'.format(vm, disk, pp(disk_info))) print('\n# Example: Create a new IDE disk on a specific bus and ' 'specific unit') disk_create_spec = Disk.CreateSpec( type=Disk.HostBusAdapterType.IDE, ide=IdeAddressSpec(False, False), new_vmdk=Disk.VmdkCreateSpec(capacity=10 * GiB)) disk = client.vcenter.vm.hardware.Disk.create(vm=vm, spec=disk_create_spec) print('vm.hardware.Disk.create({}, {}) -> {}'.format( vm, disk_create_spec, disk)) disks_to_delete.append(disk) disk_info = client.vcenter.vm.hardware.Disk.get(vm, disk) print('vm.hardware.Disk.get({}, {}) -> {}'.format(vm, disk, pp(disk_info))) print( '\n# Example: Attach an existing VMDK using the default bus and unit') datastore_path = datastore_root_path + '/attach-defaults.vmdk' delete_vmdk_if_exist(client, service_instance._stub, datacenter_name, datastore_name, datastore_path) create_vmdk(service_instance, datacenter_mo, datastore_path) disk_create_spec = Disk.CreateSpec(backing=Disk.BackingSpec( type=Disk.BackingType.VMDK_FILE, vmdk_file=datastore_path)) disk = client.vcenter.vm.hardware.Disk.create(vm=vm, spec=disk_create_spec) print('vm.hardware.Disk.create({}, {}) -> {}'.format( vm, disk_create_spec, disk)) disks_to_delete.append(disk) disk_info = client.vcenter.vm.hardware.Disk.get(vm, disk) print('vm.hardware.Disk.get({}, {}) -> {}'.format(vm, disk, pp(disk_info))) print('\n# Example: Attach an existing VMDK as a SCSI disk') datastore_path = datastore_root_path + '/attach-scsi.vmdk' delete_vmdk_if_exist(client, service_instance._stub, datacenter_name, datastore_name, datastore_path) create_vmdk(service_instance, datacenter_mo, datastore_path) disk_create_spec = Disk.CreateSpec(type=Disk.HostBusAdapterType.SCSI, backing=Disk.BackingSpec( type=Disk.BackingType.VMDK_FILE, vmdk_file=datastore_path)) disk = client.vcenter.vm.hardware.Disk.create(vm=vm, spec=disk_create_spec) print('vm.hardware.Disk.create({}, {}) -> {}'.format( vm, disk_create_spec, disk)) disks_to_delete.append(disk) disk_info = client.vcenter.vm.hardware.Disk.get(vm, disk) print('vm.hardware.Disk.get({}, {}) -> {}'.format(vm, disk, pp(disk_info))) print('\n# Example: Attach an existing VMDK as a SCSI disk ' 'to a specific bus') datastore_path = datastore_root_path + '/attach-scsi0.vmdk' delete_vmdk_if_exist(client, service_instance._stub, datacenter_name, datastore_name, datastore_path) create_vmdk(service_instance, datacenter_mo, datastore_path) disk_create_spec = Disk.CreateSpec(type=Disk.HostBusAdapterType.SCSI, scsi=ScsiAddressSpec(bus=0), backing=Disk.BackingSpec( type=Disk.BackingType.VMDK_FILE, vmdk_file=datastore_path)) disk = client.vcenter.vm.hardware.Disk.create(vm=vm, spec=disk_create_spec) print('vm.hardware.Disk.create({}, {}) -> {}'.format( vm, disk_create_spec, disk)) disks_to_delete.append(disk) disk_info = client.vcenter.vm.hardware.Disk.get(vm, disk) print('vm.hardware.Disk.get({}, {}) -> {}'.format(vm, disk, pp(disk_info))) print('\n# Example: Attach an existing VMDK as a SCSI disk ' 'to a specific bus and specific unit') datastore_path = datastore_root_path + '/attach-scsi0:11.vmdk' delete_vmdk_if_exist(client, service_instance._stub, datacenter_name, datastore_name, datastore_path) create_vmdk(service_instance, datacenter_mo, datastore_path) disk_create_spec = Disk.CreateSpec(type=Disk.HostBusAdapterType.SCSI, scsi=ScsiAddressSpec(bus=0, unit=11), backing=Disk.BackingSpec( type=Disk.BackingType.VMDK_FILE, vmdk_file=datastore_path)) disk = client.vcenter.vm.hardware.Disk.create(vm=vm, spec=disk_create_spec) print('vm.hardware.Disk.create({}, {}) -> {}'.format( vm, disk_create_spec, disk)) disks_to_delete.append(disk) disk_info = client.vcenter.vm.hardware.Disk.get(vm, disk) print('vm.hardware.Disk.get({}, {}) -> {}'.format(vm, disk, pp(disk_info))) # Samples to update operation to change backing # Save the disk_info so we can delete the VMDK global saved_disk_info saved_disk_info = disk_info print( '\n# Example: Change the backing of the last disk to a new VMDK file.') datastore_path = datastore_root_path + '/update-scsi0:11.vmdk' delete_vmdk_if_exist(client, service_instance._stub, datacenter_name, datastore_name, datastore_path) create_vmdk(service_instance, datacenter_mo, datastore_path) disk_update_spec = Disk.UpdateSpec(backing=Disk.BackingSpec( type=Disk.BackingType.VMDK_FILE, vmdk_file=datastore_path)) print('vm.hardware.Disk.update({}, {}, {})'.format(vm, disk, disk_update_spec)) client.vcenter.vm.hardware.Disk.update(vm=vm, disk=disk, spec=disk_update_spec) disk_info = client.vcenter.vm.hardware.Disk.get(vm, disk) print('vm.hardware.Disk.get({}, {}) -> {}'.format(vm, disk, pp(disk_info)))
def run(self): # Get a placement spec datacenter_name = 'Datacenter' # testbed.config['VM_DATACENTER_NAME'] # vm_folder_name = 'kong111_166' #testbed.config['VM_FOLDER2_NAME'] datastore_name = 'datastore-717' # testbed.config['VM_DATASTORE_NAME'] std_portgroup_name = 'VM Network' # testbed.config['STDPORTGROUP_NAME'] host = 'host-716' diskprovisioningtpye = DiskProvisioningType('eagerZeroedThick') if not self.placement_spec: # self.placement_spec = vm_placement_helper.get_placement_spec_for_resource_pool( # self.client, # datacenter_name, # vm_folder_name, # datastore_name) self.placement_spec = VM.PlacementSpec(host=host, datastore=datastore_name, folder='group-v3') # Get a standard network backing standard_network = network_helper.get_network_backing( self.client, std_portgroup_name, datacenter_name, Network.Type.STANDARD_PORTGROUP) """ Create a basic VM. Using the provided PlacementSpec, create a VM with a selected Guest OS and provided name. Create a VM with the following configuration: * Create 2 disks and specify one of them on scsi0:0 since it's the boot disk * Specify 1 ethernet adapter using a Standard Portgroup backing * Setup for PXE install by selecting network as first boot device Use guest and system provided defaults for most configuration settings. """ guest_os = 'CENTOS_6_64' # testbed.config['VM_GUESTOS'] hardware = '' # boot_disk = Disk.CreateSpec(type=Disk.HostBusAdapterType.SCSI, # scsi=ScsiAddressSpec(bus=0, unit=0), # new_vmdk=Disk.VmdkCreateSpec()) data_disk = Disk.CreateSpec(new_vmdk=Disk.VmdkCreateSpec( capacity=self.cap)) nic = Ethernet.CreateSpec( start_connected=True, backing=Ethernet.BackingSpec( type=Ethernet.BackingType.STANDARD_PORTGROUP, network=standard_network)) sata_adapt = Sata.CreateSpec() cpu = Cpu.UpdateSpec(count=self.cpu, cores_per_socket=1, hot_add_enabled=True, hot_remove_enabled=True) memory = Memory.UpdateSpec(size_mib=self.memory, hot_add_enabled=True) # boot_device_order = [ # BootDevice.EntryCreateSpec(BootDevice.Type.ETHERNET), # BootDevice.EntryCreateSpec(BootDevice.Type.DISK)] # host1=Host.list() # print (host1) placement = VM.PlacementSpec(host=host, datastore=datastore_name, folder='group-v3') vm_create_spec = VM.CreateSpec(name=self.vm_name, guest_os=guest_os, cpu=cpu, memory=memory, placement=placement, disks=[data_disk], nics=[nic], sata_adapters=[sata_adapt]) print('\n# Example: create_basic_vm: Creating a VM using spec\n-----') print(pp(vm_create_spec)) print('-----') vm = self.client.vcenter.VM.create(vm_create_spec) print("create_basic_vm: Created VM '{}' ({})".format(self.vm_name, vm)) vm_info = self.client.vcenter.VM.get(vm) print('vm.get({}) -> {}'.format(vm, pp(vm_info))) self.client.vcenter.vm.Power.start(vm) return vm