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


Python Ip.get_by_octs_and_environment方法代码示例

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


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

示例1: handle_get

# 需要导入模块: from networkapi.ip.models import Ip [as 别名]
# 或者: from networkapi.ip.models.Ip import get_by_octs_and_environment [as 别名]
    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,代码行数:56,代码来源:IpResource.py


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