def get_resource_pool(stub_config, datacenter_name):
    """
    Returns the identifier of the first resourcepool in the datacenter
    """
    datacenter = datacenter_helper.get_datacenter(stub_config, datacenter_name)
    if not datacenter:
        print("Datacenter '{}' not found".format(datacenter_name))
        return None

    filter_spec = ResourcePool.FilterSpec(datacenters=set([datacenter]))

    resource_pool_svc = ResourcePool(stub_config)
    resource_pool_summaries = resource_pool_svc.list(filter_spec)
    if len(resource_pool_summaries) > 0:
        resource_pool = resource_pool_summaries[0].resource_pool
        print("Selecting ResourcePool '{}'".format(resource_pool))
        return resource_pool
    else:
        print("ResourcePool not found in Datacenter '{}'".format(
            datacenter_name))
        return None
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]

    resource_pool_svc = ResourcePool(context.stub_config)
    filter = ResourcePool.FilterSpec(datacenters=set([datacenter]))
    resource_pool_summaries = resource_pool_svc.list(filter=filter)

    resource_pool = None
    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']

    folder_svc = Folder(context.stub_config)
    filter = Folder.FilterSpec(
        names=set([folder_name]),
        datacenters=set([datacenter]))
    folder_summaries = folder_svc.list(filter=filter)

    folder = None
    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']

    datastore_svc = Datastore(context.stub_config)
    filter = Datastore.FilterSpec(
        names=set([datastore_name]),
        datacenters=set([datacenter]))
    datastore_summaries = datastore_svc.list(filter=filter)

    datastore = None
    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