~ubuntu-branches/ubuntu/raring/nova/raring-proposed

« back to all changes in this revision

Viewing changes to nova/virt/vmwareapi/vif.py

  • Committer: Package Import Robot
  • Author(s): Adam Gandelman
  • Date: 2013-08-09 10:12:27 UTC
  • mto: This revision was merged to the branch mainline in revision 107.
  • Revision ID: package-import@ubuntu.com-20130809101227-flqfubhwpot76pob
Tags: upstream-2013.1.3
ImportĀ upstreamĀ versionĀ 2013.1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
from oslo.config import cfg
21
21
 
22
22
from nova import exception
23
 
from nova.openstack.common import log as logging
24
23
from nova.virt.vmwareapi import network_util
25
24
 
26
25
 
27
 
LOG = logging.getLogger(__name__)
28
 
 
29
26
CONF = cfg.CONF
30
27
 
31
28
vmwareapi_vif_opts = [
37
34
CONF.register_opts(vmwareapi_vif_opts)
38
35
 
39
36
 
40
 
def ensure_vlan_bridge(session, vif, cluster=None):
 
37
def ensure_vlan_bridge(session, vif, cluster=None, create_vlan=True):
41
38
    """Create a vlan and bridge unless they already exist."""
42
39
    vlan_num = vif['network'].get_meta('vlan')
43
40
    bridge = vif['network']['bridge']
44
41
    vlan_interface = CONF.vmwareapi_vlan_interface
45
42
 
46
 
    # Check if the vlan_interface physical network adapter exists on the
47
 
    # host.
48
 
    if not network_util.check_if_vlan_interface_exists(session,
49
 
                                                       vlan_interface,
50
 
                                                       cluster):
51
 
        raise exception.NetworkAdapterNotFound(adapter=vlan_interface)
52
 
 
 
43
    network_ref = network_util.get_network_with_the_name(session, bridge,
 
44
                                                         cluster)
53
45
    # Get the vSwitch associated with the Physical Adapter
54
46
    vswitch_associated = network_util.get_vswitch_for_vlan_interface(
55
 
                                        session, vlan_interface, cluster)
 
47
                                    session, vlan_interface, cluster)
56
48
    if vswitch_associated is None:
57
49
        raise exception.SwitchNotFoundForNetworkAdapter(
58
50
            adapter=vlan_interface)
59
 
    # Check whether bridge already exists and retrieve the the ref of the
60
 
    # network whose name_label is "bridge"
61
 
    network_ref = network_util.get_network_with_the_name(session, bridge,
62
 
                                                         cluster)
63
 
    if network_ref is None:
 
51
    # Check if the vlan_interface physical network adapter exists on the
 
52
    # host.
 
53
    if not network_util.check_if_vlan_interface_exists(session,
 
54
                                        vlan_interface, cluster):
 
55
        raise exception.NetworkAdapterNotFound(adapter=vlan_interface)
 
56
    if create_vlan:
 
57
 
 
58
        if network_ref is None:
64
59
        # Create a port group on the vSwitch associated with the
65
60
        # vlan_interface corresponding physical network adapter on the ESX
66
61
        # host.
67
 
        network_util.create_port_group(session, bridge,
 
62
            network_util.create_port_group(session, bridge,
68
63
                                       vswitch_associated, vlan_num,
69
64
                                       cluster)
 
65
        else:
 
66
            # Get the vlan id and vswitch corresponding to the port group
 
67
            _get_pg_info = network_util.get_vlanid_and_vswitch_for_portgroup
 
68
            pg_vlanid, pg_vswitch = _get_pg_info(session, bridge, cluster)
 
69
 
 
70
            # Check if the vswitch associated is proper
 
71
            if pg_vswitch != vswitch_associated:
 
72
                raise exception.InvalidVLANPortGroup(
 
73
                    bridge=bridge, expected=vswitch_associated,
 
74
                    actual=pg_vswitch)
 
75
 
 
76
            # Check if the vlan id is proper for the port group
 
77
            if pg_vlanid != vlan_num:
 
78
                raise exception.InvalidVLANTag(bridge=bridge, tag=vlan_num,
 
79
                                           pgroup=pg_vlanid)
70
80
    else:
71
 
        # Get the vlan id and vswitch corresponding to the port group
72
 
        _get_pg_info = network_util.get_vlanid_and_vswitch_for_portgroup
73
 
        pg_vlanid, pg_vswitch = _get_pg_info(session, bridge, cluster)
74
 
 
75
 
        # Check if the vswitch associated is proper
76
 
        if pg_vswitch != vswitch_associated:
77
 
            raise exception.InvalidVLANPortGroup(
78
 
                bridge=bridge, expected=vswitch_associated,
79
 
                actual=pg_vswitch)
80
 
 
81
 
        # Check if the vlan id is proper for the port group
82
 
        if pg_vlanid != vlan_num:
83
 
            raise exception.InvalidVLANTag(bridge=bridge, tag=vlan_num,
84
 
                                           pgroup=pg_vlanid)
 
81
        if network_ref is None:
 
82
            network_util.create_port_group(session, bridge,
 
83
                                       vswitch_associated, 0,
 
84
                                       cluster)