This example is based on the code in the vm_placement_helper.py sample file.
Note: For a complete and up-to-date version of the sample code, see the
vsphere-automation-sdk-python VMware repository at GitHub.
... 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