Exemple #1
0
def _get_vm_update_versioned_driver_values(spec):
    """Generates the static driver values for each vm, for updates.

    :param spec: specification of event generation.
    :type spec: dict
    :return: list of static driver values for each vm updates.
    :rtype: list
    """

    vm_host_mapping = spec[MAPPING_KEY]
    static_info = None
    if spec[STATIC_INFO_FKEY] is not None:
        static_info = utils.load_specs(spec[STATIC_INFO_FKEY])
    static_values = []
    for vm_name, host_name in vm_host_mapping:
        mapping = {
            'nova_object.data': {
                'host': host_name,
                'display_name': vm_name
            }
        }
        static_values.append(
            combine_data(static_info, mapping,
                         spec.get(EXTERNAL_INFO_KEY, None)))

    return static_values
def _get_vm_snapshot_driver_values(spec):
    """Generates the static driver values for each vm.

    :param spec: specification of event generation.
    :type spec: dict
    :return: list of static driver values for each vm.
    :rtype: list
    """

    vm_host_mapping = spec[MAPPING_KEY]
    static_info_re = None
    if spec[STATIC_INFO_FKEY] is not None:
        static_info_re = utils.load_specs(spec[STATIC_INFO_FKEY])
    static_values = []
    host_ids = {}
    for vm_name, host_name in vm_host_mapping:
        if host_name not in host_ids.keys():
            host_ids[host_name] = exrex.getone('[0-9a-f]{56}')

        mapping = {'hostid': host_ids[host_name],
                   'hostname': host_name,
                   "OS-EXT-SRV-ATTR:host": host_name,
                   "OS-EXT-SRV-ATTR:hypervisor_hostname": host_name,
                   'name': vm_name}
        static_values.append(combine_data(
            static_info_re, mapping, spec.get(EXTERNAL_INFO_KEY, None)
        ))
    return static_values
def _get_host_snapshot_driver_values(spec):
    """Generates the static driver values for each host.

    :param spec: specification of event generation.
    :type spec: dict
    :return: list of static driver values for each host.
    :rtype: list
    """

    host_zone_mapping = spec[MAPPING_KEY]
    static_info_re = None
    if spec[STATIC_INFO_FKEY] is not None:
        static_info_re = utils.load_specs(spec[STATIC_INFO_FKEY])
    static_values = []
    for host_name, zone_name in host_zone_mapping:

        mapping = {
            'host_name': host_name,
            'zone': zone_name,
            '_info': {
                'host_name': host_name,
                'zone': zone_name
            }
        }
        static_values.append(
            combine_data(static_info_re, mapping,
                         spec.get(EXTERNAL_INFO_KEY, None)))
    return static_values
def _get_vm_snapshot_driver_values(spec):
    """Generates the static driver values for each vm.

    :param spec: specification of event generation.
    :type spec: dict
    :return: list of static driver values for each vm.
    :rtype: list
    """

    vm_host_mapping = spec[MAPPING_KEY]
    static_info_re = None
    if spec[STATIC_INFO_FKEY] is not None:
        static_info_re = utils.load_specs(spec[STATIC_INFO_FKEY])
    static_values = []
    host_ids = {}
    for vm_name, host_name in vm_host_mapping:
        if host_name not in host_ids.keys():
            host_ids[host_name] = str(randint(0, 1000000))

        mapping = {
            'hostid': host_ids[host_name],
            'hostname': host_name,
            "OS-EXT-SRV-ATTR:host": host_name,
            "OS-EXT-SRV-ATTR:hypervisor_hostname": host_name,
            'name': vm_name,
            'id': str(randint(0, 1000000)),
        }
        static_values.append(
            combine_data(static_info_re, mapping,
                         spec.get(EXTERNAL_INFO_KEY, None)))
    return static_values
    def __init__(self, spec):
        """Initializes the trace generator according to the specs.

        NOTE: The dynamic file given determines the manner in which information
        is extracted and overlapped between the three sources of info.
        Any new spec file needs to be added here as well.

        :param spec: specification of the trace characteristics.
        :type spec: dict
        Sample format:
        {
        tg.DYNAMIC_INFO_FKEY: tg.TRANS_INST_SNAPSHOT_D, # dynamic info file
        tg.STATIC_INFO_FKEY: tg.TRANS_INST_SNAPSHOT_S, # static info file
        tg.MAPPING_KEY: mapping,  # inter-entity mapping, e.g., vm-host
        tg.NAME_KEY: 'Instance (vm) snapshot generator', # name for gen
        tg.NUM_EVENTS: 10 # how many events of this type to generate
         }
        """

        static_info_parsers = \
            {SYNC_INST_SNAPSHOT_D: _get_sync_vm_snapshot_values,
             SYNC_INST_UPDATE_D: _get_sync_vm_update_values,
             SYNC_HOST_SNAPSHOT_D: _get_sync_host_snapshot_values,
             SYNC_ZONE_SNAPSHOT_D: _get_sync_zone_snapshot_values,
             TRANS_INST_SNAPSHOT_D: _get_trans_vm_snapshot_values,
             TRANS_HOST_SNAPSHOT_D: _get_trans_host_snapshot_values,
             TRANS_ZONE_SNAPSHOT_D: _get_trans_zone_snapshot_values}

        dynam_specs = utils.load_specs(spec[DYNAMIC_INFO_FKEY])
        dynamic_spec_filename = spec[DYNAMIC_INFO_FKEY].split('/')[-1]
        static_specs = static_info_parsers[dynamic_spec_filename](spec)
        self.name = spec.get(NAME_KEY, 'generator')

        self._models = [bem(dynam_specs, details) for details in static_specs]
Exemple #6
0
def _get_stack_update_driver_values(spec):
    """Generates the static driver values for each volume.

    :param spec: specification of event generation.
    :type spec: dict
    :return: list of static driver values for each volume.
    :rtype: list
    """

    volume_instance_mapping = spec[MAPPING_KEY]
    static_info_re = None
    if spec[STATIC_INFO_FKEY] is not None:
        static_info_re = utils.load_specs(spec[STATIC_INFO_FKEY])
    static_values = []

    for stack_name, instance_name, volume_name in volume_instance_mapping:
        mapping = {'stack_identity': stack_name,
                   'stack_name': stack_name,
                   'resources': [{'resource_type': "OS::Nova::Server",
                                  'physical_resource_id': instance_name},
                                 {'resource_type': "OS::Cinder::Volume",
                                  'physical_resource_id': volume_name}]}
        static_values.append(combine_data(
            static_info_re, mapping, spec.get(EXTERNAL_INFO_KEY, None)
        ))
    return static_values
Exemple #7
0
def _get_trans_aodh_alarm_snapshot_values(spec):
    """Generates the dynamic transformer values for Aodh datasource.

    :param spec: specification of event generation.
    :type spec: dict
    :return: list of dynamic transformer values for Aodh datasource.
    :rtype: list
    """

    alarm_resources_mapping = spec[MAPPING_KEY]
    static_info = None
    if spec[STATIC_INFO_FKEY] is not None:
        static_info = utils.load_specs(spec[STATIC_INFO_FKEY])

    static_values = []
    for alarm_id, resource_id in alarm_resources_mapping:
        mapping = {
            'alarm_id': alarm_id,
            'resource_id': resource_id,
            'graph_query_result': [{
                'id': resource_id
            }]
        }
        static_values.append(
            combine_data(static_info, mapping,
                         spec.get(EXTERNAL_INFO_KEY, None)))
    return static_values
def _get_volume_update_driver_values(spec):
    """Generates the static driver values for each volume.

    :param spec: specification of event generation.
    :type spec: dict
    :return: list of static driver values for each volume.
    :rtype: list
    """

    volume_instance_mapping = spec[MAPPING_KEY]
    static_info_re = None
    if spec[STATIC_INFO_FKEY] is not None:
        static_info_re = utils.load_specs(spec[STATIC_INFO_FKEY])
    static_values = []

    for volume_name, instance_name in volume_instance_mapping:
        mapping = {
            'volume_id': volume_name,
            'display_name': volume_name,
            'volume_attachment': [{
                'instance_uuid': instance_name
            }]
        }
        static_values.append(
            combine_data(static_info_re, mapping,
                         spec.get(EXTERNAL_INFO_KEY, None)))
    return static_values
def _get_stack_update_driver_values(spec):
    """Generates the static driver values for each volume.

    :param spec: specification of event generation.
    :type spec: dict
    :return: list of static driver values for each volume.
    :rtype: list
    """

    volume_instance_mapping = spec[MAPPING_KEY]
    static_info_re = None
    if spec[STATIC_INFO_FKEY] is not None:
        static_info_re = utils.load_specs(spec[STATIC_INFO_FKEY])
    static_values = []

    for stack_name, instance_name, volume_name in volume_instance_mapping:
        mapping = {
            'stack_identity':
            stack_name,
            'stack_name':
            stack_name,
            'resources': [{
                'resource_type': "OS::Nova::Server",
                'physical_resource_id': instance_name
            }, {
                'resource_type': "OS::Cinder::Volume",
                'physical_resource_id': volume_name
            }]
        }
        static_values.append(
            combine_data(static_info_re, mapping,
                         spec.get(EXTERNAL_INFO_KEY, None)))
    return static_values
Exemple #10
0
 def _file_to_vertex(self, relative_path, index=0):
     full_path = RESOURCES_PATH + "/vertices/"
     props = utils.load_specs(relative_path, full_path)
     if props.get(VProps.ID):
         props[VProps.ID] = uuidutils.generate_uuid()
     props[VProps.NAME] = "%s-%s" % (props[VProps.VITRAGE_TYPE], str(index))
     props[VProps.VITRAGE_ID] = uuidutils.generate_uuid()
     return Vertex(props[VProps.VITRAGE_ID], props)
 def _load_resource_file(self, filename, folder):
     full_path = RESOURCES_PATH + '/' + folder + '/'
     cache_key = (filename, folder)
     props = self.files_cache.get(cache_key, None)
     if not props:
         props = utils.load_specs(filename, full_path)
         self.files_cache[cache_key] = props
     return copy.copy(props)
Exemple #12
0
    def __init__(self, spec):
        """Initializes the trace generator according to the specs.

        NOTE: The dynamic file given determines the manner in which information
        is extracted and overlapped between the three sources of info.
        Any new spec file needs to be added here as well.

        :param spec: specification of the trace characteristics.
        :type spec: dict
        Sample format:
        {
        tg.DYNAMIC_INFO_FKEY: tg.TRANS_INST_SNAPSHOT_D, # dynamic info file
        tg.STATIC_INFO_FKEY: tg.TRANS_INST_SNAPSHOT_S, # static info file
        tg.MAPPING_KEY: mapping,  # inter-entity mapping, e.g., vm-host
        tg.NAME_KEY: 'Instance (vm) snapshot generator', # name for gen
        tg.NUM_EVENTS: 10 # how many events of this type to generate
         }
        """

        static_info_parsers = \
            {DRIVER_AODH_UPDATE_D: _get_aodh_alarm_update_driver_values,
             DRIVER_DOCTOR_UPDATE_D: _get_simple_update_driver_values,
             DRIVER_COLLECTD_UPDATE_D: _get_simple_update_driver_values,
             DRIVER_KUBE_SNAPSHOT_D: _get_k8s_node_snapshot_driver_values,
             DRIVER_INST_SNAPSHOT_D: _get_vm_snapshot_driver_values,
             DRIVER_INST_UPDATE_D: _get_vm_update_driver_values,
             DRIVER_HOST_SNAPSHOT_D: _get_host_snapshot_driver_values,
             DRIVER_ZONE_SNAPSHOT_D: _get_zone_snapshot_driver_values,
             DRIVER_VOLUME_SNAPSHOT_D: _get_volume_snapshot_driver_values,
             DRIVER_VOLUME_UPDATE_D: _get_volume_update_driver_values,
             DRIVER_STACK_SNAPSHOT_D: _get_stack_snapshot_driver_values,
             DRIVER_STACK_UPDATE_D: _get_stack_update_driver_values,
             DRIVER_SWITCH_SNAPSHOT_D: _get_switch_snapshot_driver_values,
             DRIVER_STATIC_SNAPSHOT_D: _get_static_snapshot_driver_values,
             DRIVER_NAGIOS_SNAPSHOT_D: _get_nagios_alarm_driver_values,
             DRIVER_ZABBIX_SNAPSHOT_D: _get_zabbix_alarm_driver_values,
             DRIVER_CONSISTENCY_UPDATE_D:
                 _get_consistency_update_driver_values,
             DRIVER_PROMETHEUS_UPDATE_D: _get_simple_update_driver_values,

             TRANS_AODH_SNAPSHOT_D: _get_trans_aodh_alarm_snapshot_values,
             TRANS_AODH_UPDATE_D: _get_trans_aodh_alarm_snapshot_values,
             TRANS_DOCTOR_UPDATE_D: _get_simple_trans_alarm_update_values,
             TRANS_COLLECTD_UPDATE_D: _get_simple_trans_alarm_update_values,
             TRANS_PROMETHEUS_UPDATE_D: _get_simple_trans_alarm_update_values,
             TRANS_INST_SNAPSHOT_D: _get_trans_vm_snapshot_values,
             TRANS_HOST_SNAPSHOT_D: _get_trans_host_snapshot_values,
             TRANS_ZONE_SNAPSHOT_D: _get_trans_zone_snapshot_values}

        target_folder = spec[DYNAMIC_INFO_FPATH] \
            if spec.get(DYNAMIC_INFO_FPATH) else None
        dynam_specs = utils.load_specs(spec[DYNAMIC_INFO_FKEY],
                                       target_folder=target_folder)
        dynamic_spec_filename = spec[DYNAMIC_INFO_FKEY].split('/')[-1]
        static_specs = static_info_parsers[dynamic_spec_filename](spec)
        self.name = spec.get(NAME_KEY, 'generator')

        self._models = [Bem(dynam_specs, details) for details in static_specs]
Exemple #13
0
def _get_aodh_alarm_update_driver_values(spec):
    alarms = spec[MAPPING_KEY]
    static_info = None
    if spec[STATIC_INFO_FKEY] is not None:
        static_info = utils.load_specs(spec[STATIC_INFO_FKEY])
    static_values = []
    for alarm in alarms:
        alarm_id = {"alarm_id": alarm}
        static_values.append(combine_data(
            static_info, alarm_id, spec.get(EXTERNAL_INFO_KEY, None)))
    return static_values
def _get_nagios_alarm_driver_values(spec):
    hosts = spec[MAPPING_KEY]
    static_info_re = None
    if spec[STATIC_INFO_FKEY] is not None:
        static_info_re = utils.load_specs(spec[STATIC_INFO_FKEY])

    static_values = []
    for host_name in hosts:
        host_info = {'resource_name': host_name}
        static_values.append(combine_data(
            static_info_re, host_info, spec.get(EXTERNAL_INFO_KEY, None)
        ))
    return static_values
Exemple #15
0
def _get_trove_instance_snapshot_driver_values(spec):
    inst_srv_mapping = spec[MAPPING_KEY]
    static_info = None
    if spec[STATIC_INFO_FKEY] is not None:
        static_info = utils.load_specs(spec[STATIC_INFO_FKEY])
    static_values = []

    for inst_name, srv_name in inst_srv_mapping:
        mapping = {'id': inst_name, 'name': inst_name, 'server_id': srv_name}
        static_values.append(
            combine_data(static_info, mapping,
                         spec.get(EXTERNAL_INFO_KEY, None)))
    return static_values
def _get_zabbix_alarm_driver_values(spec):
    hosts = spec[MAPPING_KEY]
    static_info_re = None
    if spec[STATIC_INFO_FKEY] is not None:
        static_info_re = utils.load_specs(spec[STATIC_INFO_FKEY])

    static_values = []
    for host_name in hosts:
        host_info = {'resource_name': host_name}
        static_values.append(
            combine_data(static_info_re, host_info,
                         spec.get(EXTERNAL_INFO_KEY, None)))
    return static_values
Exemple #17
0
def _get_trans_collectd_alarm_update_values(spec):
    """Generates the dynamic transformer values for a Collectd alarm

    :param spec: specification of event generation.
    :type spec: dict
    :return: list of dynamic transformer values for a Collectd alarm
    :rtype: list with one alarm
    """

    static_info = None
    if spec[STATIC_INFO_FKEY] is not None:
        static_info = utils.load_specs(spec[STATIC_INFO_FKEY])

    return [combine_data(static_info, None, spec.get(EXTERNAL_INFO_KEY, None))]
Exemple #18
0
    def __init__(self, spec):
        """Initializes the trace generator according to the specs.

        NOTE: The dynamic file given determines the manner in which information
        is extracted and overlapped between the three sources of info.
        Any new spec file needs to be added here as well.

        :param spec: specification of the trace characteristics.
        :type spec: dict
        Sample format:
        {
        tg.DYNAMIC_INFO_FKEY: tg.TRANS_INST_SNAPSHOT_D, # dynamic info file
        tg.STATIC_INFO_FKEY: tg.TRANS_INST_SNAPSHOT_S, # static info file
        tg.MAPPING_KEY: mapping,  # inter-entity mapping, e.g., vm-host
        tg.NAME_KEY: 'Instance (vm) snapshot generator', # name for gen
        tg.NUM_EVENTS: 10 # how many events of this type to generate
         }
        """

        static_info_parsers = \
            {DRIVER_INST_SNAPSHOT_D: _get_vm_snapshot_driver_values,
             DRIVER_INST_UPDATE_D: _get_vm_update_driver_values,
             DRIVER_HOST_SNAPSHOT_D: _get_host_snapshot_driver_values,
             DRIVER_ZONE_SNAPSHOT_D: _get_zone_snapshot_driver_values,
             DRIVER_VOLUME_SNAPSHOT_D: _get_volume_snapshot_driver_values,
             DRIVER_VOLUME_UPDATE_D: _get_volume_update_driver_values,
             DRIVER_STACK_SNAPSHOT_D: _get_stack_snapshot_driver_values,
             DRIVER_STACK_UPDATE_D: _get_stack_update_driver_values,
             DRIVER_SWITCH_SNAPSHOT_D: _get_switch_snapshot_driver_values,
             DRIVER_NAGIOS_SNAPSHOT_D: _get_nagios_alarm_driver_values,
             DRIVER_ZABBIX_SNAPSHOT_D: _get_zabbix_alarm_driver_values,
             DRIVER_CONSISTENCY_UPDATE_D:
                 _get_consistency_update_driver_values,

             TRANS_AODH_SNAPSHOT_D: _get_trans_aodh_alarm_snapshot_values,
             TRANS_INST_SNAPSHOT_D: _get_trans_vm_snapshot_values,
             TRANS_HOST_SNAPSHOT_D: _get_trans_host_snapshot_values,
             TRANS_ZONE_SNAPSHOT_D: _get_trans_zone_snapshot_values}

        target_folder = spec[DYNAMIC_INFO_FPATH] \
            if spec.get(DYNAMIC_INFO_FPATH) else None
        dynam_specs = utils.load_specs(spec[DYNAMIC_INFO_FKEY],
                                       target_folder=target_folder)
        dynamic_spec_filename = spec[DYNAMIC_INFO_FKEY].split('/')[-1]
        static_specs = static_info_parsers[dynamic_spec_filename](spec)
        self.name = spec.get(NAME_KEY, 'generator')

        self._models = [Bem(dynam_specs, details) for details in static_specs]
def _get_trove_cluster_snapshot_driver_values(spec):
    clust_inst_mapping = spec[MAPPING_KEY]
    static_info = None
    if spec[STATIC_INFO_FKEY] is not None:
        static_info = utils.load_specs(spec[STATIC_INFO_FKEY])
    static_values = []

    for clust_name, inst_name in clust_inst_mapping:
        mapping = {'id': clust_name,
                   'name': clust_name,
                   'instances': [
                       {'id': inst_name, 'name': inst_name}
                   ]}
        static_values.append(combine_data(
            static_info, mapping, spec.get(EXTERNAL_INFO_KEY, None)))
    return static_values
def _get_zone_snapshot_driver_values(spec):
    """Generates the static driver values for each zone.

    :param spec: specification of event generation.
    :type spec: dict
    :return: list of static driver values for each host.
    :rtype: list
    """

    host_zone_mapping = spec[MAPPING_KEY]
    static_info_re = None
    if spec[STATIC_INFO_FKEY] is not None:
        static_info_re = utils.load_specs(spec[STATIC_INFO_FKEY])
    static_values = []
    host_info = {
        "nova-compute": {
            "active": "True",
            "available": "False",
            "updated_at": "2016-01-05T06:39:52\\.000000"
        }
    }

    zones_info = {}
    for host_name, zone_name in host_zone_mapping:
        zone_info = zones_info.get(zone_name, {})
        zone_info[host_name] = host_info
        zones_info[zone_name] = zone_info

    for zone_name in zones_info.keys():
        mapping = {
            'zoneName': zone_name,
            'hosts': zones_info.get(zone_name, {}),
            '_info': {
                'zoneName': zone_name,
                'hosts': zones_info.get(zone_name, {})
            }
        }
        static_values.append(
            combine_data(static_info_re, mapping,
                         spec.get(EXTERNAL_INFO_KEY, None)))
    return static_values
def _get_trans_zone_snapshot_values(spec):
    """Generates the static driver values for each zone.

    :param spec: specification of event generation.
    :type spec: dict
    :return: list of static driver values for each zone.
    :rtype: list
    """

    zone_cluster_mapping = spec[MAPPING_KEY]
    static_info_re = None
    if spec[STATIC_INFO_FKEY] is not None:
        static_info_re = utils.load_specs(spec[STATIC_INFO_FKEY])
    static_values = []
    for zone_name, cluster_name in zone_cluster_mapping:
        mapping = {'name': zone_name, 'id': zone_name}
        static_values.append(
            combine_data(static_info_re, mapping,
                         spec.get(EXTERNAL_INFO_KEY, None)))

    return static_values
def _get_trans_vm_snapshot_values(spec):
    """Generates the static transformer values for each vm.

    :param spec: specification of event generation.
    :type spec: dict
    :return: list of static transformer values for each vm.
    :rtype: list
    """

    vm_host_mapping = spec[MAPPING_KEY]
    static_info_re = None
    if spec[STATIC_INFO_FKEY] is not None:
        static_info_re = utils.load_specs(spec[STATIC_INFO_FKEY])
    static_values = []
    for vm_name, host_name in vm_host_mapping:
        mapping = {'hostname': host_name, 'id': vm_name, 'name': vm_name}
        static_values.append(
            combine_data(static_info_re, mapping,
                         spec.get(EXTERNAL_INFO_KEY, None)))

    return static_values
def _get_consistency_update_driver_values(spec):
    """Generates the static driver values for each consistency event.

    :param spec: specification of event generation.
    :type spec: dict
    :return: list of static driver values for each consistency event.
    :rtype: list
    """

    entity_num = spec[MAPPING_KEY]
    static_info_re = None
    if spec[STATIC_INFO_FKEY] is not None:
        static_info_re = utils.load_specs(spec[STATIC_INFO_FKEY])
    static_values = []

    for i in range(entity_num):
        mapping = {}
        static_values.append(
            combine_data(static_info_re, mapping,
                         spec.get(EXTERNAL_INFO_KEY, None)))
    return static_values
def _get_consistency_update_driver_values(spec):
    """Generates the static driver values for each consistency event.

    :param spec: specification of event generation.
    :type spec: dict
    :return: list of static driver values for each consistency event.
    :rtype: list
    """

    entity_num = spec[MAPPING_KEY]
    static_info_re = None
    if spec[STATIC_INFO_FKEY] is not None:
        static_info_re = utils.load_specs(spec[STATIC_INFO_FKEY])
    static_values = []

    for i in range(entity_num):
        mapping = {}
        static_values.append(combine_data(
            static_info_re, mapping, spec.get(EXTERNAL_INFO_KEY, None)
        ))
    return static_values
def _get_switch_snapshot_driver_values(spec):
    """Generates the static driver values for each zone.

    :param spec: specification of event generation.
    :type spec: dict
    :return: list of static driver values for each zone.
    :rtype: list
    """

    host_switch_mapping = spec[MAPPING_KEY]
    static_info_re = None
    if spec[STATIC_INFO_FKEY] is not None:
        static_info_re = utils.load_specs(spec[STATIC_INFO_FKEY])

    static_values = []

    switches_info = {}
    for host_name, switch_name in host_switch_mapping:
        switch_info = switches_info.get(switch_name, [])

        relationship_info = {
            "type": NOVA_HOST_DATASOURCE,
            "name": host_name,
            "id": host_name,
            "relation_type": "contains"
        }

        switch_info.append(relationship_info)
        switches_info[switch_name] = switch_info

    for host_name, switch_name in host_switch_mapping:
        mapping = {
            'name': switch_name,
            'id': switch_name,
            'relationships': switches_info[switch_name]
        }
        static_values.append(
            combine_data(static_info_re, mapping,
                         spec.get(EXTERNAL_INFO_KEY, None)))
    return static_values
def _get_zone_snapshot_driver_values(spec):
    """Generates the static driver values for each zone.

    :param spec: specification of event generation.
    :type spec: dict
    :return: list of static driver values for each host.
    :rtype: list
    """

    host_zone_mapping = spec[MAPPING_KEY]
    static_info_re = None
    if spec[STATIC_INFO_FKEY] is not None:
        static_info_re = utils.load_specs(spec[STATIC_INFO_FKEY])
    static_values = []
    host_info = {
        "nova-compute": {
            "active": "True",
            "available": "False",
            "updated_at": "2016-01-05T06:39:52\\.000000"
        }
    }

    zones_info = {}
    for host_name, zone_name in host_zone_mapping:
        zone_info = zones_info.get(zone_name, {})
        zone_info[host_name] = host_info
        zones_info[zone_name] = zone_info

    for zone_name in zones_info.keys():
        mapping = {
            'zoneName': zone_name,
            'hosts': zones_info.get(zone_name, {}),
            '_info': {'zoneName': zone_name,
                      'hosts': zones_info.get(zone_name, {})
                      }
        }
        static_values.append(combine_data(
            static_info_re, mapping, spec.get(EXTERNAL_INFO_KEY, None)
        ))
    return static_values
def _get_vm_update_driver_values(spec):
    """Generates the static driver values for each vm, for updates.

    :param spec: specification of event generation.
    :type spec: dict
    :return: list of static driver values for each vm updates.
    :rtype: list
    """

    vm_host_mapping = spec[MAPPING_KEY]
    static_info_re = None
    if spec[STATIC_INFO_FKEY] is not None:
        static_info_re = utils.load_specs(spec[STATIC_INFO_FKEY])
    static_values = []
    for vm_name, host_name in vm_host_mapping:
        mapping = {'payload': {'host': host_name,
                               'display_name': vm_name}}
        static_values.append(combine_data(
            static_info_re, mapping, spec.get(EXTERNAL_INFO_KEY, None)
        ))

    return static_values
def _get_trans_zone_snapshot_values(spec):
    """Generates the static driver values for each zone.

    :param spec: specification of event generation.
    :type spec: dict
    :return: list of static driver values for each zone.
    :rtype: list
    """

    zone_cluster_mapping = spec[MAPPING_KEY]
    static_info_re = None
    if spec[STATIC_INFO_FKEY] is not None:
        static_info_re = utils.load_specs(spec[STATIC_INFO_FKEY])
    static_values = []
    for zone_name, cluster_name in zone_cluster_mapping:
        mapping = {'name': zone_name,
                   'id': zone_name}
        static_values.append(combine_data(
            static_info_re, mapping, spec.get(EXTERNAL_INFO_KEY, None)
        ))

    return static_values
def _get_switch_snapshot_driver_values(spec):
    """Generates the static driver values for each zone.

    :param spec: specification of event generation.
    :type spec: dict
    :return: list of static driver values for each zone.
    :rtype: list
    """

    host_switch_mapping = spec[MAPPING_KEY]
    static_info_re = None
    if spec[STATIC_INFO_FKEY] is not None:
        static_info_re = utils.load_specs(spec[STATIC_INFO_FKEY])

    static_values = []

    switches_info = {}
    for host_name, switch_name in host_switch_mapping:
        switch_info = switches_info.get(switch_name, [])

        relationship_info = {"type": NOVA_HOST_DATASOURCE,
                             "name": host_name,
                             "id": host_name,
                             "relation_type": "contains"
                             }

        switch_info.append(relationship_info)
        switches_info[switch_name] = switch_info

    for host_name, switch_name in host_switch_mapping:
        mapping = {'name': switch_name,
                   'id': switch_name,
                   'relationships': switches_info[switch_name]
                   }
        static_values.append(combine_data(static_info_re,
                                          mapping,
                                          spec.get(EXTERNAL_INFO_KEY, None)))
    return static_values
Exemple #30
0
def _get_trans_aodh_alarm_snapshot_values(spec):
    """Generates the static transformer values for each vm.

    :param spec: specification of event generation.
    :type spec: dict
    :return: list of static transformer values for each vm.
    :rtype: list
    """

    alarm_resources_mapping = spec[MAPPING_KEY]
    static_info_re = None
    if spec[STATIC_INFO_FKEY] is not None:
        static_info_re = utils.load_specs(spec[STATIC_INFO_FKEY])

    static_values = []
    for alarm_id, resource_id in alarm_resources_mapping:
        mapping = {'alarm_id': alarm_id,
                   'resource_id': resource_id,
                   'graph_query_result': [{'id': resource_id}]}
        static_values.append(combine_data(
            static_info_re, mapping, spec.get(EXTERNAL_INFO_KEY, None)
        ))
    return static_values
def _get_volume_update_driver_values(spec):
    """Generates the static driver values for each volume.

    :param spec: specification of event generation.
    :type spec: dict
    :return: list of static driver values for each volume.
    :rtype: list
    """

    volume_instance_mapping = spec[MAPPING_KEY]
    static_info_re = None
    if spec[STATIC_INFO_FKEY] is not None:
        static_info_re = utils.load_specs(spec[STATIC_INFO_FKEY])
    static_values = []

    for volume_name, instance_name in volume_instance_mapping:
        mapping = {'volume_id': volume_name,
                   'display_name': volume_name,
                   'volume_attachment': [{'instance_uuid': instance_name}]}
        static_values.append(combine_data(
            static_info_re, mapping, spec.get(EXTERNAL_INFO_KEY, None)
        ))
    return static_values
def _get_host_snapshot_driver_values(spec):
    """Generates the static driver values for each host.

    :param spec: specification of event generation.
    :type spec: dict
    :return: list of static driver values for each host.
    :rtype: list
    """

    host_zone_mapping = spec[MAPPING_KEY]
    static_info_re = None
    if spec[STATIC_INFO_FKEY] is not None:
        static_info_re = utils.load_specs(spec[STATIC_INFO_FKEY])
    static_values = []
    for host_name, zone_name in host_zone_mapping:

        mapping = {'host_name': host_name,
                   'zone': zone_name,
                   '_info': {'host_name': host_name,
                             'zone': zone_name}}
        static_values.append(combine_data(
            static_info_re, mapping, spec.get(EXTERNAL_INFO_KEY, None)
        ))
    return static_values
Exemple #33
0
 def _file_to_edge(relative_path, source_id, target_id):
     full_path = RESOURCES_PATH + "/edges/"
     props = utils.load_specs(relative_path, full_path)
     return Edge(source_id, target_id,
                 props[EdgeProperties.RELATIONSHIP_TYPE], props)
Exemple #34
0
def _get_static_snapshot_driver_values(spec):
    """Generates the static driver values for static datasource.

    :param spec: specification of event generation.
    :type spec: dict
    :return: list of driver values for static datasource.
    :rtype: list
    """

    host_switch_mapping = spec[MAPPING_KEY]

    if spec[STATIC_INFO_FKEY] is not None:
        static_info_spec = utils.load_specs(spec[STATIC_INFO_FKEY])
    else:
        static_info_spec = None

    static_values = []

    # use defaultdict to create placeholder
    relationships = defaultdict(lambda: [])
    entities = defaultdict(lambda: {})
    touched = set({})

    for host_index, switch_index in host_switch_mapping:
        host_id = "h{}".format(host_index)
        switch_id = "s{}".format(switch_index)

        relationship = {
            StaticFields.SOURCE: switch_id,
            StaticFields.TARGET: host_id,
            StaticFields.RELATIONSHIP_TYPE: EdgeLabel.ATTACHED
        }
        rel = relationship.copy()
        rel[StaticFields.TARGET] = entities[host_id]
        relationships[switch_id].append(rel)

    for host_index, switch_index in host_switch_mapping:
        switch_id = "s{}".format(switch_index)
        if switch_id not in touched:
            switch_name = "switch-{}".format(switch_index)
            vals = {
                StaticFields.STATIC_ID: switch_id,
                StaticFields.TYPE: 'switch',
                StaticFields.ID: str(randint(0, 100000)),
                StaticFields.NAME: switch_name,
                StaticFields.RELATIONSHIPS: relationships[switch_id]
            }
            entities[switch_id].update(**vals)
            touched.add(switch_id)

        host_id = "h{}".format(host_index)
        if host_id not in touched:
            vals = {
                StaticFields.STATIC_ID: host_id,
                StaticFields.TYPE: NOVA_HOST_DATASOURCE,
                StaticFields.ID: str(randint(0, 100000)),
                StaticFields.RELATIONSHIPS: relationships[host_id]
            }
            entities[host_id].update(**vals)
            touched.add(host_id)

    for vals in entities.values():
        static_values.append(
            combine_data(static_info_spec, vals,
                         spec.get(EXTERNAL_INFO_KEY, None)))

    custom_num = 10
    for index in range(custom_num):
        source_id = 'c{}'.format(index)
        target_id = 'c{}'.format(custom_num - 1 - index)
        source_name = 'custom-{}'.format(source_id)
        vals = {
            StaticFields.STATIC_ID:
            source_id,
            StaticFields.TYPE:
            'custom',
            StaticFields.ID:
            str(randint(0, 100000)),
            StaticFields.NAME:
            source_name,
            StaticFields.RELATIONSHIPS: [{
                StaticFields.SOURCE:
                source_id,
                StaticFields.TARGET:
                entities[target_id],
                StaticFields.RELATIONSHIP_TYPE:
                'custom'
            }]
        }
        entities[source_id].update(**vals)
        static_values.append(
            combine_data(static_info_spec, vals,
                         spec.get(EXTERNAL_INFO_KEY, None)))

    # TODO(yujunz) verify self-pointing relationship

    return static_values