def get_datastore(stub_config, datacenter_name, datastore_name):
    """
    Returns the identifier of a datastore
    Note: The method assumes that there is only one datastore and datacenter
    with the mentioned names.
    """
    datacenter = datacenter_helper.get_datacenter(stub_config, datacenter_name)
    if not datacenter:
        print("Datacenter '{}' not found".format(datacenter_name))
        return None

    filter_spec = Datastore.FilterSpec(names=set([datastore_name]),
                                       datacenters=set([datacenter]))

    datastore_svc = Datastore(stub_config)
    datastore_summaries = datastore_svc.list(filter_spec)
    if len(datastore_summaries) > 0:
        datastore = datastore_summaries[0].datastore
        return datastore
    else:
        return None
Esempio n. 2
0
 def get_datastore_by_name(self, datacenter_name, datastore_name):
     """
     Returns the identifier of a datastore
     with the mentioned names.
     """
     datacenter = self.get_datacenter_by_name(datacenter_name)
     if not datacenter:
         return None
     names = set([datastore_name]) if datastore_name else None
     filter_spec = Datastore.FilterSpec(datacenters=set([datacenter]),
                                        names=names)
     datastore_summaries = self.api_client.vcenter.Datastore.list(filter_spec)
     datastore = datastore_summaries[0].datastore if len(datastore_summaries) > 0 else None
     return datastore
Esempio n. 3
0
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
Esempio n. 4
0
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
Esempio n. 5
0
datacenter_summaries = client.vcenter.Datacenter.list(filter_spec)
datacenter = datacenter_summaries[0].datacenter

filter_spec = Folder.FilterSpec(names=set(['VmFolder'])
                                #, datacenters=set(['Datacenter'])
                                )
folder_summaries = client.vcenter.Folder.list(filter_spec)
folder = folder_summaries[0].folder
print(folder)

filter_spec = Host.FilterSpec(names=set(['esxi-1.prod.vmware.haf']))
host_summaries = client.vcenter.Host.list(filter_spec)
host = host_summaries[0]
print(host)

filter_spec = Datastore.FilterSpec(names=set(['Kingston120G']))
datastore_summaries = client.vcenter.Datastore.list(filter_spec)
datastore = datastore_summaries[0]
print(datastore)

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)