X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=blobdiff_plain;f=n2vc%2Fvnf.py;h=74f4d9432d0efdd7b4e508a4429627bab0c8f537;hp=38a9d154482d64925772c25836f7c8b8832072f4;hb=bc0daf83db3d783039db7c8c8496a4eb0ceddfe0;hpb=b2a07f566be558a8b59b8b5dedfe8da5ae1b0132 diff --git a/n2vc/vnf.py b/n2vc/vnf.py index 38a9d15..74f4d94 100644 --- a/n2vc/vnf.py +++ b/n2vc/vnf.py @@ -246,9 +246,15 @@ class N2VC: is bootstrapped to. This method will write the public key to disk in that location: ~/.local/share/juju/ssh/juju_id_rsa.pub """ + # Make sure that we have a public key before writing to disk if public_key is None or len(public_key) == 0: - return - + if 'OSM_VCA_PUBKEY' in os.environ: + public_key = os.getenv('OSM_VCA_PUBKEY', '') + if len(public_key == 0): + return + else: + return + path = "{}/.local/share/juju/ssh".format( os.path.expanduser('~'), ) @@ -281,9 +287,10 @@ class N2VC: vdu: ... - relation: - - provides: dataVM:db - requires: mgmtVM:app + vca-relationships: + relation: + - provides: dataVM:db + requires: mgmtVM:app This tells N2VC that the charm referred to by the dataVM vdu offers a relation named 'db', and the mgmtVM vdu has an 'app' endpoint that should be connected to a database. @@ -333,8 +340,9 @@ class N2VC: # Loop through relations for cfg in configs: if 'juju' in cfg: - if 'relation' in juju: - for rel in juju['relation']: + juju = cfg['juju'] + if 'vca-relationships' in juju and 'relation' in juju['vca-relationships']: + for rel in juju['vca-relationships']['relation']: try: # get the application name for the provides @@ -437,11 +445,10 @@ class N2VC: # Register this application with the model-level event monitor # ################################################################ if callback: - self.monitors[model_name].AddApplication( + self.log.debug("JujuApi: Registering callback for {}".format( application_name, - callback, - *callback_args - ) + )) + await self.Subscribe(model_name, application_name, callback, *callback_args) ######################################################## # Check for specific machine placement (native charms) # @@ -451,8 +458,8 @@ class N2VC: if all(k in machine_spec for k in ['host', 'user']): # Enlist an existing machine as a Juju unit machine = await model.add_machine(spec='ssh:{}@{}:{}'.format( - machine_spec['user'], - machine_spec['host'], + machine_spec['username'], + machine_spec['hostname'], self.GetPrivateKeyPath(), )) to = machine.id @@ -497,10 +504,19 @@ class N2VC: # Where to deploy the charm to. to=to, ) - - # Map the vdu id<->app name, - # - await self.Relate(model_name, vnfd) + ############################# + # Map the vdu id<->app name # + ############################# + try: + await self.Relate(model_name, vnfd) + except KeyError as ex: + # We don't currently support relations between NS and VNF/VDU charms + self.log.warn("[N2VC] Relations not supported: {}".format(ex)) + except Exception as ex: + # This may happen if not all of the charms needed by the relation + # are ready. We can safely ignore this, because Relate will be + # retried when the endpoint of the relation is deployed. + self.log.warn("[N2VC] Relations not ready") # ####################################### # # Execute initial config primitive(s) # @@ -795,7 +811,7 @@ class N2VC: app = await self.get_application(model, application_name) if app: # Remove this application from event monitoring - self.monitors[model_name].RemoveApplication(application_name) + await self.Unsubscribe(model_name, application_name) # self.notify_callback(model_name, application_name, "removing", callback, *callback_args) self.log.debug( @@ -900,6 +916,33 @@ class N2VC: return True return False + async def Subscribe(self, ns_name, application_name, callback, *callback_args): + """Subscribe to callbacks for an application. + + :param ns_name str: The name of the Network Service + :param application_name str: The name of the application + :param callback obj: The callback method + :param callback_args list: The list of arguments to append to calls to + the callback method + """ + self.monitors[ns_name].AddApplication( + application_name, + callback, + *callback_args + ) + + async def Unsubscribe(self, ns_name, application_name): + """Unsubscribe to callbacks for an application. + + Unsubscribes the caller from notifications from a deployed application. + + :param ns_name str: The name of the Network Service + :param application_name str: The name of the application + """ + self.monitors[ns_name].RemoveApplication( + application_name, + ) + # Non-public methods async def add_relation(self, model_name, relation1, relation2): """