Пример #1
0
def ensure_vlan_bridge(session, vif, cluster=None, create_vlan=True):
    """Create a vlan and bridge unless they already exist."""
    vlan_num = vif["network"].get_meta("vlan")
    bridge = vif["network"]["bridge"]
    vlan_interface = CONF.vmware.vlan_interface

    network_ref = network_util.get_network_with_the_name(session, bridge, cluster)
    if network_ref and network_ref["type"] == "DistributedVirtualPortgroup":
        return network_ref

    if not network_ref:
        # Create a port group on the vSwitch associated with the
        # vlan_interface corresponding physical network adapter on the ESX
        # host.
        vswitch_associated = _get_associated_vswitch_for_interface(session, vlan_interface, cluster)
        network_util.create_port_group(session, bridge, vswitch_associated, vlan_num if create_vlan else 0, cluster)
        network_ref = network_util.get_network_with_the_name(session, bridge, cluster)
    elif create_vlan:
        # Get the vSwitch associated with the Physical Adapter
        vswitch_associated = _get_associated_vswitch_for_interface(session, vlan_interface, cluster)
        # Get the vlan id and vswitch corresponding to the port group
        _get_pg_info = network_util.get_vlanid_and_vswitch_for_portgroup
        pg_vlanid, pg_vswitch = _get_pg_info(session, bridge, cluster)

        # Check if the vswitch associated is proper
        if pg_vswitch != vswitch_associated:
            raise exception.InvalidVLANPortGroup(bridge=bridge, expected=vswitch_associated, actual=pg_vswitch)

        # Check if the vlan id is proper for the port group
        if pg_vlanid != vlan_num:
            raise exception.InvalidVLANTag(bridge=bridge, tag=vlan_num, pgroup=pg_vlanid)
    return network_ref
def _get_neutron_network(session, cluster, vif):
    if vif['type'] == model.VIF_TYPE_OVS:
        _check_ovs_supported_version(session)

        # Check if this is the NSX-MH plugin is used
        if CONF.vmware.integration_bridge:
            network_id = CONF.vmware.integration_bridge
            network_ref = None  # Not supported with Nuage
        else:
            network_id = vif['network']['bridge']
            network_ref = network_util.get_network_with_the_name(
                session, network_id, cluster)
        if not network_ref:
            raise exception.NetworkNotFoundForBridge(bridge=network_id)

    elif vif['type'] == model.VIF_TYPE_DVS:
        network_id = vif['network']['bridge']
        network_ref = network_util.get_network_with_the_name(
            session, network_id, cluster)
        if not network_ref:
            raise exception.NetworkNotFoundForBridge(bridge=network_id)
    else:
        reason = _('vif type %s not supported') % vif['type']
        raise exception.InvalidInput(reason=reason)
    return network_ref
Пример #3
0
def _get_neutron_network(session, cluster, vif):
    if vif['type'] == model.VIF_TYPE_OVS:
        _check_ovs_supported_version(session)
        # Check if this is the NSX-MH plugin is used
        if CONF.vmware.integration_bridge:
            net_id = CONF.vmware.integration_bridge
            use_external_id = False
            network_type = 'opaque'
        else:
            # The NSX|V3 plugin will pass the nsx-logical-switch-id as part
            # of the port details. This will enable the VC to connect to
            # that specific opaque network
            net_id = (vif.get('details')
                      and vif['details'].get('nsx-logical-switch-id'))
            if not net_id:
                # Make use of the original one, in the event that the
                # plugin does not pass the aforementioned id
                LOG.info('NSX Logical switch ID is not present. '
                         'Using network ID to attach to the '
                         'opaque network.')
                net_id = vif['network']['id']
            use_external_id = True
            network_type = 'nsx.LogicalSwitch'
        network_ref = {
            'type': 'OpaqueNetwork',
            'network-id': net_id,
            'network-type': network_type,
            'use-external-id': use_external_id
        }
    elif vif['type'] == model.VIF_TYPE_DVS:
        # Port binding for DVS VIF types may pass the name
        # of the port group, so use it if present
        network_id = vif.get('details', {}).get('dvs_port_group_name')
        if network_id is None:
            # Make use of the original one, in the event that the
            # port binding does not provide this key in VIF details
            network_id = vif['network']['bridge']
        network_ref = network_util.get_network_with_the_name(
            session, network_id, cluster)
        if not network_ref:
            # We may have a provider network for a portgroup. The portgroup
            # will have the same name as the network 'label'. This is enforced
            # when the provider network is created
            network_id = vif['network']['label']
            network_ref = network_util.get_network_with_the_name(
                session, network_id, cluster)
        if not network_ref:
            raise exception.NetworkNotFoundForBridge(bridge=network_id)
        if vif.get('details') and vif['details'].get('dvs_port_key'):
            network_ref['dvs_port_key'] = vif['details']['dvs_port_key']
    else:
        reason = _('vif type %s not supported') % vif['type']
        raise exception.InvalidInput(reason=reason)
    return network_ref
Пример #4
0
 def test_ensure_vlan_bridge_with_network(self):
     self.mox.StubOutWithMock(network_util, 'get_network_with_the_name')
     self.mox.StubOutWithMock(network_util,
                              'get_vswitch_for_vlan_interface')
     self.mox.StubOutWithMock(network_util,
                              'check_if_vlan_interface_exists')
     self.mox.StubOutWithMock(network_util, 'create_port_group')
     vm_network = {'name': 'VM Network', 'type': 'Network'}
     network_util.get_network_with_the_name(
         self.session, 'fa0', self.cluster).AndReturn(vm_network)
     self.mox.ReplayAll()
     vif.ensure_vlan_bridge(self.session, self.vif, create_vlan=False)
 def test_ensure_vlan_bridge_with_network(self):
     self.mox.StubOutWithMock(network_util, 'get_network_with_the_name')
     self.mox.StubOutWithMock(network_util,
         'get_vswitch_for_vlan_interface')
     self.mox.StubOutWithMock(network_util,
         'check_if_vlan_interface_exists')
     self.mox.StubOutWithMock(network_util, 'create_port_group')
     vm_network = {'name': 'VM Network', 'type': 'Network'}
     network_util.get_network_with_the_name(self.session, 'fa0',
         self.cluster).AndReturn(vm_network)
     self.mox.ReplayAll()
     vif.ensure_vlan_bridge(self.session, self.vif, create_vlan=False)
Пример #6
0
    def test_ensure_vlan_bridge_without_vlan(self):
        self.mox.StubOutWithMock(network_util, "get_network_with_the_name")
        self.mox.StubOutWithMock(network_util, "get_vswitch_for_vlan_interface")
        self.mox.StubOutWithMock(network_util, "check_if_vlan_interface_exists")
        self.mox.StubOutWithMock(network_util, "create_port_group")

        network_util.get_network_with_the_name(self.session, "fa0", self.cluster).AndReturn(None)
        network_util.get_vswitch_for_vlan_interface(self.session, "vmnet0", self.cluster).AndReturn("vmnet0")
        network_util.check_if_vlan_interface_exists(self.session, "vmnet0", self.cluster).AndReturn(True)
        network_util.create_port_group(self.session, "fa0", "vmnet0", 0, self.cluster)
        self.mox.ReplayAll()
        vif.ensure_vlan_bridge(self.session, self.vif, create_vlan=False)
Пример #7
0
def _get_neutron_network(session, cluster, vif):
    if vif['type'] == model.VIF_TYPE_OVS:
        _check_ovs_supported_version(session)
        # Check if this is the NSX-MH plugin is used
        if CONF.vmware.integration_bridge:
            net_id = CONF.vmware.integration_bridge
            use_external_id = False
            network_type = 'opaque'
        else:
            # The NSX|V3 plugin will pass the nsx-logical-switch-id as part
            # of the port details. This will enable the VC to connect to
            # that specific opaque network
            net_id = (vif.get('details') and
                      vif['details'].get('nsx-logical-switch-id'))
            if not net_id:
                # Make use of the original one, in the event that the
                # plugin does not pass the aforementioned id
                LOG.info('NSX Logical switch ID is not present. '
                         'Using network ID to attach to the '
                         'opaque network.')
                net_id = vif['network']['id']
            use_external_id = True
            network_type = 'nsx.LogicalSwitch'
        network_ref = {'type': 'OpaqueNetwork',
                       'network-id': net_id,
                       'network-type': network_type,
                       'use-external-id': use_external_id}
    elif vif['type'] == model.VIF_TYPE_DVS:
        # Port binding for DVS VIF types may pass the name
        # of the port group, so use it if present
        network_id = vif.get('details', {}).get('dvs_port_group_name')
        if network_id is None:
            # Make use of the original one, in the event that the
            # port binding does not provide this key in VIF details
            network_id = vif['network']['bridge']
        network_ref = network_util.get_network_with_the_name(
                session, network_id, cluster)
        if not network_ref:
            # We may have a provider network for a portgroup. The portgroup
            # will have the same name as the network 'label'. This is enforced
            # when the provider network is created
            network_id = vif['network']['label']
            network_ref = network_util.get_network_with_the_name(
                    session, network_id, cluster)
        if not network_ref:
            raise exception.NetworkNotFoundForBridge(bridge=network_id)
        if vif.get('details') and vif['details'].get('dvs_port_key'):
            network_ref['dvs_port_key'] = vif['details']['dvs_port_key']
    else:
        reason = _('vif type %s not supported') % vif['type']
        raise exception.InvalidInput(reason=reason)
    return network_ref
Пример #8
0
Файл: vif.py Проект: bclau/nova
def ensure_vlan_bridge(session, vif, cluster=None, create_vlan=True):
    """Create a vlan and bridge unless they already exist."""
    vlan_num = vif['network'].get_meta('vlan')
    bridge = vif['network']['bridge']
    vlan_interface = CONF.vmware.vlan_interface

    network_ref = network_util.get_network_with_the_name(session, bridge,
                                                         cluster)
    if network_ref and network_ref['type'] == 'DistributedVirtualPortgroup':
        return network_ref

    # Get the vSwitch associated with the Physical Adapter
    vswitch_associated = network_util.get_vswitch_for_vlan_interface(
                                    session, vlan_interface, cluster)
    if vswitch_associated is None:
        raise exception.SwitchNotFoundForNetworkAdapter(
            adapter=vlan_interface)
    # Check if the vlan_interface physical network adapter exists on the
    # host.
    if not network_util.check_if_vlan_interface_exists(session,
                                        vlan_interface, cluster):
        raise exception.NetworkAdapterNotFound(adapter=vlan_interface)

    if network_ref is None:
        # Create a port group on the vSwitch associated with the
        # vlan_interface corresponding physical network adapter on the ESX
        # host.
        network_util.create_port_group(session, bridge,
                                       vswitch_associated,
                                       vlan_num if create_vlan else 0,
                                       cluster)
        network_ref = network_util.get_network_with_the_name(session,
                                                             bridge,
                                                             cluster)
    elif create_vlan:
        # Get the vlan id and vswitch corresponding to the port group
        _get_pg_info = network_util.get_vlanid_and_vswitch_for_portgroup
        pg_vlanid, pg_vswitch = _get_pg_info(session, bridge, cluster)

        # Check if the vswitch associated is proper
        if pg_vswitch != vswitch_associated:
            raise exception.InvalidVLANPortGroup(
                bridge=bridge, expected=vswitch_associated,
                actual=pg_vswitch)

        # Check if the vlan id is proper for the port group
        if pg_vlanid != vlan_num:
            raise exception.InvalidVLANTag(bridge=bridge, tag=vlan_num,
                                       pgroup=pg_vlanid)
    return network_ref
Пример #9
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.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
Пример #10
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
Пример #11
0
def _get_neutron_network(session, cluster, vif):
    if vif['type'] == model.VIF_TYPE_OVS:
        _check_ovs_supported_version(session)
        # Check if this is the NSX-MH plugin is used
        if CONF.vmware.integration_bridge:
            net_id = CONF.vmware.integration_bridge
            use_external_id = False
            network_type = 'opaque'
        else:
            net_id = vif['network']['id']
            use_external_id = True
            network_type = 'nsx.LogicalSwitch'
        network_ref = {
            'type': 'OpaqueNetwork',
            'network-id': net_id,
            'network-type': network_type,
            'use-external-id': use_external_id
        }
    elif vif['type'] == model.VIF_TYPE_DVS:
        network_id = vif['network']['bridge']
        network_ref = network_util.get_network_with_the_name(
            session, network_id, cluster)
        if not network_ref:
            raise exception.NetworkNotFoundForBridge(bridge=network_id)
    else:
        reason = _('vif type %s not supported') % vif['type']  # noqa
        raise exception.InvalidInput(reason=reason)
    return network_ref
Пример #12
0
    def _get_network_dvs_match(self, name, token=False):
        net_morefs = [vim_util.get_moref("dvportgroup-135", "DistributedVirtualPortgroup")]
        networks = self._build_cluster_networks(net_morefs)

        def mock_call_method(module, method, *args, **kwargs):
            if method == "get_object_properties":
                return networks
            if method == "get_object_property":
                result = fake.DataObject()
                if not token or self._continue_retrieval_called:
                    result.name = name
                else:
                    result.name = "fake_name"
                result.key = "fake_key"
                result.distributedVirtualSwitch = "fake_dvs"
                return result
            if method == "continue_retrieval":
                if token:
                    self._continue_retrieval_called = True
                    return networks
            if method == "cancel_retrieval":
                self._cancel_retrieval_called = True

        with mock.patch.object(self._session, "_call_method", mock_call_method):
            res = network_util.get_network_with_the_name(self._session, "fake_net", "fake_cluster")
            self.assertIsNotNone(res)
Пример #13
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)
Пример #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_network_no_match(self):
        net_morefs = [vim_util.get_moref("dvportgroup-135",
                                         "DistributedVirtualPortgroup"),
                      vim_util.get_moref("dvportgroup-136",
                                         "DistributedVirtualPortgroup")]
        networks = self._build_cluster_networks(net_morefs)
        self._continue_retrieval_called = False

        def mock_call_method(module, method, *args, **kwargs):
            if method == 'get_object_properties':
                return networks
            if method == 'get_object_property':
                result = fake.DataObject()
                result.name = 'no-match'
                return result
            if method == 'continue_retrieval':
                self._continue_retrieval_called = True

        with mock.patch.object(self._session, '_call_method',
                               mock_call_method):
            res = network_util.get_network_with_the_name(self._session,
                                                        'fake_net',
                                                        'fake_cluster')
            self.assertTrue(self._continue_retrieval_called)
            self.assertIsNone(res)
    def test_get_network_no_match(self):
        net_morefs = [
            vim_util.get_moref("dvportgroup-135",
                               "DistributedVirtualPortgroup"),
            vim_util.get_moref("dvportgroup-136",
                               "DistributedVirtualPortgroup")
        ]
        networks = self._build_cluster_networks(net_morefs)
        self._continue_retrieval_called = False

        def mock_call_method(module, method, *args, **kwargs):
            if method == 'get_object_properties':
                return networks
            if method == 'get_object_property':
                result = fake.DataObject()
                result.name = 'no-match'
                return result
            if method == 'continue_retrieval':
                self._continue_retrieval_called = True

        with mock.patch.object(self._session, '_call_method',
                               mock_call_method):
            res = network_util.get_network_with_the_name(
                self._session, 'fake_net', 'fake_cluster')
            self.assertTrue(self._continue_retrieval_called)
            self.assertIsNone(res)
    def _get_network_dvs_match(self, name, token=False):
        net_morefs = [
            vim_util.get_moref("dvportgroup-135",
                               "DistributedVirtualPortgroup")
        ]
        networks = self._build_cluster_networks(net_morefs)

        def mock_call_method(module, method, *args, **kwargs):
            if method == 'get_object_properties':
                return networks
            if method == 'get_object_property':
                result = fake.DataObject()
                if not token or self._continue_retrieval_called:
                    result.name = name
                else:
                    result.name = 'fake_name'
                result.key = 'fake_key'
                result.distributedVirtualSwitch = 'fake_dvs'
                return result
            if method == 'continue_retrieval':
                if token:
                    self._continue_retrieval_called = True
                    return networks
            if method == 'cancel_retrieval':
                self._cancel_retrieval_called = True

        with mock.patch.object(self._session, '_call_method',
                               mock_call_method):
            res = network_util.get_network_with_the_name(
                self._session, 'fake_net', 'fake_cluster')
            self.assertIsNotNone(res)
Пример #18
0
def _get_neutron_network(session, cluster, vif):
    if vif['type'] == model.VIF_TYPE_OVS:
        _check_ovs_supported_version(session)
        # Check if this is the NSX-MH plugin is used
        if CONF.vmware.integration_bridge:
            net_id = CONF.vmware.integration_bridge
            use_external_id = False
            network_type = 'opaque'
        else:
            net_id = vif['network']['id']
            use_external_id = True
            network_type = 'nsx.LogicalSwitch'
        network_ref = {'type': 'OpaqueNetwork',
                       'network-id': net_id,
                       'network-type': network_type,
                       'use-external-id': use_external_id}
    elif vif['type'] == model.VIF_TYPE_DVS:
        network_id = vif['network']['bridge']
        network_ref = network_util.get_network_with_the_name(
                session, network_id, cluster)
        if not network_ref:
            raise exception.NetworkNotFoundForBridge(bridge=network_id)
    else:
        reason = _('vif type %s not supported') % vif['type']
        raise exception.InvalidInput(reason=reason)
    return network_ref
    def test_ensure_vlan_bridge_with_existing_dvs(self):
        network_ref = {'dvpg': 'dvportgroup-2062',
                       'type': 'DistributedVirtualPortgroup'}
        self.mox.StubOutWithMock(network_util, 'get_network_with_the_name')
        self.mox.StubOutWithMock(network_util,
            'get_vswitch_for_vlan_interface')
        self.mox.StubOutWithMock(network_util,
            'check_if_vlan_interface_exists')
        self.mox.StubOutWithMock(network_util, 'create_port_group')

        network_util.get_network_with_the_name(self.session, 'fa0',
            self.cluster).AndReturn(network_ref)
        self.mox.ReplayAll()
        ref = vif.ensure_vlan_bridge(self.session,
                                     self.vif,
                                     create_vlan=False)
        self.assertThat(ref, matchers.DictMatches(network_ref))
Пример #20
0
    def test_ensure_vlan_bridge_with_existing_dvs(self):
        network_ref = {
            'dvpg': 'dvportgroup-2062',
            'type': 'DistributedVirtualPortgroup'
        }
        self.mox.StubOutWithMock(network_util, 'get_network_with_the_name')
        self.mox.StubOutWithMock(network_util,
                                 'get_vswitch_for_vlan_interface')
        self.mox.StubOutWithMock(network_util,
                                 'check_if_vlan_interface_exists')
        self.mox.StubOutWithMock(network_util, 'create_port_group')

        network_util.get_network_with_the_name(
            self.session, 'fa0', self.cluster).AndReturn(network_ref)
        self.mox.ReplayAll()
        ref = vif.ensure_vlan_bridge(self.session, self.vif, create_vlan=False)
        self.assertThat(ref, matchers.DictMatches(network_ref))
Пример #21
0
def ensure_vlan_bridge(session, vif, cluster=None, create_vlan=True):
    """Create a vlan and bridge unless they already exist."""
    neutron_vlan = vif['network'].get_meta('vmware_neutron_vlan')
    nova_vlan = vif['network'].get_meta('vlan')
    vlan_num = neutron_vlan if neutron_vlan else nova_vlan
    neutron_bridge = vif['network'].get_meta('vmware_neutron_bridge')
    nova_bridge = vif['network']['bridge']
    bridge = neutron_bridge if neutron_bridge else nova_bridge
    vlan_interface = CONF.vmware.vlan_interface

    network_ref = network_util.get_network_with_the_name(
        session, bridge, cluster)
    if network_ref and network_ref['type'] == 'DistributedVirtualPortgroup':
        return network_ref

    if not network_ref:
        # Create a port group on the vSwitch associated with the
        # vlan_interface corresponding physical network adapter on the ESX
        # host.
        vswitch_associated = _get_associated_vswitch_for_interface(
            session, vlan_interface, cluster)
        network_util.create_port_group(session, bridge, vswitch_associated,
                                       vlan_num if create_vlan else 0, cluster)
        network_ref = network_util.get_network_with_the_name(
            session, bridge, cluster)
    elif create_vlan:
        # Get the vSwitch associated with the Physical Adapter
        vswitch_associated = _get_associated_vswitch_for_interface(
            session, vlan_interface, cluster)
        # Get the vlan id and vswitch corresponding to the port group
        _get_pg_info = network_util.get_vlanid_and_vswitch_for_portgroup
        pg_vlanid, pg_vswitch = _get_pg_info(session, bridge, cluster)

        # Check if the vswitch associated is proper
        if pg_vswitch != vswitch_associated:
            raise exception.InvalidVLANPortGroup(bridge=bridge,
                                                 expected=vswitch_associated,
                                                 actual=pg_vswitch)

        # Check if the vlan id is proper for the port group
        if pg_vlanid != vlan_num:
            raise exception.InvalidVLANTag(bridge=bridge,
                                           tag=vlan_num,
                                           pgroup=pg_vlanid)
    return network_ref
Пример #22
0
    def test_ensure_vlan_bridge_without_vlan(self):
        self.mox.StubOutWithMock(network_util, 'get_network_with_the_name')
        self.mox.StubOutWithMock(network_util,
                                 'get_vswitch_for_vlan_interface')
        self.mox.StubOutWithMock(network_util,
                                 'check_if_vlan_interface_exists')
        self.mox.StubOutWithMock(network_util, 'create_port_group')

        network_util.get_network_with_the_name(self.session, 'fa0',
                                               self.cluster).AndReturn(None)
        network_util.get_vswitch_for_vlan_interface(
            self.session, 'vmnet0', self.cluster).AndReturn('vmnet0')
        network_util.check_if_vlan_interface_exists(
            self.session, 'vmnet0', self.cluster).AndReturn(True)
        network_util.create_port_group(self.session, 'fa0', 'vmnet0', 0,
                                       self.cluster)
        self.mox.ReplayAll()
        vif.ensure_vlan_bridge(self.session, self.vif, create_vlan=False)
Пример #23
0
    def test_ensure_vlan_bridge_without_vlan(self):
        self.mox.StubOutWithMock(network_util, 'get_network_with_the_name')
        self.mox.StubOutWithMock(network_util,
            'get_vswitch_for_vlan_interface')
        self.mox.StubOutWithMock(network_util,
            'check_if_vlan_interface_exists')
        self.mox.StubOutWithMock(network_util, 'create_port_group')

        network_util.get_network_with_the_name(self.session, 'fa0',
            self.cluster).AndReturn(None)
        network_util.get_vswitch_for_vlan_interface(self.session, 'vmnet0',
            self.cluster).AndReturn('vmnet0')
        network_util.check_if_vlan_interface_exists(self.session, 'vmnet0',
        self.cluster).AndReturn(True)
        network_util.create_port_group(self.session, 'fa0', 'vmnet0', 0,
            self.cluster)
        self.mox.ReplayAll()
        vif.ensure_vlan_bridge(self.session, self.vif, create_vlan=False)
Пример #24
0
    def test_get_network_network_match(self):
        net_morefs = [vim_util.get_moref("network-54", "Network")]
        networks = self._build_cluster_networks(net_morefs)

        def mock_call_method(module, method, *args, **kwargs):
            if method == "get_object_properties":
                return networks
            if method == "get_object_property":
                return "fake_net"

        with mock.patch.object(self._session, "_call_method", mock_call_method):
            res = network_util.get_network_with_the_name(self._session, "fake_net", "fake_cluster")
            self.assertIsNotNone(res)
Пример #25
0
def get_neutron_network(session, network_name, cluster, vif):
    opaque = None
    if vif["type"] != model.VIF_TYPE_DVS:
        opaque = _get_opaque_network(session, cluster)
    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
Пример #26
0
    def test_get_network_network_match(self):
        net_morefs = [vim_util.get_moref("network-54", "Network")]
        networks = self._build_cluster_networks(net_morefs)

        def mock_call_method(module, method, *args, **kwargs):
            if method == 'get_object_properties':
                return networks
            if method == 'get_object_property':
                return 'fake_net'

        with mock.patch.object(self._session, '_call_method',
                               mock_call_method):
            res = network_util.get_network_with_the_name(
                self._session, 'fake_net', 'fake_cluster')
            self.assertIsNotNone(res)
Пример #27
0
def ensure_vlan_bridge(session, vif, cluster=None, create_vlan=True):
    """Create a vlan and bridge unless they already exist."""
    vlan_num = vif['network'].get_meta('vlan')
    bridge = vif['network']['bridge']
    vlan_interface = CONF.vmware.vlan_interface

    network_ref = network_util.get_network_with_the_name(session, bridge,
                                                         cluster)
    # Get the vSwitch associated with the Physical Adapter
    vswitch_associated = network_util.get_vswitch_for_vlan_interface(
                                    session, vlan_interface, cluster)
    if vswitch_associated is None:
        raise exception.SwitchNotFoundForNetworkAdapter(
            adapter=vlan_interface)
    # Check if the vlan_interface physical network adapter exists on the
    # host.
    if not network_util.check_if_vlan_interface_exists(session,
                                        vlan_interface, cluster):
        raise exception.NetworkAdapterNotFound(adapter=vlan_interface)
    if create_vlan:

        if network_ref is None:
        # Create a port group on the vSwitch associated with the
        # vlan_interface corresponding physical network adapter on the ESX
        # host.
            network_util.create_port_group(session, bridge,
                                       vswitch_associated, vlan_num,
                                       cluster)
        else:
            # Get the vlan id and vswitch corresponding to the port group
            _get_pg_info = network_util.get_vlanid_and_vswitch_for_portgroup
            pg_vlanid, pg_vswitch = _get_pg_info(session, bridge, cluster)

            # Check if the vswitch associated is proper
            if pg_vswitch != vswitch_associated:
                raise exception.InvalidVLANPortGroup(
                    bridge=bridge, expected=vswitch_associated,
                    actual=pg_vswitch)

            # Check if the vlan id is proper for the port group
            if pg_vlanid != vlan_num:
                raise exception.InvalidVLANTag(bridge=bridge, tag=vlan_num,
                                           pgroup=pg_vlanid)
    else:
        if network_ref is None:
            network_util.create_port_group(session, bridge,
                                       vswitch_associated, 0,
                                       cluster)
Пример #28
0
def get_neutron_network(session, network_name, cluster, vif):
    opaque = None
    if vif['type'] != model.VIF_TYPE_DVS:
        opaque = _get_opaque_network(session, cluster)
    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
Пример #29
0
def ensure_vlan_bridge(self, session, network, cluster=None):
    """Create a vlan and bridge unless they already exist."""
    vlan_num = network['vlan']
    bridge = network['bridge']
    vlan_interface = CONF.vmwareapi_vlan_interface

    # Check if the vlan_interface physical network adapter exists on the
    # host.
    if not network_util.check_if_vlan_interface_exists(session,
                                                       vlan_interface,
                                                       cluster):
        raise exception.NetworkAdapterNotFound(adapter=vlan_interface)

    # Get the vSwitch associated with the Physical Adapter
    vswitch_associated = network_util.get_vswitch_for_vlan_interface(
                                        session, vlan_interface, cluster)
    if vswitch_associated is None:
        raise exception.SwitchNotFoundForNetworkAdapter(
            adapter=vlan_interface)
    # Check whether bridge already exists and retrieve the the ref of the
    # network whose name_label is "bridge"
    network_ref = network_util.get_network_with_the_name(session, bridge,
                                                         cluster)
    if network_ref is None:
        # Create a port group on the vSwitch associated with the
        # vlan_interface corresponding physical network adapter on the ESX
        # host.
        network_util.create_port_group(session, bridge,
                                       vswitch_associated, vlan_num,
                                       cluster)
    else:
        # Get the vlan id and vswitch corresponding to the port group
        _get_pg_info = network_util.get_vlanid_and_vswitch_for_portgroup
        pg_vlanid, pg_vswitch = _get_pg_info(session, bridge, cluster)

        # Check if the vswitch associated is proper
        if pg_vswitch != vswitch_associated:
            raise exception.InvalidVLANPortGroup(
                bridge=bridge, expected=vswitch_associated,
                actual=pg_vswitch)

        # Check if the vlan id is proper for the port group
        if pg_vlanid != vlan_num:
            raise exception.InvalidVLANTag(bridge=bridge, tag=vlan_num,
                                           pgroup=pg_vlanid)
Пример #30
0
def ensure_vlan_bridge(self, session, network):
    """Create a vlan and bridge unless they already exist."""
    vlan_num = network['vlan']
    bridge = network['bridge']
    vlan_interface = CONF.vmwareapi_vlan_interface

    # Check if the vlan_interface physical network adapter exists on the
    # host.
    if not network_util.check_if_vlan_interface_exists(session,
                                                       vlan_interface):
        raise exception.NetworkAdapterNotFound(adapter=vlan_interface)

    # Get the vSwitch associated with the Physical Adapter
    vswitch_associated = network_util.get_vswitch_for_vlan_interface(
        session, vlan_interface)
    if vswitch_associated is None:
        raise exception.SwitchNotFoundForNetworkAdapter(adapter=vlan_interface)
    # Check whether bridge already exists and retrieve the the ref of the
    # network whose name_label is "bridge"
    network_ref = network_util.get_network_with_the_name(session, bridge)
    if network_ref is None:
        # Create a port group on the vSwitch associated with the
        # vlan_interface corresponding physical network adapter on the ESX
        # host.
        network_util.create_port_group(session, bridge, vswitch_associated,
                                       vlan_num)
    else:
        # Get the vlan id and vswitch corresponding to the port group
        _get_pg_info = network_util.get_vlanid_and_vswitch_for_portgroup
        pg_vlanid, pg_vswitch = _get_pg_info(session, bridge)

        # Check if the vswitch associated is proper
        if pg_vswitch != vswitch_associated:
            raise exception.InvalidVLANPortGroup(bridge=bridge,
                                                 expected=vswitch_associated,
                                                 actual=pg_vswitch)

        # Check if the vlan id is proper for the port group
        if pg_vlanid != vlan_num:
            raise exception.InvalidVLANTag(bridge=bridge,
                                           tag=vlan_num,
                                           pgroup=pg_vlanid)
Пример #31
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.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
Пример #32
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
    def _get_network_dvs_match(self, name):
        net_morefs = [vim_util.get_moref("dvportgroup-135",
                                         "DistributedVirtualPortgroup")]
        networks = self._build_cluster_networks(net_morefs)

        def mock_call_method(module, method, *args, **kwargs):
            if method == 'get_object_properties':
                return networks
            if method == 'get_object_property':
                result = fake.DataObject()
                result.name = name
                result.key = 'fake_key'
                result.distributedVirtualSwitch = 'fake_dvs'
                return result

        with mock.patch.object(self._session, '_call_method',
                               mock_call_method):
            res = network_util.get_network_with_the_name(self._session,
                                                        'fake_net',
                                                        'fake_cluster')
            self.assertIsNotNone(res)
Пример #34
0
    def _get_network_dvs_match(self, name):
        net_morefs = [vim_util.get_moref("dvportgroup-135",
                                         "DistributedVirtualPortgroup")]
        networks = self._build_cluster_networks(net_morefs)

        def mock_call_method(module, method, *args, **kwargs):
            if method == 'get_object_properties':
                return networks
            if method == 'get_object_property':
                result = fake.DataObject()
                result.name = name
                result.key = 'fake_key'
                result.distributedVirtualSwitch = 'fake_dvs'
                return result

        with mock.patch.object(self._session, '_call_method',
                               mock_call_method):
            res = network_util.get_network_with_the_name(self._session,
                                                        'fake_net',
                                                        'fake_cluster')
            self.assertIsNotNone(res)
Пример #35
0
def _get_neutron_network(session, cluster, vif):
    if vif['type'] == model.VIF_TYPE_OVS:
        _check_ovs_supported_version(session)
        # Check if this is the NSX-MH plugin is used
        if CONF.vmware.integration_bridge:
            net_id = CONF.vmware.integration_bridge
            use_external_id = False
            network_type = 'opaque'
        else:
            # The NSX|V3 plugin will pass the nsx-logical-switch-id as part
            # of the port details. This will enable the VC to connect to
            # that specific opaque network
            net_id = (vif.get('details')
                      and vif['details'].get('nsx-logical-switch-id'))
            if not net_id:
                # Make use of the original one, in the event that the
                # plugin does not pass the aforementioned id
                LOG.info(
                    _LI('NSX Logical switch ID is not present. '
                        'Using network ID to attach to the '
                        'opaque network.'))
                net_id = vif['network']['id']
            use_external_id = True
            network_type = 'nsx.LogicalSwitch'
        network_ref = {
            'type': 'OpaqueNetwork',
            'network-id': net_id,
            'network-type': network_type,
            'use-external-id': use_external_id
        }
    elif vif['type'] == model.VIF_TYPE_DVS:
        network_id = vif['network']['bridge']
        network_ref = network_util.get_network_with_the_name(
            session, network_id, cluster)
        if not network_ref:
            raise exception.NetworkNotFoundForBridge(bridge=network_id)
    else:
        reason = _('vif type %s not supported') % vif['type']
        raise exception.InvalidInput(reason=reason)
    return network_ref
Пример #36
0
def _get_neutron_network(session, cluster, vif):
    if vif['type'] == model.VIF_TYPE_OVS:
        _check_ovs_supported_version(session)
        # Check if this is the NSX-MH plugin is used
        if CONF.vmware.integration_bridge:
            net_id = CONF.vmware.integration_bridge
            use_external_id = False
            network_type = 'opaque'
        else:
            net_id = vif['network']['id']
            use_external_id = True
            network_type = 'nsx.LogicalSwitch'
        network_ref = {
            'type': 'OpaqueNetwork',
            'network-id': net_id,
            'network-type': network_type,
            'use-external-id': use_external_id
        }
    elif vif['type'] == model.VIF_TYPE_DVS:
        # Port binding for DVS VIF types may pass the name
        # of the port group, so use it if present
        network_id = vif.get('details', {}).get('dvs_port_group_name')
        if network_id is None:
            # Make use of the original one, in the event that the
            # port binding does not provide this key in VIF details
            #network_id = vif['network']['bridge']

            network_id = (CONF.vmware.integration_bridge or "br-int")

        network_ref = network_util.get_network_with_the_name(
            session, network_id, cluster)
        if not network_ref:
            raise exception.NetworkNotFoundForBridge(bridge=network_id)
        if vif.get('details') and vif['details'].get('dvs_port_key'):
            network_ref['dvs_port_key'] = vif['details']['dvs_port_key']
    else:
        reason = _('vif type %s not supported') % vif['type']
        raise exception.InvalidInput(reason=reason)
    return network_ref
def _get_neutron_network(session, cluster, vif):
    if vif['type'] == model.VIF_TYPE_OVS:
        _check_ovs_supported_version(session)
        # Check if this is the NSX-MH plugin is used
        if CONF.vmware.integration_bridge:
            net_id = CONF.vmware.integration_bridge
            use_external_id = False
            network_type = 'opaque'
        else:
            # The NSX|V3 plugin will pass the nsx-logical-switch-id as part
            # of the port details. This will enable the VC to connect to
            # that specific opaque network
            net_id = (vif.get('details') and
                      vif['details'].get('nsx-logical-switch-id'))
            if not net_id:
                # Make use of the original one, in the event that the
                # plugin does not pass the aforementioned id
                LOG.info(_LI('NSX Logical switch ID is not present. '
                             'Using network ID to attach to the '
                             'opaque network.'))
                net_id = vif['network']['id']
            use_external_id = True
            network_type = 'nsx.LogicalSwitch'
        network_ref = {'type': 'OpaqueNetwork',
                       'network-id': net_id,
                       'network-type': network_type,
                       'use-external-id': use_external_id}
    elif vif['type'] == model.VIF_TYPE_DVS:
        network_id = vif['network']['bridge']
        network_ref = network_util.get_network_with_the_name(
                session, network_id, cluster)
        if not network_ref:
            raise exception.NetworkNotFoundForBridge(bridge=network_id)
    else:
        reason = _('vif type %s not supported') % vif['type']
        raise exception.InvalidInput(reason=reason)
    return network_ref
Пример #38
0
 def _check_if_network_bridge_exists(network_name):
     network_ref = network_util.get_network_with_the_name(
         self._session, network_name)
     if network_ref is None:
         raise exception.NetworkNotFoundForBridge(bridge=network_name)
     return network_ref
Пример #39
0
 def _check_if_network_bridge_exists(network_name):
     network_ref = network_util.get_network_with_the_name(
                   self._session, network_name)
     if network_ref is None:
         raise exception.NetworkNotFoundForBridge(bridge=network_name)
     return network_ref