Beispiel #1
0
    def get(self, request, *args, **kwargs):
        try:

            env_id = kwargs.get('env_id')

            data = dict()

            if env_id:
                log.info('Get Routers by environment.')

                routers_list = []
                rot_do_ambiente = facade.get_routers_by_environment(
                    int(env_id))
                for r in rot_do_ambiente:
                    router_id = r.equipamento.id
                    router = Equipamento().get_by_pk(router_id)
                    routers_list.append(facade.get_equipment_map(router))

                data['routers'] = routers_list

            return CustomResponse(data,
                                  status=status.HTTP_200_OK,
                                  request=request)

        except ObjectDoesNotExist, exception:
            log.error(exception)
            raise api_exceptions.ObjectDoesNotExistException(
                'Equipment Does Not Exist')
    def get(self, request, *args, **kwargs):
        """
        Returns list of pool by environment vip
        """
        try:
            environment_vip_id = kwargs['environment_vip_id']
            pools = facade.get_pool_list_by_environmentvip(environment_vip_id)
            only_main_property = True

            # serializer pools
            pool_serializer = serializers.PoolV3Serializer(
                pools,
                many=True,
                fields=(
                    'id',
                    'identifier',
                ) + self.fields,
                include=self.include,
                exclude=self.exclude,
                kind=self.kind)

            # prepare serializer with customized properties
            response = render_to_json(pool_serializer,
                                      main_property='server_pools',
                                      obj_model=pools,
                                      request=request,
                                      only_main_property=only_main_property)

            return CustomResponse(response,
                                  status=status.HTTP_200_OK,
                                  request=request)
        except Exception, exception:
            log.exception(exception)
            raise rest_exceptions.NetworkAPIException(exception)
Beispiel #3
0
    def get(self, request, *args, **kwargs):
        """
        Method to return option vip list by environment id
        Param environment_vip_id: environment id
        Return option vip object list
        """
        try:
            environment_vip_id = kwargs['environment_vip_id']

            options_vip = facade.get_option_vip_by_environment_vip_ids(
                [environment_vip_id])

            if options_vip:
                options_vip = options_vip[0]

            serializer_options = serializers.OptionVipEnvironmentVipV3Serializer(
                options_vip,
                many=True,
                fields=self.fields,
                include=self.include,
                exclude=self.exclude,
                kind=self.kind)
            return CustomResponse(serializer_options.data,
                                  status=status.HTTP_200_OK,
                                  request=request)
        except Exception, exception:
            log.error(exception)
            raise api_exceptions.NetworkAPIException()
Beispiel #4
0
    def delete(self, request, *args, **kwargs):
        """
        Delete environment
        """
        env_ids = kwargs['environment_ids'].split(';')
        response = {}
        facade.delete_environment(env_ids)

        return CustomResponse(response, status=status.HTTP_200_OK, request=request)
    def delete(self, request, *args, **kwargs):
        """
        Deletes list of networkv4
        """

        response = list()
        obj_ids = kwargs['obj_id'].split(';')
        facade.delete_networkipv4(obj_ids, request.user)

        return CustomResponse(response,
                              status=status.HTTP_200_OK,
                              request=request)
    def delete(self, request, *args, **kwargs):
        """
        Delete vrfs
        """
        vrf_ids = kwargs['vrf_ids'].split(';')
        response = {}
        for id in vrf_ids:
            pass  # TODO When key is related to other tables, Django removes tuples of these tables
            # facade.delete_vrf(id)

        return CustomResponse(response,
                              status=status.HTTP_200_OK,
                              request=request)
Beispiel #7
0
    def post(self, request, *args, **kwargs):
        """
        Create new environment
        """
        envs = request.DATA
        json_validate(SPECS.get('environment_post')).validate(envs)
        response = list()
        for pool in envs['environments']:

            env = facade.create_environment(pool)
            response.append({'id': env.id})

        return CustomResponse(response, status=status.HTTP_201_CREATED, request=request)
Beispiel #8
0
    def put(self, request, *args, **kwargs):

        envs = request.DATA
        json_validate(SPECS.get('environment_vip_put')).validate(envs)
        response = list()
        for env in envs['environments_vip']:

            ret = facade.update_environment_vip(env)
            response.append({'id': ret.id, 'msg': 'success'})

        return CustomResponse(response,
                              status=status.HTTP_200_OK,
                              request=request)
    def get(self, request, *args, **kwargs):
        """
        Returns a list of pools with updated states of members
        """

        try:
            pool_ids = kwargs.get('pool_ids').split(';')
            checkstatus = request.GET.get('checkstatus') or '0'

            response = dict()

            server_pools = models_vips.ServerPool.objects.filter(
                id__in=pool_ids)

            if checkstatus == '1':

                serializer_server_pool = serializers.PoolV3Serializer(
                    server_pools, many=True)

                mbr_state = facade_pool_deploy.get_poolmember_state(
                    serializer_server_pool.data)

                for server_pool in server_pools:

                    if mbr_state.get(server_pool.id):
                        query_pools = models_vips.ServerPoolMember.objects.filter(
                            server_pool=server_pool)

                        for pm in query_pools:

                            member_checked_status = mbr_state[server_pool.id][
                                pm.id]
                            pm.member_status = member_checked_status
                            pm.last_status_update = datetime.now()
                            pm.save(request.user)

                # get pools updated
                server_pools = models_vips.ServerPool.objects.filter(
                    id__in=pool_ids)

            serializer_server_pool = serializers.PoolV3Serializer(server_pools,
                                                                  many=True)

            response['server_pools'] = serializer_server_pool.data
            return CustomResponse(response,
                                  status=status.HTTP_200_OK,
                                  request=request)

        except Exception, exception:
            log.error(exception)
            raise rest_exceptions.NetworkAPIException(exception)
    def delete(self, request, *args, **kwargs):
        """
        Method to delete
        Delete server pool
        :url /api/v3/pool/<pool_ids>/
        :param pool_ids=<pool_ids>
        """
        pool_ids = kwargs['pool_ids'].split(';')
        response = {}
        facade.delete_pool(pool_ids)

        return CustomResponse(response,
                              status=status.HTTP_200_OK,
                              request=request)
    def put(self, request, *args, **kwargs):
        """
        Update vrfs
        """
        vrfs = request.DATA
        json_validate(SPECS.get('vrf_put')).validate(vrfs)
        response = list()
        for vrf in vrfs['vrfs']:
            vrf = facade.update_vrf(vrf)
            response.append({'id': vrf.id})

        return CustomResponse(response,
                              status=status.HTTP_200_OK,
                              request=request)
    def post(self, request, *args, **kwargs):
        """
        Create new vrfs
        """
        vrfs = request.DATA
        json_validate(SPECS.get('vrf_post')).validate(vrfs)
        response = list()
        for vrf in vrfs['vrfs']:
            vrf = facade.create_vrf(vrf)
            response.append({'id': vrf.id})

        return CustomResponse(response,
                              status=status.HTTP_201_CREATED,
                              request=request)
Beispiel #13
0
    def get(self, request, *args, **kwargs):
        """
        Method to return finality, client or environment vip list.
        Param request.GET["finality"]: finality of environment(optional)
        Param request.GET["client"]: client of environment(optional)
        Param request.GET["environmentp44"]: environmentp44(optional)
        Return finality list: when request has no finality and client.
        Return client list: when request has only finality.
        Return environment vip list: when request has finality and client.
        Return object environment vip: when request has finality and client and environmentp44.
        """

        try:
            data = request.GET

            finality = data.get('finality', '')
            client = data.get('client', '')
            environmentp44 = data.get('environmentp44', '')

            if client != '' and finality != '':
                if environmentp44 != '':
                    obj = EnvironmentVip().get_by_values(
                        finality, client, environmentp44)
                    many = False
                else:
                    obj = EnvironmentVip(
                    ).list_all_ambientep44_by_finality_and_cliente(
                        finality, client)
                    many = True

                evip_values = serializers.EnvironmentVipV3Serializer(
                    obj,
                    many=many,
                    fields=self.fields,
                    include=self.include,
                    exclude=self.exclude,
                    kind=self.kind).data
            elif finality != '':
                evip_values = EnvironmentVip().list_all_clientes_by_finalitys(
                    finality)
            else:
                evip_values = EnvironmentVip().list_all_finalitys()

            return CustomResponse(evip_values,
                                  status=status.HTTP_200_OK,
                                  request=request)
        except Exception, exception:
            log.error(exception)
            raise api_exceptions.NetworkAPIException()
    def put(self, request, *args, **kwargs):
        """Enable/Disable pool member by list of server pool
        """
        try:
            pools = request.DATA
            json_validate(SPECS.get('pool_member_status')).validate(pools)
            response = facade_pool_deploy.set_poolmember_state(
                pools, request.user)

            return CustomResponse(response,
                                  status=status.HTTP_200_OK,
                                  request=request)
        except Exception, exception:
            log.error(exception)
            raise rest_exceptions.NetworkAPIException(exception)
Beispiel #15
0
    def put(self, request, *args, **kwargs):
        """
        Update environment
        """
        envs = request.DATA
        json_validate(SPECS.get('environment_put')).validate(envs)
        response = list()
        for env in envs['environments']:

            env = facade.update_environment(env)
            response.append({
                'id': env.id
            })

        return CustomResponse(response, status=status.HTTP_200_OK, request=request)
    def delete(self, request, *args, **kwargs):

        response = list()
        obj_ids = kwargs['obj_id'].split(';')
        for obj_id in obj_ids:
            # deploy network configuration
            status_deploy = facade.undeploy_networkipv6(obj_id, request.user)
            response.append({
                'status': status_deploy,
                'id': obj_id,
            })

        return CustomResponse(response,
                              status=status.HTTP_200_OK,
                              request=request)
    def post(self, request, *args, **kwargs):
        """
        Save server pool
        """
        pools = request.DATA
        json_validate(SPECS.get('pool_post')).validate(pools)
        verify_ports(pools)
        response = list()
        for pool in pools['server_pools']:
            facade.validate_save(pool)

            pl = facade.create_pool(pool, request.user)
            response.append({'id': pl.id})

        return CustomResponse(response,
                              status=status.HTTP_201_CREATED,
                              request=request)
Beispiel #18
0
    def post(self, request, *args, **kwargs):
        """
        Creates list of equipments
        """

        data = request.DATA

        json_validate(SPECS.get('equipment_post')).validate(data)

        response = list()
        for equipment in data['equipments']:
            eqpt = facade.create_equipment(equipment, request.user)
            response.append({'id': eqpt.id})

        return CustomResponse(response,
                              status=status.HTTP_201_CREATED,
                              request=request)
Beispiel #19
0
    def post(self, request, *args, **kwargs):
        """
        Creates list of vlans
        """

        data = request.DATA

        json_validate(SPECS.get('vlan_post')).validate(data)

        response = list()
        for vlan in data['vlans']:
            vl = facade.create_vlan(vlan, request.user)
            response.append({'id': vl.id})

        return CustomResponse(response,
                              status=status.HTTP_201_CREATED,
                              request=request)
    def post(self, request, *args, **kwargs):
        """
        Creates list of networkv4
        """

        data = request.DATA

        json_validate(SPECS.get('networkv4_post')).validate(data)

        response = list()
        for networkv4 in data['networks']:
            vl = facade.create_networkipv4(networkv4, request.user)
            response.append({'id': vl.id})

        return CustomResponse(response,
                              status=status.HTTP_201_CREATED,
                              request=request)
    def put(self, request, *args, **kwargs):
        """
        Updates list of networkv6
        """

        data = request.DATA

        json_validate(SPECS.get('networkv6_put')).validate(data)

        response = list()
        for networkv6 in data['networks']:
            vl = facade.update_networkipv6(networkv6, request.user)
            response.append({'id': vl.id})

        return CustomResponse(response,
                              status=status.HTTP_200_OK,
                              request=request)
    def get(self, request, *args, **kwargs):
        """
        Return server pools by ids or dict
        """
        try:
            if not kwargs.get('pool_ids'):
                obj_model = facade.get_pool_by_search(self.search)
                pools = obj_model['query_set']
                only_main_property = False
            else:
                pool_ids = kwargs['pool_ids'].split(';')
                pools = facade.get_pool_by_ids(pool_ids)
                only_main_property = True
                obj_model = None

            self.include = (
                'servicedownaction__details',
                'environment__details',
                'groups_permissions__details',
            )

            # serializer pools
            pool_serializer = serializers.PoolV3Serializer(
                pools,
                many=True,
                fields=self.fields,
                include=self.include,
                exclude=self.exclude,
                kind=self.kind)

            # prepare serializer with customized properties
            response = render_to_json(pool_serializer,
                                      main_property='server_pools',
                                      obj_model=obj_model,
                                      request=request,
                                      only_main_property=only_main_property)

            return CustomResponse(response,
                                  status=status.HTTP_200_OK,
                                  request=request)

        except Exception, exception:
            log.exception(exception)
            raise rest_exceptions.NetworkAPIException(exception)
Beispiel #23
0
    def get(self, request, *args, **kwargs):
        """
        Method to return option vip list by environment id and option vip type
        Param environment_vip_id: environment id
        Param type_option: environment id
        Return option vip object list
        """
        try:
            environment_vip_ids = kwargs['environment_vip_id'].split(';')
            type_option_vip = facade.get_type_option_vip_by_environment_vip_ids(
                environment_vip_ids)

            return CustomResponse(type_option_vip,
                                  status=status.HTTP_200_OK,
                                  request=request)

        except Exception, exception:
            log.error(exception)
            raise api_exceptions.NetworkAPIException()
    def put(self, request, *args, **kwargs):
        """
        Updates server pool
        """

        pools = request.DATA
        json_validate(SPECS.get('pool_put')).validate(pools)
        verify_ports(pools)
        response = dict()
        # response = list()
        for pool in pools['server_pools']:
            facade.validate_save(pool)
            facade.update_pool(pool, request.user)
            # pl = facade.update_pool(pool)
            # response.append({'id': pl.id})

        return CustomResponse(response,
                              status=status.HTTP_200_OK,
                              request=request)
Beispiel #25
0
    def get(self, request, *args, **kwargs):
        """
        Returns a list of vip request by pool id
        """
        try:

            pool_id = int(kwargs['pool_id'])

            extends_search = {
                'viprequestport__viprequestportpool__server_pool': pool_id
            }
            self.search['extends_search'] = \
                [ex.append(extends_search) for ex in self.search['extends_search']] \
                if self.search['extends_search'] else [extends_search]

            vips_requests = facade.get_vip_request_by_search(self.search)

            only_main_property = False

            # serializer vips
            serializer_vips = VipRequestV3Serializer(
                vips_requests['query_set'],
                many=True,
                fields=self.fields,
                include=self.include,
                exclude=self.exclude,
                kind=self.kind)

            # prepare serializer with customized properties
            response = render_to_json(serializer_vips,
                                      main_property='vips',
                                      obj_model=vips_requests,
                                      request=request,
                                      only_main_property=only_main_property)

            return CustomResponse(response,
                                  status=status.HTTP_200_OK,
                                  request=request)

        except Exception, exception:
            log.error(exception)
            raise api_exceptions.NetworkAPIException(exception)
Beispiel #26
0
    def post(self, request, *args, **kwargs):
        """
        Creates list of vip request
        """

        data = request.DATA

        json_validate(SPECS.get('vip_request_post')).validate(data)

        response = list()
        verify_ports_vip(data)
        for vip in data['vips']:

            facade.validate_save(vip)
            vp = facade.create_vip_request(vip, request.user)
            response.append({'id': vp.id})

        return CustomResponse(response,
                              status=status.HTTP_201_CREATED,
                              request=request)
Beispiel #27
0
    def get(self, request, *args, **kwargs):
        """
        Returns a list of vlans with details by ids ou dict

        """
        try:

            if not kwargs.get('obj_ids'):
                obj_model = facade.get_vlan_by_search(self.search)
                vlans = obj_model['query_set']
                only_main_property = False
            else:
                obj_ids = kwargs['obj_ids'].split(';')
                vlans = facade.get_vlan_by_ids(obj_ids)
                obj_model = None
                only_main_property = True

            # serializer vips
            serializer_vips = serializers.VlanV3Serializer(
                vlans,
                many=True,
                fields=self.fields,
                include=self.include,
                exclude=self.exclude,
                kind=self.kind)

            # prepare serializer with customized properties
            response = render_to_json(serializer_vips,
                                      main_property='vlans',
                                      obj_model=obj_model,
                                      request=request,
                                      only_main_property=only_main_property)

            return CustomResponse(response,
                                  status=status.HTTP_200_OK,
                                  request=request)

        except Exception, exception:
            log.error(exception)
            raise api_exceptions.NetworkAPIException(exception)
Beispiel #28
0
    def get(self, request, *args, **kwargs):
        """
        Method to return option vip list by environment id and option vip type
        Param environment_vip_id: environment id
        Param type_option: environment id
        Return option vip object list
        """
        try:
            environment_vip_ids = kwargs['environment_vip_id'].split(';')
            type_option = urllib.unquote(kwargs['type_option']).decode('utf8')
            search_list = list()

            for environment_vip_id in environment_vip_ids:
                search_list.append({
                    'environment_vip_id': environment_vip_id,
                    'type_option': type_option
                })

            options_vips = facade.get_option_vip_by_environment_vip_type(
                search_list)

            data = dict()
            data['optionsvip'] = list()
            for options_vip in options_vips:
                serializer_options = serializers.OptionVipV3Serializer(
                    options_vip,
                    many=True,
                    fields=self.fields,
                    include=self.include,
                    exclude=self.exclude,
                    kind=self.kind)
                data['optionsvip'].append(serializer_options.data)

            return CustomResponse(data,
                                  status=status.HTTP_200_OK,
                                  request=request)

        except Exception, exception:
            log.error(exception)
            raise api_exceptions.NetworkAPIException()
    def get(self, request, *args, **kwargs):
        """
        Returns a list of networkv6 by ids ou dict
        """

        try:

            if not kwargs.get('obj_id'):
                obj_model = facade.get_networkipv6_by_search(self.search)
                networks = obj_model['query_set']
                only_main_property = False
            else:
                obj_ids = kwargs.get('obj_id').split(';')
                networks = facade.get_networkipv6_by_ids(obj_ids)
                only_main_property = True
                obj_model = None

            # serializer networks
            serializer_net = serializers.NetworkIPv6V3Serializer(
                networks,
                many=True,
                fields=self.fields,
                include=self.include,
                exclude=self.exclude,
                kind=self.kind)

            # prepare serializer with customized properties
            data = render_to_json(serializer_net,
                                  main_property='networks',
                                  obj_model=obj_model,
                                  request=request,
                                  only_main_property=only_main_property)

            return CustomResponse(data,
                                  status=status.HTTP_200_OK,
                                  request=request)

        except Exception, exception:
            log.error(exception)
            raise api_exceptions.NetworkAPIException(exception)
    def get(self, request, *args, **kwargs):
        """
        Returns a list of vrf by ids ou dict
        """

        try:

            if not kwargs.get('vrf_ids'):
                obj_model = facade.get_vrfs_by_search(self.search)
                vrfs = obj_model['query_set']
                only_main_property = False
            else:
                vrf_ids = kwargs.get('vrf_ids').split(';')
                vrfs = facade.get_vrfs_by_ids(vrf_ids)
                only_main_property = True
                obj_model = None

            serializer_class = serializers.VrfV3Serializer

            # serializer vrfs
            serializer_vrf = serializer_class(vrfs,
                                              many=True,
                                              fields=self.fields,
                                              include=self.include,
                                              exclude=self.exclude)

            # prepare serializer with customized properties
            response = render_to_json(serializer_vrf,
                                      main_property='vrfs',
                                      obj_model=obj_model,
                                      request=request,
                                      only_main_property=only_main_property)

            return CustomResponse(response,
                                  status=status.HTTP_200_OK,
                                  request=request)

        except Exception, exception:
            log.error(exception)
            raise api_exceptions.NetworkAPIException(exception)