with self._use_driver(account) as drv:
vm_id = drv.nova_server_create(**kwargs)
if floating_ip:
- self.prepare_vdu_on_boot(account, vm_id, floating_ip)
-
+ self.prepare_vdu_on_boot(account, vm_id, floating_ip, mgmt_network = None)
return vm_id
@rwstatus
vm.state = vm_info['status']
for network_name, network_info in vm_info['addresses'].items():
if network_info:
- if network_name == mgmt_network:
+ if network_name == mgmt_network :
vm.public_ip = next((item['addr']
for item in network_info
if item['OS-EXT-IPS:type'] == 'floating'),
return link
@staticmethod
- def _fill_vdu_info(vm_info, flavor_info, mgmt_network, port_list, server_group, volume_list = None):
+ def _fill_vdu_info(vm_info, flavor_info, mgmt_network, port_list, server_group, volume_list = None, overridden_mgmt_network = None):
"""Create a GI object for VDUInfoParams
Converts VM information dictionary object returned by openstack
vdu.name = vm_info['name']
vdu.vdu_id = vm_info['id']
for network_name, network_info in vm_info['addresses'].items():
- if network_info and network_name == mgmt_network:
+ if network_info and network_name == mgmt_network or network_name == overridden_mgmt_network :
for interface in network_info:
- if 'OS-EXT-IPS:type' in interface:
- if interface['OS-EXT-IPS:type'] == 'fixed':
- vdu.management_ip = interface['addr']
- elif interface['OS-EXT-IPS:type'] == 'floating':
- vdu.public_ip = interface['addr']
+ for interface in network_info:
+ if 'OS-EXT-IPS:type' in interface:
+ if interface['OS-EXT-IPS:type'] == 'fixed':
+ vdu.management_ip = interface['addr']
+ elif interface['OS-EXT-IPS:type'] == 'floating':
+ vdu.public_ip = interface['addr']
# Look for any metadata
for key, value in vm_info['metadata'].items():
account - a cloud account
c_point - connection_points
"""
+
kwargs = {}
kwargs['name'] = c_point.name
kwargs['network_id'] = c_point.virtual_link_id
else:
raise NotImplementedError("Port Type: %s not supported" %(c_point.type_yang))
+ if c_point.static_ip_address:
+ kwargs["ip_address"] = c_point.static_ip_address
+
with self._use_driver(account) as drv:
if c_point.has_field('security_group'):
group = drv.neutron_security_group_by_name(c_point.security_group)
if group is not None:
kwargs['security_groups'] = [group['id']]
+ self.log.debug("Create connection point port : {}".
+ format(kwargs))
return drv.neutron_port_create(**kwargs)
def _allocate_floating_ip(self, drv, pool_name):
raise OpenstackCALOperationFailure("Create-flavor operation failed for cloud account: %s" %(account.name))
return flavor_id
- def _create_vm(self, account, vduinfo, pci_assignement=None, server_group=None, port_list=None, network_list=None, imageinfo_list=None):
+ def _create_vm(self, account, vduinfo, pci_assignement=None, server_group=None, port_list=None, network_list=None, imageinfo_list=None, mgmt_network = None):
"""Create a new virtual machine.
Arguments:
with self._use_driver(account) as drv:
vm_id = drv.nova_server_create(**kwargs)
if floating_ip:
- self.prepare_vdu_on_boot(account, vm_id, floating_ip)
+ self.prepare_vdu_on_boot(account, vm_id, floating_ip, mgmt_network)
return vm_id
The vdu_id
"""
### First create required number of ports aka connection points
+ # Add the mgmt_ntwk by default.
+
+ mgmt_network_id = None
with self._use_driver(account) as drv:
+ mgmt_network_id = drv._mgmt_network_id
### If floating_ip is required and we don't have one, better fail before any further allocation
if vdu_init.has_field('allocate_public_address') and vdu_init.allocate_public_address:
if account.openstack.has_field('floating_ip_pool'):
floating_ip = self._allocate_floating_ip(drv, pool_name)
else:
floating_ip = None
-
port_list = []
network_list = []
imageinfo_list = []
- for c_point in vdu_init.connection_points:
+ explicit_mgmt_network = None
+ if vdu_init.get_mgmt_network() is not None:
+ explicit_mgmt_network = vdu_init.get_mgmt_network()
+
+ for c_point in reversed(vdu_init.connection_points):
+ # if the user has specified explicit mgmt_network connection point
+ # then remove the mgmt_network from the VM list
if c_point.virtual_link_id in network_list:
assert False, "Only one port per network supported. Refer: http://specs.openstack.org/openstack/nova-specs/specs/juno/implemented/nfv-multiple-if-1-net.html"
else:
with self._use_driver(account) as drv:
### Now Create VM
vm_network_list = []
- vm_network_list.append(drv._mgmt_network_id)
+ if explicit_mgmt_network is None:
+ vm_network_list.append(drv._mgmt_network_id)
if vdu_init.has_field('volumes'):
# Only combination supported: Image->Volume
if pci_assignement != '':
vm.user_tags.pci_assignement = pci_assignement
- vm_id = self._create_vm(account, vdu_init, pci_assignement=pci_assignement, server_group=server_group, port_list=port_list, network_list=vm_network_list, imageinfo_list = imageinfo_list)
- self.prepare_vdu_on_boot(account, vm_id, floating_ip)
+ vm_id = self._create_vm(account, vdu_init, pci_assignement=pci_assignement, server_group=server_group, port_list=port_list, network_list=vm_network_list, imageinfo_list = imageinfo_list, mgmt_network = explicit_mgmt_network)
return vm_id
def prepare_vpci_metadata(self, drv, vdu_init):
- def prepare_vdu_on_boot(self, account, server_id, floating_ip):
- cmd = PREPARE_VM_CMD.format(auth_url = account.openstack.auth_url,
+ def prepare_vdu_on_boot(self, account, server_id, floating_ip, mgmt_network = None):
+
+ if(mgmt_network is None):
+ cmd = PREPARE_VM_CMD.format(auth_url = account.openstack.auth_url,
username = account.openstack.key,
password = account.openstack.secret,
tenant_name = account.openstack.tenant,
mgmt_network = account.openstack.mgmt_network,
server_id = server_id)
+ else:
+ cmd = PREPARE_VM_CMD.format(auth_url = account.openstack.auth_url,
+ username = account.openstack.key,
+ password = account.openstack.secret,
+ tenant_name = account.openstack.tenant,
+ mgmt_network = mgmt_network,
+ server_id = server_id)
if floating_ip is not None:
cmd += (" --floating_ip "+ floating_ip.ip)
@rwstatus(ret_on_failure=[None])
- def do_get_vdu(self, account, vdu_id):
+ def do_get_vdu(self, account, vdu_id, mgmt_network = None):
"""Get information about a virtual deployment unit.
Arguments:
Object of type RwcalYang.VDUInfoParams
"""
with self._use_driver(account) as drv:
-
- ### Get list of ports excluding the one for management network
- port_list = [p for p in drv.neutron_port_list(**{'device_id': vdu_id}) if p['network_id'] != drv.get_mgmt_network_id()]
+ port_list = drv.neutron_port_list(**{'device_id': vdu_id})
vm = drv.nova_server_get(vdu_id)
account.openstack.mgmt_network,
port_list,
server_group,
- volume_list = openstack_srv_volume_list)
+ volume_list = openstack_srv_volume_list,
+ overridden_mgmt_network = mgmt_network)
if vdu_info.state == 'active':
try:
console_info = drv.nova_server_console(vdu_info.vdu_id)
with self._use_driver(account) as drv:
vms = drv.nova_server_list()
for vm in vms:
- ### Get list of ports excluding one for management network
- port_list = [p for p in drv.neutron_port_list(**{'device_id': vm['id']}) if p['network_id'] != drv.get_mgmt_network_id()]
+ port_list = drv.neutron_port_list(**{'device_id': vm['id']})
flavor_info = None