本文整理汇总了Python中networkapi.ambiente.models.EnvironmentVip.get_by_values方法的典型用法代码示例。如果您正苦于以下问题:Python EnvironmentVip.get_by_values方法的具体用法?Python EnvironmentVip.get_by_values怎么用?Python EnvironmentVip.get_by_values使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkapi.ambiente.models.EnvironmentVip
的用法示例。
在下文中一共展示了EnvironmentVip.get_by_values方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate
# 需要导入模块: from networkapi.ambiente.models import EnvironmentVip [as 别名]
# 或者: from networkapi.ambiente.models.EnvironmentVip import get_by_values [as 别名]
def validate(self, attrs):
"""
Check the Environment Vip is valid.
"""
try:
finalidade = attrs.get("finalidade")
cliente = attrs.get("cliente")
ambiente = attrs.get("ambiente")
EnvironmentVip.get_by_values(finalidade, cliente, ambiente)
ip_to_vip = attrs.get("ip") or attrs.get("ipv6")
if not ip_to_vip:
raise serializers.ValidationError("Is required to enter any Ip")
except EnvironmentVipNotFoundError, exception:
raise serializers.ValidationError(exception.message)
示例2: validate
# 需要导入模块: from networkapi.ambiente.models import EnvironmentVip [as 别名]
# 或者: from networkapi.ambiente.models.EnvironmentVip import get_by_values [as 别名]
def validate(self, attrs):
"""
Check the Environment Vip is valid.
"""
try:
finalidade = attrs.get('finalidade')
cliente = attrs.get('cliente')
ambiente = attrs.get('ambiente')
EnvironmentVip.get_by_values(
finalidade,
cliente,
ambiente
)
ip_to_vip = attrs.get('ip') or attrs.get('ipv6')
if not ip_to_vip:
raise serializers.ValidationError('Is required to enter any Ip')
except EnvironmentVipNotFoundError, exception:
raise serializers.ValidationError(exception.message)
示例3: server_pool_ips_can_associate_with_vip_request
# 需要导入模块: from networkapi.ambiente.models import EnvironmentVip [as 别名]
# 或者: from networkapi.ambiente.models.EnvironmentVip import get_by_values [as 别名]
def server_pool_ips_can_associate_with_vip_request(vip_request, vip_port_to_pool_to_remove=[]):
try:
environment_vip = EnvironmentVip.get_by_values(vip_request.finalidade, vip_request.cliente, vip_request.ambiente)
server_pool_list_add_list = _get_server_pool_list(vip_request)
server_pool_list_remove_list = _get_server_pool_list_by_vip_port_to_pool(vip_port_to_pool_to_remove)
for server_pool in server_pool_list_add_list:
if server_pool not in server_pool_list_remove_list:
server_pool_member_list = server_pool.serverpoolmember_set.all()
_reals_can_associate_server_pool_by_environment_vip_on_request_vip(server_pool, server_pool_member_list, environment_vip)
except Exception, error:
log.error(error)
raise error
示例4: administrate_real
# 需要导入模块: from networkapi.ambiente.models import EnvironmentVip [as 别名]
# 或者: from networkapi.ambiente.models.EnvironmentVip import get_by_values [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:
#.........这里部分代码省略.........
示例5: handle_put
# 需要导入模块: from networkapi.ambiente.models import EnvironmentVip [as 别名]
# 或者: from networkapi.ambiente.models.EnvironmentVip import get_by_values [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
#.........这里部分代码省略.........
示例6: handle_put
# 需要导入模块: from networkapi.ambiente.models import EnvironmentVip [as 别名]
# 或者: from networkapi.ambiente.models.EnvironmentVip import get_by_values [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:
#.........这里部分代码省略.........
示例7: __post_virtual_group_vip
# 需要导入模块: from networkapi.ambiente.models import EnvironmentVip [as 别名]
# 或者: from networkapi.ambiente.models.EnvironmentVip import get_by_values [as 别名]
def __post_virtual_group_vip(self, vip_maps, user, vip_equipment_ip_map, resp_vip_maps):
try:
for vip_map in vip_maps:
resp_vip_map = dict()
vip_id = vip_map.get('id')
resp_vip_map['id'] = vip_id
id_vip_request_map = vip_map.get('requisicao_vip')
ip_map = vip_map.get('ip')
# Somente insere o IP do VIP se a requisição de VIP ainda não foi criada
# (id_vip_request_map is None).
if (ip_map is not None) and (id_vip_request_map is None):
# Insere o IP do VIP e o associa aos balanceadores
balanceadores_map = vip_map.get('balanceadores')
if balanceadores_map is None:
return self.response_error(3, u'Não existe valor para a tag balanceadors do vip %s do XML de requisição.' % vip_id)
equipments_ids = balanceadores_map.get('id_equipamento')
if len(equipments_ids) == 0:
return self.response_error(3, u'Não existe valor para a tag id_equipamento do vip %s do XML de requisição.' % vip_id)
# Insere um IP e o relacionamento dele com o primeiro
# balanceador
equip_id = equipments_ids[0]
ip_map['id_equipamento'] = equip_id
response_ip = insert_ip(ip_map, user)
if response_ip[0] != 0:
return self.__treat_response_error(response_ip)
# Insere o relacionamento entre o IP e os demais
# balanceadores
for equip_id in equipments_ids[1:len(equipments_ids)]:
insert_ip_equipment(
response_ip[1].get('id'), equip_id, user)
resp_vip_map['ip'] = response_ip[1]
vip_map['id_ip'] = response_ip[1].get('id')
# Constroe o reals
# Obtem os reals já criados e que foram enviados no XML de
# requisição
reals_map = vip_map.get('reals')
if reals_map is not None:
real_maps = reals_map.get('real', [])
else:
real_maps = []
# Adiciona os novos reals para os equipamentos criados
equipment_ip_maps = vip_equipment_ip_map.get(vip_id)
if equipment_ip_maps is not None:
for equipment_ip_map in equipment_ip_maps:
real_name = equipment_ip_map.get(
'nome_equipamento') # + sufix
real_ip = equipment_ip_map.get('ip')
real_maps.append(
{'real_name': real_name, 'real_ip': real_ip})
vip_map['reals'] = {'real': real_maps}
reals_priority_map = vip_map.get('reals_prioritys')
if reals_priority_map is not None:
reals_priority_map = reals_priority_map.get(
'reals_priority')
if reals_priority_map is None:
reals_priority_map = ['0' for __real in real_maps]
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:
#.........这里部分代码省略.........
示例8: handle_post
# 需要导入模块: from networkapi.ambiente.models import EnvironmentVip [as 别名]
# 或者: from networkapi.ambiente.models.EnvironmentVip import get_by_values [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:
#.........这里部分代码省略.........
示例9: handle_put
# 需要导入模块: from networkapi.ambiente.models import EnvironmentVip [as 别名]
# 或者: from networkapi.ambiente.models.EnvironmentVip import get_by_values [as 别名]
def handle_put(self, request, user, *args, **kwargs):
"""Treat requests PUT change request VIP.
URLs: /requestvip/<id_vip>/
deprecated:: Use the new rest API
"""
self.log.info("Change request VIP")
try:
vip_id = kwargs.get('id_vip')
# 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.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, 'vip_id', vip_id)
# 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 Vip validated
if not is_valid_boolean_param(vip_map.get('validado')):
self.log.error(
u'The validated parameter is not a valid value: %s.', vip_map.get('validado'))
raise InvalidValueError(
None, 'validated', vip_map.get('validado'))
# Valid Vip vip_created
if not is_valid_boolean_param(vip_map.get('vip_criado')):
self.log.error(
u'The vip_created parameter is not a valid value: %s.', vip_map.get('vip_criado'))
raise InvalidValueError(
None, 'vip_created', vip_map.get('vip_criado'))
# 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'))
# Existing Vip ID
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'))
#.........这里部分代码省略.........
示例10: insert_vip_request
# 需要导入模块: from networkapi.ambiente.models import EnvironmentVip [as 别名]
# 或者: from networkapi.ambiente.models.EnvironmentVip import get_by_values [as 别名]
def insert_vip_request(vip_map, user):
'''Insere uma requisição de VIP.
@param vip_map: Mapa com os dados da requisição.
@param user: Usuário autenticado.
@return: Em caso de sucesso: tupla (0, <requisição de VIP>).
Em caso de erro: tupla (código da mensagem de erro, argumento01, argumento02, ...)
@raise IpNotFoundError: IP não cadastrado.
@raise IpError: Falha ao pesquisar o IP.
@raise HealthcheckExpectNotFoundError: HealthcheckExpect não cadastrado.
@raise HealthcheckExpectError: Falha ao pesquisar o HealthcheckExpect.
@raise InvalidFinalidadeValueError: Finalidade com valor inválido.
@raise InvalidClienteValueError: Cliente com valor inválido.
@raise InvalidAmbienteValueError: Ambiente com valor inválido.
@raise InvalidCacheValueError: Cache com valor inválido.
@raise InvalidMetodoBalValueError: Valor do método de balanceamento inválido.
@raise InvalidPersistenciaValueError: Persistencia com valor inválido.
@raise InvalidHealthcheckTypeValueError: Healthcheck_Type com valor inválido ou inconsistente em relação ao valor do healthcheck_expect.
@raise InvalidTimeoutValueError: Timeout com valor inválido.
@raise InvalidHostNameError: Host não cadastrado.
@raise EquipamentoError: Falha ao pesquisar o equipamento.
@raise InvalidMaxConValueError: Número máximo de conexões com valor inválido.
@raise InvalidBalAtivoValueError: Bal_Ativo com valor inválido.
@raise InvalidTransbordoValueError: Transbordo com valor inválido.
@raise InvalidServicePortValueError: Porta do Serviço com valor inválido.
@raise InvalidRealValueError: Valor inválido de um real.
@raise InvalidHealthcheckValueError: Valor do healthcheck inconsistente em relação ao valor do healthcheck_type.
@raise RequisicaoVipsError: Falha ao inserir a requisição de VIP.
@raise UserNotAuthorizedError:
'''
log = Log('insert_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.')
ip_id = vip_map.get('id_ip')
if not is_valid_int_greater_zero_param(ip_id):
log.error(u'The ip_id parameter is not a valid value: %s.', ip_id)
raise InvalidValueError(None, 'ip_id', ip_id)
else:
ip_id = int(ip_id)
vip = RequisicaoVips()
vip.ip = Ip()
vip.ip.id = ip_id
# Valid ports
vip_map, code = vip.valid_values_ports(vip_map)
if code is not None:
return code, vip
# get environmentVip dor validation dynamic heathcheck
finalidade = vip_map.get('finalidade')
cliente = vip_map.get('cliente')
ambiente = vip_map.get('ambiente')
if not is_valid_string_minsize(finalidade, 3) or not is_valid_string_maxsize(finalidade, 50):
log.error(u'Finality value is invalid: %s.', finalidade)
raise InvalidValueError(None, 'finalidade', finalidade)
if not is_valid_string_minsize(cliente, 3) or not is_valid_string_maxsize(cliente, 50):
log.error(u'Client value is invalid: %s.', cliente)
raise InvalidValueError(None, 'cliente', cliente)
if not is_valid_string_minsize(ambiente, 3) or not is_valid_string_maxsize(ambiente, 50):
log.error(u'Environment value is invalid: %s.', ambiente)
raise InvalidValueError(None, 'ambiente', ambiente)
try:
environment_vip = EnvironmentVip.get_by_values(
finalidade, cliente, ambiente)
except Exception, e:
raise EnvironmentVipNotFoundError(
e, 'The fields finality or client or ambiente is None')
示例11: handle_put
# 需要导入模块: from networkapi.ambiente.models import EnvironmentVip [as 别名]
# 或者: from networkapi.ambiente.models.EnvironmentVip import get_by_values [as 别名]
def handle_put(self, request, user, *args, **kwargs):
"""
Handles PUT requests to change the VIP's healthcheck.
URL: vip/<id_vip>/healthcheck
"""
self.log.info("Change VIP's healthcheck")
try:
# Commons Validations
# 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
vip_id = kwargs.get("id_vip")
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)
# Existing Vip ID
vip = RequisicaoVips.get_by_pk(vip_id)
with distributedlock(LOCK_VIP % vip_id):
vip_old = clone(vip)
# Vip must be created
if not vip.vip_criado:
self.log.error(u"Healthcheck 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)
# 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.")
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
healthcheck_type = upper(str(vip_map["healthcheck_type"]))
healthcheck = vip_map["healthcheck"]
id_healthcheck_expect = vip_map["id_healthcheck_expect"]
vars = vip.variables_to_map()
environment_vip = EnvironmentVip.get_by_values(
vars.get("finalidade"), vars.get("cliente"), vars.get("ambiente")
)
healthcheck_is_valid = RequisicaoVips.heathcheck_exist(healthcheck_type, environment_vip.id)
# healthcheck_type exist'
if not healthcheck_is_valid:
self.log.error(u"The healthcheck_type parameter not exist.")
raise InvalidValueError(
u"The healthcheck_type parameter not exist.", "healthcheck_type", healthcheck_type
)
# If healthcheck_type is not HTTP id_healthcheck_expect and
#.........这里部分代码省略.........