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


Python ProfitBricksService.get_lan方法代码示例

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


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

示例1: TestLan

# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import get_lan [as 别名]
class TestLan(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.resource = resource()
        self.client = ProfitBricksService(
            username=configuration.USERNAME,
            password=configuration.PASSWORD,
            headers=configuration.HEADERS)

        # Create test datacenter.
        self.datacenter = self.client.create_datacenter(
            datacenter=Datacenter(**self.resource['datacenter']))
        wait_for_completion(self.client, self.datacenter, 'create_datacenter')

        # Create test LAN.
        self.lan = self.client.create_lan(
            datacenter_id=self.datacenter['id'],
            lan=LAN(**self.resource['lan']))
        wait_for_completion(self.client, self.lan, 'create_lan')

        # Create test server.
        self.server = self.client.create_server(
            datacenter_id=self.datacenter['id'],
            server=Server(**self.resource['server']))
        wait_for_completion(self.client, self.server, 'create_server')

        # Create test NIC1.
        nic1 = NIC(**self.resource['nic'])
        nic1.lan = self.lan['id']
        self.nic1 = self.client.create_nic(
            datacenter_id=self.datacenter['id'],
            server_id=self.server['id'],
            nic=nic1)
        wait_for_completion(self.client, self.nic1, 'create_nic1')

        # Create test NIC2.
        nic2 = NIC(**self.resource['nic'])
        nic2.lan = self.lan['id']
        self.nic2 = self.client.create_nic(
            datacenter_id=self.datacenter['id'],
            server_id=self.server['id'],
            nic=nic2)
        wait_for_completion(self.client, self.nic2, 'create_nic2')

    @classmethod
    def tearDownClass(self):
        self.client.delete_datacenter(datacenter_id=self.datacenter['id'])

    def test_list_lans(self):
        lans = self.client.list_lans(datacenter_id=self.datacenter['id'])

        self.assertGreater(len(lans), 0)
        self.assertEqual(lans['items'][0]['type'], 'lan')
        self.assertIn(lans['items'][0]['id'], ('1', '2', '3'))
        self.assertEqual(lans['items'][0]['properties']['name'], self.resource['lan']['name'])
        self.assertTrue(lans['items'][0]['properties']['public'], self.resource['lan']['public'])

    def test_get_lan(self):
        lan = self.client.get_lan(datacenter_id=self.datacenter['id'], lan_id=self.lan['id'])

        self.assertEqual(lan['type'], 'lan')
        self.assertEqual(lan['id'], self.lan['id'])
        self.assertEqual(lan['properties']['name'], self.resource['lan']['name'])
        self.assertTrue(lan['properties']['public'], self.resource['lan']['public'])

    def test_delete_lan(self):
        lan = self.client.create_lan(
            datacenter_id=self.datacenter['id'],
            lan=LAN(**self.resource['lan']))
        wait_for_completion(self.client, self.lan, 'create_lan')

        lan = self.client.delete_lan(datacenter_id=self.datacenter['id'], lan_id=lan['id'])

        self.assertTrue(lan)

    def test_update_lan(self):
        lan = self.client.update_lan(
            datacenter_id=self.datacenter['id'],
            lan_id=self.lan['id'],
            name=self.resource['lan']['name'] + ' RENAME',
            public=False)

        self.assertEqual(lan['type'], 'lan')
        self.assertEqual(lan['properties']['name'], self.resource['lan']['name'] + ' RENAME')
        self.assertFalse(lan['properties']['public'])

    def test_create_lan(self):
        self.assertEqual(self.lan['id'], '1')
        self.assertEqual(self.lan['type'], 'lan')
        self.assertEqual(self.lan['properties']['name'], self.resource['lan']['name'])
        self.assertEqual(self.lan['properties']['public'], self.resource['lan']['public'])

    def test_create_complex_lan(self):
        resource = NIC(**self.resource['nic'])

        nic1 = self.client.create_nic(
            datacenter_id=self.datacenter['id'],
            server_id=self.server['id'],
            nic=resource)
        wait_for_completion(self.client, nic1, 'create_nic1')
#.........这里部分代码省略.........
开发者ID:jbuchhammer,项目名称:profitbricks-sdk-python,代码行数:103,代码来源:test_lan_live.py

示例2: TestLan

# 需要导入模块: from profitbricks.client import ProfitBricksService [as 别名]
# 或者: from profitbricks.client.ProfitBricksService import get_lan [as 别名]
class TestLan(unittest.TestCase):
    def setUp(self):
        self.lan = ProfitBricksService(username='username', password='password')

    def test_list_lans(self):
        lans = self.lan.list_lans(datacenter_id=datacenter_id)

        self.assertEqual(len(lans), 4)
        self.assertEqual(lans['items'][0]['id'], lan_id)
        self.assertEqual(lans['items'][0]['properties']['name'], 'public Lan 4')

    def test_get_lan(self):
        lan = self.lan.get_lan(datacenter_id=datacenter_id, lan_id=lan_id)

        self.assertEqual(lan['properties']['name'], 'public Lan 4')
        self.assertTrue(lan['properties']['public'])

    def test_delete_lan(self):
        lan = self.lan.delete_lan(datacenter_id=datacenter_id, lan_id=lan_id)
        self.assertTrue(lan)

    def test_update_lan(self):
        lan = self.lan.update_lan(datacenter_id=datacenter_id,
                                  lan_id=lan_id,
                                  name='new lan 4 name',
                                  public=False)

        self.assertEqual(lan['properties']['name'], 'public Lan 4')
        self.assertTrue(lan['properties']['public'])

    def test_create_lan(self):
        i = LAN(
            name='public Lan 4',
            public=True)

        response = self.lan.create_lan(datacenter_id=datacenter_id, lan=i)

        self.assertEqual(response['properties']['name'], 'public Lan 4')
        self.assertTrue(response['properties']['public'])

    def test_create_complex_lan(self):
        nics = ['<NIC-ID-1>', '<NIC-ID-2>']

        i = LAN(
            name='public Lan 4',
            public=True,
            nics=nics)

        response = self.lan.create_lan(datacenter_id=datacenter_id, lan=i)

        self.assertEqual(response['properties']['name'], 'public Lan 4')
        self.assertTrue(response['properties']['public'])

    def test_get_lan_members(self):
        members = self.lan.get_lan_members(datacenter_id=datacenter_id,
                                           lan_id=lan_id)

        self.assertEqual(len(members), 4)
        self.assertEqual(members['items'][0]['id'], '<NIC-ID>')
        self.assertEqual(members['items'][0]['properties']['name'], 'nic1')
        self.assertEqual(members['items'][0]['properties']['mac'], 'AB:21:23:09:78:C2')
开发者ID:grandvizier,项目名称:profitbricks-sdk-python,代码行数:63,代码来源:test_lan.py


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