本文整理汇总了Python中networkapi.equipamento.models.Equipamento.get_by_name方法的典型用法代码示例。如果您正苦于以下问题:Python Equipamento.get_by_name方法的具体用法?Python Equipamento.get_by_name怎么用?Python Equipamento.get_by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkapi.equipamento.models.Equipamento
的用法示例。
在下文中一共展示了Equipamento.get_by_name方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: aplicar
# 需要导入模块: from networkapi.equipamento.models import Equipamento [as 别名]
# 或者: from networkapi.equipamento.models.Equipamento import get_by_name [as 别名]
def aplicar(rack):
path_config = settings.PATH_TO_CONFIG +'*'+rack.nome+'*'
arquivos = glob.glob(path_config)
#Get all files and search for equipments of the rack
for var in arquivos:
name_equipaments = var.split('/')[-1][:-4]
for nome in name_equipaments:
#Check if file is config relative to this rack
if rack.nome in nome:
#Apply config only in spines. Leaves already have all necessary config in startup
if "ADD" in nome:
#Check if equipment in under maintenance. If so, does not aplly on it
try:
equip = Equipamento.get_by_name(nome)
if not equip.maintenance:
(erro, result) = commands.getstatusoutput("/usr/bin/backuper -T acl -b %s -e -i %s -w 300" % (var, nome))
if erro:
raise RackAplError(None, None, "Falha ao aplicar as configuracoes: %s" %(result))
except RackAplError, e:
raise e
except:
#Error equipment not found, do nothing
pass
示例2: inserir_equip
# 需要导入模块: from networkapi.equipamento.models import Equipamento [as 别名]
# 或者: from networkapi.equipamento.models.Equipamento import get_by_name [as 别名]
def inserir_equip(user, variablestochangecore, rede_id):
ip = Ip()
ip.descricao = None
ip.oct1, ip.oct2, ip.oct3, ip.oct4 = str(variablestochangecore["IPCORE"]).split('.')
equip = Equipamento.get_by_name(variablestochangecore["EQUIP_NAME"])
rede = NetworkIPv4.get_by_pk(rede_id)
ip.save_ipv4(equip.id, user, rede)
if ip.id is None:
raise RackAplError (None, None, "Erro ao inserir os equipamentos")
# Delete vlan's cache
destroy_cache_function([rede.vlan_id])
list_id_equip = []
list_id_equip.append(equip.id)
destroy_cache_function(list_id_equip, True)
return 0
示例3: post
# 需要导入模块: from networkapi.equipamento.models import Equipamento [as 别名]
# 或者: from networkapi.equipamento.models.Equipamento import get_by_name [as 别名]
def post(self, *args, **kwargs):
try:
log.info('RACK deploy.')
rack_id = kwargs.get('rack_id')
rack = facade.get_by_pk(rack_id)
try:
PATH_TO_ADD_CONFIG = get_variable('path_to_add_config')
REL_PATH_TO_ADD_CONFIG = get_variable('rel_path_to_add_config')
except ObjectDoesNotExist:
raise var_exceptions.VariableDoesNotExistException("Erro buscando a variável PATH_TO_ADD_CONFIG ou "
"REL_PATH_TO_ADD_CONFIG.")
path_config = PATH_TO_ADD_CONFIG + '*' + rack.nome + '*'
arquivos = glob.glob(path_config)
# Get all files and search for equipments of the rack
for var in arquivos:
filename_equipments = var.split('/')[-1]
rel_filename = "../../" + REL_PATH_TO_ADD_CONFIG + filename_equipments
log.debug("rel_filename: %s" % rel_filename)
# Check if file is config relative to this rack
if rack.nome in filename_equipments:
# Apply config only in spines. Leaves already have all necessary config in startup
if "ADD" in filename_equipments:
# Check if equipment in under maintenance. If so, does not aplly on it
equipment_name = filename_equipments.split('-ADD-')[0]
log.debug("equipment_name: %s" % equipment_name)
try:
equip = Equipamento.get_by_name(equipment_name)
if not equip.maintenance:
(erro, result) = commands.getstatusoutput("/usr/bin/backuper -T acl -b %s -e -i %s -w "
"300" % (rel_filename, equipment_name))
log.debug("erro: %s, result: %s" % (str(erro), str(result)))
if erro:
raise exceptions.RackAplError()
except exceptions.RackAplError, e:
raise e
except:
# Error equipment not found, do nothing
pass
示例4: handle_post
# 需要导入模块: from networkapi.equipamento.models import Equipamento [as 别名]
# 或者: from networkapi.equipamento.models.Equipamento import get_by_name [as 别名]
def handle_post(self, request, user, *args, **kwargs):
"""Handles POST requests to list all equip scripts by equipment name.
URLs: equipamentoroteiro/name/
"""
try:
# Commons Validations
# User permission
if not has_perm(user, AdminPermission.EQUIPMENT_MANAGEMENT, AdminPermission.READ_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
return self.not_authorized()
# 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)
equip_script_map = networkapi_map.get('equipamento_roteiro')
if equip_script_map is None:
msg = u'There is no value to the equipamento_roteiro tag of XML request.'
self.log.error(msg)
return self.response_error(3, msg)
# Get XML data
name = equip_script_map.get('name')
# Name must NOT be none and 50 is the maxsize
if not is_valid_string_maxsize(name, 50):
self.log.error(u'Parameter name is invalid. Value: %s.', name)
raise InvalidValueError(None, 'name', name)
# Equipment
try:
# Find equipment by name to check if it exist
equip = Equipamento.get_by_name(name)
except EquipamentoNotFoundError, e:
return self.response_error(117, name)
# Business Rules
# List access related with equip
equip_script_list = equip.equipamentoroteiro_set.all()
# Permissions
equip_script_list = equip_script_list.filter(equipamento__grupos__direitosgrupoequipamento__ugrupo__in=user.grupos.all(
), equipamento__grupos__direitosgrupoequipamento__escrita='1')
map_dicts = []
for equip_script in equip_script_list:
es_map = dict()
es_map['id'] = equip_script.id
es_map['roteiro_id'] = equip_script.roteiro.id
es_map['roteiro_name'] = equip_script.roteiro.roteiro
es_map['roteiro_desc'] = equip_script.roteiro.descricao
es_map[
'tipo_roteiro_id'] = equip_script.roteiro.tipo_roteiro.id
es_map[
'tipo_roteiro_name'] = equip_script.roteiro.tipo_roteiro.tipo
es_map[
'tipo_roteiro_desc'] = equip_script.roteiro.tipo_roteiro.descricao
map_dicts.append(es_map)
equip_map = dict()
equip_map['id'] = equip.id
equip_map['name'] = equip.nome
equip_script_map = dict()
equip_script_map['equipamento_roteiro'] = map_dicts
equip_script_map['equipamento'] = equip_map
# Return XML
return self.response(dumps_networkapi(equip_script_map))
示例5: handle_post
# 需要导入模块: from networkapi.equipamento.models import Equipamento [as 别名]
# 或者: from networkapi.equipamento.models.Equipamento import get_by_name [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)
示例6: handle_put
# 需要导入模块: from networkapi.equipamento.models import Equipamento [as 别名]
# 或者: from networkapi.equipamento.models.Equipamento import get_by_name [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
#.........这里部分代码省略.........
示例7: handle_put
# 需要导入模块: from networkapi.equipamento.models import Equipamento [as 别名]
# 或者: from networkapi.equipamento.models.Equipamento import get_by_name [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:
#.........这里部分代码省略.........
示例8: __post_virtual_group_vip
# 需要导入模块: from networkapi.equipamento.models import Equipamento [as 别名]
# 或者: from networkapi.equipamento.models.Equipamento import get_by_name [as 别名]
#.........这里部分代码省略.........
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:
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'))
示例9: handle_post
# 需要导入模块: from networkapi.equipamento.models import Equipamento [as 别名]
# 或者: from networkapi.equipamento.models.Equipamento import get_by_name [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:
#.........这里部分代码省略.........
示例10: handle_put
# 需要导入模块: from networkapi.equipamento.models import Equipamento [as 别名]
# 或者: from networkapi.equipamento.models.Equipamento import get_by_name [as 别名]
#.........这里部分代码省略.........
# 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'))
# 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
示例11: is_valid_int_greater_equal_zero_param
# 需要导入模块: from networkapi.equipamento.models import Equipamento [as 别名]
# 或者: from networkapi.equipamento.models.Equipamento import get_by_name [as 别名]
return code, vip
# Valid maxcon
if not is_valid_int_greater_equal_zero_param(vip_map.get('maxcon')):
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,
示例12: handle_get
# 需要导入模块: from networkapi.equipamento.models import Equipamento [as 别名]
# 或者: from networkapi.equipamento.models.Equipamento import get_by_name [as 别名]
def handle_get(self, request, user, *args, **kwargs):
"""Handles POST requests to find all Equipments by search parameters.
URLs: /equipment/find/
"""
self.log.info('Find all Equipments')
try:
# Commons Validations
# User permission
if not has_perm(user, AdminPermission.EQUIPMENT_MANAGEMENT, AdminPermission.READ_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
return self.not_authorized()
# Business Validations
# Get data from URL GET parameters
equip_name = kwargs.get('equip_name').strip()
id_ambiente = kwargs.get('id_ambiente')
# Business Rules
# Start with alls
ambiente = Ambiente.get_by_pk(id_ambiente)
# Get Equipment
equip = Equipamento.get_by_name(equip_name)
lista_ips_equip = set()
lista_ipsv6_equip = set()
environment_vip_list = EnvironmentVip.get_environment_vips_by_environment_id(id_ambiente)
environment_list_related = EnvironmentEnvironmentVip.get_environment_list_by_environment_vip_list(environment_vip_list)
# # Get all IPV4's Equipment
for environment in environment_list_related:
for ipequip in equip.ipequipamento_set.select_related().all():
network_ipv4 = ipequip.ip.networkipv4
if network_ipv4.vlan.ambiente == environment:
lista_ips_equip.add(ipequip.ip)
# # Get all IPV6's Equipment
for environment in environment_list_related:
for ipequip in equip.ipv6equipament_set.select_related().all():
network_ipv6 = ipequip.ip.networkipv6
if network_ipv6.vlan.ambiente == environment:
lista_ipsv6_equip.add(ipequip.ip)
# lists and dicts for return
lista_ip_entregue = list()
lista_ip6_entregue = list()
for ip in lista_ips_equip:
dict_ips4 = dict()
dict_network = dict()
dict_ips4['id'] = ip.id
dict_ips4['ip'] = "%s.%s.%s.%s" % (
ip.oct1, ip.oct2, ip.oct3, ip.oct4)
dict_network['id'] = ip.networkipv4_id
dict_network["network"] = "%s.%s.%s.%s" % (
ip.networkipv4.oct1, ip.networkipv4.oct2, ip.networkipv4.oct3, ip.networkipv4.oct4)
dict_network["mask"] = "%s.%s.%s.%s" % (
ip.networkipv4.mask_oct1, ip.networkipv4.mask_oct2, ip.networkipv4.mask_oct3, ip.networkipv4.mask_oct4)
dict_ips4['network'] = dict_network
lista_ip_entregue.append(dict_ips4)
for ip in lista_ipsv6_equip:
dict_ips6 = dict()
dict_network = dict()
dict_ips6['id'] = ip.id
dict_ips6['ip'] = "%s:%s:%s:%s:%s:%s:%s:%s" % (
ip.block1, ip.block2, ip.block3, ip.block4, ip.block5, ip.block6, ip.block7, ip.block8)
dict_network['id'] = ip.networkipv6.id
dict_network["network"] = "%s:%s:%s:%s:%s:%s:%s:%s" % (
ip.networkipv6.block1, ip.networkipv6.block2, ip.networkipv6.block3, ip.networkipv6.block4, ip.networkipv6.block5, ip.networkipv6.block6, ip.networkipv6.block7, ip.networkipv6.block8)
dict_network["mask"] = "%s:%s:%s:%s:%s:%s:%s:%s" % (
ip.networkipv6.block1, ip.networkipv6.block2, ip.networkipv6.block3, ip.networkipv6.block4, ip.networkipv6.block5, ip.networkipv6.block6, ip.networkipv6.block7, ip.networkipv6.block8)
dict_ips6['network'] = dict_network
lista_ip6_entregue.append(dict_ips6)
lista_ip_entregue = lista_ip_entregue if len(
lista_ip_entregue) > 0 else None
lista_ip6_entregue = lista_ip6_entregue if len(
lista_ip6_entregue) > 0 else None
return self.response(dumps_networkapi({'list_ipv4': lista_ip_entregue, 'list_ipv6': lista_ip6_entregue}))
except InvalidValueError, e:
#.........这里部分代码省略.........
示例13: handle_post
# 需要导入模块: from networkapi.equipamento.models import Equipamento [as 别名]
# 或者: from networkapi.equipamento.models.Equipamento import get_by_name [as 别名]
def handle_post(self, request, user, *args, **kwargs):
'''Handles POST requests to get all Ips (v4) or (v6) of equip on Divisao DC and Ambiente Logico of fisrt Network4 and 6 (if exists) of Environment Vip.
URL: ip/getbyequipandevip/
'''
self.log.info('Get Ips by Equip - Evip')
try:
# User permission
if not has_perm(user, AdminPermission.IPS, AdminPermission.READ_OPERATION):
raise UserNotAuthorizedError(
None, u'User does not have permission to perform the operation.')
# 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)
ip_map = networkapi_map.get('ip_map')
if ip_map is None:
msg = u'There is no value to the ip tag of XML request.'
self.log.error(msg)
return self.response_error(3, msg)
# Get XML data
id_evip = ip_map.get('id_evip')
equip_name = ip_map.get('equip_name')
# Valid id_evip
if not is_valid_int_greater_zero_param(id_evip):
self.log.error(
u'Parameter id_evip is invalid. Value: %s.', id_evip)
raise InvalidValueError(None, 'id_evip', id_evip)
# Valid equip_name
if not is_valid_string_minsize(equip_name, 3) or not is_valid_string_maxsize(equip_name, 80) or not is_valid_regex(equip_name, "^[A-Z0-9-_]+$"):
self.log.error(
u'Parameter equip_name is invalid. Value: %s', equip_name)
raise InvalidValueError(None, 'equip_name', equip_name)
# Business Rules
# Get Environment VIp
evip = EnvironmentVip.get_by_pk(id_evip)
# Get Equipment
equip = Equipamento.get_by_name(equip_name)
lista_ips_equip = list()
lista_ipsv6_equip = list()
# GET DIVISAO DC AND AMBIENTE_LOGICO OF NET4 AND NET6
lista_amb_div_4 = list()
lista_amb_div_6 = list()
for net in evip.networkipv4_set.select_related().all():
dict_div_4 = dict()
dict_div_4['divisao_dc'] = net.vlan.ambiente.divisao_dc_id
dict_div_4[
'ambiente_logico'] = net.vlan.ambiente.ambiente_logico_id
if dict_div_4 not in lista_amb_div_4:
lista_amb_div_4.append(dict_div_4)
for net in evip.networkipv6_set.select_related().all():
dict_div_6 = dict()
dict_div_6['divisao_dc'] = net.vlan.ambiente.divisao_dc_id
dict_div_6[
'ambiente_logico'] = net.vlan.ambiente.ambiente_logico_id
if dict_div_6 not in lista_amb_div_6:
lista_amb_div_6.append(dict_div_6)
# Get all IPV4's Equipment
for ipequip in equip.ipequipamento_set.select_related().all():
if ipequip.ip not in lista_ips_equip:
for dict_div_amb in lista_amb_div_4:
# if ipequip.ip.networkipv4.ambient_vip is not None and
# ipequip.ip.networkipv4.ambient_vip.id == evip.id:
if (ipequip.ip.networkipv4.vlan.ambiente.divisao_dc.id == dict_div_amb.get('divisao_dc') and ipequip.ip.networkipv4.vlan.ambiente.ambiente_logico.id == dict_div_amb.get('ambiente_logico')):
lista_ips_equip.append(ipequip.ip)
# Get all IPV6'S Equipment
for ipequip in equip.ipv6equipament_set.select_related().all():
if ipequip.ip not in lista_ipsv6_equip:
for dict_div_amb in lista_amb_div_6:
# if ipequip.ip.networkipv6.ambient_vip is not None and
# ipequip.ip.networkipv6.ambient_vip.id == evip.id:
print ipequip.ip.networkipv6.vlan.ambiente.divisao_dc.id
print dict_div_amb.get('divisao_dc')
if (ipequip.ip.networkipv6.vlan.ambiente.divisao_dc.id == dict_div_amb.get('divisao_dc') and ipequip.ip.networkipv6.vlan.ambiente.ambiente_logico.id == dict_div_amb.get('ambiente_logico')):
lista_ipsv6_equip.append(ipequip.ip)
# lists and dicts for return
lista_ip_entregue = list()
lista_ip6_entregue = list()
#.........这里部分代码省略.........