本文整理汇总了Python中networkapi.util.is_valid_int_greater_zero_param函数的典型用法代码示例。如果您正苦于以下问题:Python is_valid_int_greater_zero_param函数的具体用法?Python is_valid_int_greater_zero_param怎么用?Python is_valid_int_greater_zero_param使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_valid_int_greater_zero_param函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_post
def handle_post(self, request, user, *args, **kwargs):
"""Handles POST requests associate environment to ip config
URL: ipconfig/
"""
try:
# Commons Validations
# User permission
if not has_perm(user, AdminPermission.ENVIRONMENT_MANAGEMENT, AdminPermission.WRITE_OPERATION):
return self.not_authorized()
# Business Validations
# Load XML data
xml_map, attrs_map = loads(request.raw_post_data)
# XML data format
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.')
environment_map = networkapi_map.get('ambiente')
if environment_map is None:
return self.response_error(3, u'Não existe valor para a tag ambiente do XML de requisição.')
# Get XML data
id_environment = environment_map.get('id_environment')
id_ip_config = environment_map.get('id_ip_config')
# Valid environment
if not is_valid_int_greater_zero_param(id_environment):
raise InvalidValueError(None, 'id_environment', id_environment)
# Valid ip config
if not is_valid_int_greater_zero_param(id_ip_config):
raise InvalidValueError(None, 'id_ip_config', id_ip_config)
# Environment must exists
environment = Ambiente().get_by_pk(id_environment)
# Ip config must exists
ip_conf = IPConfig().get_by_pk(id_ip_config)
# Makes the relationship
config = ConfigEnvironment()
config.ip_config = ip_conf
config.environment = environment
config.save(user)
# Make return xml
conf_env_map = dict()
conf_env_map['id_config_do_ambiente'] = config.id
return self.response(dumps_networkapi({'config_do_ambiente': conf_env_map}))
except InvalidValueError, e:
return self.response_error(269, e.param, e.value)
示例2: handle_put
def handle_put(self, request, user, *args, **kwargs):
'''Trata as requisições de PUT para inserir o relacionamento entre IP e Equipamento.
URL: ip/<id_ip>/equipamento/<id_equipamento>/$
'''
try:
ip_id = kwargs.get('id_ip')
equip_id = kwargs.get('id_equipamento')
if not is_valid_int_greater_zero_param(ip_id):
self.log.error(
u'The ip_id parameter is not a valid value: %s.', ip_id)
raise InvalidValueError(None, 'ip_id', ip_id)
if not is_valid_int_greater_zero_param(equip_id):
self.log.error(
u'The equip_id parameter is not a valid value: %s.', equip_id)
raise InvalidValueError(None, 'equip_id', equip_id)
Ip.get_by_pk(ip_id)
with distributedlock(LOCK_IP_EQUIPMENT % (ip_id, equip_id)):
ip_equipment = insert_ip_equipment(ip_id, equip_id, user)
ipequipamento_map = dict()
ipequipamento_map['id'] = ip_equipment.id
map = dict()
map['ip_equipamento'] = ipequipamento_map
return self.response(dumps_networkapi(map))
except InvalidValueError, e:
return self.response_error(269, e.param, e.value)
示例3: handle_delete
def handle_delete(self, request, user, *args, **kwargs):
"""
Handles DELETE requests to create a relationship of Environment with EnvironmentVip.
URL: environment/<environment_id>/environmentvip/<environment_vip_id>/
"""
self.log.info("Remove a relationship of Environment with EnvironmentVip")
try:
# Commons Validations
# User permission
if not has_perm(user, AdminPermission.ENVIRONMENT_MANAGEMENT, AdminPermission.WRITE_OPERATION):
self.log.error(u"User does not have permission to perform the operation.")
raise UserNotAuthorizedError(None)
# Valid Environment
environment_id = kwargs.get("environment_id")
if not is_valid_int_greater_zero_param(environment_id):
self.log.error(u"The environment_id parameter is not a valid value: %s.", environment_id)
raise InvalidValueError(None, "environment_id", environment_id)
# Valid EnvironmentVip ID
environment_vip_id = kwargs.get("environment_vip_id")
if not is_valid_int_greater_zero_param(environment_vip_id):
self.log.error(u"The id_environment_vip parameter is not a valid value: %s.", environment_vip_id)
raise InvalidValueError(None, "environment_vip_id", environment_vip_id)
# Business Validations
# Existing Environment ID
environment = Ambiente.get_by_pk(environment_id)
# Existing EnvironmentVip ID
environment_vip = EnvironmentVip.get_by_pk(environment_vip_id)
# Business Rules
environment_environment_vip = EnvironmentEnvironmentVip().get_by_environment_environment_vip(
environment.id, environment_vip.id
)
server_pool_list = EnvironmentEnvironmentVip.get_server_pool_member_by_environment_environment_vip(
environment_environment_vip
)
# Valid integraty between environment/environmentvip related with reals
# if exists reals fot this environment then raise a exception
if server_pool_list:
raise EnvironmentEnvironmentServerPoolLinked({"environment": environment.name})
# Delete
environment_environment_vip.delete()
# Return nothing
return self.response(dumps_networkapi({}))
except UserNotAuthorizedError:
return self.not_authorized()
except InvalidValueError, e:
return self.response_error(269, e.param, e.value)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:59,代码来源:EnvironmentEnvironmentVipAssociationResource.py
示例4: handle_delete
def handle_delete(self, request, user, *args, **kwargs):
"""Treat DELETE requests to remove IP and Equipment relationship.
URL: ip/<id_ip>/equipamento/<id_equipamento>/$
"""
try:
ip_id = kwargs.get('id_ip')
equip_id = kwargs.get('id_equipamento')
if not is_valid_int_greater_zero_param(ip_id):
self.log.error(
u'The ip_id parameter is not a valid value: %s.', ip_id)
raise InvalidValueError(None, 'ip_id', ip_id)
if not is_valid_int_greater_zero_param(equip_id):
self.log.error(
u'The equip_id parameter is not a valid value: %s.', equip_id)
raise InvalidValueError(None, 'equip_id', equip_id)
Ip.get_by_pk(ip_id)
Equipamento.get_by_pk(equip_id)
with distributedlock(LOCK_IP_EQUIPMENT % (ip_id, equip_id)):
ipv4 = Ip.get_by_pk(ip_id)
equipament = Equipamento.get_by_pk(equip_id)
# Delete vlan's cache
destroy_cache_function([ipv4])
# delete equipment's cache
destroy_cache_function([equip_id], True)
server_pool_member_list = ServerPoolMember.objects.filter(
ip=ipv4)
if server_pool_member_list.count() != 0:
# IP associated with Server Pool
server_pool_name_list = set()
for member in server_pool_member_list:
item = '{}: {}'.format(
member.server_pool.id, member.server_pool.identifier)
server_pool_name_list.add(item)
server_pool_name_list = list(server_pool_name_list)
server_pool_identifiers = ', '.join(server_pool_name_list)
raise IpCantRemoveFromServerPool({'ip': mount_ipv4_string(ipv4), 'equip_name': equipament.nome, 'server_pool_identifiers': server_pool_identifiers},
'Ipv4 não pode ser disassociado do equipamento %s porque ele está sendo utilizando nos Server Pools (id:identifier) %s' % (equipament.nome, server_pool_identifiers))
remove_ip_equipment(ip_id, equip_id, user)
return self.response(dumps_networkapi({}))
except IpCantRemoveFromServerPool, e:
return self.response_error(385, e.cause.get('ip'), e.cause.get('equip_name'), e.cause.get('server_pool_identifiers'))
示例5: handle_delete
def handle_delete(self, request, user, *args, **kwargs):
"""
Handles DELETE requests to remove a relationship of OptionVip with EnvironmentVip.
URL: optionvip/<id_option_vip>/environmentvip/<id_environment_vip>/
"""
self.log.info("Remove a relationship of OptionVip with EnvironmentVip")
try:
# Commons Validations
# User permission
if not has_perm(user, AdminPermission.OPTION_VIP, AdminPermission.WRITE_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
raise UserNotAuthorizedError(None)
# Valid OptionVip ID
option_vip_id = kwargs.get('id_option_vip')
if not is_valid_int_greater_zero_param(option_vip_id):
self.log.error(
u'The id_option_vip parameter is not a valid value: %s.', option_vip_id)
raise InvalidValueError(None, 'id_option_vip', option_vip_id)
# Valid EnvironmentVip ID
environment_vip_id = kwargs.get('id_environment_vip')
if not is_valid_int_greater_zero_param(environment_vip_id):
self.log.error(
u'The id_environment_vip parameter is not a valid value: %s.', environment_vip_id)
raise InvalidValueError(
None, 'id_environment_vip', environment_vip_id)
# Business Validations
# Existing OptionVip ID
option_vip = OptionVip.get_by_pk(option_vip_id)
# Existing EnvironmentVip ID
environment_vip = EnvironmentVip.get_by_pk(environment_vip_id)
# Business Rules
# Find
opt_vip_env_vip = OptionVipEnvironmentVip().get_by_option_environment(
option_vip.id, environment_vip.id)
# Delete
opt_vip_env_vip.delete()
# Return nothing
return self.response(dumps_networkapi({}))
except UserNotAuthorizedError:
return self.not_authorized()
except InvalidValueError, e:
return self.response_error(269, e.param, e.value)
示例6: handle_delete
def handle_delete(self, request, user, *args, **kwargs):
"""Treat DELETE requests to dissociate User and Group.
URL: usergroup/user/<id_user>/ugroup/<id_group>/dissociate/
"""
try:
self.log.info('Dissociate User and Group.')
# 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_user = kwargs.get('id_user')
id_group = kwargs.get('id_group')
# Valid ID User
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)
# Valid ID Group
if not is_valid_int_greater_zero_param(id_group):
self.log.error(
u'The id_group parameter is not a valid value: %s.', id_group)
raise InvalidValueError(None, 'id_group', id_group)
# Find User by ID to check if it exist
Usuario.get_by_pk(id_user)
# Find Group by ID to check if it exist
UGrupo.get_by_pk(id_group)
# Find UserGroup by ID to check if it exist
user_group = UsuarioGrupo.get_by_user_group(id_user, id_group)
with distributedlock(LOCK_USER_GROUP % (id_user, id_group)):
try:
# remove UserGroup
user_group.delete()
except Exception, e:
self.log.error(u'Failed to remove the UserGroup.')
raise GrupoError(e, u'Failed to remove the UserGroup.')
return self.response(dumps_networkapi({}))
except InvalidValueError, e:
return self.response_error(269, e.param, e.value)
示例7: handle_get
def handle_get(self, request, user, *args, **kwargs):
"""Trata as requisições de GET para listar os direitos de grupo de usuários em grupo de equipamentos.
URLs: direitosgrupoequipamento/$
direitosgrupoequipamento/ugrupo/<id_grupo_usuario>/$
direitosgrupoequipamento/egrupo/<id_grupo_equipamento>/$
direitosgrupoequipamento/<id_direito>/$
"""
try:
if not has_perm(user, AdminPermission.USER_ADMINISTRATION, AdminPermission.READ_OPERATION):
return self.not_authorized()
map_list = []
right_id = kwargs.get('id_direito')
if not is_valid_int_greater_zero_param(right_id, False):
self.log.error(
u'The right_id parameter is not a valid value: %s.', right_id)
raise InvalidValueError(None, 'right_id', right_id)
if right_id is not None:
map_list.append(
self.__get_direito_map(DireitosGrupoEquipamento.get_by_pk(right_id)))
else:
ugroup = kwargs.get('id_grupo_usuario')
egroup = kwargs.get('id_grupo_equipamento')
if not is_valid_int_greater_zero_param(ugroup, False):
self.log.error(
u'The ugroup_id parameter is not a valid value: %s.', ugroup)
raise InvalidValueError(None, 'ugroup_id', ugroup)
if not is_valid_int_greater_zero_param(egroup, False):
self.log.error(
u'The egroup_id parameter is not a valid value: %s.', egroup)
raise InvalidValueError(None, 'egroup_id', egroup)
if ugroup is not None:
UGrupo.get_by_pk(ugroup)
if egroup is not None:
EGrupo.get_by_pk(egroup)
rights = DireitosGrupoEquipamento.search(ugroup, None, egroup)
for right in rights:
map_list.append(self.__get_direito_map(right))
return self.response(dumps_networkapi({'direito_grupo_equipamento': map_list}))
except InvalidValueError, e:
return self.response_error(269, e.param, e.value)
示例8: handle_put
def handle_put(self, request, user, *args, **kwargs):
"""Treat PUT requests to associate Filter and TipoEquipamento.
URL: filter/<filter_id>/equiptype/<equiptype_id>
"""
try:
self.log.info('')
# Commons Validations
# User permission
if not has_perm(user, AdminPermission.ENVIRONMENT_MANAGEMENT, AdminPermission.WRITE_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'])
if not is_valid_int_greater_zero_param(kwargs['id_equiptype']):
self.log.error(
u'Parameter id_equiptype is invalid. Value: %s.', kwargs['id_equiptype'])
raise InvalidValueError(
None, 'id_equiptype', kwargs['id_equiptype'])
else:
# Check existence
tp_equip = TipoEquipamento().get_by_pk(kwargs['id_equiptype'])
association = FilterEquipType()
association.filter = fil
association.equiptype = tp_equip
# Check existence
association.validate()
# Save association
association.save()
fil_et_map = dict()
fil_et_map['id'] = association.id
return self.response(dumps_networkapi({'equiptype_filter_xref': fil_et_map}))
except InvalidValueError, e:
return self.response_error(269, e.param, e.value)
示例9: handle_delete
def handle_delete(self, request, user, *args, **kwargs):
"""Trata uma requisição DELETE para excluir uma informação de acesso a equipamento
URL: /equipamentoacesso/id_equipamento/id_tipo_acesso/
"""
# Verifica acesso e obtém dados do request
try:
# Obtém argumentos passados na URL
id_equipamento = kwargs.get('id_equipamento')
# Valid ID Equipment
if not is_valid_int_greater_zero_param(id_equipamento):
self.log.error(
u'The id_equipamento parameter is not a valid value: %s.', id_equipamento)
raise InvalidValueError(None, 'id_equipamento', id_equipamento)
id_tipo_acesso = kwargs.get('id_tipo_acesso')
# Valid ID Equipment
if not is_valid_int_greater_zero_param(id_tipo_acesso):
self.log.error(
u'The id_tipo_acesso parameter is not a valid value: %s.', id_tipo_acesso)
raise InvalidValueError(None, 'id_tipo_acesso', id_tipo_acesso)
Equipamento.get_by_pk(id_equipamento)
TipoAcesso.get_by_pk(id_tipo_acesso)
# Após obtenção do id_equipamento podemos verificar a permissão
if not has_perm(user,
AdminPermission.EQUIPMENT_MANAGEMENT,
AdminPermission.WRITE_OPERATION,
None,
id_equipamento,
AdminPermission.EQUIP_WRITE_OPERATION):
return self.not_authorized()
with distributedlock(LOCK_EQUIPMENT_ACCESS % id_tipo_acesso):
# Remove a informação de acesso a equipamento
EquipamentoAcesso.remove(user, id_equipamento, id_tipo_acesso)
# Retorna response vazio em caso de sucesso
return self.response(dumps_networkapi({}))
except InvalidValueError, e:
return self.response_error(269, e.param, e.value)
示例10: 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)
示例11: 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)
示例12: generate_and_deploy_channel_config_sync
def generate_and_deploy_channel_config_sync(user, id_channel):
if not is_valid_int_greater_zero_param(id_channel):
raise exceptions.InvalidIdInterfaceException()
channel = PortChannel.get_by_pk(id_channel)
interfaces = channel.list_interfaces()
#group interfaces by equipment
equipment_interfaces = dict()
for interface in interfaces:
if interface.equipamento.id not in equipment_interfaces:
equipment_interfaces[interface.equipamento.id] = []
equipment_interfaces[interface.equipamento.id].append(interface)
files_to_deploy = {}
for equipment_id in equipment_interfaces.keys():
grouped_interfaces = equipment_interfaces[equipment_id]
file_to_deploy = _generate_config_file(grouped_interfaces)
files_to_deploy[equipment_id] = file_to_deploy
#TODO Deploy config file
#make separate threads
for equipment_id in files_to_deploy.keys():
lockvar = LOCK_INTERFACE_DEPLOY_CONFIG % (equipment_id)
equipamento = Equipamento.get_by_pk(equipment_id)
status_deploy = deploy_config_in_equipment_synchronous(files_to_deploy[equipment_id], equipamento, lockvar)
return status_deploy
示例13: handle_delete
def handle_delete(self, request, user, *args, **kwargs):
"""Treat DELETE requests to remove Filters.
URL: filter/<id_filter>/
"""
try:
self.log.info('Remove Filter')
# Commons Validations
# User permission
if not has_perm(user, AdminPermission.ENVIRONMENT_MANAGEMENT, AdminPermission.WRITE_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'])
try:
# Remove filter and its relationships
fil.delete()
except Exception, e:
self.log.error(u'Failed to remove the filter.')
raise e
return self.response(dumps_networkapi({}))
示例14: 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)
示例15: handle_delete
def handle_delete(self, request, user, *args, **kwargs):
"""Treat requests DELETE to remove Rule.
URL: rule/delete/<id_rule>/
"""
try:
self.log.info('Delete rule from an 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_rule = kwargs.get('id_rule')
if not is_valid_int_greater_zero_param(id_rule):
self.log.error(
u'The id_rule parameter is not a valid value: %s.', id_rule)
raise InvalidValueError(None, 'id_rule', id_rule)
rule = Rule.objects.get(pk=id_rule)
rule.delete()
return self.response(dumps_networkapi({}))
except InvalidValueError, e:
return self.response_error(269, e.param, e.value)