from .wim.engine import WimEngine
from .wim.persistence import WimPersistence
from copy import deepcopy
+from pprint import pformat
#
global global_config
# Auxiliary dictionaries from x to y
sce_net2instance = {}
net2task_id = {'scenario': {}}
+ # Mapping between local networks and WIMs
+ wim_usage = {}
def ip_profile_IM2RO(ip_profile_im):
# translate from input format to database format
if not involved_datacenters:
involved_datacenters.append(default_datacenter_id)
+ # --> WIM
+ # TODO: use this information during network creation
+ wim_account_id = None
+ if len(involved_datacenters) > 1 and 'uuid' in sce_net:
+ # OBS: sce_net without uuid are used internally to VNFs
+ # and the assumption is that VNFs will not be split among
+ # different datacenters
+ wim_account_id = wim_engine.find_suitable_wim_account(
+ involved_datacenters, tenant_id)
+ wim_usage[sce_net['uuid']] = wim_account_id
+ # <-- WIM
+
descriptor_net = {}
if instance_dict.get("networks") and instance_dict["networks"].get(sce_net["name"]):
descriptor_net = instance_dict["networks"][sce_net["name"]]
db_instance_action["number_tasks"] = task_index
# --> WIM
- wan_links = wim_engine.derive_wan_links(db_instance_nets, tenant_id)
+ logger.debug('wim_usage:\n%s\n\n', pformat(wim_usage))
+ wan_links = wim_engine.derive_wan_links(wim_usage, db_instance_nets, tenant_id)
wim_actions = wim_engine.create_actions(wan_links)
wim_actions, db_instance_action = (
wim_engine.incorporate_actions(wim_actions, db_instance_action))
"""Find a single WIM that is able to connect all the datacenters
listed
- Raises
+ Raises:
NoWimConnectedToDatacenters: if no WIM connected to all datacenters
at once is found
"""
# used here)
return suitable_wim_ids[0]
+ def find_suitable_wim_account(self, datacenter_ids, tenant):
+ """Find a WIM account that is able to connect all the datacenters
+ listed
+
+ Arguments:
+ datacenter_ids (list): List of UUIDs of all the datacenters (vims),
+ that need to be connected.
+ tenant (str): UUID of the OSM tenant
+
+ Returns:
+ str: UUID of the WIM account that is able to connect all the
+ datacenters.
+ """
+ wim_id = self.find_common_wim(datacenter_ids, tenant)
+ return self.persist.get_wim_account_by(wim_id, tenant)['uuid']
+
def derive_wan_link(self,
+ wim_usage,
instance_scenario_id, sce_net_id,
networks, tenant):
"""Create a instance_wim_nets record for the given information"""
- datacenters = [n['datacenter_id'] for n in networks]
- wim_id = self.find_common_wim(datacenters, tenant)
-
- account = self.persist.get_wim_account_by(wim_id, tenant)
+ if sce_net_id in wim_usage:
+ account_id = wim_usage[sce_net_id]
+ account = self.persist.get_wim_account_by(uuid=account_id)
+ wim_id = account['wim_id']
+ else:
+ datacenters = [n['datacenter_id'] for n in networks]
+ wim_id = self.find_common_wim(datacenters, tenant)
+ account = self.persist.get_wim_account_by(wim_id, tenant)
return {
'uuid': str(uuid4()),
'wim_account_id': account['uuid']
}
- def derive_wan_links(self, networks, tenant=None):
+ def derive_wan_links(self, wim_usage, networks, tenant=None):
"""Discover and return what are the wan_links that have to be created
considering a set of networks (VLDs) required for a scenario instance
(NSR).
Arguments:
+ wim_usage(dict): Mapping between sce_net_id and wim_id
networks(list): Dicts containing the information about the networks
that will be instantiated to materialize a Network Service
(scenario) instance.
+ Corresponding to the ``instance_net`` record.
Returns:
list: list of WAN links to be written to the database
if counter > 1]
return [
- self.derive_wan_link(key[0], key[1], grouped_networks[key], tenant)
+ self.derive_wan_link(wim_usage,
+ key[0], key[1], grouped_networks[key], tenant)
for key in wan_groups
]
kwargs.setdefault('WHERE', {'wim_account.uuid': uuid})
return self.query(FROM=_WIM_ACCOUNT_JOIN, **kwargs)
- def get_wim_account_by(self, wim=None, tenant=None, **kwargs):
+ def get_wim_account_by(self, wim=None, tenant=None, uuid=None, **kwargs):
"""Similar to ``get_wim_accounts_by``, but ensuring just one result"""
kwargs.setdefault('error_if_multiple', True)
- return self.get_wim_accounts_by(wim, tenant, **kwargs)[0]
+ return self.get_wim_accounts_by(wim, tenant, uuid, **kwargs)[0]
def get_wim_accounts(self, **kwargs):
"""Retrieve all the accounts from the database"""
# When we receive a list of 4 instance nets, representing
# 2 VLDs connecting 2 datacenters each
instance_nets = eg.instance_nets(2, 2)
- wan_links = engine.derive_wan_links(
- instance_nets, uuid('tenant0'))
+ wan_links = engine.derive_wan_links({}, instance_nets, uuid('tenant0'))
# Then we should derive 2 wan_links with the same instance_scenario_id
# and different scenario_network_id