Example #1
0
def cleanup_nfs_datastore(context):
    """Cleanup NFS datastore after running vcenter samples"""
    # Remove NFS datastore from each Host
    host1_name = context.testbed.config['ESX_HOST1']
    host2_name = context.testbed.config['ESX_HOST2']
    names = set([host1_name, host2_name])

    datastore_name = context.testbed.config['NFS_DATASTORE_NAME']

    # Use vAPI find the Host managed identities
    host_svc = Host(context.stub_config)
    host_summaries = host_svc.list(Host.FilterSpec(names=names))

    for host_summary in host_summaries:
        # Convert the host identifier into a ManagedObject
        host = host_summary.host
        host_mo = vim.HostSystem(host, context.soap_stub)

        for datastore_mo in host_mo.datastore:
            if datastore_mo.name == datastore_name:
                datastore_system = host_mo.configManager.datastoreSystem
                datastore_system.RemoveDatastore(datastore_mo)
                print("Removed NFS Volume '{}' ({}) from Host '{}' ({})".
                      format(datastore_name, datastore_mo._moId,
                             host_mo.name, host_mo._moId))
Example #2
0
def detect_nfs_datastore_on_host(context, host_name):
    """Find NFS datastore on host"""
    names = set([host_name])
    datastore_name = context.testbed.config['NFS_DATASTORE_NAME']

    # Use vAPI find the Host managed identities
    host_svc = Host(context.stub_config)
    host_summaries = host_svc.list(Host.FilterSpec(names=names))

    for host_summary in host_summaries:
        # Convert the host identifier into a ManagedObject
        host = host_summary.host
        host_mo = vim.HostSystem(host, context.soap_stub)

        for datastore_mo in host_mo.datastore:
            if (datastore_mo.name == datastore_name and
                datastore_mo.summary.type == 'NFS'):
                datastore = datastore_mo._moId
                print("Detected NFS Volume '{}' as {} on Host '{}' ({})".
                      format(datastore_name, datastore, host_name, host))
                context.testbed.entities['HOST_NFS_DATASTORE_IDS'][host_name] \
                    = datastore
                return True

    print("NFS Volume '{}' missing on Host '{}'".
          format(datastore_name, host_name))
    return False
def detect_stdportgroup(context, host_name, network_name):
    """Find Distributed Switch based on host and network name"""
    # Ensure the standard switch is available on the host
    names = set([host_name])

    # Use vAPI find the Host managed identities
    host_svc = Host(context.stub_config)
    host_summaries = host_svc.list(Host.FilterSpec(names=names))

    for host_summary in host_summaries:
        # Convert the host identifier into a ManagedObject
        host = host_summary.host
        host_mo = vim.HostSystem(host, context.soap_stub)

        for network_mo in host_mo.network:
            if (type(network_mo) == vim.Network and
                        network_mo.name == network_name):
                network = network_mo._moId
                print(
                    "Detected Standard Portgroup '{}' as {} on Host '{}' ({})".
                    format(network_name, network, host_name, host))
                context.testbed.entities['HOST_STANDARD_SWITCH_IDS'][
                    host_name] = network
                return True

    print("Standard Portgroup '{}' missing on Host '{}'".
          format(network_name, host_name))
    return False
Example #4
0
def setup_vmfs_datastore(context, host_name, datastore_name):
    """Find VMFS datastore given host and datastore names"""
    context.testbed.entities['HOST_VMFS_DATASTORE_IDS'] = {}

    names = set([host_name])

    # Use vAPI find the Host managed identities
    host_svc = Host(context.stub_config)
    host_summaries = host_svc.list(Host.FilterSpec(names=names))

    host_summary = host_summaries[0]
    # Convert the host identifier into a ManagedObject
    host = host_summary.host
    host_mo = vim.HostSystem(host, context.soap_stub)

    vmfs_datastores = dict([(datastore_mo.name, datastore_mo)
                            for datastore_mo in host_mo.datastore
                            if datastore_mo.summary.type == 'VMFS'])

    # The VMFS volume exists.  No need to do anything
    if datastore_name in vmfs_datastores:
        datastore = vmfs_datastores[datastore_name]._moId
        print("Detected VMFS Volume '{}' as {} on Host '{}' ({})".
              format(datastore_name, datastore, host_name, host))
        context.testbed.entities['HOST_VMFS_DATASTORE_IDS'][host_name] \
            = datastore
        return True

    # Rename a VMFS datastore
    if len(vmfs_datastores) > 0:
        datastore_mo = list(vmfs_datastores.values())[0]
        datastore = datastore_mo._moId
        print("Renaming VMFS Volume '{}' ({}) on Host '{}' ({}) to '{}'".
              format(datastore_mo.name, datastore,
                     host_name, host, datastore_name))
        task = datastore_mo.Rename(datastore_name)
        pyVim.task.WaitForTask(task)
        return True

    return False