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


Python Ip.get_by_octs方法代码示例

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


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

示例1: handle_post

# 需要导入模块: from networkapi.ip.models import Ip [as 别名]
# 或者: from networkapi.ip.models.Ip import get_by_octs [as 别名]
    def handle_post(self, request, user, *args, **kwargs):
        """Handles POST requests to get an IPv4 or Ipv6 by oct or blocks .

        URL: ip/getbyoctblock/
        """

        self.log.info("Get a Ipv4's or Ipv6's")

        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)
            ip_map = networkapi_map.get('ip_map')
            if ip_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
            ip = ip_map.get('ip')

            # 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()

            # Valid ip
            if not is_valid_ip_ipaddr(ip):
                self.log.error(u'Parameter ip is invalid. Value: %s.', ip)
                raise InvalidValueError(None, 'ip', ip)

            # Business Rules
            version = ''
            ip_list = ip.split('.')

            if len(ip_list) == 1:

                ip_list = ip.split(':')
                ips = Ipv6.get_by_blocks(ip_list[0], ip_list[1], ip_list[2], ip_list[
                                         3], ip_list[4], ip_list[5], ip_list[6], ip_list[7])
                version = IP_VERSION.IPv6[1]

            else:

                ips = Ip.get_by_octs(
                    ip_list[0], ip_list[1], ip_list[2], ip_list[3])
                version = IP_VERSION.IPv4[1]

            ips_list = []
            for ip in ips:
                ip_dict = model_to_dict(ip)
                ip_dict['version'] = version
                ips_list.append(ip_dict)

            return self.response(dumps_networkapi({'ips': ips_list}))

        except XMLError, x:
            self.log.error(u'Error reading the XML request.')
            return self.response_error(3, x)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:71,代码来源:IpGetOctBlockResource.py


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