예제 #1
0
def cleanup_cluster(context):
    """Delete cluster after vcenter sample run"""
    cluster1_name = context.testbed.config['CLUSTER1_NAME']
    names = set([cluster1_name])

    cluster_svc = Cluster(context.stub_config)
    cluster_summaries = cluster_svc.list(Cluster.FilterSpec(names=names))
    print("Found '{}' Clusters matching names {}".format(
        len(cluster_summaries), ", ".join(["'{}'".format(n) for n in names])))

    if len(cluster_summaries) < 1:
        return

    # Delete the cluster using the managed object
    cluster = cluster_summaries[0].cluster
    cluster_mo = vim.ClusterComputeResource(cluster, context.soap_stub)

    print("Deleting Cluster '{}' ({})".format(cluster, cluster1_name))
    task = cluster_mo.Destroy()
    pyVim.task.WaitForTask(task)
예제 #2
0
def get_cluster(stub_config, datacenter_name, cluster_name):
    """
    Returns the identifier of a cluster
    Note: The method assumes only one cluster and datacenter
    with the mentioned name.
    """

    datacenter = datacenter_helper.get_datacenter(stub_config, datacenter_name)
    if not datacenter:
        print("Datacenter '{}' not found".format(datacenter_name))
        return None

    filter_spec = Cluster.FilterSpec(names=set([cluster_name]),
                                     datacenters=set([datacenter]))

    cluster_svc = Cluster(stub_config)
    cluster_summaries = cluster_svc.list(filter_spec)
    if len(cluster_summaries) > 0:
        cluster = cluster_summaries[0].cluster
        print("Detected cluster '{}' as {}".format(cluster_name, cluster))
        return cluster
    else:
        print("Cluster '{}' not found".format(cluster_name))
        return None
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']
    names = set([cluster_name])

    cluster_svc = Cluster(context.stub_config)
    filter = Cluster.FilterSpec(
        names=set([cluster_name]),
        datacenters=set([datacenter]))
    cluster_summaries = cluster_svc.list(filter=filter)

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

    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 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']

    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,
                                      cluster=cluster,
                                      datastore=datastore)
    print("get_placement_spec_for_cluster: Result is '{}'".
          format(placement_spec))
    return placement_spec