def publish_measurement_group(sub_model, measurement_group, nf, change_type): """ Publishes an event for measurement group against nfs to MR Args: sub_model(SubscriptionModel): Subscription model object measurement_group (MeasurementGroupModel): Measurement group to publish nf (NetworkFunction): Network function to publish change_type (string): defines event type like CREATE or DELETE """ event_body = nf_service.create_nf_event_body(nf, change_type, sub_model) event_body['subscription'] = { "administrativeState": measurement_group.administrative_state, "subscriptionName": sub_model.subscription_name, "fileBasedGP": measurement_group.file_based_gp, "fileLocation": measurement_group.file_location, "measurementGroup": { "measurementGroupName": measurement_group.measurement_group_name, "measurementTypes": measurement_group.measurement_type, "managedObjectDNsBasic": measurement_group.managed_object_dns_basic } } logger.debug(f'Event Body: {event_body}') AppConfig.get_instance().publish_to_topic( MRTopic.POLICY_PM_PUBLISHER.value, event_body)
def get_aai_model_data(app_conf, model_invariant_id, model_version_id, nf_name): """ Get the sdnc_model info for the xNF from AAI. Args: model_invariant_id (str): the AAI model-invariant-id model_version_id (str): the AAI model-version-id app_conf (AppConfig): the AppConfig object. nf_name (str): The xNF name. Returns: json (dict): the sdnc_model json object. """ session = requests.Session() aai_model_ver_endpoint = \ f'{_get_aai_service_url()}/service-design-and-creation/models/model/' \ f'{model_invariant_id}/model-vers/model-ver/{model_version_id}' logger.info(f'Fetching sdnc-model info for xNF: {nf_name} from AAI.') headers = _get_aai_request_headers() response = session.get(aai_model_ver_endpoint, headers=headers, auth=HTTPBasicAuth(app_conf.aaf_id, app_conf.aaf_pass), verify=(app_conf.ca_cert_path if app_conf.enable_tls else False), cert=((app_conf.cert_path, app_conf.key_path) if app_conf.enable_tls else None)) response.raise_for_status() if response.ok: data = json.loads(response.text) logger.debug(f'Successfully fetched sdnc-model info from AAI: {data}') return data
def create(self): """ Creates a NetworkFunction database entry """ existing_nf = NetworkFunctionModel.query.filter( NetworkFunctionModel.nf_name == self.nf_name).one_or_none() if existing_nf is None: new_nf = NetworkFunctionModel( nf_name=self.nf_name, ipv4_address=self.ipv4_address, ipv6_address=self.ipv6_address, model_invariant_id=self.model_invariant_id, model_version_id=self.model_version_id, model_name=self.model_name, sdnc_model_name=self.sdnc_model_name, sdnc_model_version=self.sdnc_model_version) db.session.add(new_nf) db.session.commit() logger.info( f'Network Function {new_nf.nf_name} successfully created.') return new_nf else: logger.debug( f'Network function {existing_nf.nf_name} already exists,' f' returning this network function..') return existing_nf
def execute(self): """ Processes AAI UPDATE events for each filtered xNFs where orchestration status is set to Active. """ self.app.app_context().push() logger.info('Polling MR for XNF AAI events.') try: aai_events = AppConfig.get_instance().get_from_topic( MRTopic.AAI_SUBSCRIBER.value, 'dcae_pmsh_aai_event') if aai_events is not None and len(aai_events) != 0: pmsh_nf_names = list(nf.nf_name for nf in NetworkFunction.get_all()) aai_events = [json.loads(e) for e in aai_events] xnf_events = [ e for e in aai_events if is_pnf_xnf(e['event-header']['entity-type']) ] new_nfs = [] for entry in xnf_events: logger.debug(f'AAI-EVENT entry: {entry}') aai_entity = entry['entity'] action = entry['event-header']['action'] entity_type = entry['event-header']['entity-type'] xnf_name = aai_entity['pnf-name'] if entity_type == XNFType.PNF.value \ else aai_entity['vnf-name'] if aai_entity['orchestration-status'] != 'Active': logger.info( f'Skipping XNF {xnf_name} as its orchestration-status ' f'is not "Active"') continue nf = NetworkFunction( nf_name=xnf_name, ipv4_address=aai_entity['ipaddress-v4-oam'], ipv6_address=aai_entity['ipaddress-v6-oam'], model_invariant_id=aai_entity['model-invariant-id'], model_version_id=aai_entity['model-version-id']) if action == AAIEvent.DELETE.value and xnf_name in pmsh_nf_names: logger.info( f'Delete event found for network function {nf.nf_name}' ) NetworkFunction.delete(nf_name=nf.nf_name) logger.info(f'{nf.nf_name} successfully deleted.') elif action == AAIEvent.UPDATE.value and \ xnf_name not in pmsh_nf_names and \ nf.set_nf_model_params(AppConfig.get_instance()): new_nfs.append(nf) if new_nfs: self.apply_nfs_to_subscriptions(new_nfs) except Exception as e: logger.error(f'Failed to process AAI event due to: {e}')
def __call__(self, sig_num, frame): logger.info('Graceful shutdown of PMSH initiated.') logger.debug(f'ExitHandler was called with signal number: {sig_num}.') try: subscriptions_all = subscription_service.query_all_subscriptions() for subscription in subscriptions_all: for mg in subscription.measurement_groups: if mg.administrative_state == AdministrativeState.UNLOCKED.value: measurement_group_service.\ update_admin_status(mg, AdministrativeState.LOCKED.value) except Exception as e: logger.error(f'Failed to shut down PMSH application: {e}', exc_info=True) for thread in self.periodic_tasks: logger.info(f'Cancelling thread {thread.name}') thread.cancel() logger.info('Closing all DB connections') db.session.bind.dispose() db.session.close() db.engine.dispose() ExitHandler.shutdown_signal_received = True
def _get_all_aai_nf_data(app_conf): """ Return queried nf data from the AAI service. Args: app_conf (AppConfig): the AppConfig object. Returns: dict: the json response from AAI query, else None. """ nf_data = None try: session = requests.Session() aai_named_query_endpoint = f'{_get_aai_service_url()}{"/query"}' logger.info('Fetching XNFs from AAI.') headers = _get_aai_request_headers() data = """ {'start': ['network/pnfs', 'network/generic-vnfs'] }""" params = {'format': 'simple', 'nodesOnly': 'true'} response = session.put(aai_named_query_endpoint, headers=headers, auth=HTTPBasicAuth(app_conf.aaf_id, app_conf.aaf_pass), data=data, params=params, verify=(app_conf.ca_cert_path if app_conf.enable_tls else False), cert=((app_conf.cert_path, app_conf.key_path) if app_conf.enable_tls else None)) response.raise_for_status() if response.ok: nf_data = json.loads(response.text) logger.info('Successfully fetched XNFs from AAI') logger.debug(f'XNFs from AAI: {nf_data}') except Exception as e: logger.error(f'Failed to get XNFs from AAI: {e}', exc_info=True) return nf_data