18
18
"""VIF drivers for VMWare."""
21
20
from nova import exception
22
21
from nova import flags
23
22
from nova import log as logging
24
from nova import utils
25
23
from nova.virt.vif import VIFDriver
26
from nova.virt.vmwareapi_conn import VMWareAPISession
27
24
from nova.virt.vmwareapi import network_utils
30
27
LOG = logging.getLogger("nova.virt.vmwareapi.vif")
32
29
FLAGS = flags.FLAGS
30
FLAGS['vmwareapi_vlan_interface'].SetDefault('vmnic0')
35
33
class VMWareVlanBridgeDriver(VIFDriver):
36
34
"""VIF Driver to setup bridge/VLAN networking using VMWare API."""
38
36
def plug(self, instance, network, mapping):
37
"""Plug the VIF to specified instance using information passed.
38
Currently we are plugging the VIF(s) during instance creation itself.
39
We can use this method when we add support to add additional NIC to
40
an existing instance."""
43
def ensure_vlan_bridge(self, session, network):
39
44
"""Create a vlan and bridge unless they already exist."""
40
45
vlan_num = network['vlan']
41
46
bridge = network['bridge']
42
bridge_interface = network['bridge_interface']
47
vlan_interface = FLAGS.vmwareapi_vlan_interface
44
# Open vmwareapi session
45
host_ip = FLAGS.vmwareapi_host_ip
46
host_username = FLAGS.vmwareapi_host_username
47
host_password = FLAGS.vmwareapi_host_password
48
if not host_ip or host_username is None or host_password is None:
49
raise Exception(_('Must specify vmwareapi_host_ip, '
50
'vmwareapi_host_username '
51
'and vmwareapi_host_password to use '
52
'connection_type=vmwareapi'))
53
session = VMWareAPISession(host_ip, host_username, host_password,
54
FLAGS.vmwareapi_api_retry_count)
55
vlan_interface = bridge_interface
56
49
# Check if the vlan_interface physical network adapter exists on the
58
51
if not network_utils.check_if_vlan_interface_exists(session,
94
87
def unplug(self, instance, network, mapping):
88
"""Cleanup operations like deleting port group if no instance
89
is associated with it."""