def get_ids(kind, pop_url, pop_id): """ Return list of IDs for a given kind :param kind: Kind of the resources ids required :param pop_url: url of the PoP DB :param pop_id: PoP ID :return list: list of IDs """ results = list() if kind == 'switch': for existing_uuid in odl_glue.get_switches_ids(pop_url, pop_id): results.append(existing_uuid) elif kind == 'switch-interface': for existing_uuid in odl_glue.get_switch_interfaces(pop_url, pop_id): results.append(existing_uuid) elif kind == 'pop': for existing_uuid in epa_glue.get_pop_ids(pop_url): results.append(existing_uuid) else: for existing_uuid in epa_glue.get_resource_openstack_ids(pop_url, pop_id, kind, []): results.append(existing_uuid) return results
def get_resource_entities(pop_url, pop_id, openstack_types, query): """ Retrieve a list of entities and their links for a given list of types :param pop_url: Url of PoP DB :param pop_id: PoP ID :param openstack_types: list of type :param query: optional query parameters :return dict: keys resources' uuids, values resources' properties """ results = {} for resource_type in openstack_types: # For switches call Opendaylight if resource_type == 'switch': for uuid in odl_glue.get_switches_ids(pop_url, pop_id): entity = EPARegistry.get_occi_resource(resource_type, uuid) results[uuid] = entity # For switches' interfaces call Opendaylight elif resource_type == 'switch-interface': for uuid in odl_glue.get_switch_interfaces(pop_url, pop_id): entity = EPARegistry.get_occi_resource(resource_type, uuid) results[uuid] = entity # For all others resources query EPA DB else: for uuid in epa_glue.get_resource_openstack_ids(pop_url, pop_id, resource_type, query): entity = EPARegistry.get_occi_resource(resource_type, uuid) results[uuid] = entity # Retrieve links for the resources that should be returned links = {} for source_uuid in results: if results[source_uuid].kind.term == 'switch': for target_uuid in odl_glue.get_switch_interfaces_by_switch_id(pop_url, pop_id, source_uuid): target_type = 'switch-interface' link_uuid = source_uuid + '->' + target_uuid source_entity = results[source_uuid] kind = source_entity.kind.term + '_link' target_entity = EPARegistry.get_occi_resource(target_type, target_uuid) links[link_uuid] = EPARegistry.get_occi_link(kind, link_uuid, source_entity, target_entity) elif results[source_uuid].kind.term == 'switch-interface': switch_uuid = odl_glue.get_switch_by_interface(pop_url, pop_id, source_uuid) if switch_uuid: switch_type = 'switch' source_entity = results[source_uuid] kind = source_entity.kind.term + '_link' switch_entity = EPARegistry.get_occi_resource(switch_type, switch_uuid) switch_link_uuid = uuid + '->' + switch_uuid links[switch_link_uuid] = EPARegistry.get_occi_link(kind, switch_link_uuid, results[source_uuid], switch_entity) osdev_uuid = odl_glue.get_os_dev_by_switch_interface(pop_url, pop_id, source_uuid) if osdev_uuid: osdev_type = 'osdev' osdev_entity = EPARegistry.get_occi_resource(osdev_type, osdev_uuid) osdev_link_uuid = uuid + '->' + osdev_uuid links[osdev_link_uuid] = EPARegistry.get_occi_link(kind, osdev_link_uuid, results[source_uuid], osdev_entity) elif results[source_uuid].kind.term == 'osdev': mac = epa_glue.get_mac_by_osdev_uuid(pop_url, pop_id, source_uuid) if mac: switch_interface = odl_glue.get_switch_interface_by_mac(pop_url, pop_id, mac) if switch_interface: target_uuid = switch_interface target_type = 'switch-interface' link_uuid = source_uuid + '->' + target_uuid source_entity = results[source_uuid] kind = source_entity.kind.term + '_link' target_entity = EPARegistry.get_occi_resource(target_type, target_uuid) links[link_uuid] = EPARegistry.get_occi_link(kind, link_uuid, source_entity, target_entity) else: for target_link in epa_glue.get_links_target_uuid(pop_url, pop_id, source_uuid): target_uuid = target_link[0] target_type = target_link[1] link_uuid = source_uuid + '->' + target_uuid source_entity = results[source_uuid] kind = source_entity.kind.term + '_link' target_entity = EPARegistry.get_occi_resource(target_type, target_uuid) links[link_uuid] = EPARegistry.get_occi_link(kind, link_uuid, source_entity, target_entity) results.update(links) EPARegistry.add_pop_id_to_resources(results, pop_id) return results.values()