예제 #1
0
파일: vif.py 프로젝트: cp16net/reddwarf
    def plug(self, instance, network, mapping):
        """Create a vlan and bridge unless they already exist."""
        vlan_num = network['vlan']
        bridge = network['bridge']
        bridge_interface = network['bridge_interface']

        # Open vmwareapi session
        host_ip = FLAGS.vmwareapi_host_ip
        host_username = FLAGS.vmwareapi_host_username
        host_password = FLAGS.vmwareapi_host_password
        if not host_ip or host_username is None or host_password is None:
            raise Exception(
                _('Must specify vmwareapi_host_ip, '
                  'vmwareapi_host_username '
                  'and vmwareapi_host_password to use '
                  'connection_type=vmwareapi'))
        session = VMWareAPISession(host_ip, host_username, host_password,
                                   FLAGS.vmwareapi_api_retry_count)
        vlan_interface = bridge_interface
        # Check if the vlan_interface physical network adapter exists on the
        # host.
        if not network_utils.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_utils.get_vswitch_for_vlan_interface(
            session, vlan_interface)
        if vswitch_associated is None:
            raise exception.SwicthNotFoundForNetworkAdapter(
                adapter=vlan_interface)
        # Check whether bridge already exists and retrieve the the ref of the
        # network whose name_label is "bridge"
        network_ref = network_utils.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_utils.create_port_group(session, bridge,
                                            vswitch_associated, vlan_num)
        else:
            # Get the vlan id and vswitch corresponding to the port group
            pg_vlanid, pg_vswitch = \
                network_utils.get_vlanid_and_vswitch_for_portgroup(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)
예제 #2
0
def _get_associated_vswitch_for_interface(session, interface, cluster=None):
    # Check if the physical network adapter exists on the host.
    if not network_util.check_if_vlan_interface_exists(session, interface,
                                                       cluster):
        raise exception.NetworkAdapterNotFound(adapter=interface)
    # Get the vSwitch associated with the Physical Adapter
    vswitch_associated = network_util.get_vswitch_for_vlan_interface(
        session, interface, cluster)
    if not vswitch_associated:
        raise exception.SwitchNotFoundForNetworkAdapter(adapter=interface)
    return vswitch_associated
예제 #3
0
파일: vif.py 프로젝트: wingo1990/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)
    # 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)
예제 #4
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 = FLAGS.vmwareapi_vlan_interface

        # Check if the vlan_interface physical network adapter exists on the
        # host.
        if not network_utils.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_utils.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_utils.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_utils.create_port_group(session, bridge,
                                            vswitch_associated, vlan_num)
        else:
            # Get the vlan id and vswitch corresponding to the port group
            pg_vlanid, pg_vswitch = \
                network_utils.get_vlanid_and_vswitch_for_portgroup(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)