當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。