當前位置: 首頁>>代碼示例>>Python>>正文


Python Vlan.calculate_vlan_number方法代碼示例

本文整理匯總了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)
開發者ID:andrewsmedina,項目名稱:GloboNetworkAPI,代碼行數:72,代碼來源:VlanCheckNumberAvailable.py


注:本文中的networkapi.vlan.models.Vlan.calculate_vlan_number方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。