def get_subnet_detail_by_id(request): try: id = request.GET['id'] data = NetworkAction().get_subnet_detail(id) allocation_pool = data.get('allocation_pools', None) if allocation_pool: data['allocation_pools'] = allocation_pool[0][ 'start'] + '--' + allocation_pool[0]['end'] dns_nameserver_list = data.get('dns_nameservers', None) if dns_nameserver_list: for name_servers in dns_nameserver_list: name_server = name_server + ' ' + name_servers data['dns_nameservers'] = name_server except Exception as e: raise e return Response(data)
def get_fwaas_group_list(request): try: res_list = [] data = NetworkAction().list_firewall() for da in data: ingress_policy_id = da.get('ingress_firewall_policy_id', '') egress_policy_id = da.get('egress_firewall_policy_id', '') res_ingress_policy_name = '' res_egress_policy_name = '' if ingress_policy_id: res_ingress_policy = NetworkAction().get_firewall_policy( ingress_policy_id) res_ingress_policy_name = res_ingress_policy.get('name', '') else: res_ingress_policy_name = '' if egress_policy_id: res_egress_policy = NetworkAction().get_firewall_policy( egress_policy_id) res_egress_policy_name = res_egress_policy.get('name', '') else: res_egress_policy_name = '' res_dict = { 'id': da.get('id', None), 'status': da.get('status', None), 'name': da.get('name', None), 'description': da.get('description', None), 'ingress_name': res_ingress_policy_name, 'engress_name': res_egress_policy_name, 'ingress_id': ingress_policy_id, 'engress_id': egress_policy_id, } res_list.append(res_dict) except Exception as e: raise e return list_view(request, res_list, serializers.FwaasGroupListSerializer)
def get_router_detail_by_id(request): try: id = request.GET['id'] data = NetworkAction().get_router(id) external_gateway_info = data.get('external_gateway_info', None) if external_gateway_info: data['network_id'] = external_gateway_info.get('network_id', None) data['enable_snat'] = external_gateway_info.get( 'enable_snat', None) external_fixed_ips = external_gateway_info.get( 'external_fixed_ips', None) address = '' if external_fixed_ips: for fixed_ip in external_fixed_ips: address = address + ' ' + fixed_ip.get( 'ip_address', None) data['external_fixed_ips'] = address except Exception as e: raise e return Response(data)
def get_fwaas_group_detail_by_id(request): try: id = request.GET.get('id', None) res_list = [] if not id or id == '|': return Response(None) id_list = id.split('|') index = 1 for item in id_list: if item != 'null' and item != None: data = NetworkAction().get_firewall_policy(item) rules_list = data.get('firewall_rules', None) if rules_list: for rule_id in rules_list: rule_dict = NetworkAction().get_firewall_rule(rule_id) if index == 1: type = 'ingress' else: type = 'engress' res_dict = { 'id': rule_dict.get('id', None), 'description': rule_dict.get('description', None), 'name': rule_dict.get('name', None), 'protocol': rule_dict.get('protocol', None), 'shared': rule_dict.get('shared', None), 'enabled': rule_dict.get('enabled', None), 'action': rule_dict.get('action', None), 'type': type, 'source_ip_address': rule_dict.get('source_ip_address', 'All'), 'destination_ip_address': rule_dict.get('destination_ip_address', 'All'), 'destination_port': rule_dict.get('destination_port', 'All'), 'source_port': rule_dict.get('source_port', 'All'), } res_list.append(res_dict) index = index + 1 except Exception as e: raise e return list_view(request, res_list, serializers.FwaasRuleListSerializer)