def _convert_to_heat_monitoring_prop(self, mon_policy, vnf): metadata = self.metadata trigger_name, trigger_dict = list(mon_policy.items())[0] tpl_condition = trigger_dict['condition'] properties = dict() if not (trigger_dict.get('metadata') and metadata): raise vnfm.MetadataNotMatched() matching_metadata_dict = dict() properties['meter_name'] = trigger_dict['metrics'] is_matched = False for vdu_name, metadata_dict in metadata['vdus'].items(): if trigger_dict['metadata'] ==\ metadata_dict['metering.vnf']: is_matched = True if not is_matched: raise vnfm.MetadataNotMatched() matching_metadata_dict['metadata.user_metadata.vnf'] =\ trigger_dict['metadata'] properties['matching_metadata'] = \ matching_metadata_dict properties['comparison_operator'] = \ tpl_condition['comparison_operator'] properties['period'] = tpl_condition['period'] properties['evaluation_periods'] = tpl_condition['evaluations'] properties['statistic'] = tpl_condition['method'] properties['description'] = tpl_condition['constraint'] properties['threshold'] = tpl_condition['threshold'] # alarm url process here alarm_url = vnf['attributes'].get(trigger_name) if alarm_url: alarm_url = str(alarm_url) LOG.debug('Alarm url in heat %s', alarm_url) properties['alarm_actions'] = [alarm_url] return properties
def _process_query_metadata(metadata, policy, unique_id): query_mtdata = dict() triggers = policy.entity_tpl['triggers'] for trigger_name, trigger_dict in triggers.items(): resource_type = trigger_dict.get('condition').get('resource_type') # TODO(phuoc): currently, Tacker only supports resource_type with # instance value. Other types such as instance_network_interface, # instance_disk can be supported in the future. if resource_type == 'instance': if not (trigger_dict.get('metadata') and metadata): raise vnfm.MetadataNotMatched() is_matched = False for vdu_name, metadata_dict in metadata['vdus'].items(): trigger_dict['metadata'] = \ (trigger_dict['metadata'] + '-' + unique_id)[:15] if trigger_dict['metadata'] == \ metadata_dict['metering.server_group']: is_matched = True if not is_matched: raise vnfm.MetadataNotMatched() query_template = dict() query_template['str_replace'] = dict() query_template['str_replace']['template'] = \ '{"=": {"server_group": "scaling_group_id"}}' scaling_group_param = \ {'scaling_group_id': trigger_dict['metadata']} query_template['str_replace']['params'] = scaling_group_param else: raise vnfm.InvalidResourceType(resource_type=resource_type) query_mtdata[trigger_name] = query_template return query_mtdata
def _process_matching_metadata(metadata, policy): matching_mtdata = dict() triggers = policy.entity_tpl['triggers'] for trigger_name, trigger_dict in triggers.items(): if not (trigger_dict.get('metadata') and metadata): raise vnfm.MetadataNotMatched() is_matched = False for vdu_name, metadata_dict in metadata['vdus'].items(): if trigger_dict['metadata'] ==\ metadata_dict['metering.vnf']: is_matched = True if not is_matched: raise vnfm.MetadataNotMatched() matching_mtdata[trigger_name] = dict() matching_mtdata[trigger_name]['metadata.user_metadata.vnf'] =\ trigger_dict['metadata'] return matching_mtdata
def _process_query_metadata(metadata, policy): query_mtdata = dict() triggers = policy.entity_tpl['triggers'] for trigger_name, trigger_dict in triggers.items(): if not (trigger_dict.get('metadata') and metadata): raise vnfm.MetadataNotMatched() is_matched = False for vdu_name, metadata_dict in metadata['vdus'].items(): if trigger_dict['metadata'] ==\ metadata_dict['metering.server_group']: is_matched = True if not is_matched: raise vnfm.MetadataNotMatched() query_template = '{"=": {"server_group": "scaling_group_id"}}' query_mtdata[trigger_name] = \ query_template.replace("scaling_group_id", trigger_dict['metadata']) return query_mtdata