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, 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()