示例#1
0
def get_vswitch_for_vlan_interface(session, vlan_interface, cluster=None):
    """
    Gets the vswitch associated with the physical network adapter
    with the name supplied.
    """
    # Get the list of vSwicthes on the Host System
    host_mor = vm_util.get_host_ref(session, cluster)
    vswitches_ret = session._call_method(vim_util, "get_dynamic_property",
                                         host_mor, "HostSystem",
                                         "config.network.vswitch")
    # Meaning there are no vSwitches on the host. Shouldn't be the case,
    # but just doing code check
    if not vswitches_ret:
        return
    vswitches = vswitches_ret.HostVirtualSwitch
    # Get the vSwitch associated with the network adapter
    for elem in vswitches:
        try:
            for nic_elem in elem.pnic:
                if str(nic_elem).split('-')[-1].find(vlan_interface) != -1:
                    return elem.name
        # Catching Attribute error as a vSwitch may not be associated with a
        # physical NIC.
        except AttributeError:
            pass
示例#2
0
def create_port_group(session, pg_name, vswitch_name, vlan_id=0, cluster=None):
    """
    Creates a port group on the host system with the vlan tags
    supplied. VLAN id 0 means no vlan id association.
    """
    client_factory = session._get_vim().client.factory
    add_prt_grp_spec = vm_util.get_add_vswitch_port_group_spec(
                    client_factory,
                    vswitch_name,
                    pg_name,
                    vlan_id)
    host_mor = vm_util.get_host_ref(session, cluster)
    network_system_mor = session._call_method(vim_util,
        "get_dynamic_property", host_mor,
        "HostSystem", "configManager.networkSystem")
    LOG.debug(_("Creating Port Group with name %s on "
                "the ESX host") % pg_name)
    try:
        session._call_method(session._get_vim(),
                "AddPortGroup", network_system_mor,
                portgrp=add_prt_grp_spec)
    except error_util.VimFaultException as exc:
        # There can be a race condition when two instances try
        # adding port groups at the same time. One succeeds, then
        # the other one will get an exception. Since we are
        # concerned with the port group being created, which is done
        # by the other call, we can ignore the exception.
        if error_util.FAULT_ALREADY_EXISTS not in exc.fault_list:
            raise exception.NovaException(exc)
    LOG.debug(_("Created Port Group with name %s on "
                "the ESX host") % pg_name)
示例#3
0
def rescan_iscsi_hba(session, cluster=None):
    """Rescan the iSCSI HBA to discover iSCSI targets."""
    host_mor = vm_util.get_host_ref(session, cluster)
    storage_system_mor = session._call_method(vim_util, "get_dynamic_property",
                                              host_mor, "HostSystem",
                                              "configManager.storageSystem")
    hbas_ret = session._call_method(vim_util,
                                    "get_dynamic_property",
                                    storage_system_mor,
                                    "HostStorageSystem",
                                    "storageDeviceInfo.hostBusAdapter")
    # Meaning there are no host bus adapters on the host
    if hbas_ret is None:
        return
    host_hbas = hbas_ret.HostHostBusAdapter
    if not host_hbas:
        return
    for hba in host_hbas:
        if hba.__class__.__name__ == 'HostInternetScsiHba':
            hba_device = hba.device
            break
    else:
        return

    LOG.debug(_("Rescanning HBA %s") % hba_device)
    session._call_method(session._get_vim(), "RescanHba", storage_system_mor,
                         hbaDevice=hba_device)
    LOG.debug(_("Rescanned HBA %s ") % hba_device)
示例#4
0
def rescan_iscsi_hba(session, cluster=None, target_portal=None):
    """Rescan the iSCSI HBA to discover iSCSI targets."""
    host_mor = vm_util.get_host_ref(session, cluster)
    storage_system_mor = session._call_method(vim_util, "get_dynamic_property",
                                              host_mor, "HostSystem",
                                              "configManager.storageSystem")
    hbas_ret = session._call_method(vim_util,
                                    "get_dynamic_property",
                                    storage_system_mor,
                                    "HostStorageSystem",
                                    "storageDeviceInfo.hostBusAdapter")
    # Meaning there are no host bus adapters on the host
    if hbas_ret is None:
        return
    host_hbas = hbas_ret.HostHostBusAdapter
    if not host_hbas:
        return
    for hba in host_hbas:
        if hba.__class__.__name__ == 'HostInternetScsiHba':
            hba_device = hba.device
            if target_portal:
                # Check if iscsi host is already in the send target host list
                send_targets = getattr(hba, 'configuredSendTarget', [])
                send_tgt_portals = ['%s:%s' % (s.address, s.port) for s in
                                    send_targets]
                if target_portal not in send_tgt_portals:
                    _add_iscsi_send_target_host(session, storage_system_mor,
                                                hba_device, target_portal)
            break
    else:
        return
    LOG.debug("Rescanning HBA %s", hba_device)
    session._call_method(session._get_vim(), "RescanHba", storage_system_mor,
                         hbaDevice=hba_device)
    LOG.debug("Rescanned HBA %s ", hba_device)
示例#5
0
def get_available_datastores(session, cluster=None, datastore_regex=None):
    """Get the datastore list and choose the first local storage."""
    if cluster:
        mobj = cluster
        resource_type = "ClusterComputeResource"
    else:
        mobj = vm_util.get_host_ref(session)
        resource_type = "HostSystem"
    ds = session._call_method(vim_util, "get_dynamic_property", mobj,
                              resource_type, "datastore")
    if not ds:
        return []
    data_store_mors = ds.ManagedObjectReference
    # NOTE(garyk): use utility method to retrieve remote objects
    data_stores = session._call_method(vim_util,
            "get_properties_for_a_collection_of_objects",
            "Datastore", data_store_mors,
            ["summary.type", "summary.name", "summary.accessible"])

    allowed = []
    while data_stores:
        allowed.extend(_get_allowed_datastores(data_stores, datastore_regex,
                                               ['VMFS', 'NFS']))
        token = _get_token(data_stores)
        if not token:
            break

        data_stores = session._call_method(vim_util,
                                           "continue_to_get_objects",
                                           token)
    return allowed
示例#6
0
文件: ds_util.py 项目: NxtCloud/nova
def get_available_datastores(session, cluster=None, datastore_regex=None):
    """Get the datastore list and choose the first local storage."""
    if cluster:
        mobj = cluster
        resource_type = "ClusterComputeResource"
    else:
        mobj = vm_util.get_host_ref(session)
        resource_type = "HostSystem"
    ds = session._call_method(vim_util, "get_dynamic_property", mobj,
                              resource_type, "datastore")
    if not ds:
        return []
    data_store_mors = ds.ManagedObjectReference
    # NOTE(garyk): use utility method to retrieve remote objects
    data_stores = session._call_method(vim_util,
            "get_properties_for_a_collection_of_objects",
            "Datastore", data_store_mors,
            ["summary.type", "summary.name", "summary.accessible",
            "summary.maintenanceMode"])

    allowed = []
    while data_stores:
        allowed.extend(_get_allowed_datastores(data_stores, datastore_regex))
        token = _get_token(data_stores)
        if not token:
            break

        data_stores = session._call_method(vim_util,
                                           "continue_to_get_objects",
                                           token)
    return allowed
示例#7
0
文件: vif.py 项目: wingo1990/nova
def get_neutron_network(session, network_name, cluster, vif):
    host = vm_util.get_host_ref(session, cluster)
    try:
        opaque = session._call_method(vim_util, "get_dynamic_property", host,
                                      "HostSystem",
                                      "config.network.opaqueNetwork")
    except error_util.VimFaultException:
        opaque = None
    network_ref = None
    if opaque:
        bridge = vif['network']['id']
        opaque_networks = opaque.HostOpaqueNetworkInfo
        for network in opaque_networks:
            if network['opaqueNetworkId'] == bridge:
                network_ref = {'type': 'OpaqueNetwork',
                               'network-id': network['opaqueNetworkId'],
                               'network-name': network['opaqueNetworkName'],
                               'network-type': network['opaqueNetworkType']}
                break
    else:
        bridge = network_name
        network_ref = network_util.get_network_with_the_name(
                session, network_name, cluster)
    if network_ref is None:
        raise exception.NetworkNotFoundForBridge(bridge=bridge)
    return network_ref
示例#8
0
文件: vif.py 项目: bclau/nova
def get_neutron_network(session, network_name, cluster, vif):
    host = vm_util.get_host_ref(session, cluster)
    try:
        opaque = session._call_method(vim_util, "get_dynamic_property", host,
                                      "HostSystem",
                                      "config.network.opaqueNetwork")
    except error_util.VimFaultException:
        opaque = None
    network_ref = None
    if opaque:
        bridge = vif['network']['id']
        opaque_networks = opaque.HostOpaqueNetworkInfo
        for network in opaque_networks:
            if network['opaqueNetworkId'] == bridge:
                network_ref = {'type': 'OpaqueNetwork',
                               'network-id': network['opaqueNetworkId'],
                               'network-name': network['opaqueNetworkName'],
                               'network-type': network['opaqueNetworkType']}
                break
    else:
        bridge = network_name
        network_ref = network_util.get_network_with_the_name(
                session, network_name, cluster)
    if network_ref is None:
        raise exception.NetworkNotFoundForBridge(bridge=bridge)
    return network_ref
示例#9
0
def get_vswitch_for_vlan_interface(session, vlan_interface, cluster=None):
    """
    Gets the vswitch associated with the physical network adapter
    with the name supplied.
    """
    # Get the list of vSwicthes on the Host System
    host_mor = vm_util.get_host_ref(session, cluster)
    vswitches_ret = session._call_method(vim_util,
                "get_dynamic_property", host_mor,
                "HostSystem", "config.network.vswitch")
    # Meaning there are no vSwitches on the host. Shouldn't be the case,
    # but just doing code check
    if not vswitches_ret:
        return
    vswitches = vswitches_ret.HostVirtualSwitch
    # Get the vSwitch associated with the network adapter
    for elem in vswitches:
        try:
            for nic_elem in elem.pnic:
                if str(nic_elem).split('-')[-1].find(vlan_interface) != -1:
                    return elem.name
        # Catching Attribute error as a vSwitch may not be associated with a
        # physical NIC.
        except AttributeError:
            pass
示例#10
0
def rescan_iscsi_hba(session, cluster=None):
    """
    Rescan the iSCSI HBA to discover iSCSI targets.
    """
    host_mor = vm_util.get_host_ref(session, cluster)
    storage_system_mor = session._call_method(vim_util, "get_dynamic_property",
                                              host_mor, "HostSystem",
                                              "configManager.storageSystem")
    hbas_ret = session._call_method(vim_util,
                                    "get_dynamic_property",
                                    storage_system_mor,
                                    "HostStorageSystem",
                                    "storageDeviceInfo.hostBusAdapter")
    # Meaning there are no host bus adapters on the host
    if hbas_ret is None:
        return
    host_hbas = hbas_ret.HostHostBusAdapter
    if not host_hbas:
        return
    for hba in host_hbas:
        if hba.__class__.__name__ == 'HostInternetScsiHba':
            hba_device = hba.device
            break
    else:
        return

    LOG.debug(_("Rescanning HBA %s") % hba_device)
    session._call_method(session._get_vim(), "RescanHba", storage_system_mor,
                         hbaDevice=hba_device)
    LOG.debug(_("Rescanned HBA %s ") % hba_device)
示例#11
0
def create_port_group(session, pg_name, vswitch_name, vlan_id=0, cluster=None):
    """
    Creates a port group on the host system with the vlan tags
    supplied. VLAN id 0 means no vlan id association.
    """
    client_factory = session._get_vim().client.factory
    add_prt_grp_spec = vm_util.get_add_vswitch_port_group_spec(
        client_factory, vswitch_name, pg_name, vlan_id)
    host_mor = vm_util.get_host_ref(session, cluster)
    network_system_mor = session._call_method(vim_util, "get_dynamic_property",
                                              host_mor, "HostSystem",
                                              "configManager.networkSystem")
    LOG.debug(
        _("Creating Port Group with name %s on "
          "the ESX host") % pg_name)
    try:
        session._call_method(session._get_vim(),
                             "AddPortGroup",
                             network_system_mor,
                             portgrp=add_prt_grp_spec)
    except error_util.AlreadyExistsException:
        # There can be a race condition when two instances try
        # adding port groups at the same time. One succeeds, then
        # the other one will get an exception. Since we are
        # concerned with the port group being created, which is done
        # by the other call, we can ignore the exception.
        LOG.debug(_("Port Group %s already exists."), pg_name)
    LOG.debug(
        _("Created Port Group with name %s on "
          "the ESX host") % pg_name)
示例#12
0
 def test_get_neutron_network_bridge_network_not_found(self):
     self.mox.StubOutWithMock(vm_util, 'get_host_ref')
     self.mox.StubOutWithMock(self.session, '_call_method')
     self.mox.StubOutWithMock(network_util, 'get_network_with_the_name')
     vm_util.get_host_ref(self.session,
             self.cluster).AndReturn('fake-host')
     opaque = fake.DataObject()
     opaque.HostOpaqueNetworkInfo = ['fake-network-info']
     self.session._call_method(vutil, "get_object_property",
              'fake-host', 'config.network.opaqueNetwork').AndReturn(None)
     network_util.get_network_with_the_name(self.session, 0,
         self.cluster).AndReturn(None)
     self.mox.ReplayAll()
     self.assertRaises(exception.NetworkNotFoundForBridge,
                       vif.get_neutron_network, self.session,
                       self.vif['network']['id'], self.cluster, self.vif)
示例#13
0
def create_port_group(session, pg_name, vswitch_name, vlan_id=0, cluster=None):
    """Creates a port group on the host system with the vlan tags
    supplied. VLAN id 0 means no vlan id association.
    """
    client_factory = session.vim.client.factory
    add_prt_grp_spec = vm_util.get_add_vswitch_port_group_spec(
                    client_factory,
                    vswitch_name,
                    pg_name,
                    vlan_id)
    host_mor = vm_util.get_host_ref(session, cluster)
    network_system_mor = session._call_method(vim_util,
        "get_dynamic_property", host_mor,
        "HostSystem", "configManager.networkSystem")
    LOG.debug("Creating Port Group with name %s on "
              "the ESX host", pg_name)
    try:
        session._call_method(session.vim,
                "AddPortGroup", network_system_mor,
                portgrp=add_prt_grp_spec)
    except vexc.AlreadyExistsException:
        # There can be a race condition when two instances try
        # adding port groups at the same time. One succeeds, then
        # the other one will get an exception. Since we are
        # concerned with the port group being created, which is done
        # by the other call, we can ignore the exception.
        LOG.debug("Port Group %s already exists.", pg_name)
    LOG.debug("Created Port Group with name %s on "
              "the ESX host", pg_name)
示例#14
0
 def test_get_neutron_network_bridge_network_not_found(self):
     self.mox.StubOutWithMock(vm_util, 'get_host_ref')
     self.mox.StubOutWithMock(self.session, '_call_method')
     self.mox.StubOutWithMock(network_util, 'get_network_with_the_name')
     vm_util.get_host_ref(self.session, self.cluster).AndReturn('fake-host')
     opaque = fake.DataObject()
     opaque.HostOpaqueNetworkInfo = ['fake-network-info']
     self.session._call_method(
         vim_util, "get_dynamic_property", 'fake-host', 'HostSystem',
         'config.network.opaqueNetwork').AndReturn(None)
     network_util.get_network_with_the_name(self.session, 0,
                                            self.cluster).AndReturn(None)
     self.mox.ReplayAll()
     self.assertRaises(exception.NetworkNotFoundForBridge,
                       vif.get_neutron_network, self.session,
                       self.vif['network']['id'], self.cluster, self.vif)
示例#15
0
 def test_get_neutron_network_opaque_network_not_found(self):
     self.mox.StubOutWithMock(vm_util, 'get_host_ref')
     self.mox.StubOutWithMock(self.session, '_call_method')
     self.mox.StubOutWithMock(vif, '_get_network_ref_from_opaque')
     vm_util.get_host_ref(self.session,
             self.cluster).AndReturn('fake-host')
     opaque = fake.DataObject()
     opaque.HostOpaqueNetworkInfo = ['fake-network-info']
     self.session._call_method(vutil, "get_object_property",
              'fake-host', 'config.network.opaqueNetwork').AndReturn(opaque)
     vif._get_network_ref_from_opaque(opaque.HostOpaqueNetworkInfo,
             CONF.vmware.integration_bridge,
             self.vif['network']['id']).AndReturn(None)
     self.mox.ReplayAll()
     self.assertRaises(exception.NetworkNotFoundForBridge,
                       vif.get_neutron_network, self.session,
                       self.vif['network']['id'], self.cluster, self.vif)
示例#16
0
def _get_opaque_network(session, cluster):
    host = vm_util.get_host_ref(session, cluster)
    try:
        opaque = session._call_method(vutil, "get_object_property", host,
                                      "config.network.opaqueNetwork")
    except vexc.InvalidPropertyException:
        opaque = None
    return opaque
示例#17
0
文件: test_vif.py 项目: Redosen/nova
 def test_get_neutron_network_opaque_network_not_found(self):
     self.mox.StubOutWithMock(vm_util, 'get_host_ref')
     self.mox.StubOutWithMock(self.session, '_call_method')
     self.mox.StubOutWithMock(vif, '_get_network_ref_from_opaque')
     vm_util.get_host_ref(self.session,
             self.cluster).AndReturn('fake-host')
     opaque = fake.DataObject()
     opaque.HostOpaqueNetworkInfo = ['fake-network-info']
     self.session._call_method(vim_util, "get_dynamic_property",
              'fake-host', 'HostSystem',
              'config.network.opaqueNetwork').AndReturn(opaque)
     vif._get_network_ref_from_opaque(opaque.HostOpaqueNetworkInfo,
             CONF.vmware.integration_bridge,
             self.vif['network']['id']).AndReturn(None)
     self.mox.ReplayAll()
     self.assertRaises(exception.NetworkNotFoundForBridge,
                       vif.get_neutron_network, self.session,
                       self.vif['network']['id'], self.cluster, self.vif)
示例#18
0
文件: vif.py 项目: Dynavisor/nova
def _get_opaque_network(session, cluster):
    host = vm_util.get_host_ref(session, cluster)
    try:
        opaque = session._call_method(vim_util, "get_dynamic_property", host,
                                      "HostSystem",
                                      "config.network.opaqueNetwork")
    except vexc.InvalidPropertyException:
        opaque = None
    return opaque
示例#19
0
 def test_get_neutron_network(self):
     self.mox.StubOutWithMock(vm_util, 'get_host_ref')
     self.mox.StubOutWithMock(self.session, '_call_method')
     self.mox.StubOutWithMock(vif, '_get_network_ref_from_opaque')
     vm_util.get_host_ref(self.session, self.cluster).AndReturn('fake-host')
     opaque = fake.DataObject()
     opaque.HostOpaqueNetworkInfo = ['fake-network-info']
     self.session._call_method(
         vim_util, "get_dynamic_property", 'fake-host', 'HostSystem',
         'config.network.opaqueNetwork').AndReturn(opaque)
     vif._get_network_ref_from_opaque(
         opaque.HostOpaqueNetworkInfo, CONF.vmware.integration_bridge,
         self.vif['network']['id']).AndReturn('fake-network-ref')
     self.mox.ReplayAll()
     network_ref = vif.get_neutron_network(self.session,
                                           self.vif['network']['id'],
                                           self.cluster, self.vif)
     self.assertEqual(network_ref, 'fake-network-ref')
示例#20
0
 def test_get_neutron_network(self):
     self.mox.StubOutWithMock(vm_util, 'get_host_ref')
     self.mox.StubOutWithMock(self.session, '_call_method')
     self.mox.StubOutWithMock(vif, '_get_network_ref_from_opaque')
     vm_util.get_host_ref(self.session,
             self.cluster).AndReturn('fake-host')
     opaque = fake.DataObject()
     opaque.HostOpaqueNetworkInfo = ['fake-network-info']
     self.session._call_method(vutil, "get_object_property",
              'fake-host', 'config.network.opaqueNetwork').AndReturn(opaque)
     vif._get_network_ref_from_opaque(opaque.HostOpaqueNetworkInfo,
             CONF.vmware.integration_bridge,
             self.vif['network']['id']).AndReturn('fake-network-ref')
     self.mox.ReplayAll()
     network_ref = vif.get_neutron_network(self.session,
                                           self.vif['network']['id'],
                                           self.cluster,
                                           self.vif)
     self.assertEqual(network_ref, 'fake-network-ref')
示例#21
0
def get_network_with_the_name(session, network_name="vmnet0", cluster=None):
    """Gets reference to the network whose name is passed as the
    argument.
    """
    host = vm_util.get_host_ref(session, cluster)
    if cluster is not None:
        vm_networks_ret = session._call_method(vim_util,
                                               "get_dynamic_property", cluster,
                                               "ClusterComputeResource",
                                               "network")
    else:
        vm_networks_ret = session._call_method(vim_util,
                                               "get_dynamic_property", host,
                                               "HostSystem", "network")

    # Meaning there are no networks on the host. suds responds with a ""
    # in the parent property field rather than a [] in the
    # ManagedObjectReference property field of the parent
    if not vm_networks_ret:
        LOG.debug("No networks configured on host!")
        return
    vm_networks = vm_networks_ret.ManagedObjectReference
    network_obj = {}
    LOG.debug("Configured networks: %s", vm_networks)
    for network in vm_networks:
        # Get network properties
        if network._type == 'DistributedVirtualPortgroup':
            props = session._call_method(vim_util,
                                         "get_dynamic_property", network,
                                         "DistributedVirtualPortgroup",
                                         "config")
            # NOTE(asomya): This only works on ESXi if the port binding is
            # set to ephemeral
            # For a VLAN the network name will be the UUID. For a VXLAN
            # network this will have a VXLAN prefix and then the network name.
            if network_name in props.name:
                network_obj['type'] = 'DistributedVirtualPortgroup'
                network_obj['dvpg'] = props.key
                dvs_props = \
                    session._call_method(vim_util,
                                         "get_dynamic_property",
                                         props.distributedVirtualSwitch,
                                         "VmwareDistributedVirtualSwitch",
                                         "uuid")
                network_obj['dvsw'] = dvs_props
        else:
            props = session._call_method(vim_util,
                                         "get_dynamic_property", network,
                                         "Network", "summary.name")
            if props == network_name:
                network_obj['type'] = 'Network'
                network_obj['name'] = network_name
    if (len(network_obj) > 0):
        return network_obj
    LOG.debug("Network %s not found on host!", network_name)
示例#22
0
def get_network_with_the_name(session, network_name="vmnet0", cluster=None):
    """
    Gets reference to the network whose name is passed as the
    argument.
    """
    host = vm_util.get_host_ref(session, cluster)
    if cluster is not None:
        vm_networks_ret = session._call_method(vim_util,
                                               "get_dynamic_property", cluster,
                                               "ClusterComputeResource",
                                               "network")
    else:
        vm_networks_ret = session._call_method(vim_util,
                                               "get_dynamic_property", host,
                                               "HostSystem", "network")

    # Meaning there are no networks on the host. suds responds with a ""
    # in the parent property field rather than a [] in the
    # ManagedObjectReference property field of the parent
    if not vm_networks_ret:
        return None
    vm_networks = vm_networks_ret.ManagedObjectReference
    networks = session._call_method(vim_util,
                       "get_properties_for_a_collection_of_objects",
                       "Network", vm_networks, ["summary.name"])
    network_obj = {}
    LOG.warn(vm_networks)
    for network in vm_networks:
        # Get network properties
        if network._type == 'DistributedVirtualPortgroup':
            props = session._call_method(vim_util,
                        "get_dynamic_property", network,
                        "DistributedVirtualPortgroup", "config")
            # NOTE(asomya): This only works on ESXi if the port binding is
            # set to ephemeral
            if props.name == network_name:
                network_obj['type'] = 'DistributedVirtualPortgroup'
                network_obj['dvpg'] = props.key
                dvs_props = session._call_method(vim_util,
                                "get_dynamic_property",
                                props.distributedVirtualSwitch,
                                "VmwareDistributedVirtualSwitch", "uuid")
                network_obj['dvsw'] = dvs_props
        else:
            props = session._call_method(vim_util,
                        "get_dynamic_property", network,
                        "Network", "summary.name")
            if props == network_name:
                network_obj['type'] = 'Network'
                network_obj['name'] = network_name
    if (len(network_obj) > 0):
        return network_obj
    else:
        return None
示例#23
0
def get_network_with_the_name(session, network_name="vmnet0", cluster=None):
    """
    Gets reference to the network whose name is passed as the
    argument.
    """
    host = vm_util.get_host_ref(session, cluster)
    if cluster is not None:
        vm_networks_ret = session._call_method(vim_util,
                                               "get_dynamic_property", cluster,
                                               "ClusterComputeResource",
                                               "network")
    else:
        vm_networks_ret = session._call_method(vim_util,
                                               "get_dynamic_property", host,
                                               "HostSystem", "network")

    # Meaning there are no networks on the host. suds responds with a ""
    # in the parent property field rather than a [] in the
    # ManagedObjectReference property field of the parent
    if not vm_networks_ret:
        return None
    vm_networks = vm_networks_ret.ManagedObjectReference
    networks = session._call_method(
        vim_util, "get_properties_for_a_collection_of_objects", "Network",
        vm_networks, ["summary.name"])
    network_obj = {}
    LOG.warn(vm_networks)
    for network in vm_networks:
        # Get network properties
        if network._type == 'DistributedVirtualPortgroup':
            props = session._call_method(vim_util, "get_dynamic_property",
                                         network,
                                         "DistributedVirtualPortgroup",
                                         "config")
            # NOTE(asomya): This only works on ESXi if the port binding is
            # set to ephemeral
            if props.name == network_name:
                network_obj['type'] = 'DistributedVirtualPortgroup'
                network_obj['dvpg'] = props.key
                dvs_props = session._call_method(
                    vim_util, "get_dynamic_property",
                    props.distributedVirtualSwitch,
                    "VmwareDistributedVirtualSwitch", "uuid")
                network_obj['dvsw'] = dvs_props
        else:
            props = session._call_method(vim_util, "get_dynamic_property",
                                         network, "Network", "summary.name")
            if props == network_name:
                network_obj['type'] = 'Network'
                network_obj['name'] = network_name
    if (len(network_obj) > 0):
        return network_obj
    else:
        return None
示例#24
0
def get_network_with_the_name(session, network_name="vmnet0", cluster=None):
    """Gets reference to the network whose name is passed as the
    argument.
    """
    host = vm_util.get_host_ref(session, cluster)
    if cluster is not None:
        vm_networks_ret = session._call_method(vim_util,
                                               "get_dynamic_property", cluster,
                                               "ClusterComputeResource",
                                               "network")
    else:
        vm_networks_ret = session._call_method(vim_util,
                                               "get_dynamic_property", host,
                                               "HostSystem", "network")

    # Meaning there are no networks on the host. suds responds with a ""
    # in the parent property field rather than a [] in the
    # ManagedObjectReference property field of the parent
    if not vm_networks_ret:
        LOG.debug("No networks configured on host!")
        return
    vm_networks = vm_networks_ret.ManagedObjectReference
    network_obj = {}
    LOG.debug("Configured networks: %s", vm_networks)
    for network in vm_networks:
        # Get network properties
        if network._type == 'DistributedVirtualPortgroup':
            props = session._call_method(vim_util, "get_dynamic_property",
                                         network,
                                         "DistributedVirtualPortgroup",
                                         "config")
            # NOTE(asomya): This only works on ESXi if the port binding is
            # set to ephemeral
            # For a VLAN the network name will be the UUID. For a VXLAN
            # network this will have a VXLAN prefix and then the network name.
            if network_name in props.name:
                network_obj['type'] = 'DistributedVirtualPortgroup'
                network_obj['dvpg'] = props.key
                dvs_props = \
                    session._call_method(vim_util,
                                         "get_dynamic_property",
                                         props.distributedVirtualSwitch,
                                         "VmwareDistributedVirtualSwitch",
                                         "uuid")
                network_obj['dvsw'] = dvs_props
        else:
            props = session._call_method(vim_util, "get_dynamic_property",
                                         network, "Network", "summary.name")
            if props == network_name:
                network_obj['type'] = 'Network'
                network_obj['name'] = network_name
    if (len(network_obj) > 0):
        return network_obj
    LOG.debug("Network %s not found on host!", network_name)
示例#25
0
def check_if_vlan_interface_exists(session, vlan_interface, cluster=None):
    """Checks if the vlan_interface exists on the esx host."""
    host_mor = vm_util.get_host_ref(session, cluster)
    physical_nics_ret = session._call_method(vutil, "get_object_property",
                                             host_mor, "config.network.pnic")
    # Meaning there are no physical nics on the host
    if not physical_nics_ret:
        return False
    physical_nics = physical_nics_ret.PhysicalNic
    for pnic in physical_nics:
        if vlan_interface == pnic.device:
            return True
    return False
示例#26
0
 def host_power_action(self, host, action):
     """Reboots or shuts down the host."""
     host_mor = vm_util.get_host_ref(self._session)
     LOG.debug(_("%(action)s %(host)s"), {"action": action, "host": host})
     if action == "reboot":
         host_task = self._session._call_method(self._session._get_vim(), "RebootHost_Task", host_mor, force=False)
     elif action == "shutdown":
         host_task = self._session._call_method(self._session._get_vim(), "ShutdownHost_Task", host_mor, force=False)
     elif action == "startup":
         host_task = self._session._call_method(
             self._session._get_vim(), "PowerUpHostFromStandBy_Task", host_mor, timeoutSec=60
         )
     self._session._wait_for_task(host_task)
示例#27
0
def check_if_vlan_interface_exists(session, vlan_interface, cluster=None):
    """Checks if the vlan_interface exists on the esx host."""
    host_mor = vm_util.get_host_ref(session, cluster)
    physical_nics_ret = session._call_method(vim_util,
                "get_dynamic_property", host_mor,
                "HostSystem", "config.network.pnic")
    # Meaning there are no physical nics on the host
    if not physical_nics_ret:
        return False
    physical_nics = physical_nics_ret.PhysicalNic
    for pnic in physical_nics:
        if vlan_interface == pnic.device:
            return True
    return False
示例#28
0
 def remove_port_group(self, name):
     session = self._session
     host_mor = vm_util.get_host_ref(session)
     network_system_mor = session._call_method(vim_util,
                                               "get_dynamic_property",
                                               host_mor,
                                               "HostSystem",
                                               "configManager.networkSystem")
     try:
         session._call_method(session._get_vim(),
                              "RemovePortGroup", network_system_mor,
                              pgName=name) 
     except error_util.VimFaultException as exc:
         pass
示例#29
0
def get_vlanid_and_vswitch_for_portgroup(session, pg_name, cluster=None):
    """Get the vlan id and vswicth associated with the port group."""
    host_mor = vm_util.get_host_ref(session, cluster)
    port_grps_on_host_ret = session._call_method(
        vim_util, "get_dynamic_property", host_mor, "HostSystem", "config.network.portgroup"
    )
    if not port_grps_on_host_ret:
        msg = _("ESX SOAP server returned an empty port group " "for the host system in its response")
        LOG.error(msg)
        raise exception.NovaException(msg)
    port_grps_on_host = port_grps_on_host_ret.HostPortGroup
    for p_gp in port_grps_on_host:
        if p_gp.spec.name == pg_name:
            p_grp_vswitch_name = p_gp.vswitch.split("-")[-1]
            return p_gp.spec.vlanId, p_grp_vswitch_name
示例#30
0
    def _init_vlans(self, esx_session):
        session = esx_session
        host_mor = vm_util.get_host_ref(session)
        port_grps_on_host_ret = session._call_method(vim_util,
                                                     "get_dynamic_property",
                                                     host_mor,
                                                     "HostSystem",
                                                     "config.network.portgroup")
        if not port_grps_on_host_ret:
            return

        port_grps_on_host = port_grps_on_host_ret.HostPortGroup
        for p_gp in port_grps_on_host:
            if p_gp.spec.vlanId >= 0:
                self._vlan_id_bits[p_gp.spec.vlanId] = 1
示例#31
0
 def host_maintenance_mode(self, host, mode):
     """Start/Stop host maintenance window. On start, it triggers
     guest VMs evacuation.
     """
     host_mor = vm_util.get_host_ref(self._session)
     LOG.debug(_("Set maintenance mod on %(host)s to %(mode)s"), {"host": host, "mode": mode})
     if mode:
         host_task = self._session._call_method(
             self._session._get_vim(), "EnterMaintenanceMode_Task", host_mor, timeout=0, evacuatePoweredOffVms=True
         )
     else:
         host_task = self._session._call_method(
             self._session._get_vim(), "ExitMaintenanceMode_Task", host_mor, timeout=0
         )
     self._session._wait_for_task(host_task)
示例#32
0
文件: volume_util.py 项目: CLisa/nova
def get_host_iqn(session, cluster=None):
    """Return the host iSCSI IQN."""
    host_mor = vm_util.get_host_ref(session, cluster)
    hbas_ret = session._call_method(vim_util, "get_dynamic_property",
                                    host_mor, "HostSystem",
                                    "config.storageDevice.hostBusAdapter")

    # Meaning there are no host bus adapters on the host
    if hbas_ret is None:
        return
    host_hbas = hbas_ret.HostHostBusAdapter
    if not host_hbas:
        return
    for hba in host_hbas:
        if hba.__class__.__name__ == 'HostInternetScsiHba':
            return hba.iScsiName
示例#33
0
def get_vlanid_and_vswitch_for_portgroup(session, pg_name, cluster=None):
    """Get the vlan id and vswicth associated with the port group."""
    host_mor = vm_util.get_host_ref(session, cluster)
    port_grps_on_host_ret = session._call_method(vim_util,
                "get_dynamic_property", host_mor,
                "HostSystem", "config.network.portgroup")
    if not port_grps_on_host_ret:
        msg = _("ESX SOAP server returned an empty port group "
                "for the host system in its response")
        LOG.error(msg)
        raise exception.NovaException(msg)
    port_grps_on_host = port_grps_on_host_ret.HostPortGroup
    for p_gp in port_grps_on_host:
        if p_gp.spec.name == pg_name:
            p_grp_vswitch_name = p_gp.vswitch.split("-")[-1]
            return p_gp.spec.vlanId, p_grp_vswitch_name
示例#34
0
    def _iscsi_get_host_iqn(self):
        """Return the host iSCSI IQN."""
        host_mor = vm_util.get_host_ref(self._session, self._cluster)
        hbas_ret = self._session._call_method(
            vim_util, "get_dynamic_property", host_mor, "HostSystem",
            "config.storageDevice.hostBusAdapter")

        # Meaning there are no host bus adapters on the host
        if hbas_ret is None:
            return
        host_hbas = hbas_ret.HostHostBusAdapter
        if not host_hbas:
            return
        for hba in host_hbas:
            if hba.__class__.__name__ == 'HostInternetScsiHba':
                return hba.iScsiName
示例#35
0
文件: host.py 项目: noorul/nova
    def update_status(self):
        """Update the current state of the host.
        """
        host_mor = vm_util.get_host_ref(self._session, self._cluster)
        if host_mor is None:
            return

        summary = self._session._call_method(vim_util,
                                             "get_dynamic_property",
                                             host_mor,
                                             "HostSystem",
                                             "summary")

        if summary is None:
            return

        try:
            ds = vm_util.get_datastore_ref_and_name(self._session,
                                                    self._cluster)
        except exception.DatastoreNotFound:
            ds = (None, None, 0, 0)

        data = {}
        data["vcpus"] = summary.hardware.numCpuThreads
        data["cpu_info"] =\
        {"vendor": summary.hardware.vendor,
         "model": summary.hardware.cpuModel,
         "topology": {"cores": summary.hardware.numCpuCores,
                      "sockets": summary.hardware.numCpuPkgs,
                      "threads": summary.hardware.numCpuThreads}
        }
        data["disk_total"] = ds[2] / (1024 * 1024 * 1024)
        data["disk_available"] = ds[3] / (1024 * 1024 * 1024)
        data["disk_used"] = data["disk_total"] - data["disk_available"]
        data["host_memory_total"] = summary.hardware.memorySize / (1024 * 1024)
        data["host_memory_free"] = data["host_memory_total"] -\
                                   summary.quickStats.overallMemoryUsage
        data["hypervisor_type"] = summary.config.product.name
        data["hypervisor_version"] = summary.config.product.version
        data["hypervisor_hostname"] = self._host_name
        data["supported_instances"] = [('i686', 'vmware', 'hvm'),
                                       ('x86_64', 'vmware', 'hvm')]

        self._stats = data
        return data
示例#36
0
文件: host.py 项目: JacobMulero/nova
    def update_status(self):
        """Update the current state of the host.
        """
        host_mor = vm_util.get_host_ref(self._session, self._cluster)
        if host_mor is None:
            return

        summary = self._session._call_method(vim_util,
                                             "get_dynamic_property",
                                             host_mor,
                                             "HostSystem",
                                             "summary")

        if summary is None:
            return

        try:
            ds = vm_util.get_datastore_ref_and_name(self._session,
                                                    self._cluster)
        except exception.DatastoreNotFound:
            ds = (None, None, 0, 0)

        data = {}
        data["vcpus"] = summary.hardware.numCpuThreads
        data["cpu_info"] =\
        {"vendor": summary.hardware.vendor,
         "model": summary.hardware.cpuModel,
         "topology": {"cores": summary.hardware.numCpuCores,
                      "sockets": summary.hardware.numCpuPkgs,
                      "threads": summary.hardware.numCpuThreads}
        }
        data["disk_total"] = ds[2] / (1024 * 1024)
        data["disk_available"] = ds[3] / (1024 * 1024)
        data["disk_used"] = data["disk_total"] - data["disk_available"]
        data["host_memory_total"] = summary.hardware.memorySize / (1024 * 1024)
        data["host_memory_free"] = data["host_memory_total"] -\
                                   summary.quickStats.overallMemoryUsage
        data["hypervisor_type"] = summary.config.product.name
        data["hypervisor_version"] = summary.config.product.version
        data["hypervisor_hostname"] = self._host_name
        data["supported_instances"] = [('i686', 'vmware', 'hvm'),
                                       ('x86_64', 'vmware', 'hvm')]

        self._stats = data
        return data
示例#37
0
 def host_maintenance_mode(self, host, mode):
     """Start/Stop host maintenance window. On start, it triggers
     guest VMs evacuation.
     """
     host_mor = vm_util.get_host_ref(self._session)
     LOG.debug(_("Set maintenance mod on %(host)s to %(mode)s"),
               {'host': host, 'mode': mode})
     if mode:
         host_task = self._session._call_method(
                                 self._session._get_vim(),
                                 "EnterMaintenanceMode_Task",
                                 host_mor, timeout=0,
                                 evacuatePoweredOffVms=True)
     else:
         host_task = self._session._call_method(
                                 self._session._get_vim(),
                                 "ExitMaintenanceMode_Task",
                                 host_mor, timeout=0)
     self._session._wait_for_task(host, host_task)
示例#38
0
 def host_power_action(self, host, action):
     """Reboots or shuts down the host."""
     host_mor = vm_util.get_host_ref(self._session)
     LOG.debug(_("%(action)s %(host)s"), {'action': action, 'host': host})
     if action == "reboot":
         host_task = self._session._call_method(
                                 self._session._get_vim(),
                                 "RebootHost_Task", host_mor,
                                 force=False)
     elif action == "shutdown":
         host_task = self._session._call_method(
                                 self._session._get_vim(),
                                 "ShutdownHost_Task", host_mor,
                                 force=False)
     elif action == "startup":
         host_task = self._session._call_method(
                                 self._session._get_vim(),
                                 "PowerUpHostFromStandBy_Task", host_mor,
                                 timeoutSec=60)
     self._session._wait_for_task(host, host_task)
示例#39
0
文件: vif.py 项目: 674009287/nova
def get_neutron_network(session, network_name, cluster, vif):
    host = vm_util.get_host_ref(session, cluster)
    try:
        opaque = session._call_method(vim_util, "get_dynamic_property", host,
                                      "HostSystem",
                                      "config.network.opaqueNetwork")
    except error_util.VimFaultException:
        opaque = None
    if opaque:
        bridge = vif['network']['id']
        opaque_networks = opaque.HostOpaqueNetworkInfo
        network_ref = _get_network_ref_from_opaque(opaque_networks,
                CONF.vmware.integration_bridge, bridge)
    else:
        bridge = network_name
        network_ref = network_util.get_network_with_the_name(
                session, network_name, cluster)
    if not network_ref:
        raise exception.NetworkNotFoundForBridge(bridge=bridge)
    return network_ref
示例#40
0
    def _iscsi_get_host_iqn(self, instance):
        """Return the host iSCSI IQN."""
        try:
            host_mor = vm_util.get_host_ref_for_vm(self._session, instance)
        except exception.InstanceNotFound:
            host_mor = vm_util.get_host_ref(self._session, self._cluster)

        hbas_ret = self._session._call_method(
            vutil, "get_object_property", host_mor, "config.storageDevice.hostBusAdapter"
        )

        # Meaning there are no host bus adapters on the host
        if hbas_ret is None:
            return
        host_hbas = hbas_ret.HostHostBusAdapter
        if not host_hbas:
            return
        for hba in host_hbas:
            if hba.__class__.__name__ == "HostInternetScsiHba":
                return hba.iScsiName
示例#41
0
    def _iscsi_get_host_iqn(self, instance):
        """Return the host iSCSI IQN."""
        try:
            host_mor = vm_util.get_host_ref_for_vm(self._session, instance)
        except exception.InstanceNotFound:
            host_mor = vm_util.get_host_ref(self._session, self._cluster)

        hbas_ret = self._session._call_method(
            vutil, "get_object_property", host_mor,
            "config.storageDevice.hostBusAdapter")

        # Meaning there are no host bus adapters on the host
        if hbas_ret is None:
            return
        host_hbas = hbas_ret.HostHostBusAdapter
        if not host_hbas:
            return
        for hba in host_hbas:
            if hba.__class__.__name__ == 'HostInternetScsiHba':
                return hba.iScsiName
示例#42
0
def get_neutron_network(session, network_name, cluster, vif):
    host = vm_util.get_host_ref(session, cluster)
    try:
        opaque = session._call_method(vim_util, "get_dynamic_property", host,
                                      "HostSystem",
                                      "config.network.opaqueNetwork")
    except error_util.InvalidPropertyException:
        opaque = None
    if opaque:
        bridge = vif['network']['id']
        opaque_networks = opaque.HostOpaqueNetworkInfo
        network_ref = _get_network_ref_from_opaque(
            opaque_networks, CONF.vmware.integration_bridge, bridge)
    else:
        bridge = network_name
        network_ref = network_util.get_network_with_the_name(
            session, network_name, cluster)
    if not network_ref:
        raise exception.NetworkNotFoundForBridge(bridge=bridge)
    return network_ref
示例#43
0
文件: host.py 项目: NexusIS/nova
    def update_status(self):
        """Update the current state of the host.
        """
        host_mor = vm_util.get_host_ref(self._session)
        summary = self._session._call_method(vim_util,
                                             "get_dynamic_property",
                                             host_mor,
                                             "HostSystem",
                                             "summary")

        if summary is None:
            return

        capacity, freespace = _get_ds_capacity_and_freespace(self._session)

        data = {}
        data["vcpus"] = summary.hardware.numCpuThreads
        data["cpu_info"] = \
                {"vendor": summary.hardware.vendor,
                 "model": summary.hardware.cpuModel,
                 "topology": {"cores": summary.hardware.numCpuCores,
                              "sockets": summary.hardware.numCpuPkgs,
                              "threads": summary.hardware.numCpuThreads}
                }
        data["disk_total"] = capacity / units.Gi
        data["disk_available"] = freespace / units.Gi
        data["disk_used"] = data["disk_total"] - data["disk_available"]
        data["host_memory_total"] = summary.hardware.memorySize / units.Mi
        data["host_memory_free"] = data["host_memory_total"] - \
                                   summary.quickStats.overallMemoryUsage
        data["hypervisor_type"] = summary.config.product.name
        data["hypervisor_version"] = utils.convert_version_to_int(
                str(summary.config.product.version))
        data["hypervisor_hostname"] = self._host_name
        data["supported_instances"] = [
            (arch.I686, hvtype.VMWARE, 'hvm'),
            (arch.X86_64, hvtype.VMWARE, 'hvm')]

        self._stats = data
        return data
示例#44
0
    def update_status(self):
        """Update the current state of the host.
        """
        host_mor = vm_util.get_host_ref(self._session)
        summary = self._session._call_method(vim_util,
                                             "get_dynamic_property",
                                             host_mor,
                                             "HostSystem",
                                             "summary")

        if summary is None:
            return

        capacity, freespace = _get_ds_capacity_and_freespace(self._session)

        data = {}
        data["vcpus"] = summary.hardware.numCpuThreads
        data["cpu_info"] = \
                {"vendor": summary.hardware.vendor,
                 "model": summary.hardware.cpuModel,
                 "topology": {"cores": summary.hardware.numCpuCores,
                              "sockets": summary.hardware.numCpuPkgs,
                              "threads": summary.hardware.numCpuThreads}
                }
        data["disk_total"] = capacity / units.Gi
        data["disk_available"] = freespace / units.Gi
        data["disk_used"] = data["disk_total"] - data["disk_available"]
        data["host_memory_total"] = summary.hardware.memorySize / units.Mi
        data["host_memory_free"] = data["host_memory_total"] - \
                                   summary.quickStats.overallMemoryUsage
        data["hypervisor_type"] = summary.config.product.name
        data["hypervisor_version"] = utils.convert_version_to_int(
                str(summary.config.product.version))
        data["hypervisor_hostname"] = self._host_name
        data["supported_instances"] = [
            (arch.I686, hvtype.VMWARE, vm_mode.HVM),
            (arch.X86_64, hvtype.VMWARE, vm_mode.HVM)]

        self._stats = data
        return data
示例#45
0
    def update_status(self):
        """Update the current state of the host.
        """
        host_mor = vm_util.get_host_ref(self._session)
        summary = self._session._call_method(vim_util, "get_dynamic_property", host_mor, "HostSystem", "summary")

        if summary is None:
            return

        try:
            ds = vm_util.get_datastore_ref_and_name(self._session)
        except exception.DatastoreNotFound:
            ds = (None, None, 0, 0)

        data = {}
        data["vcpus"] = summary.hardware.numCpuThreads
        data["cpu_info"] = {
            "vendor": summary.hardware.vendor,
            "model": summary.hardware.cpuModel,
            "topology": {
                "cores": summary.hardware.numCpuCores,
                "sockets": summary.hardware.numCpuPkgs,
                "threads": summary.hardware.numCpuThreads,
            },
        }
        data["disk_total"] = ds[2] / units.Gi
        data["disk_available"] = ds[3] / units.Gi
        data["disk_used"] = data["disk_total"] - data["disk_available"]
        data["host_memory_total"] = summary.hardware.memorySize / units.Mi
        data["host_memory_free"] = data["host_memory_total"] - summary.quickStats.overallMemoryUsage
        data["hypervisor_type"] = summary.config.product.name
        data["hypervisor_version"] = utils.convert_version_to_int(str(summary.config.product.version))
        data["hypervisor_hostname"] = self._host_name
        data["supported_instances"] = [("i686", "vmware", "hvm"), ("x86_64", "vmware", "hvm")]

        self._stats = data
        return data
示例#46
0
    def _iscsi_get_target(self, data):
        """Return the iSCSI Target given a volume info."""
        target_portal = data['target_portal']
        target_iqn = data['target_iqn']
        host_mor = vm_util.get_host_ref(self._session, self._cluster)

        lst_properties = ["config.storageDevice.hostBusAdapter",
                          "config.storageDevice.scsiTopology",
                          "config.storageDevice.scsiLun"]
        prop_dict = self._session._call_method(
            vim_util, "get_dynamic_properties",
            host_mor, "HostSystem", lst_properties)
        result = (None, None)
        hbas_ret = None
        scsi_topology = None
        scsi_lun_ret = None
        if prop_dict:
            hbas_ret = prop_dict.get('config.storageDevice.hostBusAdapter')
            scsi_topology = prop_dict.get('config.storageDevice.scsiTopology')
            scsi_lun_ret = prop_dict.get('config.storageDevice.scsiLun')

        # Meaning there are no host bus adapters on the host
        if hbas_ret is None:
            return result
        host_hbas = hbas_ret.HostHostBusAdapter
        if not host_hbas:
            return result
        for hba in host_hbas:
            if hba.__class__.__name__ == 'HostInternetScsiHba':
                hba_key = hba.key
                break
        else:
            return result

        if scsi_topology is None:
            return result
        host_adapters = scsi_topology.adapter
        if not host_adapters:
            return result
        scsi_lun_key = None
        for adapter in host_adapters:
            if adapter.adapter == hba_key:
                if not getattr(adapter, 'target', None):
                    return result
                for target in adapter.target:
                    if (getattr(target.transport, 'address', None) and
                        target.transport.address[0] == target_portal and
                            target.transport.iScsiName == target_iqn):
                        if not target.lun:
                            return result
                        for lun in target.lun:
                            if 'host.ScsiDisk' in lun.scsiLun:
                                scsi_lun_key = lun.scsiLun
                                break
                        break
                break

        if scsi_lun_key is None:
            return result

        if scsi_lun_ret is None:
            return result
        host_scsi_luns = scsi_lun_ret.ScsiLun
        if not host_scsi_luns:
            return result
        for scsi_lun in host_scsi_luns:
            if scsi_lun.key == scsi_lun_key:
                return (scsi_lun.deviceName, scsi_lun.uuid)

        return result
示例#47
0
    def _iscsi_get_target(self, data):
        """Return the iSCSI Target given a volume info."""
        target_portal = data['target_portal']
        target_iqn = data['target_iqn']
        host_mor = vm_util.get_host_ref(self._session, self._cluster)

        lst_properties = ["config.storageDevice.hostBusAdapter",
                          "config.storageDevice.scsiTopology",
                          "config.storageDevice.scsiLun"]
        prop_dict = self._session._call_method(
            vim_util, "get_dynamic_properties",
            host_mor, "HostSystem", lst_properties)
        result = (None, None)
        hbas_ret = None
        scsi_topology = None
        scsi_lun_ret = None
        if prop_dict:
            hbas_ret = prop_dict.get('config.storageDevice.hostBusAdapter')
            scsi_topology = prop_dict.get('config.storageDevice.scsiTopology')
            scsi_lun_ret = prop_dict.get('config.storageDevice.scsiLun')

        # Meaning there are no host bus adapters on the host
        if hbas_ret is None:
            return result
        host_hbas = hbas_ret.HostHostBusAdapter
        if not host_hbas:
            return result
        for hba in host_hbas:
            if hba.__class__.__name__ == 'HostInternetScsiHba':
                hba_key = hba.key
                break
        else:
            return result

        if scsi_topology is None:
            return result
        host_adapters = scsi_topology.adapter
        if not host_adapters:
            return result
        scsi_lun_key = None
        for adapter in host_adapters:
            if adapter.adapter == hba_key:
                if not getattr(adapter, 'target', None):
                    return result
                for target in adapter.target:
                    if (getattr(target.transport, 'address', None) and
                        target.transport.address[0] == target_portal and
                            target.transport.iScsiName == target_iqn):
                        if not target.lun:
                            return result
                        for lun in target.lun:
                            if 'host.ScsiDisk' in lun.scsiLun:
                                scsi_lun_key = lun.scsiLun
                                break
                        break
                break

        if scsi_lun_key is None:
            return result

        if scsi_lun_ret is None:
            return result
        host_scsi_luns = scsi_lun_ret.ScsiLun
        if not host_scsi_luns:
            return result
        for scsi_lun in host_scsi_luns:
            if scsi_lun.key == scsi_lun_key:
                return (scsi_lun.deviceName, scsi_lun.uuid)

        return result