当前位置: 首页>>代码示例>>Python>>正文


Python EnvironmentVip.available_evips方法代码示例

本文整理汇总了Python中networkapi.ambiente.models.EnvironmentVip.available_evips方法的典型用法代码示例。如果您正苦于以下问题:Python EnvironmentVip.available_evips方法的具体用法?Python EnvironmentVip.available_evips怎么用?Python EnvironmentVip.available_evips使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在networkapi.ambiente.models.EnvironmentVip的用法示例。


在下文中一共展示了EnvironmentVip.available_evips方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle_get

# 需要导入模块: from networkapi.ambiente.models import EnvironmentVip [as 别名]
# 或者: from networkapi.ambiente.models.EnvironmentVip import available_evips [as 别名]
    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,代码行数:31,代码来源:EnvironmentVipSearchResource.py

示例2: handle_post

# 需要导入模块: from networkapi.ambiente.models import EnvironmentVip [as 别名]
# 或者: from networkapi.ambiente.models.EnvironmentVip import available_evips [as 别名]
    def handle_post(self, request, user, *args, **kwargs):
        """Treat POST requests to add new Network

        URL: network/add/
        """

        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)
            network_map = networkapi_map.get('network')
            if network_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
            network = network_map.get('network')
            id_vlan = network_map.get('id_vlan')
            network_type = network_map.get('id_network_type')
            environment_vip = network_map.get('id_environment_vip')

            # Valid Network
            try:
                net = IPNetwork(network)
            except ValueError, e:
                raise InvalidValueError(None, 'network', network)

            # VLAN

            # Valid vlan ID
            if not is_valid_int_greater_zero_param(id_vlan):
                raise InvalidValueError(None, 'id_vlan', id_vlan)

            # Find vlan by ID to check if it exist
            vlan = Vlan().get_by_pk(id_vlan)

            # Network Type

            # Valid network_type ID
            if not is_valid_int_greater_zero_param(network_type):
                raise InvalidValueError(None, 'id_network_type', network_type)

            # Find network_type by ID to check if it exist
            net_type = 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):
                    raise InvalidValueError(
                        None, 'id_environment_vip', environment_vip)

                evips = EnvironmentVip.objects.all()

                evip_list = EnvironmentVip.available_evips(
                    EnvironmentVip(), evips, int(id_vlan))

                # Check if the chose environment is in the same environment
                if any(int(environment_vip) == item['id'] for item in evip_list):
                    # Find Environment VIP by ID to check if it exist
                    env_vip = EnvironmentVip.get_by_pk(environment_vip)
                else:
                    raise InvalidValueError(
                        None, 'id_environment_vip', environment_vip)

            else:
                env_vip = None

            # Check unchecked exception
            blocks, network, version = break_network(network)

            expl = split(
                net.network.exploded, "." if version == IP_VERSION.IPv4[0] else ":")
            expl.append(str(net.prefixlen))

            if blocks != expl:
                raise InvalidValueError(None, 'rede', network)

            # Business Rules

#.........这里部分代码省略.........
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:103,代码来源:NetworkAddResource.py


注:本文中的networkapi.ambiente.models.EnvironmentVip.available_evips方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。