def run(): global vm vm = get_vm(client, vm_name) if not vm: raise Exception('Sample requires an existing vm with name ({}). ' 'Please create the vm first.'.format(vm_name)) print("Using VM '{}' ({}) for Cpu Sample".format(vm_name, vm)) print('\n# Example: Get current Cpu configuration') cpu_info = client.vcenter.vm.hardware.Cpu.get(vm) print('vm.hardware.Cpu.get({}) -> {}'.format(vm, pp(cpu_info))) # Save current Cpu info to verify that we have cleaned up properly global orig_cpu_info orig_cpu_info = cpu_info print('\n# Example: Update cpu field of Cpu configuration') update_spec = Cpu.UpdateSpec(count=2) print('vm.hardware.Cpu.update({}, {})'.format(vm, update_spec)) client.vcenter.vm.hardware.Cpu.update(vm, update_spec) # Get new Cpu configuration cpu_info = client.vcenter.vm.hardware.Cpu.get(vm) print('vm.hardware.Cpu.get({}) -> {}'.format(vm, pp(cpu_info))) print( '\n# Example: Update other less likely used fields of Cpu configuration' ) update_spec = Cpu.UpdateSpec(cores_per_socket=2, hot_add_enabled=True) print('vm.hardware.Cpu.update({}, {})'.format(vm, update_spec)) client.vcenter.vm.hardware.Cpu.update(vm, update_spec) # Get new Cpu configuration cpu_info = client.vcenter.vm.hardware.Cpu.get(vm) print('vm.hardware.Cpu.get({}) -> {}'.format(vm, pp(cpu_info)))
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'] 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) """ Create a default VM. Using the provided PlacementSpec, create a VM with a selected Guest OS and provided name. Use all the guest and system provided defaults. """ guest_os = testbed.config['VM_GUESTOS'] vm_create_spec = VM.CreateSpec(name=self.vm_name, guest_os=guest_os, placement=self.placement_spec) print( '\n# Example: create_default_vm: Creating a VM using spec\n-----') print(pp(vm_create_spec)) print('-----') vm = self.client.vcenter.VM.create(vm_create_spec) print("create_default_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
def create_default_vm(self): """Create default VM using set parameters by set_default_vm_spec.""" if not self.placement_spec: self.placement_spec = vm_placement_helper.get_placement_spec_for_resource_pool( self.vsphere_client, self.d_datacenter_name, self.d_vm_folder_name, self.d_datastore_name) vm_create_spec = self.vsphere_client.vcenter.VM.CreateSpec( name=self.d_vm_name_default, guest_os=self.d_vm_guestos, placement=self.placement_spec) print( '\n# Example: create_default_vm: Creating a VM using spec\n-----') print(pp(vm_create_spec)) print('-----') vm = self.vsphere_client.vcenter.VM.create(vm_create_spec) print("create_default_vm: Created VM '{}' ({})".format( self.d_vm_name_default, vm)) vm_info = self.vsphere_client.vcenter.VM.get(vm) print('vm.get({}) -> {}'.format(vm, pp(vm_info))) return vm
def run(): global vm vm = get_vm(client, vm_name) if not vm: raise Exception('Sample requires an existing vm with name ({}). ' 'Please create the vm first.'.format(vm_name)) print("Using VM '{}' ({}) for SCSI Sample".format(vm_name, vm)) print('\n# Example: List all SCSI adapters for a VM') scsi_summaries = client.vcenter.vm.hardware.adapter.Scsi.list(vm=vm) print('vm.hardware.adapter.Scsi.list({}) -> {}'.format(vm, scsi_summaries)) # Save current list of SCSI adapters to verify that we have cleaned up # properly global orig_scsi_summaries orig_scsi_summaries = scsi_summaries # Get information for each SCSI adapter on the VM for scsi_summary in scsi_summaries: scsi = scsi_summary.adapter scsi_info = client.vcenter.vm.hardware.adapter.Scsi.get(vm=vm, adapter=scsi) print('vm.hardware.adapter.Scsi.get({}, {}) -> {}'.format( vm, scsi, pp(scsi_info))) global scsis_to_delete print('\n# Example: Create SCSI adapter with defaults') scsi_create_spec = Scsi.CreateSpec() scsi = client.vcenter.vm.hardware.adapter.Scsi.create(vm, scsi_create_spec) print('vm.hardware.adapter.Scsi.create({}, {}) -> {}'.format( vm, scsi_create_spec, scsi)) scsis_to_delete.append(scsi) scsi_info = client.vcenter.vm.hardware.adapter.Scsi.get(vm, scsi) print('vm.hardware.adapter.Scsi.get({}, {}) -> {}'.format( vm, scsi, pp(scsi_info))) print('\n# Example: Create SCSI adapter with a specific bus ' 'and sharing=True') scsi_create_spec = Scsi.CreateSpec(bus=2, sharing=Scsi.Sharing.VIRTUAL) scsi = client.vcenter.vm.hardware.adapter.Scsi.create(vm, scsi_create_spec) print('vm.hardware.adapter.Scsi.create({}, {}) -> {}'.format( vm, scsi_create_spec, scsi)) scsis_to_delete.append(scsi) scsi_info = client.vcenter.vm.hardware.adapter.Scsi.get(vm, scsi) print('vm.hardware.adapter.Scsi.get({}, {}) -> {}'.format( vm, scsi, pp(scsi_info))) print('\n# Example: Update SCSI adapter by setting sharing=False') scsi_update_spec = Scsi.UpdateSpec(sharing=Scsi.Sharing.NONE) client.vcenter.vm.hardware.adapter.Scsi.update(vm, scsi, scsi_update_spec) print('vm.hardware.adapter.Scsi.update({}, {}, {})'.format( vm, scsi, scsi_create_spec)) scsi_info = client.vcenter.vm.hardware.adapter.Scsi.get(vm, scsi) print('vm.hardware.adapter.Scsi.get({}, {}) -> {}'.format( vm, scsi, pp(scsi_info))) # List all SCSI adapters for a VM scsi_summaries = client.vcenter.vm.hardware.adapter.Scsi.list(vm=vm) print('vm.hardware.adapter.Scsi.list({}) -> {}'.format(vm, scsi_summaries))
def run(): global vm vm = get_vm(client, vm_name) if not vm: raise Exception('Sample requires an existing vm with name ({}). ' 'Please create the vm first.'.format(vm_name)) print("Using VM '{}' ({}) for Memory Sample".format(vm_name, vm)) print('\n# Example: Get current Memory configuration') memory_info = client.vcenter.vm.hardware.Memory.get(vm) print('vm.hardware.Memory.get({}) -> {}'.format(vm, pp(memory_info))) # Save current Memory info to verify that we have cleaned up properly global orig_memory_info orig_memory_info = memory_info print('\n# Example: Update memory size_mib field of Memory configuration') update_spec = Memory.UpdateSpec(size_mib=8 * 1024) print('vm.hardware.Memory.update({}, {})'.format(vm, update_spec)) client.vcenter.vm.hardware.Memory.update(vm, update_spec) # Get new Memory configuration memory_info = client.vcenter.vm.hardware.Memory.get(vm) print('vm.hardware.Memory.get({}) -> {}'.format(vm, pp(memory_info))) print('\n# Example: Update hot_add_enabled field of Memory configuration') update_spec = Memory.UpdateSpec(hot_add_enabled=True) print('vm.hardware.Memory.update({}, {})'.format(vm, update_spec)) client.vcenter.vm.hardware.Memory.update(vm, update_spec) # Get new Memory configuration memory_info = client.vcenter.vm.hardware.Memory.get(vm) print('vm.hardware.Memory.get({}) -> {}'.format(vm, pp(memory_info)))
def run(self): # find the given VM self.vm = get_vm(self.vsphere_client, self.vm_name) if not self.vm: raise Exception('Sample requires an existing vm with name ({}).' 'Please create the vm first.'.format(self.vm_name)) print("Using VM '{}' ({}) for Guest Info Sample".format( self.vm_name, self.vm)) # power on the VM if necessary status = self.vsphere_client.vcenter.vm.Power.get(self.vm) if status != HardPower.Info(state=HardPower.State.POWERED_ON): print('Powering on VM.') self.vsphere_client.vcenter.vm.Power.start(self.vm) # wait for guest info to be ready wait_for_guest_info_ready(self.vsphere_client, self.vm, 600) # get the Identity identity = self.vsphere_client.vcenter.vm.guest.Identity.get(self.vm) print('vm.guest.Identity.get({})'.format(self.vm)) print('Identity: {}'.format(pp(identity))) # get the local filesystem info local_filesysteem = \ self.vsphere_client.vcenter.vm.guest.LocalFilesystem.get(self.vm) print('vm.guest.LocalFilesystem.get({})'.format(self.vm)) print('LocalFilesystem: {}'.format(pp(local_filesysteem)))
def run(): global vm vm = get_vm(stub_config, vm_name) if not vm: raise Exception('Sample requires an existing vm with name ({}). ' 'Please create the vm first.'.format(vm_name)) print("Using VM '{}' ({}) for SATA Sample".format(vm_name, vm)) # Create SATA adapter stub used for making requests global sata_svc sata_svc = Sata(stub_config) print('\n# Example: List all SATA adapters for a VM') sata_summaries = sata_svc.list(vm=vm) print('vm.hardware.adapter.Sata.list({}) -> {}'.format(vm, sata_summaries)) # Save current list of SATA adapters to verify that we have cleaned up # properly global orig_sata_summaries orig_sata_summaries = sata_summaries # Get information for each SATA adapter on the VM for sata_summary in sata_summaries: sata = sata_summary.adapter sata_info = sata_svc.get(vm=vm, adapter=sata) print('vm.hardware.adapter.Sata.get({}, {}) -> {}'.format( vm, sata, pp(sata_info))) global satas_to_delete print('\n# Example: Create SATA adapter with defaults') sata_create_spec = Sata.CreateSpec() sata = sata_svc.create(vm, sata_create_spec) print('vm.hardware.adapter.Sata.create({}, {}) -> {}'.format( vm, sata_create_spec, sata)) satas_to_delete.append(sata) sata_info = sata_svc.get(vm, sata) print('vm.hardware.adapter.Sata.get({}, {}) -> {}'.format( vm, sata, pp(sata_info))) print('\n# Example: Create SATA adapter with a specific bus') sata_create_spec = Sata.CreateSpec(bus=2) sata = sata_svc.create(vm, sata_create_spec) print('vm.hardware.adapter.Sata.create({}, {}) -> {}'.format( vm, sata_create_spec, sata)) satas_to_delete.append(sata) sata_info = sata_svc.get(vm, sata) print('vm.hardware.adapter.Sata.get({}, {}) -> {}'.format( vm, sata, pp(sata_info))) # List all SATA adapters for a VM sata_summaries = sata_svc.list(vm=vm) print('vm.hardware.adapter.Sata.list({}) -> {}'.format(vm, sata_summaries))
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 run(): global vm vm = get_vm(stub_config, vm_name) if not vm: raise Exception('Sample requires an existing vm with name ({}). ' 'Please create the vm first.'.format(vm_name)) print("Using VM '{}' ({}) for BootDevice Sample".format(vm_name, vm)) # Create BootDevice stub used for making requests global boot_device_svc boot_device_svc = BootDevice(stub_config) print('\n# Example: Get current BootDevice configuration') boot_device_entries = boot_device_svc.get(vm) print('vm.hardware.boot.Device.get({}) -> {}'.format( vm, pp(boot_device_entries))) # Save current BootDevice info to verify that we have cleaned up properly global orig_boot_device_entries orig_boot_device_entries = boot_device_entries # Get device identifiers for Disks disk_svc = Disk(stub_config) disk_summaries = disk_svc.list(vm) print('vm.hardware.Disk.list({}) -> {}'.format(vm, pp(disk_summaries))) disks = [disk_summary.disk for disk_summary in disk_summaries] # Get device identifiers for Ethernet nics ethernet_svc = Ethernet(stub_config) nic_summaries = ethernet_svc.list(vm) print('vm.hardware.Ethernet.list({}) -> {}'.format(vm, pp(nic_summaries))) nics = [nic_summary.nic for nic_summary in nic_summaries] print('\n# Example: Set Boot Order to be Floppy, ' 'Disk1, Disk2, Disk3, Cdrom,') print('# Network (nic0), Network (nic1).') boot_device_entries = [ BootDevice.Entry(BootDevice.Type.FLOPPY), BootDevice.Entry(BootDevice.Type.DISK, disks=disks), BootDevice.Entry(BootDevice.Type.CDROM) ] for nic in nics: boot_device_entries.append( BootDevice.Entry(BootDevice.Type.ETHERNET, nic=nic)) print('vm.hardware.boot.Device.set({}, {})'.format(vm, boot_device_entries)) boot_device_svc.set(vm, boot_device_entries) boot_device_entries = boot_device_svc.get(vm) print('vm.hardware.boot.Device.get({}) -> {}'.format( vm, pp(boot_device_entries)))
def cleanup(): # Clean up the saved disk from the update sample vmdk_file = saved_disk_info.backing.vmdk_file print("\n# Cleanup: Delete VMDK '{}'".format(vmdk_file)) delete_vmdk(service_instance, datacenter_mo, vmdk_file) # 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)) print('\n# Cleanup: Delete VM Disks that were added') for disk in disks_to_delete: disk_info = client.vcenter.vm.hardware.Disk.get(vm, disk) print('vm.hardware.Disk.get({}, {}) -> {}'.format( vm, disk, pp(disk_info))) vmdk_file = disk_info.backing.vmdk_file client.vcenter.vm.hardware.Disk.delete(vm, disk) print('vm.hardware.Disk.delete({}, {})'.format(vm, disk)) print("\n# Cleanup: Delete VMDK '{}'".format(vmdk_file)) delete_vmdk(service_instance, datacenter_mo, vmdk_file) print('\n# Cleanup: Remove SATA controller') print('vm.hardware.adapter.Sata.delete({}, {})'.format(vm, sata)) client.vcenter.vm.hardware.adapter.Sata.delete(vm, sata) disk_summaries = client.vcenter.vm.hardware.Disk.list(vm) print('vm.hardware.Disk.list({}) -> {}'.format(vm, disk_summaries)) if set(orig_disk_summaries) != set(disk_summaries): print( 'vm.hardware.Disk WARNING: Final Disk info does not match original' )
def run(): global vm vm = get_vm(stub_config, vm_name) if not vm: raise Exception('Sample requires an existing vm with name ({}). ' 'Please create the vm first.'.format(vm_name)) print("Using VM '{}' ({}) for Boot Sample".format(vm_name, vm)) # Create Boot stub used for making requests global boot_svc boot_svc = Boot(stub_config) print('\n# Example: Get current Boot configuration') boot_info = boot_svc.get(vm) print('vm.hardware.Boot.get({}) -> {}'.format(vm, pp(boot_info))) # Save current Boot info to verify that we have cleaned up properly global orig_boot_info orig_boot_info = boot_info print('\n# Example: Update firmware to EFI for Boot configuration') update_spec = Boot.UpdateSpec(type=Boot.Type.EFI) print('vm.hardware.Boot.update({}, {})'.format(vm, update_spec)) boot_svc.update(vm, update_spec) boot_info = boot_svc.get(vm) print('vm.hardware.Boot.get({}) -> {}'.format(vm, pp(boot_info))) print('\n# Example: Update boot firmware to tell it to enter setup mode on ' 'next boot') update_spec = Boot.UpdateSpec(enter_setup_mode=True) print('vm.hardware.Boot.update({}, {})'.format(vm, update_spec)) boot_svc.update(vm, update_spec) boot_info = boot_svc.get(vm) print('vm.hardware.Boot.get({}) -> {}'.format(vm, pp(boot_info))) print('\n# Example: Update boot firmware to introduce a delay in boot' ' process and to reboot') print('# automatically after a failure to boot. ' '(delay=10000 ms, retry=True,') print('# retry_delay=30000 ms') update_spec = Boot.UpdateSpec(delay=10000, retry=True, retry_delay=30000) print('vm.hardware.Boot.update({}, {})'.format(vm, update_spec)) boot_svc.update(vm, update_spec) boot_info = boot_svc.get(vm) print('vm.hardware.Boot.get({}) -> {}'.format(vm, pp(boot_info)))
def create_default_vm(stub_config, placement_spec): """ Create a default VM. Using the provided PlacementSpec, create a VM with a selected Guest OS and provided name. Use all the guest and system provided defaults. """ guest_os = testbed.config['VM_GUESTOS'] vm_create_spec = VM.CreateSpec(name=vm_name, guest_os=guest_os, placement=placement_spec) print('\n# Example: create_default_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_default_vm: Created VM '{}' ({})".format(vm_name, vm)) vm_info = vm_svc.get(vm) print('vm.get({}) -> {}'.format(vm, pp(vm_info))) return vm
def cleanup(): print('\n# Cleanup: Revert BootDevice configuration') boot_device_entries = orig_boot_device_entries print('vm.hardware.boot.Device.set({}, {})'.format(vm, boot_device_entries)) boot_device_svc.set(vm, boot_device_entries) boot_device_entries = boot_device_svc.get(vm) print('vm.hardware.boot.Device.get({}) -> {}'.format( vm, pp(boot_device_entries))) if boot_device_entries != orig_boot_device_entries: print('vm.hardware.boot.Device WARNING: ' 'Final BootDevice info does not match original')
def cleanup(): print('\n# Cleanup: Revert Memory configuration') update_spec = Memory.UpdateSpec(size_mib=orig_memory_info.size_mib, hot_add_enabled=orig_memory_info. hot_add_enabled) print('vm.hardware.Memory.update({}, {})'.format(vm, update_spec)) client.vcenter.vm.hardware.Memory.update(vm, update_spec) # Get final Memory configuration memory_info = client.vcenter.vm.hardware.Memory.get(vm) print('vm.hardware.Memory.get({}) -> {}'.format(vm, pp(memory_info))) if memory_info != orig_memory_info: print('vm.hardware.Memory WARNING: ' 'Final Memory info does not match original')
def setup(self, context): print('Setup Samples Started') self.context = context ########################################################################### # Getting a PlacementSpec ########################################################################### placement_spec = samples.vsphere.vcenter.vm.placement.get_placement_spec_for_resource_pool(context) print('=' * 79) print('= Resource selection') print('=' * 79) print('placement_spec={}'.format(pp(placement_spec))) ########################################################################### # Getting a Network # Choose one of the following ways to get the PlacementSpec # 1. STANDARD_PORTGROUP on DATACENTER2 # 2. DISTRIBUTED_PORTGROUP on DATACENTER2 ########################################################################### standard_network = samples.vsphere.vcenter.helper \ .network_helper.get_network_backing( context.client, context.testbed.config['STDPORTGROUP_NAME'], context.testbed.config['VM_DATACENTER_NAME'], Network.Type.STANDARD_PORTGROUP) print('standard_network={}'.format(standard_network)) distributed_network = samples.vsphere.vcenter.helper \ .network_helper.get_network_backing( context.client, context.testbed.config['VDPORTGROUP1_NAME'], context.testbed.config['VM_DATACENTER_NAME'], Network.Type.DISTRIBUTED_PORTGROUP) print('distributed_network={}'.format(distributed_network)) print('=' * 79) self.default_vm = CreateDefaultVM(context.client, placement_spec) self.basic_vm = CreateBasicVM(context.client, placement_spec) self.exhaustive_vm = CreateExhaustiveVM(context.client, placement_spec, standard_network, distributed_network) print('Setup Samples Complete')
def cleanup(): print('\n# Cleanup: Revert Cpu configuration') update_spec = \ Cpu.UpdateSpec(count=orig_cpu_info.count, cores_per_socket=orig_cpu_info.cores_per_socket, hot_add_enabled=orig_cpu_info.hot_add_enabled, hot_remove_enabled=orig_cpu_info.hot_remove_enabled) print('vm.hardware.Cpu.update({}, {})'.format(vm, update_spec)) client.vcenter.vm.hardware.Cpu.update(vm, update_spec) # Get final Cpu configuration cpu_info = client.vcenter.vm.hardware.Cpu.get(vm) print('vm.hardware.Cpu.get({}) -> {}'.format(vm, pp(cpu_info))) if cpu_info != orig_cpu_info: print( 'vm.hardware.Cpu WARNING: Final Cpu info does not match original')
def cleanup(): print('\n# Cleanup: Revert Boot configuration') update_spec = \ Boot.UpdateSpec(type=orig_boot_info.type, efi_legacy_boot=orig_boot_info.efi_legacy_boot, network_protocol=orig_boot_info.network_protocol, delay=orig_boot_info.delay, retry=orig_boot_info.retry, retry_delay=orig_boot_info.retry_delay, enter_setup_mode=orig_boot_info.enter_setup_mode) print('vm.hardware.Boot.update({}, {})'.format(vm, update_spec)) client.vcenter.vm.hardware.Boot.update(vm, update_spec) boot_info = client.vcenter.vm.hardware.Boot.get(vm) print('vm.hardware.Boot.get({}) -> {}'.format(vm, pp(boot_info))) if boot_info != orig_boot_info: print('vm.hardware.Boot WARNING: ' 'Final Boot info does not match original')
def run(): global vm vm = get_vm(stub_config, vm_name) if not vm: raise Exception('Sample requires an existing vm with name ({}).' 'Please create the vm first.'.format(vm_name)) print("Using VM '{}' ({}) for Power Sample".format(vm_name, vm)) # Create Power stub used for making requests global vm_power_svc vm_power_svc = Power(stub_config) # Get the vm power state print('\n# Example: Get current vm power state') status = vm_power_svc.get(vm) print('vm.Power.get({}) -> {}'.format(vm, pp(status))) # Power off the vm if it is on if status == Power.Info(state=Power.State.POWERED_ON): print('\n# Example: VM is powered on, power it off') vm_power_svc.stop(vm) print('vm.Power.stop({})'.format(vm)) # Power on the vm print('# Example: Power on the vm') vm_power_svc.start(vm) print('vm.Power.start({})'.format(vm)) # Suspend the vm print('\n# Example: Suspend the vm') vm_power_svc.suspend(vm) print('vm.Power.suspend({})'.format(vm)) # Resume the vm print('\n# Example: Resume the vm') vm_power_svc.start(vm) print('vm.Power.start({})'.format(vm)) # Reset the vm print('\n# Example: Reset the vm') vm_power_svc.reset(vm) print('vm.Power.reset({})'.format(vm))
def run(context): # Clean up in case of past failures cleanup(context) # Check that sample is ready to run if context.option['DO_SAMPLES']: if not validate(context): exit(0) ########################################################################### # Getting a PlacementSpec ########################################################################### placement_spec = samples.vsphere.vcenter.vm.placement \ .get_placement_spec_for_resource_pool(context) print('=' * 79) print('= Resource selection') print('=' * 79) print('placement_spec={}'.format(pp(placement_spec))) ########################################################################### # Getting a Network # Choose one of the following ways to get the PlacementSpec # 1. STANDARD_PORTGROUP on DATACENTER2 # 2. DISTRIBUTED_PORTGROUP on DATACENTER2 ########################################################################### standard_network = samples.vsphere.vcenter.helper \ .network_helper.get_standard_network_backing( context.stub_config, context.testbed.config['STDPORTGROUP_NAME'], context.testbed.config['VM_DATACENTER_NAME']) print('standard_network={}'.format(standard_network)) distributed_network = samples.vsphere.vcenter.helper \ .network_helper.get_distributed_network_backing( context.stub_config, context.testbed.config['VDPORTGROUP1_NAME'], context.testbed.config['VM_DATACENTER_NAME']) print('distributed_network={}'.format(distributed_network)) print('=' * 79) ########################################################################### # Create VM samples # # Choose one of the following ways to create the VM # 1. Default # 2. Basic (2 disks, 1 nic) # 3. Exhaustive (3 disks, 2 nics, 2 vcpu, 2 GB memory, boot=BIOS, 1 cdrom, # 1 serial port, 1 parallel port, 1 floppy, # boot_devices= [CDROM, DISK, ETHERNET]) ########################################################################### create_default_vm.create_default_vm(context.stub_config, placement_spec) create_basic_vm.create_basic_vm(context.stub_config, placement_spec, standard_network) create_exhaustive_vm.create_exhaustive_vm(context.stub_config, placement_spec, standard_network, distributed_network) ########################################################################### # Power operation samples # # Runs through the power lifecycle for the VM: start, suspend, # resume (start), stop # ########################################################################### samples.vsphere.vcenter.vm.power.setup(context) samples.vsphere.vcenter.vm.power.run() samples.vsphere.vcenter.vm.power.cleanup() ########################################################################### # Incremental device CRUDE + connect/disconnect samples # ########################################################################### if context.option['DO_SAMPLES_INCREMENTAL']: samples.vsphere.vcenter.vm.hardware.main.setup(context) samples.vsphere.vcenter.vm.hardware.main.validate(context) samples.vsphere.vcenter.vm.hardware.main.run() if context.option['DO_SAMPLES_CLEANUP']: samples.vsphere.vcenter.vm.hardware.main.cleanup() # Sample cleanup if context.option['DO_SAMPLES_CLEANUP']: cleanup(context)
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
def run(): global vm vm = get_vm(client, vm_name) if not vm: raise Exception('Sample requires an existing vm with name ({}). ' 'Please create the vm first.'.format(vm_name)) print("Using VM '{}' ({}) for CD-ROM Sample".format(vm_name, vm)) iso_datastore_path = testbed.config['ISO_DATASTORE_PATH'] # Create SATA controller print('\n# Setup: Create a SATA controller') sata_create_spec = Sata.CreateSpec() print('# Adding SATA controller for SATA Disk samples') 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: List all Cdroms for a VM') cdrom_summaries = client.vcenter.vm.hardware.Cdrom.list(vm=vm) print('vm.hardware.Cdrom.list({}) -> {}'.format(vm, cdrom_summaries)) # Save current list of Cdroms to verify that we have cleaned up properly global orig_cdrom_summaries orig_cdrom_summaries = cdrom_summaries # Get information for each CD-ROM on the VM for cdrom_summary in cdrom_summaries: cdrom = cdrom_summary.cdrom cdrom_info = client.vcenter.vm.hardware.Cdrom.get(vm=vm, cdrom=cdrom) print('vm.hardware.Cdrom.get({}, {}) -> {}'.format( vm, cdrom, pp(cdrom_info))) global cdroms_to_delete print('\n# Example: Create CD-ROM with ISO_FILE backing') cdrom_create_spec = Cdrom.CreateSpec(start_connected=True, backing=Cdrom.BackingSpec( type=Cdrom.BackingType.ISO_FILE, iso_file=iso_datastore_path)) cdrom = client.vcenter.vm.hardware.Cdrom.create(vm, cdrom_create_spec) cdroms_to_delete.append(cdrom) cdrom_info = client.vcenter.vm.hardware.Cdrom.get(vm, cdrom) print('vm.hardware.Cdrom.get({}, {}) -> {}'.format(vm, cdrom, pp(cdrom_info))) print('\n# Example: Create CD-ROM with CLIENT_DEVICE backing') cdrom_create_spec = Cdrom.CreateSpec(backing=Cdrom.BackingSpec( type=Cdrom.BackingType.CLIENT_DEVICE)) cdrom = client.vcenter.vm.hardware.Cdrom.create(vm, cdrom_create_spec) print('vm.hardware.Cdrom.create({}, {}) -> {}'.format( vm, cdrom_create_spec, cdrom)) cdroms_to_delete.append(cdrom) cdrom_info = client.vcenter.vm.hardware.Cdrom.get(vm, cdrom) print('vm.hardware.Cdrom.get({}, {}) -> {}'.format(vm, cdrom, pp(cdrom_info))) print('\n# Example: Create CD-ROM using auto-detect HOST_DEVICE backing') cdrom_create_spec = Cdrom.CreateSpec(backing=Cdrom.BackingSpec( type=Cdrom.BackingType.HOST_DEVICE)) cdrom = client.vcenter.vm.hardware.Cdrom.create(vm, cdrom_create_spec) print('vm.hardware.Cdrom.create({}, {}) -> {}'.format( vm, cdrom_create_spec, cdrom)) cdroms_to_delete.append(cdrom) cdrom_info = client.vcenter.vm.hardware.Cdrom.get(vm, cdrom) print('vm.hardware.Cdrom.get({}, {}) -> {}'.format(vm, cdrom, pp(cdrom_info))) print('\n# Example: Create SATA CD-ROM using CLIENT_DEVICE backing') cdrom_create_spec = Cdrom.CreateSpec( type=Cdrom.HostBusAdapterType.SATA, backing=Cdrom.BackingSpec(type=Cdrom.BackingType.CLIENT_DEVICE)) cdrom = client.vcenter.vm.hardware.Cdrom.create(vm, cdrom_create_spec) print('vm.hardware.Cdrom.create({}, {}) -> {}'.format( vm, cdrom_create_spec, cdrom)) cdroms_to_delete.append(cdrom) cdrom_info = client.vcenter.vm.hardware.Cdrom.get(vm, cdrom) print('vm.hardware.Cdrom.get({}, {}) -> {}'.format(vm, cdrom, pp(cdrom_info))) print('\n# Example: Create SATA CD-ROM on specific bus using ' 'CLIENT_DEVICE backing') cdrom_create_spec = Cdrom.CreateSpec( type=Cdrom.HostBusAdapterType.SATA, sata=SataAddressSpec(bus=0), backing=Cdrom.BackingSpec(type=Cdrom.BackingType.CLIENT_DEVICE)) cdrom = client.vcenter.vm.hardware.Cdrom.create(vm, cdrom_create_spec) print('vm.hardware.Cdrom.create({}, {}) -> {}'.format( vm, cdrom_create_spec, cdrom)) cdroms_to_delete.append(cdrom) cdrom_info = client.vcenter.vm.hardware.Cdrom.get(vm, cdrom) print('vm.hardware.Cdrom.get({}, {}) -> {}'.format(vm, cdrom, pp(cdrom_info))) print('\n# Example: Create SATA CD-ROM on specific bus and unit using ' 'CLIENT_DEVICE backing') cdrom_create_spec = Cdrom.CreateSpec( type=Cdrom.HostBusAdapterType.SATA, sata=SataAddressSpec(bus=0, unit=10), backing=Cdrom.BackingSpec(type=Cdrom.BackingType.CLIENT_DEVICE)) cdrom = client.vcenter.vm.hardware.Cdrom.create(vm, cdrom_create_spec) print('vm.hardware.Cdrom.create({}, {}) -> {}'.format( vm, cdrom_create_spec, cdrom)) cdroms_to_delete.append(cdrom) cdrom_info = client.vcenter.vm.hardware.Cdrom.get(vm, cdrom) print('vm.hardware.Cdrom.get({}, {}) -> {}'.format(vm, cdrom, pp(cdrom_info))) print('\n# Example: Create IDE CD-ROM using CLIENT_DEVICE backing') cdrom_create_spec = Cdrom.CreateSpec( type=Cdrom.HostBusAdapterType.IDE, backing=Cdrom.BackingSpec(type=Cdrom.BackingType.CLIENT_DEVICE)) cdrom = client.vcenter.vm.hardware.Cdrom.create(vm, cdrom_create_spec) print('vm.hardware.Cdrom.create({}, {}) -> {}'.format( vm, cdrom_create_spec, cdrom)) cdroms_to_delete.append(cdrom) cdrom_info = client.vcenter.vm.hardware.Cdrom.get(vm, cdrom) print('vm.hardware.Cdrom.get({}, {}) -> {}'.format(vm, cdrom, pp(cdrom_info))) print('\n# Example: Create IDE CD-ROM on specific bus and unit using ' 'CLIENT_DEVICE backing') cdrom_create_spec = Cdrom.CreateSpec( type=Cdrom.HostBusAdapterType.IDE, ide=IdeAddressSpec(False, True), backing=Cdrom.BackingSpec(type=Cdrom.BackingType.CLIENT_DEVICE)) cdrom = client.vcenter.vm.hardware.Cdrom.create(vm, cdrom_create_spec) print('vm.hardware.Cdrom.create({}, {}) -> {}'.format( vm, cdrom_create_spec, cdrom)) cdroms_to_delete.append(cdrom) cdrom_info = client.vcenter.vm.hardware.Cdrom.get(vm, cdrom) print('vm.hardware.Cdrom.get({}, {}) -> {}'.format(vm, cdrom, pp(cdrom_info))) # Change the last cdrom that was created print('\n# Example: Update backing from CLIENT_DEVICE to ISO_FILE') cdrom_update_spec = Cdrom.UpdateSpec(backing=Cdrom.BackingSpec( type=Cdrom.BackingType.ISO_FILE, iso_file=iso_datastore_path)) print('vm.hardware.Cdrom.update({}, {}, {})'.format( vm, cdrom, cdrom_update_spec)) client.vcenter.vm.hardware.Cdrom.update(vm, cdrom, cdrom_update_spec) cdrom_info = client.vcenter.vm.hardware.Cdrom.get(vm, cdrom) print('vm.hardware.Cdrom.get({}, {}) -> {}'.format(vm, cdrom, pp(cdrom_info))) print('\n# Example: Update start_connected=False, ' 'allow_guest_control=False') cdrom_update_spec = Cdrom.UpdateSpec(start_connected=False, allow_guest_control=False) print('vm.hardware.Cdrom.update({}, {}, {})'.format( vm, cdrom, cdrom_update_spec)) client.vcenter.vm.hardware.Cdrom.update(vm, cdrom, cdrom_update_spec) cdrom_info = client.vcenter.vm.hardware.Cdrom.get(vm, cdrom) print('vm.hardware.Cdrom.get({}, {}) -> {}'.format(vm, cdrom, pp(cdrom_info))) print('\n# Starting VM to run connect/disconnect sample') print('vm.Power.start({})'.format(vm)) client.vcenter.vm.Power.start(vm) cdrom_info = client.vcenter.vm.hardware.Cdrom.get(vm, cdrom) print('vm.hardware.Cdrom.get({}, {}) -> {}'.format(vm, cdrom, pp(cdrom_info))) print('\n# Example: Connect CD-ROM after powering on VM') client.vcenter.vm.hardware.Cdrom.connect(vm, cdrom) print('vm.hardware.Cdrom.connect({}, {})'.format(vm, cdrom)) cdrom_info = client.vcenter.vm.hardware.Cdrom.get(vm, cdrom) print('vm.hardware.Cdrom.get({}, {}) -> {}'.format(vm, cdrom, pp(cdrom_info))) print('\n# Example: Disconnect CD-ROM while VM is powered on') client.vcenter.vm.hardware.Cdrom.disconnect(vm, cdrom) print('vm.hardware.Cdrom.disconnect({}, {})'.format(vm, cdrom)) cdrom_info = client.vcenter.vm.hardware.Cdrom.get(vm, cdrom) print('vm.hardware.Cdrom.get({}, {}) -> {}'.format(vm, cdrom, pp(cdrom_info))) print('\n# Stopping VM after connect/disconnect sample') print('vm.Power.start({})'.format(vm)) client.vcenter.vm.Power.stop(vm) cdrom_info = client.vcenter.vm.hardware.Cdrom.get(vm, cdrom) print('vm.hardware.Cdrom.get({}, {}) -> {}'.format(vm, cdrom, pp(cdrom_info))) # List all Cdroms for a VM cdrom_summaries = client.vcenter.vm.hardware.Cdrom.list(vm=vm) print('vm.hardware.Cdrom.list({}) -> {}'.format(vm, cdrom_summaries))
def run(): global vm, client vm = get_vm(client, vm_name) if not vm: raise Exception('Sample requires an existing vm with name ({}). ' 'Please create the vm first.'.format(vm_name)) print("Using VM '{}' ({}) for Parallel Sample".format(vm_name, vm)) print('\n# Example: List all Parallel ports for a VM') parallel_summaries = client.vcenter.vm.hardware.Parallel.list(vm=vm) print('vm.hardware.Parallel.list({}) -> {}'.format(vm, parallel_summaries)) # Save current list of Parallel ports to verify that we have cleaned up # properly global orig_parallel_summaries orig_parallel_summaries = parallel_summaries # Get information for each Parallel port on the VM for parallel_summary in parallel_summaries: parallel = parallel_summary.port parallel_info = client.vcenter.vm.hardware.Parallel.get(vm=vm, port=parallel) print('vm.hardware.Parallel.get({}, {}) -> {}'.format( vm, parallel, pp(parallel_info))) # Make sure output file doesn't exist already cleanup_backends() print('\n# Example: Create Parallel port with defaults') parallel_create_spec = Parallel.CreateSpec() parallel = client.vcenter.vm.hardware.Parallel.create( vm, parallel_create_spec) print('vm.hardware.Parallel.create({}, {}) -> {}'.format( vm, parallel_create_spec, parallel)) global parallels_to_delete parallels_to_delete.append(parallel) parallel_info = client.vcenter.vm.hardware.Parallel.get(vm, parallel) print('vm.hardware.Parallel.get({}, {}) -> {}'.format( vm, parallel, pp(parallel_info))) print('\n# Example: Create Parallel port with FILE backing') parallel_port_datastore_path = testbed.config[ 'PARALLEL_PORT_DATASTORE_PATH'] parallel_create_spec = Parallel.CreateSpec( start_connected=True, allow_guest_control=True, backing=Parallel.BackingSpec(type=Parallel.BackingType.FILE, file=parallel_port_datastore_path)) parallel = client.vcenter.vm.hardware.Parallel.create( vm, parallel_create_spec) print('vm.hardware.Parallel.create({}, {}) -> {}'.format( vm, parallel_create_spec, parallel)) parallels_to_delete.append(parallel) parallel_info = client.vcenter.vm.hardware.Parallel.get(vm, parallel) print('vm.hardware.Parallel.get({}, {}) -> {}'.format( vm, parallel, pp(parallel_info))) print('\n# Example: Update Parallel port with same file but ' 'start_connected=False') print('# and allow_guest_control=False') parallel_port_datastore_path = testbed.config[ 'PARALLEL_PORT_DATASTORE_PATH'] parallel_update_spec = Parallel.UpdateSpec( start_connected=False, allow_guest_control=False, backing=Parallel.BackingSpec(type=Parallel.BackingType.FILE, file=parallel_port_datastore_path)) client.vcenter.vm.hardware.Parallel.update(vm, parallel, parallel_update_spec) print('vm.hardware.Parallel.update({}, {}) -> {}'.format( vm, parallel_update_spec, parallel)) parallel_info = client.vcenter.vm.hardware.Parallel.get(vm, parallel) print('vm.hardware.Parallel.get({}, {}) -> {}'.format( vm, parallel, pp(parallel_info))) print('\n# Starting VM to run connect/disconnect sample') print('vm.Power.start({})'.format(vm)) client.vcenter.vm.Power.start(vm) parallel_info = client.vcenter.vm.hardware.Parallel.get(vm, parallel) print('vm.hardware.Parallel.get({}, {}) -> {}'.format( vm, parallel, pp(parallel_info))) print('\n# Example: Connect Parallel port after powering on VM') client.vcenter.vm.hardware.Parallel.connect(vm, parallel) print('vm.hardware.Parallel.connect({}, {})'.format(vm, parallel)) parallel_info = client.vcenter.vm.hardware.Parallel.get(vm, parallel) print('vm.hardware.Parallel.get({}, {}) -> {}'.format( vm, parallel, pp(parallel_info))) print('\n# Example: Disconnect Parallel port while VM is powered on') client.vcenter.vm.hardware.Parallel.disconnect(vm, parallel) print('vm.hardware.Parallel.disconnect({}, {})'.format(vm, parallel)) parallel_info = client.vcenter.vm.hardware.Parallel.get(vm, parallel) print('vm.hardware.Parallel.get({}, {}) -> {}'.format( vm, parallel, pp(parallel_info))) print('\n# Stopping VM after connect/disconnect sample') print('vm.Power.start({})'.format(vm)) client.vcenter.vm.Power.stop(vm) parallel_info = client.vcenter.vm.hardware.Parallel.get(vm, parallel) print('vm.hardware.Parallel.get({}, {}) -> {}'.format( vm, parallel, pp(parallel_info))) # List all Parallel ports for a VM parallel_summaries = client.vcenter.vm.hardware.Parallel.list(vm=vm) print('vm.hardware.Parallel.list({}) -> {}'.format(vm, parallel_summaries)) # Always cleanup output file so the VM can be powered on next time cleanup_backends()
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
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(): global vm vm = get_vm(client, vm_name) if not vm: raise Exception('Sample requires an existing vm with name ({}). ' 'Please create the vm first.'.format(vm_name)) print("Using VM '{}' ({}) for Disk Sample".format(vm_name, vm)) # Get standard portgroup to use as backing for sample standard_network = network_helper.get_network_backing( client, testbed.config['STDPORTGROUP_NAME'], testbed.config['VM_DATACENTER_NAME'], Network.Type.STANDARD_PORTGROUP) # Get distributed portgroup to use as backing for sample distributed_network = network_helper.get_network_backing( client, testbed.config['VDPORTGROUP1_NAME'], testbed.config['VM_DATACENTER_NAME'], Network.Type.DISTRIBUTED_PORTGROUP) # Get opaque portgroup to use as backing for sample opaque_network = None if testbed.config['OPAQUEPORTGROUP1_NAME']: opaque_network = network_helper.get_network_backing( client, testbed.config['OPAQUEPORTGROUP1_NAME'], testbed.config['VM_DATACENTER_NAME'], Network.Type.OPAQUE_NETWORK) print('\n# Example: List all Ethernet adapters for a VM') nic_summaries = client.vcenter.vm.hardware.Ethernet.list(vm=vm) print('vm.hardware.Ethernet.list({}) -> {}'.format(vm, nic_summaries)) # Save current list of Ethernet adapters to verify that we have cleaned # up properly global orig_nic_summaries orig_nic_summaries = nic_summaries # Get information for each Ethernet on the VM for nic_summary in nic_summaries: nic = nic_summary.nic nic_info = client.vcenter.vm.hardware.Ethernet.get(vm=vm, nic=nic) print('vm.hardware.Ethernet.get({}, {}) -> {}'.format( vm, nic, nic_info)) global nics_to_delete print('\n# Example: Create Ethernet Nic using STANDARD_PORTGROUP with ' 'default settings') nic_create_spec = Ethernet.CreateSpec(backing=Ethernet.BackingSpec( type=Ethernet.BackingType.STANDARD_PORTGROUP, network=standard_network)) nic = client.vcenter.vm.hardware.Ethernet.create(vm, nic_create_spec) print('vm.hardware.Ethernet.create({}, {}) -> {}'.format( vm, nic_create_spec, nic)) nics_to_delete.append(nic) nic_info = client.vcenter.vm.hardware.Ethernet.get(vm, nic) print('vm.hardware.Ethernet.get({}, {}) -> {}'.format( vm, nic, pp(nic_info))) print('\n# Example: Create Ethernet Nic using DISTRIBUTED_PORTGROUP ' 'with defaults') nic_create_spec = Ethernet.CreateSpec(backing=Ethernet.BackingSpec( type=Ethernet.BackingType.DISTRIBUTED_PORTGROUP, network=distributed_network)) nic = client.vcenter.vm.hardware.Ethernet.create(vm, nic_create_spec) print('vm.hardware.Ethernet.create({}, {}) -> {}'.format( vm, nic_create_spec, nic)) nics_to_delete.append(nic) nic_info = client.vcenter.vm.hardware.Ethernet.get(vm, nic) print('vm.hardware.Ethernet.get({}, {}) -> {}'.format( vm, nic, pp(nic_info))) print('\n# Example: Create Ethernet Nic using STANDARD_' 'PORTGROUP specifying') print('# start_connected=True, allow_guest_control=True,') print('# mac_type, mac_Address, wake_on_lan_enabled') nic_create_spec = Ethernet.CreateSpec( start_connected=True, allow_guest_control=True, mac_type=Ethernet.MacAddressType.MANUAL, mac_address='01:23:45:67:89:10', wake_on_lan_enabled=True, backing=Ethernet.BackingSpec( type=Ethernet.BackingType.STANDARD_PORTGROUP, network=standard_network)) nic = client.vcenter.vm.hardware.Ethernet.create(vm, nic_create_spec) print('vm.hardware.Ethernet.create({}, {}) -> {}'.format( vm, nic_create_spec, nic)) nics_to_delete.append(nic) nic_info = client.vcenter.vm.hardware.Ethernet.get(vm, nic) print('vm.hardware.Ethernet.get({}, {}) -> {}'.format( vm, nic, pp(nic_info))) print('\n# Example: Create Ethernet Nic using DISTRIBUTED_PORTGROUP ' 'specifying') print('# start_connected=True, allow_guest_control=True,') print('# mac_type, mac_Address, wake_on_lan_enabled') nic_create_spec = Ethernet.CreateSpec( start_connected=True, allow_guest_control=True, mac_type=Ethernet.MacAddressType.MANUAL, mac_address='24:68:10:12:14:16', wake_on_lan_enabled=True, backing=Ethernet.BackingSpec( type=Ethernet.BackingType.DISTRIBUTED_PORTGROUP, network=distributed_network)) nic = client.vcenter.vm.hardware.Ethernet.create(vm, nic_create_spec) print('vm.hardware.Ethernet.create({}, {}) -> {}'.format( vm, nic_create_spec, nic)) nics_to_delete.append(nic) nic_info = client.vcenter.vm.hardware.Ethernet.get(vm, nic) print('vm.hardware.Ethernet.get({}, {}) -> {}'.format( vm, nic, pp(nic_info))) if opaque_network: print('\n# Example: Create Ethernet Nic using OPAQUE PORTGROUP with ' 'default settings') nic_create_spec = Ethernet.CreateSpec(backing=Ethernet.BackingSpec( type=Ethernet.BackingType.OPAQUE_NETWORK, network=opaque_network)) nic = client.vcenter.vm.hardware.Ethernet.create(vm, nic_create_spec) print('vm.hardware.Ethernet.create({}, {}) -> {}'.format( vm, nic_create_spec, nic)) nics_to_delete.append(nic) nic_info = client.vcenter.vm.hardware.Ethernet.get(vm, nic) print('vm.hardware.Ethernet.get({}, {}) -> {}'.format( vm, nic, pp(nic_info))) # Change the last nic that was created print('\n# Example: Update Ethernet Nic with different backing') nic_update_spec = Ethernet.UpdateSpec(backing=Ethernet.BackingSpec( type=Ethernet.BackingType.STANDARD_PORTGROUP, network=standard_network)) print('vm.hardware.Ethernet.update({}, {}, {})'.format( vm, nic, nic_update_spec)) client.vcenter.vm.hardware.Ethernet.update(vm, nic, nic_update_spec) nic_info = client.vcenter.vm.hardware.Ethernet.get(vm, nic) print('vm.hardware.Ethernet.get({}, {}) -> {}'.format( vm, nic, pp(nic_info))) print('\n# Example: Update Ethernet Nic wake_on_lan_enabled=False') print('# mac_type=GENERATED,') print('# start_connected=False,') print('# allow_guest_control=False') nic_update_spec = Ethernet.UpdateSpec( wake_on_lan_enabled=False, mac_type=Ethernet.MacAddressType.GENERATED, start_connected=False, allow_guest_control=False) print('vm.hardware.Ethernet.update({}, {}, {})'.format( vm, nic, nic_update_spec)) client.vcenter.vm.hardware.Ethernet.update(vm, nic, nic_update_spec) nic_info = client.vcenter.vm.hardware.Ethernet.get(vm, nic) print('vm.hardware.Ethernet.get({}, {}) -> {}'.format( vm, nic, pp(nic_info))) print('\n# Starting VM to run connect/disconnect sample') print('vm.Power.start({})'.format(vm)) client.vcenter.vm.Power.start(vm) nic_info = client.vcenter.vm.hardware.Ethernet.get(vm, nic) print('vm.hardware.Ethernet.get({}, {}) -> {}'.format( vm, nic, pp(nic_info))) print('\n# Example: Connect Ethernet Nic after powering on VM') client.vcenter.vm.hardware.Ethernet.connect(vm, nic) print('vm.hardware.Ethernet.connect({}, {})'.format(vm, nic)) nic_info = client.vcenter.vm.hardware.Ethernet.get(vm, nic) print('vm.hardware.Ethernet.get({}, {}) -> {}'.format( vm, nic, pp(nic_info))) print('\n# Example: Disconnect Ethernet Nic while VM is powered on') client.vcenter.vm.hardware.Ethernet.disconnect(vm, nic) print('vm.hardware.Ethernet.disconnect({}, {})'.format(vm, nic)) nic_info = client.vcenter.vm.hardware.Ethernet.get(vm, nic) print('vm.hardware.Ethernet.get({}, {}) -> {}'.format( vm, nic, pp(nic_info))) print('\n# Stopping VM after connect/disconnect sample') print('vm.Power.start({})'.format(vm)) client.vcenter.vm.Power.stop(vm) nic_info = client.vcenter.vm.hardware.Ethernet.get(vm, nic) print('vm.hardware.Ethernet.get({}, {}) -> {}'.format( vm, nic, pp(nic_info))) # List all Nics for a VM nic_summaries = client.vcenter.vm.hardware.Ethernet.list(vm=vm) print('vm.hardware.Ethernet.list({}) -> {}'.format(vm, nic_summaries))
def run(): # * Floppy images must be pre-existing. This API does not expose # a way to create new floppy images. global vm vm = get_vm(client, vm_name) if not vm: raise Exception('Sample requires an existing vm with name ({}). ' 'Please create the vm first.'.format(vm_name)) print("Using VM '{}' ({}) for Floppy Sample".format(vm_name, vm)) img_datastore_path = testbed.config['FLOPPY_DATASTORE_PATH'] print('\n# Example: List all Floppys for a VM') floppy_summaries = client.vcenter.vm.hardware.Floppy.list(vm=vm) print('vm.hardware.Floppy.list({}) -> {}'.format(vm, floppy_summaries)) # Save current list of Floppys to verify that we have cleaned up properly global orig_floppy_summaries orig_floppy_summaries = floppy_summaries # Get information for each Floppy on the VM global floppy for floppy_summary in floppy_summaries: floppy = floppy_summary.floppy floppy_info = client.vcenter.vm.hardware.Floppy.get(vm=vm, floppy=floppy) print('vm.hardware.Floppy.get({}, {}) -> {}'. format(vm, floppy, pp(floppy_info))) # Maximum 2 Floppy devices allowed so delete them as they are created except # for the last one which will be deleted at the end print('\n# Example: Create Floppy port with defaults') floppy_create_spec = Floppy.CreateSpec() floppy = client.vcenter.vm.hardware.Floppy.create(vm, floppy_create_spec) print('vm.hardware.Floppy.create({}, {}) -> {}'. format(vm, floppy_create_spec, floppy)) floppy_info = client.vcenter.vm.hardware.Floppy.get(vm, floppy) print('vm.hardware.Floppy.get({}, {}) -> {}'. format(vm, floppy, pp(floppy_info))) client.vcenter.vm.hardware.Floppy.delete(vm, floppy) print('vm.hardware.Floppy.delete({}, {})'.format(vm, floppy)) print('\n# Example: Create Floppy with CLIENT_DEVICE backing') floppy_create_spec = Floppy.CreateSpec( backing=Floppy.BackingSpec(type=Floppy.BackingType.CLIENT_DEVICE)) floppy = client.vcenter.vm.hardware.Floppy.create(vm, floppy_create_spec) print('vm.hardware.Floppy.create({}, {}) -> {}'. format(vm, floppy_create_spec, floppy)) floppy_info = client.vcenter.vm.hardware.Floppy.get(vm, floppy) print('vm.hardware.Floppy.get({}, {}) -> {}'. format(vm, floppy, pp(floppy_info))) client.vcenter.vm.hardware.Floppy.delete(vm, floppy) print('vm.hardware.Floppy.delete({}, {})'.format(vm, floppy)) print('\n# Example: Create Floppy with IMAGE_FILE backing, ' 'start_connected=True,') print(' allow_guest_control=True') floppy_create_spec = Floppy.CreateSpec( allow_guest_control=True, start_connected=True, backing=Floppy.BackingSpec(type=Floppy.BackingType.IMAGE_FILE, image_file=img_datastore_path)) floppy = client.vcenter.vm.hardware.Floppy.create(vm, floppy_create_spec) floppy_info = client.vcenter.vm.hardware.Floppy.get(vm, floppy) print('vm.hardware.Floppy.get({}, {}) -> {}'. format(vm, floppy, pp(floppy_info))) print('\n# Example: Update start_connected=False, ' 'allow_guest_control=False') floppy_update_spec = Floppy.UpdateSpec( start_connected=False, allow_guest_control=False) print('vm.hardware.Floppy.update({}, {}, {})'. format(vm, floppy, floppy_update_spec)) client.vcenter.vm.hardware.Floppy.update(vm, floppy, floppy_update_spec) floppy_info = client.vcenter.vm.hardware.Floppy.get(vm, floppy) print('vm.hardware.Floppy.get({}, {}) -> {}'. format(vm, floppy, pp(floppy_info))) print('\n# Starting VM to run connect/disconnect sample') print('vm.Power.start({})'.format(vm)) client.vcenter.vm.Power.start(vm) floppy_info = client.vcenter.vm.hardware.Floppy.get(vm, floppy) print('vm.hardware.Floppy.get({}, {}) -> {}'. format(vm, floppy, pp(floppy_info))) print('\n# Example: Connect Floppy after powering on VM') client.vcenter.vm.hardware.Floppy.connect(vm, floppy) print('vm.hardware.Floppy.connect({}, {})'.format(vm, floppy)) floppy_info = client.vcenter.vm.hardware.Floppy.get(vm, floppy) print('vm.hardware.Floppy.get({}, {}) -> {}'. format(vm, floppy, pp(floppy_info))) print('\n# Example: Disconnect Floppy while VM is powered on') client.vcenter.vm.hardware.Floppy.disconnect(vm, floppy) print('vm.hardware.Floppy.disconnect({}, {})'.format(vm, floppy)) floppy_info = client.vcenter.vm.hardware.Floppy.get(vm, floppy) print('vm.hardware.Floppy.get({}, {}) -> {}'. format(vm, floppy, pp(floppy_info))) print('\n# Stopping VM after connect/disconnect sample') print('vm.Power.start({})'.format(vm)) client.vcenter.vm.Power.stop(vm) floppy_info = client.vcenter.vm.hardware.Floppy.get(vm, floppy) print('vm.hardware.Floppy.get({}, {}) -> {}'. format(vm, floppy, pp(floppy_info))) # List all Floppys for a VM floppy_summaries = client.vcenter.vm.hardware.Floppy.list(vm=vm) print('vm.hardware.Floppy.list({}) -> {}'.format(vm, floppy_summaries))
def run(): # * Backings types are FILE, HOST_DEVICE, PIPE_SERVER, PIPE_CLIENT, # NETWORK_SERVER, NETWORK_CLIENT # * NetworkLocation: See # https://kb.vmware.com/selfservice/microsites/search.do?language=en_US # &cmd=displayKC&externalId=2004954 # * Proxy: https://www.vmware.com/support/developer/vc-sdk/visdk41pubs # /vsp41_usingproxy_virtual_serial_ports.pdf global vm, serial_svc vm = get_vm(stub_config, vm_name) if not vm: raise Exception('Sample requires an existing vm with name ({}). ' 'Please create the vm first.'.format(vm_name)) print("Using VM '{}' ({}) for Serial Sample".format(vm_name, vm)) # Create Serial port stub used for making requests serial_svc = Serial(stub_config) vm_power_svc = Power(stub_config) print('\n# Example: List all Serial ports for a VM') serial_summaries = serial_svc.list(vm=vm) print('vm.hardware.Serial.list({}) -> {}'.format(vm, serial_summaries)) # Save current list of Serial ports to verify that we have cleaned up # properly global orig_serial_summaries orig_serial_summaries = serial_summaries # Get information for each Serial port on the VM for serial_summary in serial_summaries: serial = serial_summary.port serial_info = serial_svc.get(vm=vm, port=serial) print('vm.hardware.Serial.get({}, {}) -> {}'.format( vm, serial, pp(serial_info))) global serials_to_delete print('\n# Example: Create Serial port with defaults') serial_create_spec = Serial.CreateSpec() serial = serial_svc.create(vm, serial_create_spec) print('vm.hardware.Serial.create({}, {}) -> {}'.format( vm, serial_create_spec, serial)) serials_to_delete.append(serial) serial_info = serial_svc.get(vm, serial) print('vm.hardware.Serial.get({}, {}) -> {}'.format( vm, serial, pp(serial_info))) # Make sure output file doesn't exist already cleanup_backends() print('\n# Example: Create Serial port with FILE backing') serial_port_datastore_path = testbed.config['SERIAL_PORT_DATASTORE_PATH'] serial_create_spec = Serial.CreateSpec( start_connected=True, allow_guest_control=True, backing=Serial.BackingSpec(type=Serial.BackingType.FILE, file=serial_port_datastore_path)) serial = serial_svc.create(vm, serial_create_spec) print('vm.hardware.Serial.create({}, {}) -> {}'.format( vm, serial_create_spec, serial)) serials_to_delete.append(serial) serial_info = serial_svc.get(vm, serial) print('vm.hardware.Serial.get({}, {}) -> {}'.format( vm, serial, pp(serial_info))) print('\n# Example: Create Serial port to use NETWORK_SERVER') serial_port_network_server_location = \ testbed.config['SERIAL_PORT_NETWORK_SERVER_LOCATION'] serial_create_spec = Serial.CreateSpec( start_connected=True, allow_guest_control=True, backing=Serial.BackingSpec( type=Serial.BackingType.NETWORK_SERVER, network_location=serial_port_network_server_location)) serial = serial_svc.create(vm, serial_create_spec) print('vm.hardware.Serial.create({}, {}) -> {}'.format( vm, serial_create_spec, serial)) serials_to_delete.append(serial) serial_info = serial_svc.get(vm, serial) print('vm.hardware.Serial.get({}, {}) -> {}'.format( vm, serial, pp(serial_info))) print('\n# Example: Update Serial port to use NETWORK_CLIENT') serial_port_network_client_location = \ testbed.config['SERIAL_PORT_NETWORK_CLIENT_LOCATION'] serial_port_network_proxy = testbed.config['SERIAL_PORT_NETWORK_PROXY'] serial_update_spec = Serial.UpdateSpec( start_connected=False, allow_guest_control=False, backing=Serial.BackingSpec( type=Serial.BackingType.NETWORK_CLIENT, network_location=serial_port_network_client_location, proxy=serial_port_network_proxy)) serial_svc.update(vm, serial, serial_update_spec) print('vm.hardware.Serial.update({}, {}) -> {}'.format( vm, serial_update_spec, serial)) serial_info = serial_svc.get(vm, serial) print('vm.hardware.Serial.get({}, {}) -> {}'.format( vm, serial, pp(serial_info))) print('\n# Starting VM to run connect/disconnect sample') print('vm.Power.start({})'.format(vm)) vm_power_svc.start(vm) serial_info = serial_svc.get(vm, serial) print('vm.hardware.Serial.get({}, {}) -> {}'.format( vm, serial, pp(serial_info))) print('\n# Example: Connect Serial port after powering on VM') serial_svc.connect(vm, serial) print('vm.hardware.Serial.connect({}, {})'.format(vm, serial)) serial_info = serial_svc.get(vm, serial) print('vm.hardware.Serial.get({}, {}) -> {}'.format( vm, serial, pp(serial_info))) print('\n# Example: Disconnect Serial port while VM is powered on') serial_svc.disconnect(vm, serial) print('vm.hardware.Serial.disconnect({}, {})'.format(vm, serial)) serial_info = serial_svc.get(vm, serial) print('vm.hardware.Serial.get({}, {}) -> {}'.format( vm, serial, pp(serial_info))) print('\n# Stopping VM after connect/disconnect sample') print('vm.Power.start({})'.format(vm)) vm_power_svc.stop(vm) serial_info = serial_svc.get(vm, serial) print('vm.hardware.Serial.get({}, {}) -> {}'.format( vm, serial, pp(serial_info))) # List all Serial ports for a VM serial_summaries = serial_svc.list(vm=vm) print('vm.hardware.Serial.list({}) -> {}'.format(vm, serial_summaries)) # Always cleanup output file so the VM can be powered on next time cleanup_backends()
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