class OpenmanoNsr(object):
TIMEOUT_SECS = 120
- def __init__(self, dts, log, loop, publisher, cli_api, http_api, nsd_msg, nsr_config_msg):
+ def __init__(self, dts, log, loop, publisher, cli_api, http_api, nsd_msg, nsr_config_msg,key_pairs):
self._dts = dts
self._log = log
self._loop = loop
self._vlrs = []
self._vnfrs = []
self._vdur_console_handler = {}
+ self._key_pairs = key_pairs
self._nsd_uuid = None
self._nsr_uuid = None
openmano_nsd = rift2openmano.rift2openmano_nsd(self.nsd, self.vnfds,self.vnfr_ids)
return yaml.safe_dump(openmano_nsd, default_flow_style=False)
+ def get_ssh_key_pairs(self):
+ cloud_config = {}
+ key_pairs = list()
+ for authorized_key in self._nsr_config_msg.ssh_authorized_key:
+ self._log.debug("Key pair ref present is %s",authorized_key.key_pair_ref)
+ if authorized_key.key_pair_ref in self._key_pairs:
+ key_pairs.append(self._key_pairs[authorized_key.key_pair_ref].key)
+
+ for authorized_key in self._nsd_msg.key_pair:
+ self._log.debug("Key pair NSD is %s",authorized_key)
+ key_pairs.append(authorized_key.key)
+
+ if key_pairs:
+ cloud_config["key-pairs"] = key_pairs
+
+ users = list()
+ for user_entry in self._nsr_config_msg.user:
+ self._log.debug("User present is %s",user_entry)
+ user = {}
+ user["name"] = user_entry.name
+ user["key-pairs"] = list()
+ for ssh_key in user_entry.key_pair:
+ user["key-pairs"].append(ssh_key.key)
+ users.append(user)
+
+ for user_entry in self._nsd_msg.user:
+ self._log.debug("User present in NSD is %s",user_entry)
+ user = {}
+ user["name"] = user_entry.name
+ user["key-pairs"] = list()
+ for ssh_key in user_entry.key_pair:
+ user["key-pairs"].append(ssh_key.key)
+ users.append(user)
+
+ if users:
+ cloud_config["users"] = users
+
+ self._log.debug("Cloud config formed is %s",cloud_config)
+ return cloud_config
+
@property
def openmano_instance_create_yaml(self):
openmano_instance_create["name"] = self._nsr_config_msg.name
openmano_instance_create["description"] = self._nsr_config_msg.description
openmano_instance_create["scenario"] = self._nsd_uuid
+
+ cloud_config = self.get_ssh_key_pairs()
+ if cloud_config:
+ openmano_instance_create["cloud-config"] = cloud_config
if self._nsr_config_msg.has_field("om_datacenter"):
openmano_instance_create["datacenter"] = self._nsr_config_msg.om_datacenter
openmano_instance_create["vnfs"] = {}
openmano_instance_create["networks"][vld_msg.name]["sites"].append(network)
if ip_profile:
openmano_instance_create["networks"][vld_msg.name]['ip-profile'] = ip_profile
+
return yaml.safe_dump(openmano_instance_create, default_flow_style=False)
ro_account.openmano.tenant_id,
)
- def create_nsr(self, nsr_config_msg, nsd_msg):
+ def create_nsr(self, nsr_config_msg, nsd_msg, key_pairs=None):
"""
Create Network service record
"""
self._cli_api,
self._http_api,
nsd_msg,
- nsr_config_msg
+ nsr_config_msg,
+ key_pairs
)
self._openmano_nsrs[nsr_config_msg.id] = openmano_nsr
""" Network service record """
XPATH = "D,/nsr:ns-instance-opdata/nsr:nsr"
- def __init__(self, dts, log, loop, nsm, nsm_plugin, nsr_cfg_msg, sdn_account_name, restart_mode=False):
+ def __init__(self, dts, log, loop, nsm, nsm_plugin, nsr_cfg_msg, sdn_account_name, key_pairs, restart_mode=False):
self._dts = dts
self._log = log
self._loop = loop
self._nsd = None
self._nsr_msg = None
self._nsr_regh = None
+ self._key_pairs = key_pairs
self._vlrs = []
self._vnfrs = {}
self._vnfds = {}
""" The network service DTS handler """
NSR_XPATH = "C,/nsr:ns-instance-config/nsr:nsr"
SCALE_INSTANCE_XPATH = "C,/nsr:ns-instance-config/nsr:nsr/nsr:scaling-group/nsr:instance"
+ KEY_PAIR_XPATH = "C,/nsr:key-pair"
def __init__(self, dts, log, loop, nsm):
self._dts = dts
self._nsr_regh = None
self._scale_regh = None
+ self._key_pair_regh = None
@property
def nsm(self):
return added_cfgs, deleted_cfgs, updated_cfgs
+ def get_nsr_key_pairs(dts_member_reg, xact):
+ key_pairs = {}
+ for instance_cfg, keyspec in dts_member_reg.get_xact_elements(xact, include_keyspec=True):
+ self._log.debug("Key pair received is {} KS: {}".format(instance_cfg, keyspec))
+ xpath = keyspec.to_xpath(RwNsrYang.get_schema())
+ key_pairs[instance_cfg.name] = instance_cfg
+ return key_pairs
+
def on_apply(dts, acg, xact, action, scratch):
"""Apply the configuration"""
self._log.debug("Got nsr apply (xact: %s) (action: %s)(scr: %s)",
xact, action, scratch)
- def handle_create_nsr(msg, restart_mode=False):
+ def handle_create_nsr(msg, key_pairs=None, restart_mode=False):
# Handle create nsr requests """
# Do some validations
if not msg.has_field("nsd"):
self._log.debug("Creating NetworkServiceRecord %s from nsr config %s",
msg.id, msg.as_dict())
- nsr = self.nsm.create_nsr(msg, restart_mode=restart_mode)
+ nsr = self.nsm.create_nsr(msg, key_pairs=key_pairs, restart_mode=restart_mode)
return nsr
def handle_delete_nsr(msg):
xact, action, scratch)
if action == rwdts.AppconfAction.INSTALL and xact.id is None:
+ key_pairs = []
+ for element in self._key_pair_regh.elements:
+ key_pairs.append(element)
for element in self._nsr_regh.elements:
- nsr = handle_create_nsr(element, restart_mode=True)
+ nsr = handle_create_nsr(element, key_pairs, restart_mode=True)
self._loop.create_task(begin_instantiation(nsr))
for msg in added_msgs:
if msg.id not in self._nsm.nsrs:
self._log.info("Create NSR received in on_apply to instantiate NS:%s", msg.id)
- nsr = handle_create_nsr(msg)
+ key_pairs = get_nsr_key_pairs(self._key_pair_regh, xact)
+ nsr = handle_create_nsr(msg,key_pairs)
self._loop.create_task(begin_instantiation(nsr))
for msg in deleted_msgs:
flags=rwdts.Flag.SUBSCRIBER | rwdts.Flag.DELTA_READY| rwdts.Flag.CACHE,
)
+ self._key_pair_regh = acg.register(
+ xpath=NsrDtsHandler.KEY_PAIR_XPATH,
+ flags=rwdts.Flag.SUBSCRIBER | rwdts.Flag.DELTA_READY | rwdts.Flag.CACHE,
+ )
+
class NsrOpDataDtsHandler(object):
""" The network service op data DTS handler """
# Not calling in a separate task as this is called from a separate task
yield from nsr.delete_vl_instance(vld)
- def create_nsr(self, nsr_msg, restart_mode=False):
+ def create_nsr(self, nsr_msg, key_pairs=None,restart_mode=False):
""" Create an NSR instance """
if nsr_msg.id in self._nsrs:
msg = "NSR id %s already exists" % nsr_msg.id
nsm_plugin,
nsr_msg,
sdn_account_name,
+ key_pairs,
restart_mode=restart_mode
)
self._nsrs[nsr_msg.id] = nsr
- nsm_plugin.create_nsr(nsr_msg, nsr_msg.nsd)
+ nsm_plugin.create_nsr(nsr_msg, nsr_msg.nsd, key_pairs)
return nsr