def _resource_mark_unhealthy(self): """Mark the resource unhealthy using heat.""" additional_params = self.heal_request_data_obj.additional_params for additional_param in additional_params: resource_name = additional_param.parameter res_status = self._get_resource_status( self.vnf_dict['instance_id'], resource_name) if res_status != 'CHECK_FAILED': self.heat_client.resource_mark_unhealthy( stack_id=self.vnf_dict['instance_id'], resource_name=resource_name, mark_unhealthy=True, resource_status_reason=additional_param.cause) LOG.debug("Heat stack '%s' resource '%s' marked as " "unhealthy", self.vnf_dict['instance_id'], resource_name) evt_details = (("HealVnfRequest invoked to mark resource " "'%s' to unhealthy.") % resource_name) vnfm_utils.log_events(self.context, self.vnf_dict, constants.RES_EVT_HEAL, evt_details) else: LOG.debug("Heat stack '%s' resource '%s' already mark " "unhealthy.", self.vnf_dict['instance_id'], resource_name)
def create_alarm_action(action, action_list, scaling_type): params = dict() params['vnf_id'] = vnf['id'] params['mon_policy_name'] = action driver = 'ceilometer' def _refactor_backend_policy(bk_policy_name, bk_action_name): policy = '%(policy_name)s%(action_name)s' % { 'policy_name': bk_policy_name, 'action_name': bk_action_name} return policy for index, policy_action_name in enumerate(action_list): filters = {'name': policy_action_name} bkend_policies = \ plugin.get_vnf_policies(context, vnf['id'], filters) if bkend_policies: if constants.POLICY_SCALING in str(bkend_policies[0]): action_list[index] = _refactor_backend_policy( policy_action_name, scaling_type) # Support multiple action. Ex: respawn % notify action_name = '%'.join(action_list) params['mon_policy_action'] = action_name alarm_url[action] = \ self.call_alarm_url(driver, vnf, params) details = "Alarm URL set successfully: %s" % alarm_url vnfm_utils.log_events(t_context.get_admin_context(), vnf, constants.RES_EVT_MONITOR, details)
def _resource_mark_unhealthy(self): """Mark the resource unhealthy using heat.""" additional_params = self.heal_request_data_obj.additional_params for additional_param in additional_params: resource_name = additional_param.parameter res_status = self._get_resource_status(self.stack_id, resource_name) if res_status != 'CHECK_FAILED': self.heat_client.resource_mark_unhealthy( stack_id=self.stack_id, resource_name=resource_name, mark_unhealthy=True, resource_status_reason=additional_param.cause) LOG.debug( "Heat stack '%s' resource '%s' marked as " "unhealthy", self.stack_id, resource_name) evt_details = (("HealVnfRequest invoked to mark resource " "'%s' to unhealthy.") % resource_name) vnfm_utils.log_events(self.context, self.vnf_dict, constants.RES_EVT_HEAL, evt_details) else: LOG.debug( "Heat stack '%s' resource '%s' already mark " "unhealthy.", self.stack_id, resource_name)
def execute_action(self, plugin, context, vnf_dict, args): vnfm_utils.log_events(context, vnf_dict, constants.RES_EVT_MONITOR, "ActionLogAndKill invoked") vnf_id = vnf_dict['id'] if plugin._mark_vnf_dead(vnf_dict['id']): if vnf_dict['attributes'].get('monitoring_policy'): plugin._vnf_monitor.mark_dead(vnf_dict['id']) plugin.delete_vnf(context, vnf_id) LOG.error('vnf %s dead', vnf_id)
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']) vnfm_utils.log_events(context, vnf_dict, constants.RES_EVT_MONITOR, "ActionRespawnHeat invoked")
def update_hosting_vnf(self, updated_vnf_dict, evt_details=None): with self._lock: vnf_to_update = VNFMonitor._hosting_vnfs.get( updated_vnf_dict.get('id')) if vnf_to_update: updated_vnf = copy.deepcopy(updated_vnf_dict) vnf_to_update['vnf'] = updated_vnf vnf_to_update['mgmt_ip_addresses'] = jsonutils.loads( updated_vnf_dict['mgmt_ip_address']) if evt_details is not None: vnfm_utils.log_events(t_context.get_admin_context(), vnf_to_update['vnf'], constants.RES_EVT_HEAL, evt_details=evt_details)
def add_hosting_vnf(self, new_vnf): LOG.debug('Adding host %(id)s, Mgmt IP %(ips)s', { 'id': new_vnf['id'], 'ips': new_vnf['mgmt_ip_addresses'] }) new_vnf['boot_at'] = timeutils.utcnow() with self._lock: VNFMonitor._hosting_vnfs[new_vnf['id']] = new_vnf attrib_dict = new_vnf['vnf']['attributes'] mon_policy_dict = attrib_dict['monitoring_policy'] evt_details = (("VNF added for monitoring. " "mon_policy_dict = %s,") % (mon_policy_dict)) vnfm_utils.log_events(t_context.get_admin_context(), new_vnf['vnf'], constants.RES_EVT_MONITOR, evt_details)
def add_hosting_vnf(self, new_vnf): LOG.debug('Adding host %(id)s, Mgmt IP %(ips)s', {'id': new_vnf['id'], 'ips': new_vnf['mgmt_ip_addresses']}) new_vnf['boot_at'] = timeutils.utcnow() with self._lock: VNFMonitor._hosting_vnfs[new_vnf['id']] = new_vnf attrib_dict = new_vnf['vnf']['attributes'] mon_policy_dict = attrib_dict['monitoring_policy'] evt_details = (("VNF added for monitoring. " "mon_policy_dict = %s,") % (mon_policy_dict)) vnfm_utils.log_events(t_context.get_admin_context(), new_vnf['vnf'], constants.RES_EVT_MONITOR, evt_details)
def update_vnf_with_alarm(self, plugin, context, vnf, policy_dict): triggers = policy_dict['triggers'] alarm_url = dict() for trigger_name, trigger_dict in triggers.items(): params = dict() params['vnf_id'] = vnf['id'] params['mon_policy_name'] = trigger_name driver = trigger_dict['event_type']['implementation'] # TODO(Tung Doan) trigger_dict.get('actions') needs to be used policy_action = trigger_dict.get('action') if len(policy_action) == 0: vnfm_utils.log_events(t_context.get_admin_context(), vnf, constants.RES_EVT_MONITOR, "Alarm not set: policy action missing") return # Other backend policies with the construct (policy, action) # ex: (SP1, in), (SP1, out) def _refactor_backend_policy(bk_policy_name, bk_action_name): policy = '%(policy_name)s-%(action_name)s' % { 'policy_name': bk_policy_name, 'action_name': bk_action_name } return policy for index, policy_action_name in enumerate(policy_action): filters = {'name': policy_action_name} bkend_policies =\ plugin.get_vnf_policies(context, vnf['id'], filters) if bkend_policies: bkend_policy = bkend_policies[0] if bkend_policy['type'] == constants.POLICY_SCALING: cp = trigger_dict['condition'].\ get('comparison_operator') scaling_type = 'out' if cp == 'gt' else 'in' policy_action[index] = _refactor_backend_policy( policy_action_name, scaling_type) # Support multiple action. Ex: respawn % notify action_name = '%'.join(policy_action) params['mon_policy_action'] = action_name alarm_url[trigger_name] =\ self.call_alarm_url(driver, vnf, params) details = "Alarm URL set successfully: %s" % alarm_url vnfm_utils.log_events(t_context.get_admin_context(), vnf, constants.RES_EVT_MONITOR, details) return alarm_url
def heal_vdu(self): """Update stack using heat. This will re-create the resource which are mark as unhealthy. """ # Mark all the resources as unhealthy self._resource_mark_unhealthy() self.heat_client.update(stack_id=self.stack_id, existing=True) LOG.debug( "Heat stack '%s' update initiated to revive " "unhealthy resources.", self.stack_id) evt_details = (("HealVnfRequest invoked to update the stack " "'%s'") % self.stack_id) vnfm_utils.log_events(self.context, self.vnf_dict, constants.RES_EVT_HEAL, evt_details)
def heal_vdu(self): """Update stack using heat. This will re-create the resource which are mark as unhealthy. """ # Mark all the resources as unhealthy self._resource_mark_unhealthy() self.heat_client.update(stack_id=self.vnf_dict['instance_id'], existing=True) LOG.debug("Heat stack '%s' update initiated to revive " "unhealthy resources.", self.vnf_dict['instance_id']) evt_details = (("HealVnfRequest invoked to update the stack " "'%s'") % self.vnf_dict['instance_id']) vnfm_utils.log_events(self.context, self.vnf_dict, constants.RES_EVT_HEAL, evt_details)
def update_vnf_with_alarm(self, plugin, context, vnf, policy_dict): triggers = policy_dict['triggers'] alarm_url = dict() for trigger_name, trigger_dict in triggers.items(): params = dict() params['vnf_id'] = vnf['id'] params['mon_policy_name'] = trigger_name driver = trigger_dict['event_type']['implementation'] # TODO(Tung Doan) trigger_dict.get('actions') needs to be used policy_action = trigger_dict.get('action') if len(policy_action) == 0: vnfm_utils.log_events(t_context.get_admin_context(), vnf, constants.RES_EVT_MONITOR, "Alarm not set: policy action missing") return # Other backend policies with the construct (policy, action) # ex: (SP1, in), (SP1, out) def _refactor_backend_policy(bk_policy_name, bk_action_name): policy = '%(policy_name)s-%(action_name)s' % { 'policy_name': bk_policy_name, 'action_name': bk_action_name} return policy for index, policy_action_name in enumerate(policy_action): filters = {'name': policy_action_name} bkend_policies =\ plugin.get_vnf_policies(context, vnf['id'], filters) if bkend_policies: bkend_policy = bkend_policies[0] if bkend_policy['type'] == constants.POLICY_SCALING: cp = trigger_dict['condition'].\ get('comparison_operator') scaling_type = 'out' if cp == 'gt' else 'in' policy_action[index] = _refactor_backend_policy( policy_action_name, scaling_type) # Support multiple action. Ex: respawn % notify action_name = '%'.join(policy_action) params['mon_policy_action'] = action_name alarm_url[trigger_name] =\ self.call_alarm_url(driver, vnf, params) details = "Alarm URL set successfully: %s" % alarm_url vnfm_utils.log_events(t_context.get_admin_context(), vnf, constants.RES_EVT_MONITOR, details) return alarm_url
def update_vnf_with_maintenance(self, vnf, vdu_names): maintenance = dict() vdus = dict() params = dict() params['vnf_id'] = vnf['id'] params['mon_policy_name'] = 'maintenance' params['mon_policy_action'] = vnf['tenant_id'] driver = 'ceilometer' url = self.call_alarm_url(driver, vnf, params) maintenance['url'] = url[:url.rindex('/')] vdu_names.append('ALL') for vdu in vdu_names: access_key = ''.join( random.SystemRandom().choice( string.ascii_lowercase + string.digits) for _ in range(8)) vdus[vdu] = access_key maintenance.update({'vdus': vdus}) details = "Alarm URL set successfully: %s" % maintenance['url'] vnfm_utils.log_events(t_context.get_admin_context(), vnf, constants.RES_EVT_MONITOR, details) return maintenance
def execute_action(self, plugin, context, vnf_dict, args): vnf_id = vnf_dict['id'] vnfm_utils.log_events(context, vnf_dict, constants.RES_EVT_MONITOR, "ActionAutoscalingHeat invoked") plugin.create_vnf_scale(context, vnf_id, args) 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') except Exception: LOG.exception('failed to call heat API') return 'FAILED' return cp_dict old_cp_dict = get_connection_points(vnf_dict, vim_id) vim_id = vnf_dict['vim_id'] attributes = vnf_dict['attributes'] try: rpc.init_action_rpc(cfg.CONF) servers = start_rpc_listeners(vnf_id) except Exception: LOG.exception('failed to start rpc') return 'FAILED' # Call 'vnf_scaling_event' method via ConductorRPC try: target = AutoScalingRPC.AutoScalingRPC.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_scaling_event', vnf_id=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 execute_action(self, plugin, context, vnf_dict, args): vnf_id = vnf_dict['id'] LOG.error('vnf %s dead', vnf_id) vnfm_utils.log_events(context, vnf_dict, constants.RES_EVT_MONITOR, "ActionLogOnly invoked")
def execute_action(self, plugin, context, vnf_dict, args): vnf_id = vnf_dict['id'] vnfm_utils.log_events(context, vnf_dict, constants.RES_EVT_MONITOR, "ActionAutoscalingHeat invoked") plugin.create_vnf_scale(context, vnf_id, args)