def get_vnf_package_vnfd(self, context, vnf_package, cast=False): serializer = objects_base.TackerObjectSerializer() client = rpc.get_client(self.target, version_cap=None, serializer=serializer) cctxt = client.prepare() rpc_method = cctxt.cast if cast else cctxt.call return rpc_method(context, 'get_vnf_package_vnfd', vnf_package=vnf_package)
def _update(self, status): LOG.info("VIM %s changed to status %s", self.vim_id, status) target = vim_monitor_rpc.VIMUpdateRPC.target rpc_client = rpc.get_client(target) cctxt = rpc_client.prepare() return cctxt.call(t_context.get_admin_context_without_session(), 'update_vim', vim_id=self.vim_id, status=status)
def send_notification(self, context, notification, cast=True): serializer = objects_base.TackerObjectSerializer() client = rpc.get_client(self.target, version_cap=None, serializer=serializer) cctxt = client.prepare() rpc_method = cctxt.cast if cast else cctxt.call return rpc_method(context, 'send_notification', notification=notification)
def heal(self, context, vnf_instance, heal_vnf_request, cast=True): serializer = objects_base.TackerObjectSerializer() client = rpc.get_client(self.target, version_cap=None, serializer=serializer) cctxt = client.prepare() rpc_method = cctxt.cast if cast else cctxt.call return rpc_method(context, 'heal', vnf_instance=vnf_instance, heal_vnf_request=heal_vnf_request)
def terminate(self, context, vnf_instance, terminate_vnf_req, cast=True): serializer = objects_base.TackerObjectSerializer() client = rpc.get_client(self.target, version_cap=None, serializer=serializer) cctxt = client.prepare() rpc_method = cctxt.cast if cast else cctxt.call return rpc_method(context, 'terminate', vnf_instance=vnf_instance, terminate_vnf_req=terminate_vnf_req)
def upload_vnf_package_from_uri(self, context, vnf_package, address_information, user_name=None, password=None, cast=True): serializer = objects_base.TackerObjectSerializer() client = rpc.get_client(self.target, version_cap=None, serializer=serializer) cctxt = client.prepare() rpc_method = cctxt.cast if cast else cctxt.call return rpc_method(context, 'upload_vnf_package_from_uri', vnf_package=vnf_package, address_information=address_information, user_name=user_name, password=password)
def rollback(self, context, vnf_info, vnf_instance, operation_params, cast=True): serializer = objects_base.TackerObjectSerializer() client = rpc.get_client(self.target, version_cap=None, serializer=serializer) cctxt = client.prepare() rpc_method = cctxt.cast if cast else cctxt.call return rpc_method(context, 'rollback', vnf_info=vnf_info, vnf_instance=vnf_instance, operation_params=operation_params)
def update(self, context, vnf_lcm_opoccs, body_data, vnfd_pkg_data, vnfd_id, cast=True): serializer = objects_base.TackerObjectSerializer() client = rpc.get_client(self.target, version_cap=None, serializer=serializer) cctxt = client.prepare() rpc_method = cctxt.cast if cast else cctxt.call return rpc_method(context, 'update', vnf_lcm_opoccs=vnf_lcm_opoccs, body_data=body_data, vnfd_pkg_data=vnfd_pkg_data, vnfd_id=vnfd_id)
def instantiate(self, context, vnf_instance, vnf, instantiate_vnf, vnf_lcm_op_occs_id, cast=True): serializer = objects_base.TackerObjectSerializer() client = rpc.get_client(self.target, version_cap=None, serializer=serializer) cctxt = client.prepare() rpc_method = cctxt.cast if cast else cctxt.call return rpc_method(context, 'instantiate', vnf_instance=vnf_instance, vnf_dict=vnf, instantiate_vnf=instantiate_vnf, vnf_lcm_op_occs_id=vnf_lcm_op_occs_id)
def kill_action(context, vim_obj): target = killaction.MistralActionKillRPC.target rpc_client = rpc.get_client(target) cctxt = rpc_client.prepare(server=vim_obj['id']) cctxt.cast(context, 'killAction')
def __init__(self, topic, default_version, version_cap=None): self.topic = topic target = oslo_messaging.Target(topic=topic, version=default_version) self._client = n_rpc.get_client(target, version_cap=version_cap)
def execute_action(self, plugin, context, vnf_dict, args): # Respawn Action vnf_id = vnf_dict['id'] vim_id = vnf_dict['vim_id'] attributes = vnf_dict['attributes'] LOG.info('vnf %s is dead and needs to be respawned', vnf_id) def _update_failure_count(): failure_count = int(attributes.get('failure_count', '0')) + 1 failure_count_str = str(failure_count) LOG.debug("vnf %(vnf_id)s failure count %(failure_count)s", {'vnf_id': vnf_id, 'failure_count': failure_count_str}) attributes['failure_count'] = failure_count_str attributes['dead_instance_id_' + failure_count_str] = vnf_dict[ 'instance_id'] def _fetch_vim(vim_uuid): vim_res = vim_client.VimClient().get_vim(context, vim_uuid) return vim_res def _delete_heat_stack(vim_auth): placement_attr = vnf_dict.get('placement_attr', {}) region_name = placement_attr.get('region_name') heatclient = hc.HeatClient(auth_attr=vim_auth, region_name=region_name) heatclient.delete(vnf_dict['instance_id']) LOG.debug("Heat stack %s delete initiated", vnf_dict['instance_id']) _log_monitor_events(context, vnf_dict, "ActionRespawnHeat invoked") def _respawn_vnf(): update_vnf_dict = plugin.create_vnf_sync(context, vnf_dict) LOG.info('respawned new vnf %s', update_vnf_dict['id']) plugin.config_vnf(context, update_vnf_dict) return update_vnf_dict def start_rpc_listeners(vnf_id): self.endpoints = [self] self.connection = rpc.create_connection() self.connection.create_consumer(topics.TOPIC_ACTION_KILL, self.endpoints, fanout=False, host=vnf_id) return self.connection.consume_in_threads() def get_connection_points(vnf_dict, vim_id): instance_id = vnf_dict['instance_id'] placement_attr = vnf_dict.get('placement_attr', {}) region_name = placement_attr.get('region_name') vim_res = _fetch_vim(vim_id) try: heatclient = hc.HeatClient(auth_attr=vim_res['vim_auth'], region_name=region_name) resources_ids = heatclient.resource_get_list(instance_id, nested_depth=2) vnf_details = {resource.resource_name: {"id": resource.physical_resource_id, "type": resource.resource_type} for resource in resources_ids} cp_dict = {} for name, info in vnf_details.items(): if info.get('type') == 'OS::Neutron::Port': cp_dict[name] = info.get('id') LOG.info('log: cp_dict : %s', cp_dict) ### except Exception: LOG.exception('failed to call heat API') return 'FAILED' return cp_dict old_cp_dict = get_connection_points(vnf_dict, vim_id) # Respawn if plugin._mark_vnf_dead(vnf_dict['id']): _update_failure_count() vim_res = _fetch_vim(vim_id) if vnf_dict['attributes'].get('monitoring_policy'): plugin._vnf_monitor.mark_dead(vnf_dict['id']) _delete_heat_stack(vim_res['vim_auth']) updated_vnf = _respawn_vnf() plugin.add_vnf_to_monitor(context, updated_vnf) LOG.debug("VNF %s added to monitor thread", updated_vnf['id']) if vnf_dict['attributes'].get('alarming_policy'): _delete_heat_stack(vim_res['vim_auth']) vnf_dict['attributes'].pop('alarming_policy') _respawn_vnf() # Notify and heal vnffg new_vnf_id = updated_vnf['id'] LOG.debug('log : new_vnf %s is respawned and needs to notify', \ new_vnf_id) # Start rpc connection try: rpc.init_action_rpc(cfg.CONF) ### servers = start_rpc_listeners(new_vnf_id) except Exception: LOG.exception('failed to start rpc') return 'FAILED' # Call 'vnf_respawning_event' method via ConductorRPC #TODO: try: target = AutoHealingRPC.AutoHealingRPC.target rpc_client = rpc.get_client(target) cctxt = rpc_client.prepare() # Get new_VNF status from vnfm_db status = cctxt.call(t_context.get_admin_context_without_session(), 'vnf_respawning_event', vnf_id=new_vnf_id) if status == constants.ACTIVE: new_cp_dict = get_connection_points(updated_vnf, vim_id) nfvo_plugin = manager.TackerManager.get_service_plugins()['NFVO'] LOG.debug('old_cp_dict is %s', old_cp_dict) LOG.debug('new_cp_dict is %s', new_cp_dict) nfvo_plugin.heal_vnffg(context, vnf_dict, old_cp_dict, new_cp_dict) except Exception: LOG.exception('failed to call rpc') return 'FAILED' for server in servers: try: server.stop() except Exception: LOG.exception('failed to stop rpc connection for vnf %s', new_vnf_id)
def _establish_rpc(target, event_func_name): rpc_client = rpc.get_client(target) cctxt = rpc_client.prepare() return cctxt.call(t_context.get_admin_context_without_session(), event_func_name, vnf_id=vnf_id)