本文整理汇总了Python中networkapi.ambiente.models.Ambiente类的典型用法代码示例。如果您正苦于以下问题:Python Ambiente类的具体用法?Python Ambiente怎么用?Python Ambiente使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ambiente类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: criar_vlan
def criar_vlan(user, variablestochangecore1, ambientes, active=1):
#get environment
ambiente = Ambiente()
divisaodc = DivisaoDc()
divisaodc = divisaodc.get_by_name(ambientes.get('DC'))
ambiente_log = AmbienteLogico()
ambiente_log = ambiente_log.get_by_name(ambientes.get('LOG'))
ambiente = ambiente.search(divisaodc.id, ambiente_log.id)
for amb in ambiente:
if amb.grupo_l3.nome==ambientes.get('L3'):
id_ambiente = amb
# set vlan
vlan = Vlan()
vlan.acl_file_name = None
vlan.acl_file_name_v6 = None
vlan.num_vlan = variablestochangecore1.get("VLAN_NUM")
vlan.nome = variablestochangecore1.get("VLAN_NAME")
vlan.descricao = ""
vlan.ambiente = id_ambiente
vlan.ativada = active
vlan.acl_valida = 0
vlan.acl_valida_v6 = 0
vlan.insert_vlan(user)
return vlan
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:27,代码来源:RackAplicarConfigResource.py
示例2: handle_get
def handle_get(self, request, user, *args, **kwargs):
"""Handles GET requests to find all Racks
URLs: /rack/list-rack-environment/<rack_id>/
"""
self.log.info('Find all racks environment')
try:
# 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()
environment_list = []
id = kwargs.get('rack_id')
env = EnvironmentRack()
environments = env.get_by_rack(id)
for envs in environments:
envs = model_to_dict(envs)
amb = Ambiente()
ambiente = amb.get_by_pk(envs['ambiente'])
if "PROD" in ambiente.ambiente_logico.nome:
environment_list.append(get_environment_map(ambiente))
return self.response(dumps_networkapi({'ambiente': environment_list}))
except UserNotAuthorizedError:
return self.not_authorized()
except RackError:
return self.response_error(397)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:34,代码来源:RackEnvironmentResource.py
示例3: create_environment
def create_environment(env):
"""Create environment."""
try:
env_obj = Ambiente()
env_obj.create_v3(env)
except EnvironmentErrorV3, e:
raise ValidationAPIException(str(e))
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:8,代码来源:facade.py
示例4: handle_get
def handle_get(self, request, user, *args, **kwargs):
"""Treat requests GET to verify that the IP belongs to environment.
URLs: /ip/x1.x2.x3.x4/ambiente/<id_amb>
URLs: /ip/<ip>/ambiente/<id_amb>
"""
self.log.info("GET to verify that the IP belongs to environment")
try:
# User permission
if not has_perm(user, AdminPermission.IPS, AdminPermission.READ_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
return self.not_authorized()
environment_id = kwargs.get('id_amb')
# Valid Environment ID
if not is_valid_int_greater_zero_param(environment_id):
self.log.error(
u'The id_environment parameter is not a valid value: %s.', environment_id)
raise InvalidValueError(None, 'id_environment', environment_id)
ip = kwargs.get('ip')
# Valid IP
if not is_valid_ipv4(ip):
self.log.error(u'Parameter ip is invalid. Value: %s.', ip)
raise InvalidValueError(None, 'ip', ip)
# Find Environment by ID to check if it exist
Ambiente.get_by_pk(environment_id)
# Existing IP
octs = str(IPAddress(ip, 4).exploded).split('.')
ip = Ip.get_by_octs_and_environment(
octs[0], octs[1], octs[2], octs[3], environment_id)
# Build dictionary return
ip_map = dict()
ip_map['id'] = ip.id
ip_map['id_vlan'] = ip.networkipv4.vlan.id
ip_map['oct4'] = ip.oct4
ip_map['oct3'] = ip.oct3
ip_map['oct2'] = ip.oct2
ip_map['oct1'] = ip.oct1
ip_map['descricao'] = ip.descricao
return self.response(dumps_networkapi({'ip': ip_map}))
except InvalidValueError, e:
return self.response_error(269, e.param, e.value)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:54,代码来源:IpResource.py
示例5: handle_post
def handle_post(self, request, user, *args, **kwargs):
"""Handles POST requests to save a new Rule
URL: rule/save/
"""
try:
self.log.info('Save rule to an environment')
# User permission
if not has_perm(user, AdminPermission.VIP_VALIDATION, 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.')
rule_map = networkapi_map.get('map')
if rule_map is None:
return self.response_error(3, u'There is no value to the environment_vip tag of XML request.')
# Get XML data
id_env = rule_map['id_env']
name = rule_map['name']
contents = rule_map['contents'] if type(
rule_map['contents']) is list else [rule_map['contents'], ]
blocks_id = rule_map['blocks_id'] if type(
rule_map['blocks_id']) is list else [rule_map['blocks_id'], ]
if not is_valid_int_greater_zero_param(id_env):
self.log.error(
u'The id_env parameter is not a valid value: %s.', id_env)
raise InvalidValueError(None, 'id_env', id_env)
if not name or len(name) > 80:
self.log.error(
u'The name parameter is not a valid value: %s.', name)
raise InvalidValueError(None, 'name', name)
environment = Ambiente.get_by_pk(id_env)
new_rule = Rule()
new_rule.name = name
new_rule.environment = environment
new_rule.save()
self.__save_rule_contents(
contents, blocks_id, environment, new_rule, user)
return self.response(dumps_networkapi({}))
except AmbienteNotFoundError, e:
self.log.error('Environment not found')
return self.response_error(112)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:59,代码来源:RuleResource.py
示例6: 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
示例7: handle_post
def handle_post(self, request, user, *args, **kwargs):
"""Treat requests POST to add Rack.
URL: interface/associar-ambiente/
"""
try:
self.log.info("Associa interface aos ambientes")
# User permission
if not has_perm(user, AdminPermission.EQUIPMENT_MANAGEMENT, 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.')
interface_map = networkapi_map.get('interface')
if interface_map is None:
return self.response_error(3, u'There is no value to the interface tag of XML request.')
# Get XML data
env = interface_map.get('ambiente')
interface = interface_map.get('interface')
amb_int = EnvironmentInterface()
interfaces = Interface()
amb = Ambiente()
amb_int.interface = interfaces.get_by_pk(int(interface))
amb_int.ambiente = amb.get_by_pk(int(env))
amb_int.create(user)
amb_int_map = dict()
amb_int_map['interface_ambiente'] = amb_int
return self.response(dumps_networkapi(amb_int_map))
except InvalidValueError, e:
return self.response_error(269, e.param, e.value)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:46,代码来源:InterfaceEnvironmentResource.py
示例8: handle_get
def handle_get(self, request, user, *args, **kwargs):
"""Treat requests GET to list all Environments.
URL: /ambiente/equip/id_equip
"""
try:
# Commons Validations
# User permission
if not has_perm(user, AdminPermission.ENVIRONMENT_MANAGEMENT, AdminPermission.READ_OPERATION):
return self.not_authorized()
if not has_perm(user, AdminPermission.EQUIPMENT_MANAGEMENT, AdminPermission.READ_OPERATION):
return self.not_authorized()
id_equip = kwargs.get('id_equip')
if not is_valid_int_greater_zero_param(id_equip):
raise InvalidValueError(None, 'id_equip', id_equip)
# Business Rules
equip = Equipamento.get_by_pk(id_equip)
environments_list = EquipamentoAmbiente.get_by_equipment(equip.id)
# Get all environments in DB
lists_aux = []
for environment in environments_list:
env = Ambiente.get_by_pk(environment.ambiente.id)
env_map = model_to_dict(env)
env_map['grupo_l3_name'] = env.grupo_l3.nome
env_map['ambiente_logico_name'] = env.ambiente_logico.nome
env_map['divisao_dc_name'] = env.divisao_dc.nome
env_map['is_router'] = environment.is_router
try:
env_map['range'] = str(
env.min_num_vlan_1) + ' - ' + str(env.max_num_vlan_1)
if env.min_num_vlan_1 != env.min_num_vlan_2:
env_map['range'] = env_map[
'range'] + '; ' + str(env.min_num_vlan_2) + ' - ' + str(env.max_num_vlan_2)
except:
env_map['range'] = 'Nao definido'
if env.filter is not None:
env_map['filter_name'] = env.filter.name
lists_aux.append(env_map)
# Return XML
environment_list = dict()
environment_list['ambiente'] = lists_aux
return self.response(dumps_networkapi(environment_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:globocom,项目名称:GloboNetworkAPI,代码行数:58,代码来源:EnvironmentGetByEquipResource.py
示例9: handle_delete
def handle_delete(self, request, user, *args, **kwargs):
"""Trata requisições DELETE para remover um Ambiente.
URL: ambiente/<id_ambiente>/
"""
try:
environment_id = kwargs.get('id_ambiente')
# Valid ID Environment
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)
if not has_perm(user,
AdminPermission.ENVIRONMENT_MANAGEMENT,
AdminPermission.WRITE_OPERATION):
return self.not_authorized()
with distributedlock(LOCK_ENVIRONMENT % environment_id):
# Delete vlan's cache
key_list_db = Vlan.objects.filter(ambiente__pk=environment_id)
key_list = []
for key in key_list_db:
key_list.append(key.id)
destroy_cache_function(key_list)
# Destroy equipment's cache
equip_id_list = []
envr = Ambiente.get_by_pk(environment_id)
for equipment in envr.equipamentoambiente_set.all():
equip_id_list.append(equipment.equipamento_id)
destroy_cache_function(equip_id_list, True)
Ambiente.remove(user, environment_id)
return self.response(dumps_networkapi({}))
except InvalidValueError, e:
return self.response_error(269, e.param, e.value)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:44,代码来源:AmbienteResource.py
示例10: get_environment_by_id
def get_environment_by_id(environment_id):
"""Return a environment by id.
Args:
environment_id: Id of environment
"""
try:
environment = Ambiente.get_by_pk(id=environment_id)
except AmbienteNotFoundError, e:
raise exceptions.EnvironmentDoesNotExistException(str(e))
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:11,代码来源:facade.py
示例11: save_or_update
def save_or_update(self, request, user, update=False):
try:
# User permission
if not has_perm(user, AdminPermission.VIP_VALIDATION, 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.')
map = networkapi_map.get('map')
if map is None:
return self.response_error(3, u'There is no value to the map tag of XML request.')
environment_id = map['id_env']
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)
environment = Ambiente.get_by_pk(environment_id)
if update:
for block in environment.blockrules_set.all():
block.delete()
else:
if environment.blockrules_set.count() > 0:
return self.response_error(357)
if 'blocks' in map:
blocks = map['blocks'] if type(
map['blocks']) is list else [map['blocks'], ]
for order, content in enumerate(blocks):
block = BlockRules()
block.content = content
block.order = order
block.environment = environment
block.save()
return self.response(dumps_networkapi({}))
except AmbienteNotFoundError, e:
self.log.error('Environment not found')
return self.response_error(112)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:54,代码来源:EnvironmentBlocks.py
示例12: _create_ifaces_on_trunks
def _create_ifaces_on_trunks(self, iface, envs_vlans):
log.debug("_create_ifaces_on_trunks")
for i in envs_vlans:
environment = Ambiente.get_by_pk(int(i.get('env')))
env_iface = EnvironmentInterface()
env_iface.interface = iface
env_iface.ambiente = environment
env_iface.vlans = i.get('vlans')
env_iface.create()
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:11,代码来源:facade.py
示例13: handle_post
def handle_post(self, request, user, *args, **kwargs):
"""Treat requests POST to add Rack.
URL: channel/inserir/
"""
try:
self.log.info("Inserir novo Channel")
# User permission
if not has_perm(user, AdminPermission.EQUIPMENT_MANAGEMENT, 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.')
channel_map = networkapi_map.get('channel')
if channel_map is None:
return self.response_error(3, u'There is no value to the channel tag of XML request.')
# Get XML data
interfaces = channel_map.get('interfaces')
nome = channel_map.get('nome')
lacp = channel_map.get('lacp')
int_type = channel_map.get('int_type')
vlans = channel_map.get('vlan')
envs = channel_map.get('envs')
port_channel = PortChannel()
interface = Interface()
amb = Ambiente()
cont = []
interfaces = str(interfaces).split('-')
interface_id = None
# verifica a vlan_nativa
vlan = vlans.get('vlan_nativa')
if vlan is not None:
if int(vlan) < 1 or int(vlan) > 4096:
raise InvalidValueError(None, "Vlan Nativa", "Range valido: 1 - 4096.")
if int(vlan) < 1 or 3967 < int(vlan) < 4048 or int(vlan)==4096:
raise InvalidValueError(None, "Vlan Nativa" ,"Range reservado: 3968-4047;4094.")
# verifica se o nome do port channel já existe no equipamento
channels = PortChannel.objects.filter(nome=nome)
channels_id = []
for ch in channels:
channels_id.append(int(ch.id))
if channels_id:
for var in interfaces:
if not var=="" and not var==None:
interface_id = int(var)
interface_id = interface.get_by_pk(interface_id)
equip_id = interface_id.equipamento.id
equip_interfaces = interface.search(equip_id)
for i in equip_interfaces:
try:
sw = i.get_switch_and_router_interface_from_host_interface(i.protegida)
except:
sw = None
pass
if sw.channel is not None:
if sw.channel.id in channels_id:
raise InterfaceError("O nome do port channel ja foi utilizado no equipamento")
#cria o port channel
port_channel.nome = str(nome)
port_channel.lacp = convert_string_or_int_to_boolean(lacp)
port_channel.create(user)
int_type = TipoInterface.get_by_name(str(int_type))
for var in interfaces:
if not var=="" and not var==None:
interf = interface.get_by_pk(int(var))
try:
sw_router = interf.get_switch_and_router_interface_from_host_interface(interf.protegida)
except:
raise InterfaceError("Interface não conectada")
if sw_router.channel is not None:
raise InterfaceError("Interface %s já está em um Channel" % sw_router.interface)
if cont is []:
cont.append(int(sw_router.equipamento.id))
elif not sw_router.equipamento.id in cont:
cont.append(int(sw_router.equipamento.id))
if len(cont) > 2:
raise InterfaceError("Mais de dois equipamentos foram selecionados")
if sw_router.ligacao_front is not None:
ligacao_front_id = sw_router.ligacao_front.id
else:
#.........这里部分代码省略.........
开发者ID:jotagesales,项目名称:GloboNetworkAPI,代码行数:101,代码来源:InterfaceChannelResource.py
示例14: handle_post
def handle_post(self, request, user, *args, **kwargs):
"""Treat requests POST to add Rack.
URL: channel/inserir/
"""
try:
self.log.info("Inserir novo Channel")
# User permission
if not has_perm(user, AdminPermission.EQUIPMENT_MANAGEMENT, 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.')
channel_map = networkapi_map.get('channel')
if channel_map is None:
return self.response_error(3, u'There is no value to the channel tag of XML request.')
# Get XML data
interfaces = channel_map.get('interfaces')
nome = channel_map.get('nome')
lacp = channel_map.get('lacp')
int_type = channel_map.get('int_type')
vlan = channel_map.get('vlan')
envs = channel_map.get('envs')
port_channel = PortChannel()
interface = Interface()
amb = Ambiente()
cont = []
port_channel.nome = str(nome)
port_channel.lacp = convert_string_or_int_to_boolean(lacp)
port_channel.create(user)
interfaces = str(interfaces).split('-')
int_type = TipoInterface.get_by_name(str(int_type))
for var in interfaces:
if not var=="" and not var==None:
interf = interface.get_by_pk(int(var))
try:
sw_router = interf.get_switch_and_router_interface_from_host_interface(interf.protegida)
except:
raise InterfaceError("Interface não conectada")
if sw_router.channel is not None:
raise InterfaceError("Interface %s já está em um Channel" % sw_router.interface)
for i in interface.search(sw_router.equipamento.id):
if i.channel is not None:
raise InterfaceError("Equipamento %s já possui um Channel" % sw_router.equipamento.nome)
if cont is []:
cont.append(int(sw_router.equipamento.id))
elif not sw_router.equipamento.id in cont:
cont.append(int(sw_router.equipamento.id))
if len(cont) > 2:
raise InterfaceError("Mais de dois equipamentos foram selecionados")
if sw_router.ligacao_front is not None:
ligacao_front_id = sw_router.ligacao_front.id
else:
ligacao_front_id = None
if sw_router.ligacao_back is not None:
ligacao_back_id = sw_router.ligacao_back.id
else:
ligacao_back_id = None
Interface.update(user,
sw_router.id,
interface=sw_router.interface,
protegida=sw_router.protegida,
descricao=sw_router.descricao,
ligacao_front_id=ligacao_front_id,
ligacao_back_id=ligacao_back_id,
tipo=int_type,
vlan_nativa=vlan,
channel=port_channel)
if "trunk" in int_type.tipo:
interface_list = EnvironmentInterface.objects.all().filter(interface=sw_router.id)
for int_env in interface_list:
int_env.delete(user)
if envs is not None:
if not type(envs)==unicode:
for env in envs:
amb_int = EnvironmentInterface()
amb_int.interface = sw_router
amb_int.ambiente = amb.get_by_pk(int(env))
amb_int.create(user)
else:
#.........这里部分代码省略.........
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:101,代码来源:InterfaceChannelResource.py
示例15: test_alter_valid
def test_alter_valid(self):
mock = self.mock_valid_alter()
response = self.alter(self.ID_ALTER_VALID, {self.XML_KEY: mock})
valid_response(response)
environ = Ambiente.get_by_pk(self.ID_ALTER_VALID)
self.valid_attr(mock, model_to_dict(environ))
开发者ID:itnihao,项目名称:GloboNetworkAPI,代码行数:6,代码来源:test_Environment.py
示例16: criar_ambiente
def criar_ambiente(user, ambientes, ranges, acl_path=None, filter=None, vrf=None):
#ambiente cloud
environment = Ambiente()
environment.grupo_l3 = GrupoL3()
environment.ambiente_logico = AmbienteLogico()
environment.divisao_dc = DivisaoDc()
environment.grupo_l3.id = environment.grupo_l3.get_by_name(ambientes.get('L3')).id
environment.ambiente_logico.id = environment.ambiente_logico.get_by_name(ambientes.get('LOG')).id
environment.divisao_dc.id = environment.divisao_dc.get_by_name(ambientes.get('DC')).id
environment.acl_path = acl_path
environment.ipv4_template = None
environment.ipv6_template = None
if vrf is not None:
environment.vrf = vrf
environment.max_num_vlan_1 = ranges.get('MAX')
environment.min_num_vlan_1 = ranges.get('MIN')
environment.max_num_vlan_2 = ranges.get('MAX')
environment.min_num_vlan_2 = ranges.get('MIN')
environment.link = " "
if filter is not None:
try:
filter_obj = Filter.objects.get(name__iexact=filter)
environment.filter = filter_obj
except ObjectDoesNotExist:
pass
environment.create(user)
return environment
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:36,代码来源:RackAplicarConfigResource.py
示例17: handle_post
def handle_post(self, request, user, *args, **kwargs):
"""Treat requests POST to add a HeltcheckExpect.
URL: healthcheckexpect/add/
"""
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:
msg = u'There is no value to the networkapi tag of XML request.'
self.log.error(msg)
return self.response_error(3, msg)
healthcheck_map = networkapi_map.get('healthcheck')
if healthcheck_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
match_list = healthcheck_map.get('match_list')
expect_string = healthcheck_map.get('expect_string')
environment_id = healthcheck_map.get('id_ambiente')
# Valid equip_id
if not is_valid_int_greater_zero_param(environment_id):
self.log.error(
u'Parameter environment_id is invalid. Value: %s.', environment_id)
raise InvalidValueError(None, 'environment_id', environment_id)
if expect_string is not None:
if not is_valid_string_maxsize(expect_string, 50) or not is_valid_string_minsize(expect_string, 2):
self.log.error(
u'Parameter expect_string is invalid. Value: %s.', expect_string)
raise InvalidValueError(
None, 'expect_string', expect_string)
else:
raise InvalidValueError(None, 'expect_string', expect_string)
if match_list is not None:
if not is_valid_string_maxsize(match_list, 50) or not is_valid_string_minsize(match_list, 2):
self.log.error(
u'Parameter match_list is invalid. Value: %s.', match_list)
raise InvalidValueError(None, 'match_list', match_list)
else:
raise InvalidValueError(None, 'expect_string', expect_string)
# User permission
if not has_perm(user,
AdminPermission.HEALTH_CHECK_EXPECT,
AdminPermission.WRITE_OPERATION):
return self.not_authorized()
healthcheck = HealthcheckExpect()
ambiente = Ambiente.get_by_pk(environment_id)
healthcheck.insert(user, match_list, expect_string, ambiente)
healtchcheck_dict = dict()
healtchcheck_dict['id'] = healthcheck.id
return self.response(dumps_networkapi({'healthcheck_expect': healtchcheck_dict}))
except AmbienteNotFoundError, e:
return self.response_error(112)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:71,代码来源:HealthcheckAddResource.py
示例18: handle_post
#.........这里部分代码省略.........
vlan = Vlan()
# Valid acl_file Vlan
if acl_file is not None:
if not is_valid_string_minsize(acl_file, 3) or not is_valid_string_maxsize(acl_file, 200):
self.log.error(
u'Parameter acl_file is invalid. Value: %s', acl_file)
raise InvalidValueError(None, 'acl_file', acl_file)
p = re.compile('^[A-Z0-9-_]+$')
m = p.match(acl_file)
if not m:
raise InvalidValueError(None, 'acl_file', acl_file)
# VERIFICA SE VLAN COM MESMO ACL JA EXISTE OU NAO
# commenting acl name check - issue #55
# vlan.get_vlan_by_acl(acl_file)
# Valid acl_file_v6 Vlan
if acl_file_v6 is not None:
if not is_valid_string_minsize(acl_file_v6, 3) or not is_valid_string_maxsize(acl_file_v6, 200):
self.log.error(
u'Parameter acl_file_v6 is invalid. Value: %s', acl_file_v6)
raise InvalidValueError(None, 'acl_file_v6', acl_file_v6)
p = re.compile('^[A-Z0-9-_]+$')
m = p.match(acl_file_v6)
if not m:
raise InvalidValueError(None, 'acl_file_v6', acl_file_v6)
# VERIFICA SE VLAN COM MESMO ACL JA EXISTE OU NAO
# commenting acl name check - issue #55
# vlan.get_vlan_by_acl_v6(acl_file_v6)
ambiente = Ambiente()
ambiente = ambiente.get_by_pk(environment_id)
vlan.acl_file_name = acl_file
vlan.acl_file_name_v6 = acl_file_v6
vlan.num_vlan = number
vlan.nome = name
vlan.descricao = description
vlan.ambiente = ambiente
vlan.ativada = 0
vlan.acl_valida = 0
vlan.acl_valida_v6 = 0
vlan.insert_vlan(user)
if network_ipv4:
network_ipv4 = NetworkIPv4()
vlan_map = network_ipv4.add_network_ipv4(
user, vlan.id, None, None, None)
list_equip_routers_ambient = EquipamentoAmbiente.objects.select_related('equipamento').filter(
ambiente=vlan.ambiente.id, is_router=True)
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(network_ipv4.id)
ip = str(ip).split('.')
ip_model = Ip()
ip_model.oct1 = ip[0]
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:67,代码来源:VlanInsertResource.py
示例19: handle_post
def handle_post(self, request, user, *args, **kwargs):
"""Treat requests POST to verify that the IPv6 belongs to environment.
URL: /ipv6/environment/
"""
self.log.info('Verify that the IPv6 belongs to environment')
try:
# User permission
if not has_perm(user, AdminPermission.IPS, 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.')
ipv6_map = networkapi_map.get('ipv6_map')
if ipv6_map is None:
return self.response_error(3, u'There is no value to the ipv6_map tag of XML request.')
# Get XML data
environment_id = ipv6_map.get('id_environment')
ipv6 = ipv6_map.get('ipv6')
# Valid Environment ID
if not is_valid_int_greater_zero_param(environment_id):
self.log.error(
u'The id_environment parameter is not a valid value: %s.', environment_id)
raise InvalidValueError(None, 'id_environment', environment_id)
# Valid IPv6 ID
if not is_valid_ipv6(ipv6):
self.log.error(
u'The ipv6 parameter is not a valid value: %s.', ipv6)
raise InvalidValueError(None, 'ipv6', ipv6)
blocks = str(IPv6Address(ipv6).exploded).split(':')
# Find Environment by ID to check if it exist
environment = Ambiente.get_by_pk(environment_id)
# Find Ipv6 by blocks to check if it exist
IPv6 = Ipv6.get_by_octs_and_environment(blocks[0], blocks[1], blocks[2], blocks[
3], blocks[4], blocks[5], blocks[6], blocks[7], environment_id)
# Generate return map
ipv6_map = dict()
ipv6_map['id'] = IPv6.id
ipv6_map['id_vlan'] = IPv6.networkipv6.vlan.id
ipv6_map['bloco1'] = IPv6.block1
ipv6_map['bloco2'] = IPv6.block2
ipv6_map['bloco3'] = IPv6.block3
ipv6_map['bloco4'] = IPv6.block4
ipv6_map['bloco5'] = IPv6.block5
ipv6_map['bloco6'] = IPv6.block6
ipv6_map['bloco7'] = IPv6.block7
ipv6_map['bloco8'] = IPv6.block8
ipv6_map['descricao'] = IPv6.description
return self.response(dumps_networkapi({'ipv6': ipv6_map}))
except UserNotAuthorizedError:
return self.not_authorized()
except InvalidValueError, e:
return self.response_
|
请发表评论