def get_placement_spec_for_resource_pool(stub_config, datacenter_name, vm_folder_name, datastore_name): """ Returns a VM placement spec for a resourcepool. Ensures that the vm folder and datastore are all in the same datacenter which is specified. """ resource_pool = resource_pool_helper.get_resource_pool(stub_config, datacenter_name) folder = folder_helper.get_folder(stub_config, datacenter_name, vm_folder_name) datastore = datastore_helper.get_datastore(stub_config, datacenter_name, datastore_name) # Create the vm placement spec with the datastore, resource pool and vm # folder placement_spec = VM.PlacementSpec(folder=folder, resource_pool=resource_pool, datastore=datastore) print("get_placement_spec_for_resource_pool: Result is '{}'". format(placement_spec)) return placement_spec
def get_placement_spec_for_cluster(context): """ Cluster names are not guaranteed to be unique within a vCenter instance, so we qualify our search using the Datacenter. If Folders are used, the search must be qualified using Folders since a Cluster name is not guaranteed to be unique across different Folders within a Datacenter. """ # Select a Cluster meeting our requirements datacenter_name = context.testbed.config['DATACENTER2_NAME'] datacenter = context.testbed.entities['DATACENTER_IDS'][datacenter_name] cluster_name = context.testbed.config['CLUSTER1_NAME'] filter = Cluster.FilterSpec(names=set([cluster_name]), datacenters=set([datacenter])) cluster_summaries = context.client.vcenter.Cluster.list(filter=filter) if len(cluster_summaries) > 0: cluster = cluster_summaries[0].cluster print("Selecting Cluster '{}' ({})".format(cluster_name, cluster)) else: print("Cluster '{}' not found".format(cluster_name)) return None # Select a Folder meeting our requirements. # # Must be in the same Datacenter as the Cluster that was chosen. datacenter_name = context.testbed.config['DATACENTER2_NAME'] datacenter = context.testbed.entities['DATACENTER_IDS'][datacenter_name] folder_name = context.testbed.config['VM_FOLDER2_NAME'] filter = Folder.FilterSpec(names=set([folder_name]), datacenters=set([datacenter])) folder_summaries = context.client.vcenter.Folder.list(filter=filter) if len(folder_summaries) > 0: folder = folder_summaries[0].folder print("Selecting Folder '{}' ({})".format(folder_name, folder)) else: print("Folder '{}' not found".format(folder_name)) return None # Select a Datastore meeting our requirements. # # Must be in the same Datacenter as the Cluster that was chosen. # TODO No way to validate that Cluster is connected to Datastore datacenter_name = context.testbed.config['DATACENTER2_NAME'] datacenter = context.testbed.entities['DATACENTER_IDS'][datacenter_name] # TODO Parameterize based on NFS or VMFS datastore_name = context.testbed.config['NFS_DATASTORE_NAME'] filter = Datastore.FilterSpec(names=set([datastore_name]), datacenters=set([datacenter])) datastore_summaries = context.client.vcenter.Datastore.list(filter=filter) if len(datastore_summaries) > 0: datastore = datastore_summaries[0].datastore print("Selecting Datastore '{}' ({})".format(datastore_name, datastore)) else: print("Datastore '{}' not found".format(datastore_name)) return None placement_spec = VM.PlacementSpec(folder=folder, cluster=cluster, datastore=datastore) print("get_placement_spec_for_cluster: Result is '{}'".format( placement_spec)) return placement_spec
def get_placement_spec_for_resource_pool(context): # Select a ResourcePool meeting our requirements datacenter_name = context.testbed.config['DATACENTER2_NAME'] datacenter = context.testbed.entities['DATACENTER_IDS'][datacenter_name] filter = ResourcePool.FilterSpec(datacenters=set([datacenter])) resource_pool_summaries = context.client.vcenter.ResourcePool.list( filter=filter) if len(resource_pool_summaries) > 0: resource_pool = resource_pool_summaries[0].resource_pool print('Selecting ResourcePool ({})'.format(resource_pool)) else: print("ResourcePool not found in Datacenter '{}'".format( datacenter_name)) return None # Select a Folder meeting our requirements. # # Must be in the same Datacenter as the ResourcePool that was chosen. datacenter_name = context.testbed.config['DATACENTER2_NAME'] datacenter = context.testbed.entities['DATACENTER_IDS'][datacenter_name] folder_name = context.testbed.config['VM_FOLDER2_NAME'] filter = Folder.FilterSpec(names=set([folder_name]), datacenters=set([datacenter])) folder_summaries = context.client.vcenter.Folder.list(filter=filter) if len(folder_summaries) > 0: folder = folder_summaries[0].folder print("Selecting Folder '{}' ({})".format(folder_name, folder)) else: print("Folder '{}' not found".format(folder_name)) return None # Select a Datastore meeting our requirements. # # Must be in the same Datacenter as the ResourcePool that was chosen. datacenter_name = context.testbed.config['DATACENTER2_NAME'] datacenter = context.testbed.entities['DATACENTER_IDS'][datacenter_name] # TODO Parameterize based on NFS or VMFS datastore_name = context.testbed.config['NFS_DATASTORE_NAME'] filter = Datastore.FilterSpec(names=set([datastore_name]), datacenters=set([datacenter])) datastore_summaries = context.client.vcenter.Datastore.list(filter=filter) if len(datastore_summaries) > 0: datastore = datastore_summaries[0].datastore print("Selecting Datastore '{}' ({})".format(datastore_name, datastore)) else: print("Datastore '{}' not found".format(datastore_name)) return None placement_spec = VM.PlacementSpec(folder=folder, resource_pool=resource_pool, datastore=datastore) print("get_placement_spec_for_resourcepool: Result is '{}'".format( placement_spec)) return placement_spec
# Display Single Datastore client.vcenter.Datastore.get('datastore-13') # Create Basic VM from com.vmware.vcenter_client import VM # Create VM Specification vmSpec = VM.CreateSpec() vmSpec vmSpec.guest_os = 'WINDOWS_9_64' vmSpec.name = 'CODE2219U' # Create VM Placement Specification placementSpec = VM.PlacementSpec() #placementSpec placementSpec.resource_pool = 'resgroup-8' placementSpec.datastore = 'datastore-13' placementSpec.folder = 'group-v9' # Add Placement Specification to VM Specification vmSpec.placement = placementSpec # Create new VM newVM = client.vcenter.VM.create(vmSpec) # Get VM Details client.vcenter.VM.get(newVM)
filter_spec = Network.FilterSpec(#datacenters=set(['Datacenter']), names=set(['VM Network']), types=set([Network.Type.STANDARD_PORTGROUP]) ) network_summaries = client.vcenter.Network.list(filter=filter_spec) print(network_summaries) network_summaries = client.vcenter.Network.list() network1 = network_summaries[0] print(network1) network2 = network_summaries[1] 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,
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