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


Python NetworkManager.ip_lookup方法代码示例

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


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

示例1: execute

# 需要导入模块: from SoftLayer import NetworkManager [as 别名]
# 或者: from SoftLayer.NetworkManager import ip_lookup [as 别名]
    def execute(self, args):
        mgr = NetworkManager(self.client)

        addr_info = mgr.ip_lookup(args['<ip>'])

        if not addr_info:
            return 'Not found'

        table = KeyValueTable(['Name', 'Value'])
        table.align['Name'] = 'r'
        table.align['Value'] = 'l'

        table.add_row(['id', addr_info['id']])
        table.add_row(['ip', addr_info['ipAddress']])

        subnet_table = KeyValueTable(['Name', 'Value'])
        subnet_table.align['Name'] = 'r'
        subnet_table.align['Value'] = 'l'
        subnet_table.add_row(['id', addr_info['subnet']['id']])
        subnet_table.add_row(['identifier',
                              '%s/%s'
                              % (addr_info['subnet']['networkIdentifier'],
                                 str(addr_info['subnet']['cidr']))])
        subnet_table.add_row(['netmask', addr_info['subnet']['netmask']])
        if addr_info['subnet'].get('gateway'):
            subnet_table.add_row(['gateway', addr_info['subnet']['gateway']])
        subnet_table.add_row(['type', addr_info['subnet'].get('subnetType')])

        table.add_row(['subnet', subnet_table])

        if addr_info.get('virtualGuest') or addr_info.get('hardware'):
            device_table = KeyValueTable(['Name', 'Value'])
            device_table.align['Name'] = 'r'
            device_table.align['Value'] = 'l'
            if addr_info.get('virtualGuest'):
                device = addr_info['virtualGuest']
                device_type = 'cci'
            else:
                device = addr_info['hardware']
                device_type = 'server'
            device_table.add_row(['id', device['id']])
            device_table.add_row(['name', device['fullyQualifiedDomainName']])
            device_table.add_row(['type', device_type])
            table.add_row(['device', device_table])
        return table
开发者ID:TimurNurlygayanov,项目名称:softlayer-python,代码行数:47,代码来源:subnet.py

示例2: execute

# 需要导入模块: from SoftLayer import NetworkManager [as 别名]
# 或者: from SoftLayer.NetworkManager import ip_lookup [as 别名]
    def execute(client, args):
        mgr = NetworkManager(client)

        ip = mgr.ip_lookup(args['<ip>'])

        if not ip:
            return 'Not found'

        t = KeyValueTable(['Name', 'Value'])
        t.align['Name'] = 'r'
        t.align['Value'] = 'l'

        t.add_row(['id', ip['id']])
        t.add_row(['ip', ip['ipAddress']])

        subnet_table = KeyValueTable(['Name', 'Value'])
        subnet_table.align['Name'] = 'r'
        subnet_table.align['Value'] = 'l'
        subnet_table.add_row(['id', ip['subnet']['id']])
        subnet_table.add_row(['identifier', ip['subnet']['networkIdentifier']])
        subnet_table.add_row(['netmask', ip['subnet']['netmask']])
        if ip['subnet'].get('gateway'):
            subnet_table.add_row(['gateway', ip['subnet']['gateway']])
        subnet_table.add_row(['type', ip['subnet'].get('subnetType')])

        t.add_row(['subnet', subnet_table])

        if ip.get('virtualGuest') or ip.get('hardware'):
            device_table = KeyValueTable(['Name', 'Value'])
            device_table.align['Name'] = 'r'
            device_table.align['Value'] = 'l'
            if ip.get('virtualGuest'):
                device = ip['virtualGuest']
                device_type = 'cci'
            else:
                device = ip['hardware']
                device_type = 'server'
            device_table.add_row(['id', device['id']])
            device_table.add_row(['name', device['fullyQualifiedDomainName']])
            device_table.add_row(['type', device_type])
            t.add_row(['device', device_table])
        return t
开发者ID:loles,项目名称:softlayer-api-python-client,代码行数:44,代码来源:subnet.py

示例3: NetworkTests

# 需要导入模块: from SoftLayer import NetworkManager [as 别名]
# 或者: from SoftLayer.NetworkManager import ip_lookup [as 别名]
class NetworkTests(unittest.TestCase):

    def setUp(self):
        self.client = MagicMock()
        self.network = NetworkManager(self.client)

    def test_ip_lookup(self):
        ip = '10.0.1.37'
        mcall = call(ip, mask=ANY)
        service = self.client['Network_Subnet_IpAddress']

        self.network.ip_lookup(ip)
        service.getByIpAddress.assert_has_calls(mcall)

    def test_add_subnet_returns_none_on_failure(self):
        self._setup_add_subnet_mocks()

        self.assertEqual(None, self.network.add_subnet('bad'))

    def test_add_global_ip(self):
        self._setup_add_subnet_mocks()
        # Test a global IPv4 order
        expected = {'packageId': 0,
                    'prices': [{
                        'categories': [{
                            'categoryCode': 'global_ipv4'}],
                        'id': 11,
                        'item': {'capacity': '0',
                                 'description': 'Global IPv4',
                                 'id': 10},
                        'itemId': 10,
                        'recurringFee': '0'}]}

        result = self.network.add_global_ip(test_order=True)

        self.assertEqual(expected, result)

    def test_add_subnet_for_ipv4(self):
        self._setup_add_subnet_mocks()

        # Test a four public address IPv4 order
        expected = {'packageId': 0,
                    'prices': [{
                        'categories': [{
                            'categoryCode': 'sov_sec_ip_addresses_pub'}],
                        'id': 4444,
                        'item': {
                            'capacity': '4',
                            'description': '4 Portable Public IP Addresses',
                            'id': 4440},
                        'itemId': 4440,
                        'recurringFee': '0'}]}

        result = self.network.add_subnet('public',
                                         quantity=4,
                                         vlan_id=1234,
                                         version=4,
                                         test_order=True)

        self.assertEqual(expected, result)

        # Test a global IPv4 order
        expected = {'packageId': 0,
                    'prices': [{
                        'categories': [{
                            'categoryCode': 'global_ipv4'}],
                        'id': 11,
                        'item': {'capacity': '0',
                                 'description': 'Global IPv4',
                                 'id': 10},
                        'itemId': 10,
                        'recurringFee': '0'}]}

        result = self.network.add_subnet('global',
                                         test_order=True)

        self.assertEqual(expected, result)

    def test_add_subnet_for_ipv6(self):
        self._setup_add_subnet_mocks()

        # Test a public IPv6 order
        expected = {
            'packageId': 0,
            'prices': [{
                'categories': [{'categoryCode': 'static_ipv6_addresses'}],
                'id': 664641,
                'item': {
                    'capacity': '64',
                    'description': '/64 Block Portable Public IPv6 Addresses',
                    'id': 66464},
                'itemId': 66464,
                'recurringFee': '0'}]}

        result = self.network.add_subnet('public',
                                         quantity=64,
                                         vlan_id=45678,
                                         version=6,
                                         test_order=True)

#.........这里部分代码省略.........
开发者ID:crvidya,项目名称:softlayer-api-python-client,代码行数:103,代码来源:network_tests.py

示例4: NetworkTests

# 需要导入模块: from SoftLayer import NetworkManager [as 别名]
# 或者: from SoftLayer.NetworkManager import ip_lookup [as 别名]
class NetworkTests(unittest.TestCase):
    def setUp(self):
        self.client = FixtureClient()
        self.network = NetworkManager(self.client)

    def test_ip_lookup(self):
        service = self.client["Network_Subnet_IpAddress"]

        self.network.ip_lookup("10.0.1.37")
        service.getByIpAddress.assert_called_with("10.0.1.37", mask=ANY)

    def test_add_subnet_raises_exception_on_failure(self):
        self.assertRaises(TypeError, self.network.add_subnet, ("bad"))

    def test_add_global_ip(self):
        # Test a global IPv4 order
        result = self.network.add_global_ip(test_order=True)

        self.assertEqual(Product_Order.verifyOrder, result)

    def test_add_subnet_for_ipv4(self):
        # Test a four public address IPv4 order
        result = self.network.add_subnet("public", quantity=4, vlan_id=1234, version=4, test_order=True)

        self.assertEqual(Product_Order.verifyOrder, result)

        result = self.network.add_subnet("public", quantity=4, vlan_id=1234, version=4, test_order=False)

        self.assertEqual(Product_Order.verifyOrder, result)

        result = self.network.add_subnet("global", test_order=True)

        self.assertEqual(Product_Order.verifyOrder, result)

    def test_add_subnet_for_ipv6(self):
        # Test a public IPv6 order
        result = self.network.add_subnet("public", quantity=64, vlan_id=45678, version=6, test_order=True)

        self.assertEqual(Product_Order.verifyOrder, result)

        # Test a global IPv6 order
        result = self.network.add_subnet("global", version=6, test_order=True)

        self.assertEqual(Product_Order.verifyOrder, result)

    def test_assign_global_ip(self):
        id = 9876
        target = "172.16.24.76"

        self.network.assign_global_ip(id, target)

        service = self.client["Network_Subnet_IpAddress_Global"]
        service.route.assert_called_with(target, id=id)

    def test_cancel_global_ip(self):
        service = self.client["Billing_Item"]

        self.network.cancel_global_ip(1234)
        service.cancelService.assert_called_with(id=1234)

    def test_cancel_subnet(self):
        service = self.client["Billing_Item"]

        self.network.cancel_subnet(1234)
        service.cancelService.assert_called_with(id=1056)

    def test_edit_rwhois(self):
        self.client["Account"].getRwhoisData.return_value = {"id": 954}

        expected = {
            "abuseEmail": "[email protected]",
            "address1": "123 Test Street",
            "address2": "Apt. #31",
            "city": "Anywhere",
            "companyName": "TestLayer",
            "country": "US",
            "firstName": "Bob",
            "lastName": "Bobinson",
            "postalCode": "9ba62",
            "privateResidenceFlag": False,
            "state": "TX",
        }

        self.network.edit_rwhois(
            abuse_email="[email protected]",
            address1="123 Test Street",
            address2="Apt. #31",
            city="Anywhere",
            company_name="TestLayer",
            country="US",
            first_name="Bob",
            last_name="Bobinson",
            postal_code="9ba62",
            private_residence=False,
            state="TX",
        )

        f = self.client["Network_Subnet_Rwhois_Data"].editObject
        f.assert_called_with(expected, id=954)

#.........这里部分代码省略.........
开发者ID:ryanrhanson,项目名称:softlayer-python,代码行数:103,代码来源:network_tests.py

示例5: NetworkTests

# 需要导入模块: from SoftLayer import NetworkManager [as 别名]
# 或者: from SoftLayer.NetworkManager import ip_lookup [as 别名]
class NetworkTests(unittest.TestCase):

    def setUp(self):
        self.client = FixtureClient()
        self.network = NetworkManager(self.client)

    def test_ip_lookup(self):
        service = self.client['Network_Subnet_IpAddress']

        self.network.ip_lookup('10.0.1.37')
        service.getByIpAddress.assert_called_with('10.0.1.37', mask=ANY)

    def test_add_subnet_raises_exception_on_failure(self):
        self.assertRaises(TypeError, self.network.add_subnet, ('bad'))

    def test_add_global_ip(self):
        # Test a global IPv4 order
        result = self.network.add_global_ip(test_order=True)

        self.assertEqual(Product_Order.verifyOrder, result)

    def test_add_subnet_for_ipv4(self):
        # Test a four public address IPv4 order
        result = self.network.add_subnet('public',
                                         quantity=4,
                                         vlan_id=1234,
                                         version=4,
                                         test_order=True)

        self.assertEqual(Product_Order.verifyOrder, result)

        result = self.network.add_subnet('public',
                                         quantity=4,
                                         vlan_id=1234,
                                         version=4,
                                         test_order=False)

        self.assertEqual(Product_Order.verifyOrder, result)

        result = self.network.add_subnet('global',
                                         test_order=True)

        self.assertEqual(Product_Order.verifyOrder, result)

    def test_add_subnet_for_ipv6(self):
        # Test a public IPv6 order
        result = self.network.add_subnet('public',
                                         quantity=64,
                                         vlan_id=45678,
                                         version=6,
                                         test_order=True)

        self.assertEqual(Product_Order.verifyOrder, result)

        # Test a global IPv6 order
        result = self.network.add_subnet('global',
                                         version=6,
                                         test_order=True)

        self.assertEqual(Product_Order.verifyOrder, result)

    def test_assign_global_ip(self):
        self.network.assign_global_ip(9876, '172.16.24.76')

        service = self.client['Network_Subnet_IpAddress_Global']
        service.route.assert_called_with('172.16.24.76', id=9876)

    def test_cancel_global_ip(self):
        self.network.cancel_global_ip(1234)

        service = self.client['Billing_Item']
        service.cancelService.assert_called_with(id=1234)

    def test_cancel_subnet(self):
        self.network.cancel_subnet(1234)

        service = self.client['Billing_Item']
        service.cancelService.assert_called_with(id=1056)

    def test_edit_rwhois(self):
        self.network.edit_rwhois(
            abuse_email='[email protected]',
            address1='123 Test Street',
            address2='Apt. #31',
            city='Anywhere',
            company_name='TestLayer',
            country='US',
            first_name='Bob',
            last_name='Bobinson',
            postal_code='9ba62',
            private_residence=False,
            state='TX')

        expected = {
            'abuseEmail': '[email protected]',
            'address1': '123 Test Street',
            'address2': 'Apt. #31',
            'city': 'Anywhere',
            'companyName': 'TestLayer',
            'country': 'US',
#.........这里部分代码省略.........
开发者ID:MayaY2014,项目名称:softlayer-python,代码行数:103,代码来源:network_tests.py


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