def generate_id_name_map(sdk, reverse=False):
global_id_name_dict = {}<EOL>global_name_id_dict = {}<EOL>system_list = []<EOL>if_id_to_name = {}<EOL>global_swi_id = {}<EOL>global_ln_id = {}<EOL>swi_to_wan_network_dict = {}<EOL>swi_to_site_dict = {}<EOL>wan_network_to_swi_dict = {}<EOL>all_anynets = {}<EOL>all_vpns = {}<EOL>swi_id_name_dict = {}<EOL>site_swi_dict = {}<EOL>path_id_to_name = {}<EOL>vpn_id_to_anynet_id = {}<EOL>logger.info("<STR_LIT>")<EOL>id_operator_dict, operator_id_dict = operators_to_name_dict(sdk)<EOL>if id_operator_dict:<EOL><INDENT>global_id_name_dict.update(id_operator_dict)<EOL><DEDENT>global_name_id_dict.update(operator_id_dict)<EOL>if operator_id_dict:<EOL><INDENT>global_name_id_dict.update(operator_id_dict)<EOL><DEDENT>logger.info("<STR_LIT>")<EOL>id_site_dict, site_id_dict, site_id_list, site_info_dict = siteid_to_name_dict(sdk)<EOL>global_id_name_dict.update(id_site_dict)<EOL>global_name_id_dict.update(site_id_dict)<EOL>logger.info("<STR_LIT>")<EOL>id_element_dict, element_id_dict, element_site_dict, element_id_list = elements_to_name_dict(sdk)<EOL>global_id_name_dict.update(id_element_dict)<EOL>global_name_id_dict.update(element_id_dict)<EOL>logger.info("<STR_LIT>")<EOL>id_wannetwork_dict, name_wannetwork_id_dict, wannetwork_id_list, wannetwork_type_dict = wan_network_dicts(sdk)<EOL>global_id_name_dict.update(id_wannetwork_dict)<EOL>global_name_id_dict.update(name_wannetwork_id_dict)<EOL>logger.info("<STR_LIT>")<EOL>id_circuit_categories, name_circuit_categories = circuit_categories_dicts(sdk)<EOL>global_id_name_dict.update(id_circuit_categories)<EOL>global_name_id_dict.update(name_circuit_categories)<EOL>logger.info("<STR_LIT>")<EOL>id_network_contexts, name_circuit_contexts = network_context_dicts(sdk)<EOL>global_id_name_dict.update(id_network_contexts)<EOL>global_name_id_dict.update(name_circuit_contexts)<EOL>logger.info("<STR_LIT>")<EOL>id_appdef_dict, name_appdef_dict, appdef_id_list = appdefs_to_name_dict(sdk)<EOL>global_id_name_dict.update(id_appdef_dict)<EOL>global_name_id_dict.update(name_appdef_dict)<EOL>logger.info("<STR_LIT>")<EOL>id_policyset_dict, name_policyset_dict, policyset_id_list = policyset_to_name_dict(sdk)<EOL>global_id_name_dict.update(id_policyset_dict)<EOL>global_name_id_dict.update(name_policyset_dict)<EOL>logger.info("<STR_LIT>")<EOL>id_securitypolicyset_dict, name_securitypolicyset_dict,securitypolicyset_id_list = securitypolicyset_to_name_dict(sdk)<EOL>global_id_name_dict.update(id_securitypolicyset_dict)<EOL>global_name_id_dict.update(name_securitypolicyset_dict)<EOL>logger.info("<STR_LIT>")<EOL>id_securityzone_dict, securityzone_id_dict, securityzone_id_list = securityzone_to_name_dict(sdk)<EOL>global_id_name_dict.update(id_securityzone_dict)<EOL>global_name_id_dict.update(securityzone_id_dict)<EOL>id_interface_dict = {}<EOL>logger.info("<STR_LIT>")<EOL>for site in site_id_list:<EOL><INDENT>elements = []<EOL>swi_id_dict = {}<EOL>ln_id_dict = {}<EOL>for element in element_id_list:<EOL><INDENT>site_in = element_site_dict.get(element, None)<EOL>if site_in and site_in == site:<EOL><INDENT>interfaces_list, if_id_to_name_item, if_name_to_id_item, _,_, if_id_data_entry = interface_query(site, element, sdk)<EOL>elements.append({<EOL>'<STR_LIT:id>': element,<EOL>'<STR_LIT:name>': id_element_dict.get(element, "<STR_LIT>"),<EOL>'<STR_LIT>': interfaces_list<EOL>})<EOL>if_id_to_name.update(if_id_to_name_item)<EOL>id_interface_dict.update(if_id_data_entry)<EOL><DEDENT><DEDENT>system_list.append({<EOL>'<STR_LIT:id>': site,<EOL>'<STR_LIT:name>': id_site_dict.get(site, "<STR_LIT>"),<EOL>'<STR_LIT>': elements<EOL>})<EOL>resp = sdk.get.waninterfaces(site)<EOL>swi_status = resp.cgx_status<EOL>swi_query = resp.cgx_content<EOL>if swi_status:<EOL><INDENT>for current_swi in swi_query.get('<STR_LIT>', []):<EOL><INDENT>wan_network_id = current_swi.get('<STR_LIT>', "<STR_LIT>")<EOL>swi_id = current_swi.get('<STR_LIT:id>', "<STR_LIT>")<EOL>name = current_swi.get('<STR_LIT:name>')<EOL>if name and swi_id:<EOL><INDENT>swi_id_name_dict[swi_id] = name<EOL><DEDENT>elif swi_id and wan_network_id:<EOL><INDENT>wan_network_name = id_wannetwork_dict.get(wan_network_id, wan_network_id)<EOL>swi_id_name_dict[swi_id] = "<STR_LIT>".format(wan_network_name)<EOL><DEDENT>if swi_id:<EOL><INDENT>swi_to_site_dict[swi_id] = site<EOL><DEDENT>if wan_network_id and swi_id:<EOL><INDENT>logger.debug('<STR_LIT>'.format(swi_id, site))<EOL>existing_swi_list = wan_network_to_swi_dict.get(wan_network_id, [])<EOL>swi_to_wan_network_dict[swi_id] = wan_network_id<EOL>existing_swi_list.append(swi_id)<EOL>wan_network_to_swi_dict[wan_network_id] = existing_swi_list<EOL><DEDENT><DEDENT>global_swi_id.update(swi_id_name_dict)<EOL><DEDENT>resp = sdk.get.lannetworks(site)<EOL>ln_status = resp.cgx_status<EOL>ln_query = resp.cgx_content<EOL>if ln_status:<EOL><INDENT>for ln in ln_query.get('<STR_LIT>'):<EOL><INDENT>ln_id = ln.get('<STR_LIT:id>')<EOL>ln_name = ln.get('<STR_LIT:name>')<EOL>if ln_id and ln_name:<EOL><INDENT>ln_id_dict[ln_id] = ln_name<EOL><DEDENT><DEDENT>global_ln_id.update(ln_id_dict)<EOL><DEDENT><DEDENT>logger.info("<STR_LIT>".format(len(site_id_list)))<EOL>global_id_name_dict.update(if_id_to_name)<EOL>global_id_name_dict.update(global_swi_id)<EOL>global_id_name_dict.update(global_ln_id)<EOL>for site in site_id_list:<EOL><INDENT>site_swi_list = []<EOL>query = {<EOL>"<STR_LIT:type>": "<STR_LIT>",<EOL>"<STR_LIT>": [<EOL>site<EOL>]<EOL>}<EOL>status = False<EOL>rest_call_retry = <NUM_LIT:0><EOL>resp = sdk.post.topology(query)<EOL>status = resp.cgx_status<EOL>topology = resp.cgx_content<EOL>if status and topology:<EOL><INDENT>logger.debug("<STR_LIT>".format(json.dumps(topology, indent=<NUM_LIT:4>)))<EOL>for link in topology.get('<STR_LIT>', []):<EOL><INDENT>link_type = link.get('<STR_LIT:type>', "<STR_LIT>")<EOL>if link_type in ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>source_swi = link.get('<STR_LIT>')<EOL>if not source_swi:<EOL><INDENT>source_swi = link.get('<STR_LIT>')<EOL>if source_swi:<EOL><INDENT>link['<STR_LIT>'] = source_swi<EOL><DEDENT><DEDENT>dest_swi = link.get('<STR_LIT>')<EOL>if not dest_swi:<EOL><INDENT>dest_swi = link.get('<STR_LIT>')<EOL>if dest_swi:<EOL><INDENT>link['<STR_LIT>'] = dest_swi<EOL><DEDENT><DEDENT>anynet_lookup_key = link.get('<STR_LIT>')<EOL>if not all_anynets.get(anynet_lookup_key, None):<EOL><INDENT>all_anynets[anynet_lookup_key] = link<EOL><DEDENT>else:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>elif link_type in ['<STR_LIT>']:<EOL><INDENT>vpn_lookup_key = link.get('<STR_LIT>')<EOL>if not all_vpns.get(vpn_lookup_key, None):<EOL><INDENT>all_vpns[vpn_lookup_key] = link<EOL><DEDENT><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>logger.info("<STR_LIT>".format(site))<EOL><DEDENT><DEDENT>for anynet_key, link in all_anynets.items():<EOL><INDENT>source_swi = link.get('<STR_LIT>')<EOL>if not source_swi:<EOL><INDENT>source_swi = link.get('<STR_LIT>')<EOL><DEDENT>dest_swi = link.get('<STR_LIT>')<EOL>if not dest_swi:<EOL><INDENT>dest_swi = link.get('<STR_LIT>')<EOL><DEDENT>source_site_id = swi_to_site_dict.get(source_swi, '<STR_LIT>')<EOL>target_site_id = swi_to_site_dict.get(dest_swi, '<STR_LIT>')<EOL>source_wan_network_name = link.get("<STR_LIT>")<EOL>target_wan_network_name = link.get("<STR_LIT>")<EOL>link['<STR_LIT>'] = source_site_id<EOL>link['<STR_LIT>'] = target_site_id<EOL>source_site_name = id_site_dict.get(source_site_id, source_site_id)<EOL>target_site_name = id_site_dict.get(target_site_id, target_site_id)<EOL>source_swi_name = swi_id_name_dict.get(source_swi, source_swi)<EOL>target_swi_name = swi_id_name_dict.get(dest_swi, dest_swi)<EOL>anynet_text = "<STR_LIT>".format(<EOL>source_site_name,<EOL>source_wan_network_name,<EOL>source_swi_name,<EOL>target_site_name,<EOL>target_wan_network_name,<EOL>target_swi_name,<EOL>)<EOL>path_id_to_name[anynet_key] = anynet_text<EOL><DEDENT>logger.info("<STR_LIT>".format(len(swi_to_wan_network_dict),<EOL>json.dumps(swi_to_wan_network_dict, indent=<NUM_LIT:4>)))<EOL>logger.info("<STR_LIT>".format(len(all_anynets),<EOL>json.dumps(all_anynets, indent=<NUM_LIT:4>)))<EOL>logger.info("<STR_LIT>".format(len(all_vpns),<EOL>json.dumps(all_vpns, indent=<NUM_LIT:4>)))<EOL>logger.info("<STR_LIT>".format(len(site_swi_dict),<EOL>json.dumps(site_swi_dict, indent=<NUM_LIT:4>)))<EOL>logger.info("<STR_LIT>".format(len(wan_network_to_swi_dict),<EOL>json.dumps(wan_network_to_swi_dict, indent=<NUM_LIT:4>)))<EOL>logger.info("<STR_LIT>".format(len(swi_to_site_dict),<EOL>json.dumps(swi_to_site_dict, indent=<NUM_LIT:4>)))<EOL>for vpn_key, link in all_vpns.items():<EOL><INDENT>anynet_link_id = link.get("<STR_LIT>")<EOL>source_element_id = link.get("<STR_LIT>")<EOL>target_element_id = link.get("<STR_LIT>")<EOL>vpn_id_to_anynet_id[vpn_key] = anynet_link_id<EOL>source_element_name = id_element_dict.get(source_element_id, source_element_id)<EOL>target_element_name = id_element_dict.get(target_element_id, target_element_id)<EOL>anynet_text = path_id_to_name.get(anynet_link_id, anynet_link_id)<EOL>vpn_text = "<STR_LIT>".format(<EOL>source_element_name,<EOL>anynet_text,<EOL>target_element_name<EOL>)<EOL>path_id_to_name[vpn_key] = vpn_text<EOL><DEDENT>global_id_name_dict.update(path_id_to_name)<EOL>if reverse:<EOL><INDENT>return global_id_name_dict, global_name_id_dict<EOL><DEDENT>return global_id_name_dict<EOL>
Generate the ID-NAME map dict
:param sdk: CloudGenix API constructor
:param reverse: Generate reverse name-> ID map as well, return tuple with both.
:return: ID Name dictionary