当前位置: 首页>>代码示例>>Python>>正文


Python Vlan.save方法代码示例

本文整理汇总了Python中networkapi.vlan.models.Vlan.save方法的典型用法代码示例。如果您正苦于以下问题:Python Vlan.save方法的具体用法?Python Vlan.save怎么用?Python Vlan.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在networkapi.vlan.models.Vlan的用法示例。


在下文中一共展示了Vlan.save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle_put

# 需要导入模块: from networkapi.vlan.models import Vlan [as 别名]
# 或者: from networkapi.vlan.models.Vlan import save [as 别名]
    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)
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:52,代码来源:VlanInvalidateResource.py

示例2: handle_post

# 需要导入模块: from networkapi.vlan.models import Vlan [as 别名]
# 或者: from networkapi.vlan.models.Vlan import save [as 别名]
    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)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:75,代码来源:VlanCreateAclResource.py


注:本文中的networkapi.vlan.models.Vlan.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。