• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python xml_utils.dumps_networkapi函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中networkapi.infrastructure.xml_utils.dumps_networkapi函数的典型用法代码示例。如果您正苦于以下问题:Python dumps_networkapi函数的具体用法?Python dumps_networkapi怎么用?Python dumps_networkapi使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Treat requests GET to list all the Script.

        URL: script/all
        """
        try:

            self.log.info("GET to list all the Script")

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

            id_script = kwargs.get('id_script')
            if id_script is not None:
                script = Roteiro.get_by_pk(int(id_script))
                script = model_to_dict(script)
                return self.response(dumps_networkapi({'script': script}))

            script_list = []
            for script in Roteiro.objects.all():
                script_list.append(model_to_dict(script))

            return self.response(dumps_networkapi({'script': script_list}))

        except UserNotAuthorizedError:
            return self.not_authorized()

        except RoteiroError:
            return self.response_error(1)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:31,代码来源:ScriptGetAllResource.py


示例2: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Treat requests GET to list all the Model.

        URL: model/all
        """
        try:

            self.log.info("GET to list all the Model")

            script_id = kwargs.get('script_id')

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

            model_list = []

            if script_id is not None:
                models = ModeloRoteiro.objects.filter(roteiro__id=int(script_id))
                for i in models:
                    model_list.append(self.model_map(i.modelo))
                return self.response(dumps_networkapi({'model': model_list}))

            for model in Modelo.objects.all():
                model_list.append(self.model_map(model))
            return self.response(dumps_networkapi({'model': model_list}))

        except UserNotAuthorizedError:
            return self.not_authorized()

        except EquipamentoError:
            return self.response_error(1)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:34,代码来源:ModelGetAllResource.py


示例3: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Trata as requisições GET para consulta de Informações de Acesso a Equipamentos.

        Permite a consulta de Informações de Acesso a Equipamentos existentes.

        URL: /equipamentoacesso/ 
        """

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

            # Efetua a consulta de todos os tipos de acesso
            results = EquipamentoAcesso.search(user.grupos.all())

            if results.count() > 0:
                # Monta lista com dados retornados
                map_list = []
                for item in results:
                    item_map = self.get_equipamento_acesso_map(item)
                    if item_map not in map_list:
                        map_list.append(item_map)

                # Gera response (XML) com resultados
                return self.response(dumps_networkapi({'equipamento_acesso': map_list}))
            else:
                # Gera response (XML) para resultado vazio
                return self.response(dumps_networkapi({}))

        except (EquipamentoError, GrupoError):
            return self.response_error(1)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:31,代码来源:EquipamentoAcessoResource.py


示例4: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Treat GET requests to get all network types.

        URL: /net_type/ 
        """

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

            results = TipoRede.objects.all()

            if results.count() > 0:
                map_list = []
                for item in results:
                    item_map = self.get_net_type_map(item)
                    map_list.append(item_map)

                # Build response (XML)
                return self.response(dumps_networkapi({'net_type': map_list}))
            else:
                # Build response (XML) to empty return
                return self.response(dumps_networkapi({}))

        except (VlanError, GrupoError):
            return self.response_error(1)
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:28,代码来源:NetworkTypeResource.py


示例5: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Trata as requisições GET para consulta de tipos de rede.

        Permite a consulta de tipos de rede existentes.

        URL: /tiporede/ 
        """

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

            # Efetua a consulta de todos os tipos de rede
            results = TipoRede.search()

            if results.count() > 0:
                # Monta lista com dados retornados
                map_list = []
                for item in results:
                    item_map = self.get_tipo_rede_map(item)
                    map_list.append(item_map)

                # Gera response (XML) com resultados
                return self.response(dumps_networkapi({'tipo_rede': map_list}))
            else:
                # Gera response (XML) para resultado vazio
                return self.response(dumps_networkapi({}))

        except (VlanError, GrupoError):
            return self.response_error(1)
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:30,代码来源:TipoRedeResource.py


示例6: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Treat requests GET to get Group User.

        URL: ugroup/get/<id_ugroup>/
        """
        try:

            self.log.info("Get Group User by ID")

            id_ugroup = kwargs.get('id_ugroup')

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

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

            # Find Group User by ID to check if it exist
            ugroup = UGrupo.get_by_pk(id_ugroup)

            ugroup_map = dict()
            ugroup_map['user_group'] = model_to_dict(ugroup)

            return self.response(dumps_networkapi(ugroup_map))

        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:33,代码来源:GroupUserGetByIdResource.py


示例7: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        try:
            self.log.info('Get rules in Environment')

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

            id_env = kwargs.get('id_env')

            if not is_valid_int_greater_zero_param(id_env):
                self.log.error(
                    u'The id_env parameter is not a valid value: %s.', id_env)
                raise InvalidValueError(None, 'id_env', id_env)

            Ambiente.objects.get(pk=id_env)
            rules = Rule.objects.filter(environment=id_env, vip=None)
            rule_list = []
            for rule in rules:
                rule_list.append(model_to_dict(rule))
            return self.response(dumps_networkapi({'rules': rule_list}))

        except InvalidValueError, e:
            self.log.error(
                u'Parameter %s is invalid. Value: %s.', e.param, e.value)
            return self.response_error(269, e.param, e.value)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:28,代码来源:RuleGetResource.py


示例8: handle_delete

    def handle_delete(self, request, user, *args, **kwargs):
        """Treat DELETE requests to remove Group User.

        URL: ugroup/<id_ugroup>/
        """
        try:

            self.log.info('Remove Group User')

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

            id_ugroup = kwargs.get('id_ugroup')

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

            # Find Group User by ID to check if it exist
            ugroup = UGrupo.get_by_pk(id_ugroup)

            with distributedlock(LOCK_GROUP_USER % id_ugroup):

                ugroup.delete()
                return self.response(dumps_networkapi({}))

        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:33,代码来源:GroupUserAlterRemoveResource.py


示例9: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Treat requests GET to list all Equipment Type.

        URL: equipmenttype/all
        """
        try:

            self.log.info("GET to list all Equipment Type")

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

            map_list = []
            for equipment_type in TipoEquipamento.objects.all():
                eq_tp = {
                    'id': equipment_type.id, 'nome': equipment_type.tipo_equipamento}
                map_list.append(eq_tp)

            return self.response(dumps_networkapi({'equipment_type': map_list}))

        except UserNotAuthorizedError:
            return self.not_authorized()

        except EquipamentoError:
            return self.response_error(1)
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:28,代码来源:EquipmentTypeGetAllResource.py


示例10: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Treat requests GET to get User by the identifier.

        URL: user/get/<id_user>/
        """
        try:

            self.log.info("Get User by the identifier")

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

            id_user = kwargs.get('id_user')

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

            # Find User by ID to check if it exist
            usr = Usuario.get_by_pk(id_user)

            user_map = dict()
            user_map['usuario'] = model_to_dict(usr)
            user_map['usuario']['grupos'] = user_map['usuario']['grupos'] if user_map['usuario'][
                'grupos'] is not None and len(user_map['usuario']['grupos']) > 0 else [None]

            return self.response(dumps_networkapi(user_map))

        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:35,代码来源:UserGetByIdResource.py


示例11: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Treat GET requests list all Environment VIP.

        URL: environmentvip/all/
        """

        try:

            self.log.info('List all Environment VIP')

            # Commons Validations

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

            # Business Rules

            evips = EnvironmentVip.objects.all()

            evip_list = []

            for evip in evips:
                evip_list.append(model_to_dict(evip))

            return self.response(dumps_networkapi({'environment_vip': evip_list}))

        except (EnvironmentVipError, GrupoError), e:
            self.log.error(e)
            return self.response_error(1)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:32,代码来源:EnvironmentVipResource.py


示例12: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """
        Handles GET requests to list all the VIPs.

        URL: vip/all/
        """

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

            request_vips = RequisicaoVips.get_all()
            vips = {}

            for vip in request_vips:
                request_vip_map = vip.variables_to_map()
                request_vip_map['id'] = vip.id
                request_vip_map['validado'] = vip.validado
                request_vip_map['vip_criado'] = vip.vip_criado
                request_vip_map['id_ip'] = vip.ip_id
                request_vip_map['id_ipv6'] = vip.ipv6_id
                request_vip_map[
                    'id_healthcheck_expect'] = vip.healthcheck_expect_id
                vips['vip_%s' % (vip.id)] = request_vip_map

            return self.response(dumps_networkapi(vips))

        except (RequisicaoVipsNotFoundError):
            return self.response_error(152)
        except (RequisicaoVipsError, GrupoError):
            return self.response_error(1)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:33,代码来源:RequestAllVipsResource.py


示例13: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Handles GET requests to find all Racks
        URLs: /rack/find/
        """

        self.log.info('List all Racks')

        try:

            # User permission
            if not has_perm(user, AdminPermission.EQUIPMENT_MANAGEMENT , AdminPermission.READ_OPERATION):
                self.log.error( u'User does not have permission to perform the operation.')

                return self.not_authorized()

            rack_list = []
            for rack in Rack.objects.all():
                rack_list.append(model_to_dict(rack))

            return self.response(dumps_networkapi({'rack': rack_list}))

        except UserNotAuthorizedError:
            return self.not_authorized()

        except RackError:
            return self.response_error(379)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:26,代码来源:RackListAllResource.py


示例14: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Handles GET requests to find EnvironmentInterface.

        URLs: int/get-env-by-interface/<id_interface>
        """
        self.log.info('buscando os ambientes associados a uma interface')

        try:

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

            # Get XML data
            interface = kwargs.get('id_interface')

            int_ambiente = EnvironmentInterface.get_by_interface(int(interface))

            ambiente_map = []

            for ids in int_ambiente:
                ambiente_map.append(self.get_environment_map(ids.ambiente))

            return self.response(dumps_networkapi({'ambiente': ambiente_map}))

        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:29,代码来源:InterfaceEnvironmentResource.py


示例15: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Treat GET requests to get a Filter by id.

        URL: filter/get/<id_filter>/
        """

        try:

            self.log.info("Get Filter by id")
            # Commons Validations

            # User permission
            if not has_perm(user, AdminPermission.ENVIRONMENT_MANAGEMENT, AdminPermission.READ_OPERATION):
                self.log.error(u"User does not have permission to perform the operation.")
                return self.not_authorized()

            if not is_valid_int_greater_zero_param(kwargs["id_filter"]):
                self.log.error(u"Parameter id_filter is invalid. Value: %s.", kwargs["id_filter"])
                raise InvalidValueError(None, "id_filter", kwargs["id_filter"])
            else:
                # Check existence
                fil = Filter().get_by_pk(kwargs["id_filter"])

            filter_dict = model_to_dict(fil)
            filter_dict["equip_types"] = list()
            for fil_equip_type in fil.filterequiptype_set.all():
                filter_dict["equip_types"].append(model_to_dict(fil_equip_type.equiptype))

            return self.response(dumps_networkapi({"filter": filter_dict}))

        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:32,代码来源:FilterGetByIdResource.py


示例16: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Handles GET requests to list all equipment.

        URLs: equipament/list/
        """

        try:

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

            equip_list = Equipamento.objects.all()

            map_dicts = []
            for equip in equip_list:
                map_dicts.append(model_to_dict(equip))

            equip_map = dict()
            equip_map['equipamentos'] = map_dicts

            # Return XML
            return self.response(dumps_networkapi(equip_map))

        except (EquipamentoError, GrupoError):
            return self.response_error(1)
        except XMLError, x:
            self.log.error(u'Error reading the XML request.')
            return self.response_error(3, x)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:31,代码来源:EquipmentGetAllResource.py


示例17: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Handles GET requests to find all Racks

        URLs: /rack/find/
        """

        self.log.info('Find all Racks')

        try:

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

            nome = kwargs.get('rack_name')
            rack = Rack()
            rack = rack.get_by_name(nome)
            rack = model_to_dict(rack)

            return self.response(dumps_networkapi({'rack': rack}))

        except UserNotAuthorizedError:
            return self.not_authorized()

        except RackError:
            return self.response_error(379)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:28,代码来源:RackFindResource.py


示例18: handle_post

    def handle_post(self, request, user, *args, **kwargs):
        """Trata as requisições de POST para inserir um grupo de equipamento.

        URL: egrupo/
        """
        try:
            if not has_perm(user, AdminPermission.EQUIPMENT_GROUP_MANAGEMENT, AdminPermission.WRITE_OPERATION):
                return self.not_authorized()

            xml_map, attrs_map = loads(request.raw_post_data)
            self.log.debug('XML_MAP: %s', xml_map)

            networkapi_map = xml_map.get('networkapi')
            if networkapi_map is None:
                return self.response_error(3, u'Não existe valor para a tag networkapi do XML de requisição.')

            egroup_map = networkapi_map.get('grupo')
            if egroup_map is None:
                return self.response_error(3, u'Não existe valor para a tag grupo do XML de requisição.')

            name = egroup_map.get('nome')
            if not is_valid_string_maxsize(name, 100):
                self.log.error(u'Parameter name is invalid. Value: %s', name)
                raise InvalidValueError(None, 'name', name)

            egroup = EGrupo()
            egroup.nome = name
            egroup.create(user)

            return self.response(dumps_networkapi({'grupo': {'id': egroup.id}}))

        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:33,代码来源:GrupoResource.py


示例19: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Treat GET requests list all Filters.

        URL: filter/all/
        """

        try:

            self.log.info("List all Filters")
            # Commons Validations

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

            # Business Rules
            filters = Filter.objects.all()

            filter_list = []
            for filter_ in filters:
                filter_dict = model_to_dict(filter_)
                filter_dict['equip_types'] = list()

                for fil_equip_type in filter_.filterequiptype_set.all():
                    filter_dict['equip_types'].append(
                        model_to_dict(fil_equip_type.equiptype))

                filter_list.append(filter_dict)

            return self.response(dumps_networkapi({'filter': filter_list}))

        except BaseException, e:
            return self.response_error(1)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:35,代码来源:FilterListAllResource.py


示例20: handle_post

    def handle_post(self, request, user, *args, **kwargs):
        """Treat requests POST to create the configuration file.

        URL: rack/gerar-arq-config/id_rack
        """
        try:
            self.log.info("CONFIG")

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

            rack_id = kwargs.get('id_rack')
            rack = Rack()
            rack = rack.get_by_pk(rack_id)
            var = False

            #Chama o script para gerar os arquivos de configuracao
            var = gera_config(rack)

            rack.__dict__.update(id=rack_id, config=var)
            rack.save()

            success_map = dict()
            success_map['rack_conf'] = var
            map = dict()
            map['sucesso'] = success_map
                        
            return self.response(dumps_networkapi(map))


        except RackConfigError, e:
            return self.response_error(382, e.param, e.value)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:34,代码来源:RackConfigResource.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python xml_utils.loads函数代码示例发布时间:2022-05-27
下一篇:
Python script_utils.exec_script函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap