本文整理汇总了Python中networkapi.infrastructure.xml_utils.dumps_networkapi函数的典型用法代码示例。如果您正苦于以下问题:Python dumps_networkapi函数的具体用法?Python dumps_networkapi怎么用?Python dumps_networkapi使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dumps_networkapi函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)