本文整理汇总了Python中networkapi.ambiente.models.EnvironmentVip类的典型用法代码示例。如果您正苦于以下问题:Python EnvironmentVip类的具体用法?Python EnvironmentVip怎么用?Python EnvironmentVip使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EnvironmentVip类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: create_environment_vip
def create_environment_vip(environment_vip):
try:
env = EnvironmentVip()
env.create_v3(environment_vip)
except Exception, e:
raise NetworkAPIException(str(e))
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:7,代码来源:facade.py
示例2: handle_get
def handle_get(self, request, user, *args, **kwargs):
"""Handles GET requests to find all finalitys of environment VIP.
URLs: /vip/get/finality
"""
self.log.info("Find all finality distinct of environment_vip")
try:
# Commons Validations
# 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()
evip = EnvironmentVip()
# Business Validations
evips = evip.list_all_finalitys()
finality_map = dict()
finality_list = []
for evip in evips:
finality_map["finality"] = evip.get("finalidade_txt")
finality_list.append(finality_map)
finality_map = dict()
return self.response(dumps_networkapi({"finalidade": finality_list}))
except InvalidValueError, e:
self.log.error(u"Parameter %s is invalid. Value: %s.", e.param, e.value)
return self.response_error(269, e.param, e.value)
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:33,代码来源:EnvironmentVipGetFinalityResource.py
示例3: handle_post
def handle_post(self, request, user, *args, **kwargs):
"""Treat requests Post to search cliente_txt of Environment VIP by finalidade_txt
URL: environmentvip/search/
"""
try:
self.log.info(
'Search cliente_txt Environment VIP by finalidade_txt')
# User permission
if not has_perm(user, AdminPermission.ENVIRONMENT_VIP, AdminPermission.READ_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
raise UserNotAuthorizedError(None)
# 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.')
environmentvip_map = networkapi_map.get('vip')
if environmentvip_map is None:
return self.response_error(3, u'There is no value to the vip tag of XML request.')
# Get XML data
finalidade = environmentvip_map.get('finalidade_txt')
if not is_valid_string_maxsize(finalidade, 50) or not is_valid_string_minsize(finalidade, 3) or not is_valid_text(finalidade):
self.log.error(
u'The finalidade_txt parameter is not a valid value: %s.', finalidade)
raise InvalidValueError(None, 'finalidade_txt', finalidade)
environmentVip = EnvironmentVip()
evip_values = environmentVip.list_all_clientes_by_finalitys(
finalidade)
evips = dict()
evips_list = []
for evip in evip_values:
evips['finalidade_txt'] = finalidade
evips['cliente_txt'] = evip.get('cliente_txt')
evips_list.append(evips)
evips = dict()
return self.response(dumps_networkapi({'cliente_txt': evips_list}))
except InvalidValueError, e:
return self.response_error(269, e.param, e.value)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:54,代码来源:EnvironmentVipGetClienteTxtResource.py
示例4: handle_get
def handle_get(self, request, user, *args, **kwargs):
"""Treat GET requests list all Environment VIP Availables.
URL: environmentvip/search/id_vlan
"""
try:
id_vlan = int(kwargs['id_vlan'])
self.log.info("List all Environment VIP availables")
# Commons Validations
# User permission
if not has_perm(user, AdminPermission.ENVIRONMENT_VIP, AdminPermission.READ_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
return self.not_authorized()
# Business Rules
evips = EnvironmentVip.objects.all()
evip_list = EnvironmentVip.available_evips(
EnvironmentVip(), evips, id_vlan)
return self.response(dumps_networkapi({'environment_vip': evip_list}))
except (EnvironmentVipError, GrupoError), e:
self.log.error(e)
return self.response_error(1)
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:29,代码来源:EnvironmentVipSearchResource.py
示例5: handle_delete
def handle_delete(self, request, user, *args, **kwargs):
"""
Handles DELETE requests to create a relationship of Environment with EnvironmentVip.
URL: environment/<environment_id>/environmentvip/<environment_vip_id>/
"""
self.log.info("Remove a relationship of Environment with EnvironmentVip")
try:
# Commons Validations
# User permission
if not has_perm(user, AdminPermission.ENVIRONMENT_MANAGEMENT, AdminPermission.WRITE_OPERATION):
self.log.error(u"User does not have permission to perform the operation.")
raise UserNotAuthorizedError(None)
# Valid Environment
environment_id = kwargs.get("environment_id")
if not is_valid_int_greater_zero_param(environment_id):
self.log.error(u"The environment_id parameter is not a valid value: %s.", environment_id)
raise InvalidValueError(None, "environment_id", environment_id)
# Valid EnvironmentVip ID
environment_vip_id = kwargs.get("environment_vip_id")
if not is_valid_int_greater_zero_param(environment_vip_id):
self.log.error(u"The id_environment_vip parameter is not a valid value: %s.", environment_vip_id)
raise InvalidValueError(None, "environment_vip_id", environment_vip_id)
# Business Validations
# Existing Environment ID
environment = Ambiente.get_by_pk(environment_id)
# Existing EnvironmentVip ID
environment_vip = EnvironmentVip.get_by_pk(environment_vip_id)
# Business Rules
environment_environment_vip = EnvironmentEnvironmentVip().get_by_environment_environment_vip(
environment.id, environment_vip.id
)
server_pool_list = EnvironmentEnvironmentVip.get_server_pool_member_by_environment_environment_vip(
environment_environment_vip
)
# Valid integraty between environment/environmentvip related with reals
# if exists reals fot this environment then raise a exception
if server_pool_list:
raise EnvironmentEnvironmentServerPoolLinked({"environment": environment.name})
# Delete
environment_environment_vip.delete()
# Return nothing
return self.response(dumps_networkapi({}))
except UserNotAuthorizedError:
return self.not_authorized()
except InvalidValueError, e:
return self.response_error(269, e.param, e.value)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:59,代码来源:EnvironmentEnvironmentVipAssociationResource.py
示例6: handle_post
def handle_post(self, request, user, *args, **kwargs):
"""Treat requests POST to insert Environment VIP.
URL: environmentvip/
"""
try:
self.log.info('Add Environment VIP')
# User permission
if not has_perm(user, AdminPermission.ENVIRONMENT_VIP, AdminPermission.WRITE_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
raise UserNotAuthorizedError(None)
# 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.')
environmentvip_map = networkapi_map.get('environment_vip')
if environmentvip_map is None:
return self.response_error(3, u'There is no value to the environment_vip tag of XML request.')
# New Environment Vip
environment_vip = EnvironmentVip()
# Valid Environment Vip
environment_vip.valid_environment_vip(environmentvip_map)
try:
# Save Environment Vip
environment_vip.save()
except Exception, e:
self.log.error(u'Failed to save the environment vip.')
raise EnvironmentVipError(
e, u'Failed to save the environment vip')
environment_map = dict()
environment_map['id'] = environment_vip.id
return self.response(dumps_networkapi({'environment_vip': environment_map}))
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:46,代码来源:EnvironmentVipResource.py
示例7: handle_delete
def handle_delete(self, request, user, *args, **kwargs):
"""
Handles DELETE requests to remove a relationship of OptionVip with EnvironmentVip.
URL: optionvip/<id_option_vip>/environmentvip/<id_environment_vip>/
"""
self.log.info("Remove a relationship of OptionVip with EnvironmentVip")
try:
# Commons Validations
# User permission
if not has_perm(user, AdminPermission.OPTION_VIP, AdminPermission.WRITE_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
raise UserNotAuthorizedError(None)
# Valid OptionVip ID
option_vip_id = kwargs.get('id_option_vip')
if not is_valid_int_greater_zero_param(option_vip_id):
self.log.error(
u'The id_option_vip parameter is not a valid value: %s.', option_vip_id)
raise InvalidValueError(None, 'id_option_vip', option_vip_id)
# Valid EnvironmentVip ID
environment_vip_id = kwargs.get('id_environment_vip')
if not is_valid_int_greater_zero_param(environment_vip_id):
self.log.error(
u'The id_environment_vip parameter is not a valid value: %s.', environment_vip_id)
raise InvalidValueError(
None, 'id_environment_vip', environment_vip_id)
# Business Validations
# Existing OptionVip ID
option_vip = OptionVip.get_by_pk(option_vip_id)
# Existing EnvironmentVip ID
environment_vip = EnvironmentVip.get_by_pk(environment_vip_id)
# Business Rules
# Find
opt_vip_env_vip = OptionVipEnvironmentVip().get_by_option_environment(
option_vip.id, environment_vip.id)
# Delete
opt_vip_env_vip.delete()
# Return nothing
return self.response(dumps_networkapi({}))
except UserNotAuthorizedError:
return self.not_authorized()
except InvalidValueError, e:
return self.response_error(269, e.param, e.value)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:58,代码来源:OptionVipEnvironmentVipAssociationResource.py
示例8: handle_put
def handle_put(self, request, user, *args, **kwargs):
"""Treat requests PUT to change Environment VIP.
URL: environmentvip/<id_environment_vip>/
"""
try:
self.log.info('Change Environment VIP')
id_environment_vip = kwargs.get('id_environment_vip')
# User permission
if not has_perm(user, AdminPermission.ENVIRONMENT_VIP, AdminPermission.WRITE_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
raise UserNotAuthorizedError(None)
# 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.')
environmentvip_map = networkapi_map.get('environment_vip')
if environmentvip_map is None:
return self.response_error(3, u'There is no value to the environment_vip tag of XML request.')
# Valid Environment VIP ID
if not is_valid_int_greater_zero_param(id_environment_vip):
self.log.error(
u'The id_environment_vip parameter is not a valid value: %s.', id_environment_vip)
raise InvalidValueError(
None, 'id_environment_vip', id_environment_vip)
# Find Environment VIP by ID to check if it exist
environment_vip = EnvironmentVip.get_by_pk(id_environment_vip)
with distributedlock(LOCK_ENVIRONMENT_VIP % id_environment_vip):
# Valid Environment Vip
environment_vip.valid_environment_vip(environmentvip_map)
try:
# Update Environment Vip
environment_vip.save()
except Exception, e:
self.log.error(u'Failed to update the environment vip.')
raise EnvironmentVipError(
e, u'Failed to update the environment vip')
return self.response(dumps_networkapi({}))
except InvalidValueError, e:
return self.response_error(269, e.param, e.value)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:57,代码来源:EnvironmentVipResource.py
示例9: handle_get
def handle_get(self, request, user, *args, **kwargs):
"""Treat requests GET to list all the VIPs related to Environment VIP.
URL: environmentvip/<id_environment_vip>/vip/all'
"""
try:
self.log.info(
"GET to list all the VIPs related to Environment VIP")
# User permission
if not has_perm(user, AdminPermission.ENVIRONMENT_VIP, AdminPermission.READ_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
raise UserNotAuthorizedError(None)
# Get data
id_environment_vip = kwargs.get('id_environment_vip')
# Valid Environment VIP ID
if not is_valid_int_greater_zero_param(id_environment_vip):
self.log.error(
u'The id_environment_vip parameter is not a valid value: %s.', id_environment_vip)
raise InvalidValueError(
None, 'id_environment_vip', id_environment_vip)
# Find Environment VIP by ID to check if it exist
environment_vip = EnvironmentVip.get_by_pk(id_environment_vip)
# Find Request VIP - IPv4 by ID Environment
vips_ipv4 = RequisicaoVips.objects.filter(
ip__networkipv4__ambient_vip__id=environment_vip.id)
# Find Request VIP - IPv6 by ID Environment
vips_ipv6 = RequisicaoVips.objects.filter(
ipv6__networkipv6__ambient_vip__id=environment_vip.id)
vips = {}
for vips_ip in [vips_ipv4, vips_ipv6]:
for vip in vips_ip:
v = {}
v = vip.variables_to_map()
v['id'] = vip.id
v['validado'] = vip.validado
v['vip_criado'] = vip.vip_criado
v['id_ip'] = vip.ip_id
v['id_ipv6'] = vip.ipv6_id
v['id_healthcheck_expect'] = vip.healthcheck_expect_id
vips['vip_%s' % (vip.id)] = v
return self.response(dumps_networkapi(vips))
except InvalidValueError, e:
return self.response_error(269, e.param, e.value)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:57,代码来源:RequestAllVipsEnviromentVipResource.py
示例10: validate
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)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:19,代码来源:serializers.py
示例11: handle_get
def handle_get(self, request, user, *args, **kwargs):
"""Treat requests GET to list all the Environment by Environment Vip.
URL: environment/environmentvip/<environment_vip_id>'
"""
try:
self.log.info(
'GET to list all the Environment by Environment Vip.')
# User permission
if not has_perm(user, AdminPermission.ENVIRONMENT_MANAGEMENT, AdminPermission.READ_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
raise UserNotAuthorizedError(None)
environment_vip_id = kwargs.get('environment_vip_id')
# Valid Environment VIP ID
if not is_valid_int_greater_zero_param(environment_vip_id):
self.log.error(
u'The id_environment_vip parameter is not a valid value: %s.', environment_vip_id)
raise InvalidValueError(
None, 'environment_vip_id', environment_vip_id)
# Find Environment VIP by ID to check if it exist
environment_vip = EnvironmentVip.get_by_pk(environment_vip_id)
environment_related_list = []
for env_env_vip in environment_vip.environmentenvironmentvip_set.all():
environment_map = {}
environment_map['environment_id'] = env_env_vip.environment.id
environment_map[
'environment_vip_id'] = env_env_vip.environment_vip.id
environment_map[
'environment'] = env_env_vip.environment.grupo_l3.nome
environment_map[
'ambiente_logico_name'] = env_env_vip.environment.ambiente_logico.nome
environment_map[
'divisao_dc_name'] = env_env_vip.environment.divisao_dc.nome
environment_related_list.append(environment_map)
return self.response(dumps_networkapi({'environment_related_list': environment_related_list}))
except UserNotAuthorizedError:
return self.not_authorized()
except InvalidValueError, e:
return self.response_error(269, e.param, e.value)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:52,代码来源:EnvironmentAllGetByEnvironmentVipResource.py
示例12: handle_delete
def handle_delete(self, request, user, *args, **kwargs):
"""Treat requests PUT to delete Environment VIP.
URL: environmentvip/<id_environment_vip>/
"""
try:
self.log.info('Delete Environment VIP')
id_environment_vip = kwargs.get('id_environment_vip')
# User permission
if not has_perm(user, AdminPermission.ENVIRONMENT_VIP, AdminPermission.WRITE_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
raise UserNotAuthorizedError(None)
# Valid Environment VIP ID
if not is_valid_int_greater_zero_param(id_environment_vip):
self.log.error(
u'The id_environment_vip parameter is not a valid value: %s.', id_environment_vip)
raise InvalidValueError(
None, 'id_environment_vip', id_environment_vip)
# Find Environment VIP by ID to check if it exist
environment_vip = EnvironmentVip.get_by_pk(id_environment_vip)
with distributedlock(LOCK_ENVIRONMENT_VIP % id_environment_vip):
# Find networkIPv4 by Environment VIP to check if is greater
# than zero
if len(NetworkIPv4.objects.filter(ambient_vip=environment_vip.id)) > 0:
return self.response_error(284)
# Find networkIPv6 by Environment VIP to check if is greater
# than zero
if len(NetworkIPv6.objects.filter(ambient_vip=environment_vip.id)) > 0:
return self.response_error(285)
try:
# Delete Environment Vip
environment_vip.delete()
except Exception, e:
self.log.error(u'Failed to delete the environment vip.')
raise EnvironmentVipError(
e, u'Failed to delete the environment vip')
return self.response(dumps_networkapi({}))
except InvalidValueError, e:
return self.response_error(269, e.param, e.value)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:52,代码来源:EnvironmentVipResource.py
示例13: handle_get
def handle_get(self, request, user, *args, **kwargs):
"""Treat requests GET to list all traffic return of the Option VIP by Environment Vip.
URL: environment-vip/get/trafficreturn/<id_evip>
"""
try:
self.log.info("GET to list all the Option VIP by Environment Vip - traffic return.")
# User permission
if not has_perm(user, AdminPermission.OPTION_VIP, AdminPermission.READ_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
raise UserNotAuthorizedError(None)
id_environment_vip = kwargs.get('id_evip')
# Valid Environment VIP ID
if not is_valid_int_greater_zero_param(id_environment_vip):
self.log.error(
u'The id_environment_vip parameter is not a valid value: %s.', id_environment_vip)
raise InvalidValueError(
None, 'id_environment_vip', id_environment_vip)
# Find Environment VIP by ID to check if it exist
environment_vip = EnvironmentVip.get_by_pk(id_environment_vip)
#self.log.info(str(environment_vip))
ovips = OptionVip.get_all_trafficreturn(environment_vip.id)
#self.log.info(str(ovips))
ovip_dict = dict()
ovip_list = []
for ovip in ovips:
ovip_dict['trafficreturn_opt'] = ovip.nome_opcao_txt
ovip_list.append(ovip_dict)
ovip_dict = dict()
self.log.info(str(ovip_list))
return self.response(dumps_networkapi({'trafficreturn_opt': ovip_list}))
except UserNotAuthorizedError:
return self.not_authorized()
except InvalidValueError, e:
return self.response_error(269, e.param, e.value)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:51,代码来源:OptionVipGetTrafficReturnByEVipResource.py
示例14: validate
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)
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:23,代码来源:serializers.py
示例15: server_pool_ips_can_associate_with_vip_request
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
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:17,代码来源:facade.py
示例16: handle_get
def handle_get(self, request, user, *args, **kwargs):
"""Treat requests GET to list all the Option VIP by Environment Vip.
URL: optionvip/environmentvip/<id_environment_vip>'
"""
try:
self.log.info("GET to list all the Option VIP by Environment Vip.")
# User permission
if not has_perm(user, AdminPermission.OPTION_VIP, AdminPermission.READ_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
raise UserNotAuthorizedError(None)
id_environment_vip = kwargs.get('id_environment_vip')
# Valid Environment VIP ID
if not is_valid_int_greater_zero_param(id_environment_vip):
self.log.error(
u'The id_environment_vip parameter is not a valid value: %s.', id_environment_vip)
raise InvalidValueError(
None, 'id_environment_vip', id_environment_vip)
# Find Environment VIP by ID to check if it exist
environment_vip = EnvironmentVip.get_by_pk(id_environment_vip)
ovips = []
for env in environment_vip.optionvipenvironmentvip_set.all():
ovips.append(model_to_dict(env.option))
return self.response(dumps_networkapi({'option_vip': ovips}))
except UserNotAuthorizedError:
return self.not_authorized()
except InvalidValueError, e:
return self.response_error(269, e.param, e.value)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:39,代码来源:OptionVipAllGetByEnvironmentVipResource.py
示例17: network_ipv4_add
def network_ipv4_add(self, user, vlan_id, network_type, environment_vip, prefix=None):
try:
# Valid vlan ID
if not is_valid_int_greater_zero_param(vlan_id):
self.log.error(
u'Parameter id_vlan is invalid. Value: %s.', vlan_id)
raise InvalidValueError(None, 'id_vlan', vlan_id)
# Network Type
# Valid network_type ID
"""
if not is_valid_int_greater_zero_param(network_type):
self.log.error(
u'Parameter id_tipo_rede is invalid. Value: %s.', network_type)
raise InvalidValueError(None, 'id_tipo_rede', network_type)
"""
# Find network_type by ID to check if it exist
net = None
if network_type:
net = TipoRede.get_by_pk(network_type)
# Environment Vip
if environment_vip is not None:
# Valid environment_vip ID
if not is_valid_int_greater_zero_param(environment_vip):
self.log.error(
u'Parameter id_ambiente_vip is invalid. Value: %s.', environment_vip)
raise InvalidValueError(
None, 'id_ambiente_vip', environment_vip)
# Find Environment VIP by ID to check if it exist
evip = EnvironmentVip.get_by_pk(environment_vip)
else:
evip = None
# Business Rules
# New NetworkIPv4
network_ipv4 = NetworkIPv4()
vlan_map = network_ipv4.add_network_ipv4(user, vlan_id, net, evip, prefix)
list_equip_routers_ambient = EquipamentoAmbiente.get_routers_by_environment(vlan_map['vlan']['id_ambiente'])
if list_equip_routers_ambient:
# Add Adds the first available ipv4 on all equipment
# that is configured as a router for the environment related to
# network
ip = Ip.get_first_available_ip(vlan_map['vlan']['id_network'])
ip = str(ip).split('.')
ip_model = Ip()
ip_model.oct1 = ip[0]
ip_model.oct2 = ip[1]
ip_model.oct3 = ip[2]
ip_model.oct4 = ip[3]
ip_model.networkipv4_id = network_ipv4.id
ip_model.save()
if len(list_equip_routers_ambient) > 1:
multiple_ips = True
else:
multiple_ips = False
for equip in list_equip_routers_ambient:
IpEquipamento().create(user, ip_model.id, equip.equipamento.id)
if multiple_ips:
router_ip = Ip.get_first_available_ip(vlan_map['vlan']['id_network'], True)
router_ip = str(router_ip).split('.')
ip_model2 = Ip()
ip_model2.oct1 = router_ip[0]
ip_model2.oct2 = router_ip[1]
ip_model2.oct3 = router_ip[2]
ip_model2.oct4 = router_ip[3]
ip_model2.networkipv4_id = vlan_map['vlan']['id_network']
ip_model2.save()
IpEquipamento().create(user, ip_model2.id, equip.equipamento.id)
# Return XML
return self.response(dumps_networkapi(vlan_map))
except InvalidValueError, e:
return self.response_error(269, e.param, e.value)
开发者ID:jotagesales,项目名称:GloboNetworkAPI,代码行数:92,代码来源:NetworkIPv4AddResource.py
示例18: handle_put
def handle_put(self, request, user, *args, **kwargs):
"""
Handles PUT requests to create a relationship of OptionVip with EnvironmentVip.
URL: optionvip/<id_option_vip>/environmentvip/<id_environment_vip>/
"""
self.log.info("Create a relationship of OptionVip with EnvironmentVip")
try:
# Commons Validations
# User permission
if not has_perm(user, AdminPermission.OPTION_VIP, AdminPermission.WRITE_OPERATION):
self.log.error(u"User does not have permission to perform the operation.")
raise UserNotAuthorizedError(None)
# Valid OptionVip ID
option_vip_id = kwargs.get("id_option_vip")
if not is_valid_int_greater_zero_param(option_vip_id):
self.log.error(u"The id_option_vip parameter is not a valid value: %s.", option_vip_id)
raise InvalidValueError(None, "id_option_vip", option_vip_id)
# Valid EnvironmentVip ID
environment_vip_id = kwargs.get("id_environment_vip")
if not is_valid_int_greater_zero_param(environment_vip_id):
self.log.error(u"The id_environment_vip parameter is not a valid value: %s.", environment_vip_id)
raise InvalidValueError(None, "id_environment_vip", environment_vip_id)
# Business Validations
# Existing OptionVip ID
option_vip = OptionVip.get_by_pk(option_vip_id)
# Existing EnvironmentVip ID
environment_vip = EnvironmentVip.get_by_pk(environment_vip_id)
with distributedlock(LOCK_ENVIRONMENT_VIP % environment_vip_id):
# Business Rules
# Set new values
opt_vip_env_vip = OptionVipEnvironmentVip()
opt_vip_env_vip.option = option_vip
opt_vip_env_vip.environment = environment_vip
# Existing OptionVipEnvironmentVip
opt_vip_env_vip.validate()
# Persist
opt_vip_env_vip.save(user)
# Return XML
opt_vip_env_vip_map = dict()
opt_vip_env_vip_map["opcoesvip_ambiente_xref"] = model_to_dict(opt_vip_env_vip, fields=["id"])
return self.response(dumps_networkapi(opt_vip_env_vip_map))
except UserNotAuthorizedError:
return self.not_authorized()
except InvalidValueError, e:
return self.response_error(269, e.param, e.value)
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:63,代码来源:OptionVipEnvironmentVipAssociationResource.py
示例19: handle_post
def handle_post(self, request, user, *args, **kwargs):
"""
Handles POST requests to allocate a new VLAN.
URL: vlan/
"""
self.log.info('Allocate new VLAN')
try:
# Commons Validations
# User permission
if not has_perm(user, AdminPermission.VLAN_MANAGEMENT, 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)
vlan_map = networkapi_map.get('vlan')
if vlan_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
environment = vlan_map.get('id_ambiente')
network_type = vlan_map.get('id_tipo_rede')
name = vlan_map.get('nome')
description = vlan_map.get('descricao')
environment_vip = vlan_map.get('id_ambiente_vip')
vrf = vlan_map.get('vrf')
# Name must NOT be none and 50 is the maxsize
if not is_valid_string_minsize(name, 3) or not is_valid_string_maxsize(name, 50):
self.log.error(u'Parameter nome is invalid. Value: %s.', name)
raise InvalidValueError(None, 'nome', name)
# Description can NOT be greater than 200
if not is_valid_string_minsize(description, 3, False) or not is_valid_string_maxsize(description, 200, False):
self.log.error(
u'Parameter descricao is invalid. Value: %s.', description)
raise InvalidValueError(None, 'descricao', description)
# vrf can NOT be greater than 100
if not is_valid_string_maxsize(vrf, 100, False):
self.log.error(
u'Parameter vrf is invalid. Value: %s.', vrf)
raise InvalidValueError(None, 'vrf', vrf)
# Environment
# Valid environment ID
if not is_valid_int_greater_zero_param(environment):
self.log.error(
u'Parameter id_ambiente is invalid. Value: %s.', environment)
raise InvalidValueError(None, 'id_ambiente', environment)
# Find environment by ID to check if it exist
env = Ambiente.get_by_pk(environment)
# Environment Vip
if environment_vip is not None:
# Valid environment_vip ID
if not is_valid_int_greater_zero_param(environment_vip):
self.log.error(
u'Parameter id_ambiente_vip is invalid. Value: %s.', environment_vip)
raise InvalidValueError(
None, 'id_ambiente_vip', environment_vip)
# Find Environment VIP by ID to check if it exist
evip = EnvironmentVip.get_by_pk(environment_vip)
else:
evip = None
# Network Type
# Valid network_type ID
if not is_valid_int_greater_zero_param(network_type):
self.log.error(
u'Parameter id_tipo_rede is invalid. Value: %s.', network_type)
raise InvalidValueError(None, 'id_tipo_rede', network_type)
# Find network_type by ID to check if it exist
net = TipoRede.get_by_pk(network_type)
# Business Rules
# New Vlan
#.........这里部分代码省略.........
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:101,代码来源:VlanResource.py
|
请发表评论