def dissociate_environment_and_delete(self, authenticated_user, environment_id=None):
from networkapi.requisicaovips.models import RequisicaoVips
try:
healthcheckexpects = HealthcheckExpect.objects.all()
if (environment_id is not None):
hces = healthcheckexpects.filter(ambiente__id=environment_id)
for hce in hces:
vip_criado = False
for req_vip in RequisicaoVips.get_by_healthcheck_expect(hce.id):
if req_vip.vip_criado:
vip_criado = True
# If any RequsicaoVips associated, dissociate healthcheck
# expect from Ambiente
if vip_criado:
hce.ambiente = None
hce.save(authenticated_user)
# Else, delete HealthcheckExpect object
else:
hce.delete()
except Exception, e:
self.log.error(u'Falha ao desassociar os healthcheck_expects.')
raise HealthcheckExpectError(
e, u'Falha ao desassociar os healthcheck_expects.')
def handle_delete(self, request, user, *args, **kwargs):
"""
Treat DELETE requests to remove a vip request.
Also remove reals related and balancer ips (if this ips isn't used for another vip).
URL: vip/delete/<id_vip>/
"""
try:
vip_id = kwargs.get('id_vip')
keep_ip = bool(request.REQUEST.get('keep_ip', False))
# 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.')
return self.not_authorized()
# Valid vip ID
if not is_valid_int_greater_zero_param(vip_id):
self.log.error(
u'Parameter id_vip is invalid. Value: %s.', vip_id)
raise InvalidValueError(None, 'id_vip', vip_id)
vip = RequisicaoVips.get_by_pk(vip_id)
if vip.vip_criado:
return self.response_error(370, vip_id)
ipv4 = vip.ip
ipv6 = vip.ipv6
with distributedlock(LOCK_VIP % vip_id):
try:
vip.delete_vips_and_reals(user)
vip.remove(user, vip_id)
# SYNC_VIP
delete_new(vip_id)
if ipv4 and not keep_ip:
if not self.is_ipv4_in_use(ipv4, vip_id):
ipv4.delete()
if ipv6 and not keep_ip:
if not self.is_ipv6_in_use(ipv6, vip_id):
ipv6.delete()
except IpCantRemoveFromServerPool, e:
raise e
except IpCantBeRemovedFromVip, e:
raise e
def handle_put(self, request, user, *args, **kwargs):
""" Handles a PUT request to edit the L7 filter.
URL: vip/<id_vip>/filter/
"""
if not has_perm(user,
AdminPermission.VIP_ALTER_SCRIPT,
AdminPermission.WRITE_OPERATION):
return self.not_authorized()
id_vip = kwargs.get('id_vip')
# 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.')
vip = RequisicaoVips.get_by_pk(id_vip)
# Get XML data
l7_filter = vip_map['l7_filter']
vip.l7_filter = l7_filter
vip.filter_valid = False
# If the l7_filter is a rule, set filter_valid to TRUE
if vip_map.get('rule_id') is not None:
vip.filter_valid = 1
rule = Rule.objects.get(pk=vip_map.get('rule_id'))
vip.l7_filter = '\n'.join(
rule.rulecontent_set.all().values_list('content', flat=True))
vip.rule = rule
else:
vip.filter_valid = 0
vip.rule = None
vip.save(user)
map = dict()
map['sucesso'] = 'sucesso'
return self.response(dumps_networkapi(map))
def handle_get(self, request, user, *args, **kwargs):
"""Validate L7 filter
URLs: /vip/l7/<id_vip>/validate/
"""
try:
if not has_perm(user,
AdminPermission.VIP_VALIDATION,
AdminPermission.WRITE_OPERATION):
return self.not_authorized()
self.log.info('Validate L7 filter to VIP')
id_vip = kwargs.get('id_vip')
# Valid Vip ID
if not is_valid_int_greater_zero_param(id_vip):
self.log.error(
u'The vip_id parameter is not a valid value: %s.', id_vip)
raise InvalidValueError(None)
vip = RequisicaoVips.get_by_pk(id_vip)
with distributedlock(LOCK_VIP % id_vip):
# Vip must be created
if not vip.vip_criado:
self.log.error(
u'L7 filter can not be changed because VIP has not yet been created.')
raise RequestVipsNotBeenCreatedError(None)
vip.filter_valid = True
vip.save()
map = dict()
map['sucesso'] = 'sucesso'
return self.response(dumps_networkapi(map))
except UserNotAuthorizedError:
return self.not_authorized()
#.........这里部分代码省略.........
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:
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:
#.........这里部分代码省略.........
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'))
#.........这里部分代码省略.........
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')
def handle_post(self, request, user, *args, **kwargs):
'''Treat POST requests to run remove script for vip
URL: vip/remove/
'''
try:
# Commons Validations
# User permission
if not has_perm(user, AdminPermission.VIP_REMOVE_SCRIPT, AdminPermission.WRITE_OPERATION):
self.log.error(
u'User does not have permission to perform the 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:
msg = u'There is no value to the networkapi tag of XML request.'
self.log.error(msg)
return self.response_error(3, msg)
vip_map = networkapi_map.get('vip')
if vip_map is None:
msg = u'There is no value to the vlan tag of XML request.'
self.log.error(msg)
return self.response_error(3, msg)
# Get XML data
vip_id = vip_map.get('id_vip')
# Valid vip ID
if not is_valid_int_greater_zero_param(vip_id):
self.log.error(
u'Parameter id_vip is invalid. Value: %s.', vip_id)
raise InvalidValueError(None, 'id_vip', vip_id)
# Vip must exists in database
vip = RequisicaoVips.get_by_pk(vip_id)
with distributedlock(LOCK_VIP % vip_id):
# Equipment permissions
if vip.ip is not None:
for ip_equipment in vip.ip.ipequipamento_set.all():
if not has_perm(user, AdminPermission.VIP_CREATE_SCRIPT, AdminPermission.WRITE_OPERATION, None, ip_equipment.equipamento_id, AdminPermission.EQUIP_UPDATE_CONFIG_OPERATION):
return self.not_authorized()
if vip.ipv6 is not None:
for ip_equipment in vip.ipv6.ipv6equipament_set.all():
if not has_perm(user, AdminPermission.VIP_CREATE_SCRIPT, AdminPermission.WRITE_OPERATION, None, ip_equipment.equipamento_id, AdminPermission.EQUIP_UPDATE_CONFIG_OPERATION):
return self.not_authorized()
# Must be validated
if not vip.validado:
return self.response_error(191, vip_id)
# Must be created
if not vip.vip_criado:
return self.response_error(322, vip_id)
# Business Rules
# Make command
command = VIP_REMOVE % (vip.id)
# Execute command
code, stdout, stderr = exec_script(command)
if code == 0:
success_map = dict()
success_map['codigo'] = '%04d' % code
success_map['descricao'] = {
'stdout': stdout, 'stderr': stderr}
vip.vip_criado = 0
vip.save()
#Marks the server pool as not created if the
# server pool is not used in another already created vip request
server_pools = ServerPool.objects.filter(vipporttopool__requisicao_vip=vip.id)
for server_pool in server_pools:
#Checks if server pool is still used in another created vip request
server_pools_still_used = VipPortToPool.objects.filter(server_pool=server_pool).exclude(requisicao_vip=vip.id)
vip_with_server_pool_is_created = 0
for server_pool_still_used in server_pools_still_used:
if server_pool_still_used.requisicao_vip.vip_criado:
vip_with_server_pool_is_created = 1
if not vip_with_server_pool_is_created and server_pool.pool_created:
server_pool.pool_created = 0
server_pool.save()
map = dict()
#.........这里部分代码省略.........
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)
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
#.........这里部分代码省略.........
请发表评论