def cleanup(self): print('Cleanup Samples Started') CreateDefaultVM(self.context.client).cleanup() CreateBasicVM(self.context.client).cleanup() CreateExhaustiveVM(self.context.client).cleanup() print('Cleanup Samples Complete\n')
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 create_vm(vm_name, cpu, memory, cap): session = get_unverified_session() client = create_vsphere_client(server='192.168.111.101', username='******', password='******', session=session) create_basic_vm = CreateBasicVM(client=client, vm_name=vm_name, cpu=cpu, memory=memory, cap=cap) create_basic_vm.run()