Example #1
0
    def handle_get(self, request, user, *args, **kwargs):
        """Handle GET requests to get Environment by id.

            URLs: /environment/id/<environment_id>/,
        """
        try:
            if not has_perm(user, AdminPermission.ENVIRONMENT_MANAGEMENT,
                            AdminPermission.READ_OPERATION):
                return self.not_authorized()

            environment_list = []

            environment_id = kwargs.get('environment_id')

            if not is_valid_int_greater_zero_param(environment_id):
                self.log.error(
                    u'Parameter environment_id is invalid. Value: %s.',
                    environment_id)
                raise InvalidValueError(None, 'environment_id', environment_id)

            environment_list.append(
                get_environment_map(Ambiente().get_by_pk(environment_id)))

            return self.response(
                dumps_networkapi({'ambiente': environment_list}))
        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
    def handle_get(self, request, user, *args, **kwargs):
        """Handle GET requests to get Environment by id.

            URLs: /environment/id/<environment_id>/,
        """

        try:
            if not has_perm(user, AdminPermission.ENVIRONMENT_MANAGEMENT, AdminPermission.READ_OPERATION):
                return self.not_authorized()

            environment_list = []

            environment_id = kwargs.get("environment_id")

            if not is_valid_int_greater_zero_param(environment_id):
                self.log.error(u"Parameter environment_id is invalid. Value: %s.", environment_id)
                raise InvalidValueError(None, "environment_id", environment_id)

            environment_list.append(get_environment_map(Ambiente().get_by_pk(environment_id)))

            return self.response(dumps_networkapi({"ambiente": environment_list}))
        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
Example #3
0
    def handle_post(self, request, user, *args, **kwargs):
        '''Treat POST requests to Create ACL

        URL: vlan/create/acl/
        '''
        self.log.info('Create ACL Vlan')

        try:
            is_suggest_acl_name = False
            # User permission
            if not has_perm(user, AdminPermission.VLAN_MANAGEMENT,
                            AdminPermission.WRITE_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                return self.not_authorized()

            # Load XML data
            xml_map, _ = loads(request.raw_post_data,
                               ["searchable_columns", "asorting_cols"])

            # XML data format
            networkapi_map = xml_map.get('networkapi')
            self.validate_networkapi_map(networkapi_map)

            vlan_map = networkapi_map.get('vlan')
            self.validate_vlan_map(vlan_map)

            id_vlan = vlan_map.get('id_vlan')
            network_type = vlan_map.get('network_type')

            self.validate_id_vlan(id_vlan)

            self.validate_ip_version(network_type)

            vlan = Vlan().get_by_pk(id_vlan)

            environment = get_environment_map(vlan.ambiente)

            if network_type == NETWORK_TYPES.v4:
                if not vlan.acl_file_name:
                    is_suggest_acl_name = True
                    vlan.acl_file_name = self.__create_suggest_acl_name(vlan)

                acl_name = vlan.acl_file_name
            else:
                if not vlan.acl_file_name_v6:
                    is_suggest_acl_name = True
                    vlan.acl_file_name_v6 = self.__create_suggest_acl_name(
                        vlan)

                acl_name = vlan.acl_file_name_v6

            self.validate_duplicate_acl(acl_name, environment, network_type,
                                        user)

            if is_suggest_acl_name:
                vlan.save()

            createAclCvs(acl_name, environment, network_type, user)

            # Send to Queue
            queue_manager = QueueManager()

            serializer = VlanSerializer(vlan)
            data_to_queue = serializer.data
            data_to_queue.update({'description': queue_keys.VLAN_CREATE_ACL})
            queue_manager.append({
                'action': queue_keys.VLAN_CREATE_ACL,
                'kind': queue_keys.VLAN_KEY,
                'data': data_to_queue
            })

            queue_manager.send()

            return self.response(
                dumps_networkapi({'vlan': model_to_dict(vlan)}))

        except InvalidValueError, e:
            return self.response_error(self.CODE_MESSAGE_INVALID_PARAM,
                                       e.param, e.value)
    def handle_post(self, request, user, *args, **kwargs):
        """Treat POST requests to Create Script ACL

        URL: vlan/create/script/acl/
        """
        self.log.info('Create Script ACL Vlan')

        try:
            # User permission
            if not has_perm(user, AdminPermission.VLAN_MANAGEMENT, AdminPermission.WRITE_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                return self.not_authorized()

            # Load XML data
            xml_map, _ = loads(
                request.raw_post_data, ['searchable_columns', 'asorting_cols'])

            # XML data format
            networkapi_map = xml_map.get('networkapi')
            self.validate_networkapi_map(networkapi_map)

            vlan_map = networkapi_map.get('vlan')
            self.validate_vlan_map(vlan_map)

            id_vlan = vlan_map.get('id_vlan')
            network_type = vlan_map.get('network_type')

            self.validate_id_vlan(id_vlan)

            self.validate_ip_version(network_type)

            vlan = Vlan().get_by_pk(id_vlan)

            network_ipv4 = NetworkIPv4.objects.filter(vlan=vlan).order_by('id')
            network_ipv6 = NetworkIPv6.objects.filter(vlan=vlan).order_by('id')

            vlan_formated = get_vlan_map(vlan, network_ipv4, network_ipv6)

            environment = get_environment_map(vlan.ambiente)

            if network_type == NETWORK_TYPES.v4:
                template_name = environment['ipv4_template']
                acl_name = vlan.acl_file_name
            else:
                template_name = environment['ipv6_template']
                acl_name = vlan.acl_file_name_v6

            self.validate_required_acl(acl_name)

            scriptAclCvs(
                acl_name, vlan_formated, environment, network_type, user, template_name)

            # Send to Queue
            queue_manager = QueueManager(broker_vhost='tasks',
                                         queue_name='tasks.aclapi',
                                         exchange_name='tasks.aclapi',
                                         routing_key='tasks.aclapi')

            serializer = VlanSerializer(vlan)
            data_to_queue = serializer.data
            data_to_queue.update(
                {'description': queue_keys.VLAN_CREATE_SCRIPT_ACL})
            queue_manager.append({'action': queue_keys.VLAN_CREATE_SCRIPT_ACL,
                                  'kind': queue_keys.VLAN_KEY, 'data': data_to_queue})

            queue_manager.send()

            return self.response(dumps_networkapi({'vlan': vlan_formated}))

        except InvalidValueError, e:
            return self.response_error(self.CODE_MESSAGE_INVALID_PARAM, e.param, e.value)
    def handle_post(self, request, user, *args, **kwargs):
        '''Treat POST requests to Create ACL

        URL: vlan/create/acl/
        '''
        self.log.info('Create ACL Vlan')

        try:
            is_suggest_acl_name = False
            # User permission
            if not has_perm(user, AdminPermission.VLAN_MANAGEMENT, AdminPermission.WRITE_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                return self.not_authorized()

            # Load XML data
            xml_map, _ = loads(
                request.raw_post_data, ["searchable_columns", "asorting_cols"])

            # XML data format
            networkapi_map = xml_map.get('networkapi')
            self.validate_networkapi_map(networkapi_map)

            vlan_map = networkapi_map.get('vlan')
            self.validate_vlan_map(vlan_map)

            id_vlan = vlan_map.get('id_vlan')
            network_type = vlan_map.get('network_type')

            self.validate_id_vlan(id_vlan)

            self.validate_ip_version(network_type)

            vlan = Vlan().get_by_pk(id_vlan)

            environment = get_environment_map(vlan.ambiente)

            if network_type == NETWORK_TYPES.v4:
                if not vlan.acl_file_name:
                    is_suggest_acl_name = True
                    vlan.acl_file_name = self.__create_suggest_acl_name(vlan)

                acl_name = vlan.acl_file_name
            else:
                if not vlan.acl_file_name_v6:
                    is_suggest_acl_name = True
                    vlan.acl_file_name_v6 = self.__create_suggest_acl_name(
                        vlan)

                acl_name = vlan.acl_file_name_v6

            self.validate_duplicate_acl(
                acl_name, environment, network_type, user)

            if is_suggest_acl_name:
                vlan.save()

            createAclCvs(acl_name, environment, network_type, user)

            # Send to Queue
            queue_manager = QueueManager()

            serializer = VlanSerializer(vlan)
            data_to_queue = serializer.data
            data_to_queue.update({'description': queue_keys.VLAN_CREATE_ACL})
            queue_manager.append({'action': queue_keys.VLAN_CREATE_ACL,'kind': queue_keys.VLAN_KEY,'data': data_to_queue})

            queue_manager.send()

            return self.response(dumps_networkapi({'vlan': model_to_dict(vlan)}))

        except InvalidValueError, e:
            return self.response_error(self.CODE_MESSAGE_INVALID_PARAM, e.param, e.value)
Example #6
0
    def handle_post(self, request, user, *args, **kwargs):
        '''Treat POST requests to Create Script ACL

        URL: vlan/create/script/acl/
        '''
        self.log.info('Create Script ACL Vlan')

        try:
            # User permission
            if not has_perm(user, AdminPermission.VLAN_MANAGEMENT,
                            AdminPermission.WRITE_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                return self.not_authorized()

            # Load XML data
            xml_map, _ = loads(request.raw_post_data,
                               ["searchable_columns", "asorting_cols"])

            # XML data format
            networkapi_map = xml_map.get('networkapi')
            self.validate_networkapi_map(networkapi_map)

            vlan_map = networkapi_map.get('vlan')
            self.validate_vlan_map(vlan_map)

            id_vlan = vlan_map.get('id_vlan')
            network_type = vlan_map.get('network_type')

            self.validate_id_vlan(id_vlan)

            self.validate_ip_version(network_type)

            vlan = Vlan().get_by_pk(id_vlan)

            network_ipv4 = NetworkIPv4.objects.filter(vlan=vlan).order_by('id')
            network_ipv6 = NetworkIPv6.objects.filter(vlan=vlan).order_by('id')

            vlan_formated = get_vlan_map(vlan, network_ipv4, network_ipv6)

            environment = get_environment_map(vlan.ambiente)

            if network_type == NETWORK_TYPES.v4:
                template_name = environment['ipv4_template']
                acl_name = vlan.acl_file_name
            else:
                template_name = environment['ipv6_template']
                acl_name = vlan.acl_file_name_v6

            self.validate_required_acl(acl_name)

            scriptAclCvs(acl_name, vlan_formated, environment, network_type,
                         user, template_name)

            # Send to Queue
            queue_manager = QueueManager()

            serializer = VlanSerializer(vlan)
            data_to_queue = serializer.data
            data_to_queue.update(
                {'description': queue_keys.VLAN_CREATE_SCRIPT_ACL})
            queue_manager.append({
                'action': queue_keys.VLAN_CREATE_SCRIPT_ACL,
                'kind': queue_keys.VLAN_KEY,
                'data': data_to_queue
            })

            queue_manager.send()

            return self.response(dumps_networkapi({'vlan': vlan_formated}))

        except InvalidValueError, e:
            return self.response_error(self.CODE_MESSAGE_INVALID_PARAM,
                                       e.param, e.value)