本文整理汇总了Python中networkapi.vlan.models.Vlan.calculate_vlan_number方法的典型用法代码示例。如果您正苦于以下问题:Python Vlan.calculate_vlan_number方法的具体用法?Python Vlan.calculate_vlan_number怎么用?Python Vlan.calculate_vlan_number使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkapi.vlan.models.Vlan
的用法示例。
在下文中一共展示了Vlan.calculate_vlan_number方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_get
# 需要导入模块: from networkapi.vlan.models import Vlan [as 别名]
# 或者: from networkapi.vlan.models.Vlan import calculate_vlan_number [as 别名]
def handle_get(self, request, user, *args, **kwargs):
"""Handle GET requests to check if environment has a number available.
URLs: /vlan/check_number_available/<environment>/<num_vlan>/
"""
try:
id_env = kwargs.get('id_environment')
num_vlan = kwargs.get('num_vlan')
id_vlan = kwargs.get('id_vlan')
# User permission
if not has_perm(user, AdminPermission.VLAN_MANAGEMENT, AdminPermission.READ_OPERATION):
self.log.error(
u'User does not have permission to perform the operation.')
raise UserNotAuthorizedError(None)
# Valid env 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, 'env_id', id_env)
# Valid num Vlan
if not is_valid_int_greater_zero_param(num_vlan):
self.log.error(
u'The num_vlan parameter is not a valid value: %s.', num_vlan)
raise InvalidValueError(None, 'num_vlan', id_env)
else:
num_vlan = int(num_vlan)
if is_valid_int_greater_zero_param(id_vlan):
vlan_to_edit = Vlan().get_by_pk(id_vlan)
if vlan_to_edit.num_vlan == num_vlan:
return self.response(dumps_networkapi({'has_numbers_availables': True}))
environment = Ambiente().get_by_pk(id_env)
vlan = Vlan()
vlan.ambiente = environment
# Check if environment has min/max num_vlan value or use the value
# that was configured in settings
if (vlan.ambiente.min_num_vlan_1 and vlan.ambiente.max_num_vlan_1) or (vlan.ambiente.min_num_vlan_2 and vlan.ambiente.max_num_vlan_2):
min_num_01 = vlan.ambiente.min_num_vlan_1 if vlan.ambiente.min_num_vlan_1 and vlan.ambiente.max_num_vlan_1 else vlan.ambiente.min_num_vlan_2
max_num_01 = vlan.ambiente.max_num_vlan_1 if vlan.ambiente.min_num_vlan_1 and vlan.ambiente.max_num_vlan_1 else vlan.ambiente.max_num_vlan_2
min_num_02 = vlan.ambiente.min_num_vlan_2 if vlan.ambiente.min_num_vlan_2 and vlan.ambiente.max_num_vlan_2 else vlan.ambiente.min_num_vlan_1
max_num_02 = vlan.ambiente.max_num_vlan_2 if vlan.ambiente.min_num_vlan_2 and vlan.ambiente.max_num_vlan_2 else vlan.ambiente.max_num_vlan_1
else:
min_num_01 = MIN_VLAN_NUMBER_01
max_num_01 = MAX_VLAN_NUMBER_01
min_num_02 = MIN_VLAN_NUMBER_02
max_num_02 = MAX_VLAN_NUMBER_02
has_numbers_availables = False
availables_numbers = vlan.calculate_vlan_number(
min_num_01, max_num_01, True)
if num_vlan not in availables_numbers:
availables_numbers = vlan.calculate_vlan_number(
min_num_02, max_num_02, True)
if num_vlan in availables_numbers:
has_numbers_availables = True
else:
has_numbers_availables = True
if Vlan.objects.filter(num_vlan=num_vlan, ambiente=environment):
has_numbers_availables = True
return self.response(dumps_networkapi({'has_numbers_availables': has_numbers_availables}))
except InvalidValueError, e:
return self.response_error(269, e.param, e.value)