本文整理汇总了Python中networkapi.requisicaovips.models.RequisicaoVips.valid_real_server方法的典型用法代码示例。如果您正苦于以下问题:Python RequisicaoVips.valid_real_server方法的具体用法?Python RequisicaoVips.valid_real_server怎么用?Python RequisicaoVips.valid_real_server使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkapi.requisicaovips.models.RequisicaoVips
的用法示例。
在下文中一共展示了RequisicaoVips.valid_real_server方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_post
# 需要导入模块: from networkapi.requisicaovips.models import RequisicaoVips [as 别名]
# 或者: from networkapi.requisicaovips.models.RequisicaoVips import valid_real_server [as 别名]
def handle_post(self, request, user, *args, **kwargs):
"""Handles POST requests to valid Real server.
URL: vip/real/valid/
"""
self.log.info('Valid Real Server')
try:
# 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'There is no value to the networkapi tag of XML request.')
real_map = networkapi_map.get('real')
if real_map is None:
return self.response_error(3, u'There is no value to the vip tag of XML request.')
# Get XML data
ip = real_map.get('ip')
name = real_map.get('name_equipment')
id_evip = real_map.get('id_environment_vip')
valid = real_map.get('valid')
# User permission
if not has_perm(user, AdminPermission.VIPS_REQUEST, AdminPermission.READ_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
return self.not_authorized()
# Valid IP
if not is_valid_ip_ipaddr(ip):
self.log.error(u'Parameter ip is invalid. Value: %s.', ip)
raise InvalidValueError(None, 'ip', ip)
# Valid Name Equipment
if not is_valid_string_minsize(name, 3) or not is_valid_string_maxsize(name, 80) or not is_valid_regex(name, '^[A-Z0-9-_]+$'):
self.log.error(
u'Parameter name_equipment is invalid. Value: %s', name)
raise InvalidValueError(None, 'name_equipment', name)
# Valid Environment Vip
if not is_valid_int_greater_zero_param(id_evip):
self.log.error(
u'Parameter id_environment_vip is invalid. Value: %s.', id_evip)
raise InvalidValueError(None, 'id_environment_vip', id_evip)
# Valid Equipment
equip = Equipamento.get_by_name(name)
# Valid EnvironmentVip
evip = EnvironmentVip.get_by_pk(id_evip)
version = ''
if is_valid_ipv4(ip):
version = IP_VERSION.IPv4[1]
elif is_valid_ipv6(ip):
version = IP_VERSION.IPv6[1]
ip, equip, evip = RequisicaoVips.valid_real_server(
ip, equip, evip, valid)
real_dict = {}
ip_dict = model_to_dict(ip)
ip_dict['version'] = version
real_dict['ip'] = ip_dict
real_dict['equipment'] = model_to_dict(equip)
real_dict['environmentvip'] = model_to_dict(evip)
return self.response(dumps_networkapi({'real': real_dict}))
except XMLError, x:
self.log.error(u'Error reading the XML request.')
return self.response_error(3, x)
示例2: handle_put
# 需要导入模块: from networkapi.requisicaovips.models import RequisicaoVips [as 别名]
# 或者: from networkapi.requisicaovips.models.RequisicaoVips import valid_real_server [as 别名]
def handle_put(self, request, user, *args, **kwargs):
"""Treat requests PUT change limit connections to VIP.
URLs: /vip/<id_vip>/maxcon/<maxcon>/
"""
self.log.info("Change limit connections to VIP")
try:
vip_id = kwargs.get('id_vip')
maxcon = kwargs.get('maxcon')
# User permission
if not has_perm(user, AdminPermission.VIP_ALTER_SCRIPT, AdminPermission.WRITE_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
raise UserNotAuthorizedError(None)
# Valid Vip ID
if not is_valid_int_greater_zero_param(vip_id):
self.log.error(
u'The vip_id parameter is not a valid value: %s.', vip_id)
raise InvalidValueError(None)
# Valid Maxcon
if not is_valid_int_greater_equal_zero_param(maxcon):
self.log.error(
u'The maxcon parameter is not a valid value: %s.', maxcon)
raise InvalidValueError(None)
# Existing Vip ID
vip = RequisicaoVips.get_by_pk(vip_id)
with distributedlock(LOCK_VIP % vip_id):
vip_old = clone(vip)
server_pools = ServerPool.objects.filter(vipporttopool__requisicao_vip=vip)
server_pools_old = []
server_pools_members_old = []
for sp in server_pools:
server_pools_old.append(sp)
for spm in sp.serverpoolmember_set.all():
server_pools_members_old.append(spm)
# Vip must be created
if not vip.vip_criado:
self.log.error(
u'Maxcon can not be changed because VIP has not yet been created.')
raise RequestVipsNotBeenCreatedError(None)
# Vip equipments permission
if vip.ip is not None:
for ip_equipment in vip.ip.ipequipamento_set.all():
if not has_perm(user, AdminPermission.VIP_ALTER_SCRIPT, AdminPermission.WRITE_OPERATION, None, ip_equipment.equipamento_id, AdminPermission.EQUIP_UPDATE_CONFIG_OPERATION):
self.log.error(
u'Groups of equipment registered with the IP of the VIP request is not allowed of acess.')
raise EquipmentGroupsNotAuthorizedError(None)
if vip.ipv6 is not None:
for ip_equipment in vip.ipv6.ipv6equipament_set.all():
if not has_perm(user, AdminPermission.VIP_ALTER_SCRIPT, AdminPermission.WRITE_OPERATION, None, ip_equipment.equipamento_id, AdminPermission.EQUIP_UPDATE_CONFIG_OPERATION):
self.log.error(
u'Groups of equipment registered with the IP of the VIP request is not allowed of acess.')
raise EquipmentGroupsNotAuthorizedError(None)
# Get variables
variables_map = vip.variables_to_map()
# Valid variables
vip.set_variables(variables_map)
# Valid real names and real ips of real server
if variables_map.get('reals') is not None:
evip = EnvironmentVip.get_by_values(variables_map.get(
'finalidade'), variables_map.get('cliente'), variables_map.get('ambiente'))
for real in variables_map.get('reals').get('real'):
ip_aux_error = real.get('real_ip')
equip_aux_error = real.get('real_name')
equip = Equipamento.get_by_name(equip_aux_error)
# Valid Real
RequisicaoVips.valid_real_server(
ip_aux_error, equip, evip)
# Valid reals_prioritys
variables_map, code = vip.valid_values_reals_priority(
variables_map)
if code is not None:
return self.response_error(329)
# Valid reals_weight
variables_map, code = vip.valid_values_reals_weight(
variables_map)
if code is not None:
return self.response_error(330)
# Valid ports
#.........这里部分代码省略.........
示例3: administrate_real
# 需要导入模块: from networkapi.requisicaovips.models import RequisicaoVips [as 别名]
# 或者: from networkapi.requisicaovips.models.RequisicaoVips import valid_real_server [as 别名]
def administrate_real(self, user, vip_id, equip_id, ip_id, operation, network_version, port_vip=None, port_real=None):
# Valid VIP ID
if not is_valid_int_greater_zero_param(vip_id):
self.log.error(
u'The vip_id parameter is not a valid value: %s.', vip_id)
raise InvalidValueError(None, 'vip_id', vip_id)
# Valid Equipament 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)
# Valid IP ID
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)
# Valid operation
if operation not in ['add', 'del', 'ena', 'dis', 'chk']:
self.log.error(
u'The operation parameter is not a valid value: %s.', operation)
raise InvalidValueError(None, 'operation', operation)
# Valid network version
if network_version not in ['v4', 'v6']:
self.log.error(
u'The network_version parameter is not a valid value: %s.', network_version)
raise InvalidValueError(None, 'network_version', network_version)
# User permission
if (operation == 'chk'):
if not has_perm(user, AdminPermission.VIP_ALTER_SCRIPT, AdminPermission.READ_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
raise UserNotAuthorizedError(None)
else:
if not has_perm(user, AdminPermission.VIP_ALTER_SCRIPT, AdminPermission.WRITE_OPERATION, None, equip_id, AdminPermission.EQUIP_UPDATE_CONFIG_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
raise UserNotAuthorizedError(None)
# new_call = True - New calls for Add/Del/Enable/Disable/Check with new params (Port Vip and Port Real)
# new_call = False = Old calls for compatibility
new_call = False
if port_vip != None and port_real != None:
# Valid ports
if not is_valid_int_greater_zero_param(port_vip):
self.log.error(
u'The port_vip parameter is not a valid value: %s.', port_vip)
raise InvalidValueError(None, 'port_vip', port_vip)
if not is_valid_int_greater_zero_param(port_real):
self.log.error(
u'The port_vip parameter is not a valid value: %s.', port_real)
raise InvalidValueError(None, 'port_real', port_real)
new_call = True
# Find Request VIP by ID to check if it exist
vip = RequisicaoVips.get_by_pk(vip_id)
# Get variables
variables_map = vip.variables_to_map()
# Valid variables
#vip.set_variables(variables_map)
evip = EnvironmentVip.get_by_values(variables_map.get('finalidade'), variables_map.get('cliente'), variables_map.get('ambiente'))
# Valid network_version - IPv4
if network_version == IP_VERSION.IPv4[0]:
# Find IpEquipamento to check if it exist
IpEquip = IpEquipamento().get_by_ip_equipment(ip_id, equip_id)
real_name = IpEquip.equipamento.nome
end_ip = "%s.%s.%s.%s" % (
IpEquip.ip.oct1, IpEquip.ip.oct2, IpEquip.ip.oct3, IpEquip.ip.oct4)
# Valid Real
RequisicaoVips.valid_real_server(end_ip, IpEquip.equipamento, evip, False)
# Valid network_version - IPv6
elif network_version == IP_VERSION.IPv6[0]:
# Find Ipv6Equipament to check if it exist
Ipv6Equip = Ipv6Equipament().get_by_ip_equipment(ip_id, equip_id)
real_name = Ipv6Equip.equipamento.nome
end_ip = "%s:%s:%s:%s:%s:%s:%s:%s" % (Ipv6Equip.ip.block1, Ipv6Equip.ip.block2, Ipv6Equip.ip.block3,
Ipv6Equip.ip.block4, Ipv6Equip.ip.block5, Ipv6Equip.ip.block6, Ipv6Equip.ip.block7, Ipv6Equip.ip.block8)
# Valid Real
RequisicaoVips.valid_real_server(end_ip, Ipv6Equip.equipamento, evip, False)
if (operation == 'chk'):
if IP_VERSION.IPv4[0] == network_version:
if new_call:
#.........这里部分代码省略.........
示例4: handle_put
# 需要导入模块: from networkapi.requisicaovips.models import RequisicaoVips [as 别名]
# 或者: from networkapi.requisicaovips.models.RequisicaoVips import valid_real_server [as 别名]
def handle_put(self, request, user, *args, **kwargs):
"""
Handles PUT requests to change the VIP's real server.
URL: vip/real/edit
"""
self.log.info("Change VIP's real server")
try:
# User permission
if not has_perm(user, AdminPermission.VIP_ALTER_SCRIPT, AdminPermission.WRITE_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
raise UserNotAuthorizedError(None)
# Commons Validations
# Load XML data
xml_map, attrs_map = loads(
request.raw_post_data, ['real', 'reals_weight', 'reals_priority'])
# XML data format
networkapi_map = xml_map.get('networkapi')
if networkapi_map is None:
return self.response_error(3, u'There is no value to the networkapi tag of XML request.')
vip_map = networkapi_map.get('vip')
if vip_map is None:
return self.response_error(3, u'There is no value to the vip tag of XML request.')
# Get XML data
vip_id = vip_map.get('vip_id')
alter_priority = vip_map.get('alter_priority')
# Valid VIP ID
if not is_valid_int_greater_zero_param(vip_id):
self.log.error(
u'The vip_id parameter is not a valid value: %s.', vip_id)
raise InvalidValueError(None, 'vip_id', vip_id)
# Valid Alter Priority
if not is_valid_int_greater_equal_zero_param(alter_priority):
alter_priority = 0
# Existing Vip ID
vip = RequisicaoVips.get_by_pk(vip_id)
# Clone vip
vip_old = clone(vip)
server_pools = ServerPool.objects.filter(vipporttopool__requisicao_vip=vip)
server_pools_old = []
server_pools_members_old = []
for sp in server_pools:
server_pools_old.append(sp)
for spm in sp.serverpoolmember_set.all():
server_pools_members_old.append(spm)
# Get variables
variables_map = vip.variables_to_map()
# Valid variables
vip.set_variables(variables_map)
# Get balancing method
vip_map['metodo_bal'] = str(
variables_map.get('metodo_bal')).upper()
with distributedlock(LOCK_VIP % vip_id):
# Valid real names and real ips of real server
if vip_map.get('reals') is not None:
evip = EnvironmentVip.get_by_values(variables_map.get(
'finalidade'), variables_map.get('cliente'), variables_map.get('ambiente'))
for real in vip_map.get('reals').get('real'):
ip_aux_error = real.get('real_ip')
equip_aux_error = real.get('real_name')
if equip_aux_error is not None:
equip = Equipamento.get_by_name(equip_aux_error)
else:
self.log.error(
u'The real_name parameter is not a valid value: None.')
raise InvalidValueError(None, 'real_name', 'None')
# Valid Real
RequisicaoVips.valid_real_server(
ip_aux_error, equip, evip, False)
# Valid reals_prioritys
vip_map, code = vip.valid_values_reals_priority(vip_map)
if code is not None:
return self.response_error(329)
# Valid reals_weight
vip_map, code = vip.valid_values_reals_weight(vip_map)
if code is not None:
#.........这里部分代码省略.........
示例5: __post_virtual_group_vip
# 需要导入模块: from networkapi.requisicaovips.models import RequisicaoVips [as 别名]
# 或者: from networkapi.requisicaovips.models.RequisicaoVips import valid_real_server [as 别名]
#.........这里部分代码省略.........
else:
reals_priority_map = ['0' for __real in real_maps]
vip_map['reals_prioritys'] = {
'reals_priority': reals_priority_map}
reals_weight_map = vip_map.get('reals_weights')
if reals_weight_map is not None:
reals_weight_map = reals_weight_map.get('reals_weight')
if reals_weight_map is None:
reals_weight_map = ['0' for __real in real_maps]
else:
reals_weight_map = ['0' for __real in real_maps]
vip_map['reals_weights'] = {'reals_weight': reals_weight_map}
# Valid real names and real ips of real server
if vip_map.get('reals') is not None:
evip = EnvironmentVip.get_by_values(
vip_map.get('finalidade'), vip_map.get('cliente'), vip_map.get('ambiente'))
for real in vip_map.get('reals').get('real'):
ip_aux_error = real.get('real_ip')
equip_id = real.get('real_name')
if equip_id is not None:
equip = Equipamento.get_by_name(equip_id)
else:
self.log.error(
u'The real_name parameter is not a valid value: None.')
raise InvalidValueError(None, 'real_name', 'None')
# Valid Real
RequisicaoVips.valid_real_server(
ip_aux_error, equip, evip, False)
vip_map, code = RequisicaoVips().valid_values_reals_priority(
vip_map)
if code is not None:
return self.response_error(code)
vip_map, code = RequisicaoVips().valid_values_reals_weight(
vip_map)
if code is not None:
return self.response_error(code)
# Insere ou atualiza a requisição de VIP
if (id_vip_request_map is not None):
resp_vip_map['requisicao_vip'] = id_vip_request_map
if not is_valid_int_greater_zero_param(id_vip_request_map.get('id')):
self.log.error(
u'The requisicao_vip.id parameter is not a valid value: %s.', id_vip_request_map.get('id'))
raise InvalidValueError(
None, 'requisicao_vip.id', id_vip_request_map.get('id'))
vip_request = RequisicaoVips.get_by_pk(
id_vip_request_map.get('id'))
vip_map['id_ip'] = vip_request.ip_id
if vip_request.validado:
vip_map['validado'] = '1'
else:
vip_map['validado'] = '0'
if vip_request.vip_criado:
示例6: handle_post
# 需要导入模块: from networkapi.requisicaovips.models import RequisicaoVips [as 别名]
# 或者: from networkapi.requisicaovips.models.RequisicaoVips import valid_real_server [as 别名]
def handle_post(self, request, user, *args, **kwargs):
"""Treat requests POST to insert request VIP.
URLs: /requestvip/
deprecated:: Use the new rest API
"""
self.log.info("Add request VIP")
try:
# Load XML data
xml_map, attrs_map = loads(
request.raw_post_data, ['real', 'reals_weight', 'reals_priority', 'porta'])
# XML data format
networkapi_map = xml_map.get('networkapi')
if networkapi_map is None:
return self.response_error(3, u'There is no value to the networkapi tag of XML request.')
vip_map = networkapi_map.get('vip')
if vip_map is None:
return self.response_error(3, u'There is no value to the vip tag of XML request.')
# User permission
if not has_perm(user, AdminPermission.VIPS_REQUEST, AdminPermission.WRITE_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
raise UserNotAuthorizedError(None)
# Valid Ipv4 and Ipv6 ID
if (vip_map.get('id_ipv4') is None and vip_map.get('id_ipv6') is None):
self.log.error(
u'The id_ipv4 and id_ipv6 parameter is not a valid value: %s.', vip_map.get('id_ipv4'))
raise InvalidValueError(
None, 'id_ipv4 e id_vip6', vip_map.get('id_ipv4'))
if (vip_map.get('id_ipv4') != None):
if not is_valid_int_greater_zero_param(vip_map.get('id_ipv4')):
self.log.error(
u'The id_ipv4 parameter is not a valid value: %s.', vip_map.get('id_ipv4'))
raise InvalidValueError(
None, 'id_ipv4', vip_map.get('id_ipv4'))
if (vip_map.get('id_ipv6') != None):
if not is_valid_int_greater_zero_param(vip_map.get('id_ipv6')):
self.log.error(
u'The id_ipv6 parameter is not a valid value: %s.', vip_map.get('id_ipv6'))
raise InvalidValueError(
None, 'id_ipv6', vip_map.get('id_ipv6'))
# Valid maxcon
if not is_valid_int_greater_equal_zero_param(vip_map.get('maxcon')):
self.log.error(
u'The maxcon parameter is not a valid value: %s.', vip_map.get('maxcon'))
raise InvalidValueError(None, 'maxcon', vip_map.get('maxcon'))
vip = RequisicaoVips()
finalidade = vip_map.get('finalidade')
cliente = vip_map.get('cliente')
ambiente = vip_map.get('ambiente')
try:
evip = EnvironmentVip.get_by_values(
finalidade, cliente, ambiente)
except Exception, e:
raise EnvironmentVipNotFoundError(
e, 'The fields finality or client or ambiente is None')
# Valid real names and real ips of real server
if vip_map.get('reals') is not None:
for real in vip_map.get('reals').get('real'):
ip_aux_error = real.get('real_ip')
equip_aux_error = real.get('real_name')
if equip_aux_error is not None:
equip = Equipamento.get_by_name(equip_aux_error)
else:
self.log.error(
u'The real_name parameter is not a valid value: None.')
raise InvalidValueError(None, 'real_name', 'None')
# Valid Real
RequisicaoVips.valid_real_server(
ip_aux_error, equip, evip, False)
# Valid reals_prioritys
vip_map, code = vip.valid_values_reals_priority(vip_map)
if code is not None:
return self.response_error(code)
# Valid reals_weight
vip_map, code = vip.valid_values_reals_weight(vip_map)
if code is not None:
return self.response_error(code)
# Existing IPv4 ID
if vip_map.get('id_ipv4') is not None:
#.........这里部分代码省略.........
示例7: handle_put
# 需要导入模块: from networkapi.requisicaovips.models import RequisicaoVips [as 别名]
# 或者: from networkapi.requisicaovips.models.RequisicaoVips import valid_real_server [as 别名]
#.........这里部分代码省略.........
vip = RequisicaoVips.get_by_pk(vip_id)
with distributedlock(LOCK_VIP % vip_id):
# Valid Vip created
if vip.vip_criado:
self.log.error(
u'The IP of the request for VIP %d can not be changed because the VIP is already created.' % vip.id)
raise RequisicaoVipsAlreadyCreatedError(None)
# Get variables
variables_map = vip.variables_to_map()
# Valid variables
vip.set_variables(variables_map)
evip = EnvironmentVip.get_by_values(variables_map.get(
'finalidade'), variables_map.get('cliente'), variables_map.get('ambiente'))
# Valid real names and real ips of real server
if vip_map.get('reals') is not None:
for real in vip_map.get('reals').get('real'):
ip_aux_error = real.get('real_ip')
equip_aux_error = real.get('real_name')
if equip_aux_error is not None:
equip = Equipamento.get_by_name(equip_aux_error)
else:
self.log.error(
u'The real_name parameter is not a valid value: None.')
raise InvalidValueError(None, 'real_name', 'None')
# Valid Real
RequisicaoVips.valid_real_server(
ip_aux_error, equip, evip, False)
# Valid reals_prioritys
vip_map, code = vip.valid_values_reals_priority(vip_map)
if code is not None:
return self.response_error(code)
# Valid reals_weight
vip_map, code = vip.valid_values_reals_weight(vip_map)
if code is not None:
return self.response_error(code)
# Existing IPv4 ID
if vip_map.get('id_ipv4') is not None:
vip.ip = Ip().get_by_pk(vip_map.get('id_ipv4'))
else:
vip.ip = None
# Existing IPv6 ID
if vip_map.get('id_ipv6') is not None:
vip.ipv6 = Ipv6().get_by_pk(vip_map.get('id_ipv6'))
else:
vip.ipv6 = None
# Valid ports
vip_map, code = vip.valid_values_ports(vip_map)
if code is not None:
return self.response_error(code)
# Valid HealthcheckExpect
vip_map, vip, code = vip.valid_values_healthcheck(
vip_map, vip, evip)
示例8: InvalidValueError
# 需要导入模块: from networkapi.requisicaovips.models import RequisicaoVips [as 别名]
# 或者: from networkapi.requisicaovips.models.RequisicaoVips import valid_real_server [as 别名]
log.error(
u'The maxcon parameter is not a valid value: %s.', vip_map.get('maxcon'))
raise InvalidValueError(None, 'maxcon', vip_map.get('maxcon'))
if vip_map.get("reals") is not None:
for real in vip_map.get('reals').get('real'):
ip_aux_error = real.get('real_ip')
equip_aux_error = real.get('real_name')
if equip_aux_error is not None:
equip = Equipamento.get_by_name(equip_aux_error)
else:
raise InvalidValueError(None, 'real_name', 'None')
RequisicaoVips.valid_real_server(
ip_aux_error, equip, environment_vip)
vip.create(user, vip_map)
return 0, vip
def update_vip_request(vip_id, vip_map, user):
log = Log('update_vip_request')
if not has_perm(user,
AdminPermission.VIPS_REQUEST,
AdminPermission.WRITE_OPERATION):
raise UserNotAuthorizedError(
None, u'Usuário não tem permissão para executar a operação.')