예제 #1
0
def delete_floatip_by_id(request):
    try:
        ids = request.data.getlist('ids', [])

        for flp_id in ids:
            data = NetworkAction().delete_fip(flp_id)

    except Exception as e:
        raise e

    return Response(data)
예제 #2
0
def delete_fwaas_group_by_id(request):
    try:
        ids = request.data.getlist('ids', [])

        for id in ids:
            data = NetworkAction().delete_firewall(id)

    except Exception as e:
        raise e

    return Response(data)
예제 #3
0
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 + '&nbsp' + name_servers
                data['dns_nameservers'] = name_server

    except Exception as e:
        raise e
    return Response(data)
예제 #4
0
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)
예제 #5
0
def get_router_list(request):
    try:
        res_list = []
        data = NetworkAction().list_router()

        for da in data:
            res_dict = {
                'id': da.get('id', None),
                'status': da.get('status', None),
                'name': da.get('name', None),
                'created_at': da.get('created_at', None),
            }
            res_list.append(res_dict)

    except Exception as e:
        raise e
    return list_view(request, res_list, serializers.RouterListSerializer)
예제 #6
0
def get_float_ip_list(request):
    try:
        res_list = []
        data = NetworkAction().list_floating_ip()
        # floating_list = data['floatingips']

        for da in data:
            res_dict = {
                'id': da.get('id', None),
                'status': da.get('status', None),
                'created_at': da.get('created_at', None),
                'fixed_ip_address': da.get('fixed_ip_address', None),
                'floating_ip_address': da.get('floating_ip_address', None),
            }
            res_list.append(res_dict)

    except Exception as e:
        raise e
    return list_view(request, res_list, serializers.FloatIpListSerializer)
예제 #7
0
def get_network_list(request):
    try:
        res_list = []
        # get all network
        if settings.PLATFORM_TYPE == 'ALL':
            data = NetworkAction().list_network_by_name('XOJ')
            data.extend(NetworkAction().list_network_by_name('XAD'))
        else:
            data = NetworkAction().list_network_by_name('X' +
                                                        settings.PLATFORM_TYPE)
        # get all subnet
        subnet_all = NetworkAction().list_subnet()

        for da in data:
            res_sub_list = []
            network_id = da.get('id', int)
            # subnet_list = NetworkAction().get_subnet_by_network_id(network_id)

            # get all subnet under this network
            for subnet in subnet_all:
                if subnet['network_id'] == network_id:
                    res_sub_list.append(subnet)

            res_dict = {
                'id': da.get('id', None),
                'status': da.get('status', None),
                'net_name': da.get('name', None),
                'created_at': da.get('created_at', None),
                'subnets': res_sub_list,
                'router:external': da.get('router:external', None),
                'provider:network_type': da.get('provider:network_type', None),
            }
            res_list.append(res_dict)

    except Exception as e:
        raise e
    return list_view(request, res_list, serializers.NetListSerializer)
예제 #8
0
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)
예제 #9
0
def get_fwaas_rules_list(request):
    try:

        res_list = []
        data = NetworkAction().list_firewall_rule()

        for da in data:
            res_dict = {
                'id': da.get('id', None),
                'action': da.get('action', None),
                'name': da.get('name', None),
                'description': da.get('description', None),
                'protocol': da.get('protocol', None),
                'enabled': da.get('enabled', None),
                'source_ip': da.get('source_ip_address', None),
                'destination_ip': da.get('destination_ip_address', None),
                'source_port': da.get('source_port', None),
                'destination_port': da.get('destination_port', None),
            }
            res_list.append(res_dict)

    except Exception as e:
        raise e
    return list_view(request, res_list, serializers.FwaasRuleListSerializer)
예제 #10
0
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)