Esempio n. 1
0
    def handle_put(self, request, user, *args, **kwargs):
        '''Treat PUT requests to Invalidate a vlan 

        URL: vlan/<id_vlan>/invalidate/<network>
        '''

        try:

            id_vlan = kwargs.get('id_vlan')

            network = kwargs.get('network')

            # User permission
            if not has_perm(user, AdminPermission.ACL_VLAN_VALIDATION,
                            AdminPermission.WRITE_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                raise UserNotAuthorizedError(None)

            # Valid Vlan ID
            if not is_valid_int_greater_zero_param(id_vlan):
                self.log.error(
                    u'The id_vlan parameter is not a valid value: %s.',
                    id_vlan)
                raise InvalidValueError(None, 'vlan_id', id_vlan)

            # Valid Network
            if not is_valid_version_ip(network, IP_VERSION):
                self.log.error(
                    u'The network parameter is not a valid value: %s.',
                    network)
                raise InvalidValueError(None, 'network', network)

            # Find Vlan by ID to check if it exist
            vlan = Vlan().get_by_pk(id_vlan)

            with distributedlock(LOCK_VLAN % id_vlan):

                # Set Values
                if network == IP_VERSION.IPv4[0]:
                    vlan.acl_valida = 0
                    vlan.acl_file_name = None

                else:
                    vlan.acl_valida_v6 = 0
                    vlan.acl_file_name_v6 = None

                vlan.save()

                return self.response(dumps_networkapi({}))

        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
    def handle_put(self, request, user, *args, **kwargs):
        '''Treat PUT requests to Invalidate a vlan 

        URL: vlan/<id_vlan>/invalidate/<network>
        '''

        try:

            id_vlan = kwargs.get('id_vlan')

            network = kwargs.get('network')

            # User permission
            if not has_perm(user, AdminPermission.ACL_VLAN_VALIDATION, AdminPermission.WRITE_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                raise UserNotAuthorizedError(None)

            # Valid Vlan ID
            if not is_valid_int_greater_zero_param(id_vlan):
                self.log.error(
                    u'The id_vlan parameter is not a valid value: %s.', id_vlan)
                raise InvalidValueError(None, 'vlan_id', id_vlan)

            # Valid Network
            if not is_valid_version_ip(network, IP_VERSION):
                self.log.error(
                    u'The network parameter is not a valid value: %s.', network)
                raise InvalidValueError(None, 'network', network)

            # Find Vlan by ID to check if it exist
            vlan = Vlan().get_by_pk(id_vlan)

            with distributedlock(LOCK_VLAN % id_vlan):

                # Set Values
                if network == IP_VERSION.IPv4[0]:
                    vlan.acl_valida = 0
                    vlan.acl_file_name = None

                else:
                    vlan.acl_valida_v6 = 0
                    vlan.acl_file_name_v6 = None

                vlan.save(user)

                return self.response(dumps_networkapi({}))

        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
    def activate_network(self, user, id):
        # id => ex: '55-v4' or '55-v6'
        value = id.split('-')

        if len(value) != 2:
            self.log.error(
                u'The id network parameter is invalid format: %s.', value)
            raise InvalidValueError(None, 'id_network', value)

        id_net = value[0]
        network_type = value[1]

        if not is_valid_int_greater_zero_param(id_net):
            self.log.error(
                u'The id network parameter is invalid. Value: %s.', id_net)
            raise InvalidValueError(None, 'id_network', id_net)

        if not is_valid_version_ip(network_type, IP_VERSION):
            self.log.error(
                u'The type network parameter is invalid value: %s.', network_type)
            raise InvalidValueError(None, 'network_type', network_type)

        if network_type == 'v4':
            # network_type = 'v4'

            # Make command
            command = NETWORKIPV4_CREATE % int(id_net)
            code, stdout, stderr = exec_script(command)
            if code == 0:
                # Change column 'active = 1'
                net = NetworkIPv4.get_by_pk(id_net)
                net.activate(user)
        else:
            # network_type = 'v6'

            # Make command
            command = NETWORKIPV6_CREATE % int(id_net)
            code, stdout, stderr = exec_script(command)
            if code == 0:
                # Change column 'active = 1'
                net = NetworkIPv6.get_by_pk(id_net)
                net.activate(user)

        return code, stdout, stderr
Esempio n. 4
0
    def activate_network(self, user, id):
        # id => ex: '55-v4' or '55-v6'
        value = id.split('-')

        if len(value) != 2:
            self.log.error(
                u'The id network parameter is invalid format: %s.', value)
            raise InvalidValueError(None, 'id_network', value)

        id_net = value[0]
        network_type = value[1]

        if not is_valid_int_greater_zero_param(id_net):
            self.log.error(
                u'The id network parameter is invalid. Value: %s.', id_net)
            raise InvalidValueError(None, 'id_network', id_net)

        if not is_valid_version_ip(network_type, IP_VERSION):
            self.log.error(
                u'The type network parameter is invalid value: %s.', network_type)
            raise InvalidValueError(None, 'network_type', network_type)

        if network_type == 'v4':
            # network_type = 'v4'

            # Make command
            command = NETWORKIPV4_CREATE % int(id_net)
            code, stdout, stderr = exec_script(command)
            if code == 0:
                # Change column 'active = 1'
                net = NetworkIPv4.get_by_pk(id_net)
                net.activate(user)
        else:
            # network_type = 'v6'

            # Make command
            command = NETWORKIPV6_CREATE % int(id_net)
            code, stdout, stderr = exec_script(command)
            if code == 0:
                # Change column 'active = 1'
                net = NetworkIPv6.get_by_pk(id_net)
                net.activate(user)

        return code, stdout, stderr
    def deactivate_network(self, user, id):

        id_network, network_type = self.get_id_and_net_type(id)

        if not is_valid_int_greater_zero_param(id_network):
            self.log.error(
                u'The id network parameter is invalid. Value: %s.', id_network)
            raise InvalidValueError(None, 'id_network', id_network)

        if not is_valid_version_ip(network_type, IP_VERSION):
            self.log.error(
                u'The type network parameter is invalid value: %s.', network_type)
            raise InvalidValueError(None, 'network_type', network_type)

        if network_type == self.NETWORK_TYPE_V4:
            net = NetworkIPv4.get_by_pk(id_network)

            if not self.is_active_netwok(net):
                raise NetworkInactiveError(
                    message=error_messages.get(self.CODE_MESSAGE_INACTIVE_NETWORK))

            command = NETWORKIPV4_REMOVE % int(id_network)

            code, stdout, stderr = exec_script(command)
            if code == 0:
                net = NetworkIPv4.get_by_pk(id_network)
                net.deactivate(user)
        else:

            net = NetworkIPv6.get_by_pk(id_network)

            if not self.is_active_netwok(net):
                raise NetworkInactiveError(
                    message=error_messages.get(self.CODE_MESSAGE_INACTIVE_NETWORK))

            command = NETWORKIPV6_REMOVE % int(id_network)

            code, stdout, stderr = exec_script(command)
            if code == 0:
                net.deactivate(user)

        return code, stdout, stderr
    def deactivate_network(self, user, id):

        id_network, network_type = self.get_id_and_net_type(id)

        if not is_valid_int_greater_zero_param(id_network):
            self.log.error(
                u'The id network parameter is invalid. Value: %s.', id_network)
            raise InvalidValueError(None, 'id_network', id_network)

        if not is_valid_version_ip(network_type, IP_VERSION):
            self.log.error(
                u'The type network parameter is invalid value: %s.', network_type)
            raise InvalidValueError(None, 'network_type', network_type)

        if not self.is_active_netwok(net):
            code = 0
            stdout = 'Nothing to do. Network is not active.'
            stderr = ''
        else:
            if network_type == self.NETWORK_TYPE_V4:
                net = NetworkIPv4.get_by_pk(id_network)

                command = NETWORKIPV4_REMOVE % int(id_network)

                code, stdout, stderr = exec_script(command)
                if code == 0:
                    net = NetworkIPv4.get_by_pk(id_network)
                    net.deactivate(user)
            else:
                net = NetworkIPv6.get_by_pk(id_network)

                command = NETWORKIPV6_REMOVE % int(id_network)

                code, stdout, stderr = exec_script(command)
                if code == 0:
                    net.deactivate(user)

        return code, stdout, stderr
    def deactivate_network(self, user, id):

        id_network, network_type = self.get_id_and_net_type(id)

        if not is_valid_int_greater_zero_param(id_network):
            self.log.error(u'The id network parameter is invalid. Value: %s.',
                           id_network)
            raise InvalidValueError(None, 'id_network', id_network)

        if not is_valid_version_ip(network_type, IP_VERSION):
            self.log.error(u'The type network parameter is invalid value: %s.',
                           network_type)
            raise InvalidValueError(None, 'network_type', network_type)

        if not self.is_active_netwok(net):
            code = 0
            stdout = 'Nothing to do. Network is not active.'
            stderr = ''
        else:
            if network_type == self.NETWORK_TYPE_V4:
                net = NetworkIPv4.get_by_pk(id_network)

                command = NETWORKIPV4_REMOVE % int(id_network)

                code, stdout, stderr = exec_script(command)
                if code == 0:
                    net = NetworkIPv4.get_by_pk(id_network)
                    net.deactivate(user)
            else:
                net = NetworkIPv6.get_by_pk(id_network)

                command = NETWORKIPV6_REMOVE % int(id_network)

                code, stdout, stderr = exec_script(command)
                if code == 0:
                    net.deactivate(user)

        return code, stdout, stderr
Esempio n. 8
0
 def validate_ip_version(self, network_type):
     if not is_valid_version_ip(network_type, IP_VERSION):
         self.log.error(u'The type network parameter is invalid value: %s.',
                        network_type)
         raise InvalidValueError('Invalid Network Type', 'network_type',
                                 network_type)
 def validate_ip_version(self, network_type):
     if not is_valid_version_ip(network_type, IP_VERSION):
         self.log.error(
             u'The type network parameter is invalid value: %s.', network_type)
         raise InvalidValueError(
             'Invalid Network Type', 'network_type', network_type)