diff options
| author | Yaguang Tang <yaguang.tang@canonical.com> | 2013-04-23 18:55:19 +0800 |
|---|---|---|
| committer | Yaguang Tang <yaguang.tang@canonical.com> | 2013-04-24 12:50:18 +0800 |
| commit | bc66b8aa968a0c0b74e2f21ed0fc856f8933c6d3 (patch) | |
| tree | 53b4fcfffc2a93297f124cf339ad42581490bf7f | |
| parent | 5a604b5924dae368da4b6561550bb430e3239ca3 (diff) | |
Support FlatDHCP network for VMware Hyper.
fix bug #1171783
Change-Id: Ibb75c8e3174283f0f5e94bacfd61ee93e8bd6227
| -rw-r--r-- | nova/virt/vmwareapi/vif.py | 47 | ||||
| -rw-r--r-- | nova/virt/vmwareapi/vmops.py | 12 |
2 files changed, 29 insertions, 30 deletions
diff --git a/nova/virt/vmwareapi/vif.py b/nova/virt/vmwareapi/vif.py index ed68df33c..cb8ce52c0 100644 --- a/nova/virt/vmwareapi/vif.py +++ b/nova/virt/vmwareapi/vif.py @@ -34,40 +34,40 @@ vmwareapi_vif_opts = [ CONF.register_opts(vmwareapi_vif_opts) -def ensure_vlan_bridge(session, vif, cluster=None): +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.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, + 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 create_vlan: + # 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) + 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: + if vswitch_associated is None: + raise exception.SwitchNotFoundForNetworkAdapter( + 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, + 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) + 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: @@ -79,3 +79,8 @@ def ensure_vlan_bridge(session, vif, cluster=None): 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) diff --git a/nova/virt/vmwareapi/vmops.py b/nova/virt/vmwareapi/vmops.py index 3377c247f..800a2e073 100644 --- a/nova/virt/vmwareapi/vmops.py +++ b/nova/virt/vmwareapi/vmops.py @@ -39,7 +39,6 @@ from nova import exception from nova.openstack.common import excutils from nova.openstack.common import log as logging from nova.virt import driver -from nova.virt.vmwareapi import network_util from nova.virt.vmwareapi import vif as vmwarevif from nova.virt.vmwareapi import vim_util from nova.virt.vmwareapi import vm_util @@ -164,13 +163,6 @@ class VMwareVMOps(object): vm_folder_ref = self._get_vmfolder_ref() res_pool_ref = self._get_res_pool_ref() - def _check_if_network_bridge_exists(network_name): - network_ref = network_util.get_network_with_the_name( - self._session, network_name, self._cluster) - if network_ref is None: - raise exception.NetworkNotFoundForBridge(bridge=network_name) - return network_ref - def _get_vif_infos(): vif_infos = [] if network_info is None: @@ -184,7 +176,9 @@ class VMwareVMOps(object): self._session, vif, self._cluster) else: - network_ref = _check_if_network_bridge_exists(network_name) + # FlatDHCP network without vlan. + network_ref = vmwarevif.ensure_vlan_bridge( + self._session, vif, self._cluster, create_vlan=False) vif_infos.append({'network_name': network_name, 'mac_address': mac_address, 'network_ref': network_ref, |
