當前位置: 首頁>>代碼示例>>Python>>正文


Python RackspaceCtrl.list_regions方法代碼示例

本文整理匯總了Python中gns3.cloud.rackspace_ctrl.RackspaceCtrl.list_regions方法的典型用法代碼示例。如果您正苦於以下問題:Python RackspaceCtrl.list_regions方法的具體用法?Python RackspaceCtrl.list_regions怎麽用?Python RackspaceCtrl.list_regions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gns3.cloud.rackspace_ctrl.RackspaceCtrl的用法示例。


在下文中一共展示了RackspaceCtrl.list_regions方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestRackspaceCtrl

# 需要導入模塊: from gns3.cloud.rackspace_ctrl import RackspaceCtrl [as 別名]
# 或者: from gns3.cloud.rackspace_ctrl.RackspaceCtrl import list_regions [as 別名]
class TestRackspaceCtrl(unittest.TestCase):

    def setUp(self):
        """ Set up the objects used by most of the tests. """

        self.ctrl = RackspaceCtrl('valid_user', 'valid_api_key', 'http://foo.bar:8888')
        self.ctrl.post_fn = stub_rackspace_identity_post
        self.driver_cls = MockLibCloudDriver

    def test_authenticate_valid_user(self):
        """ Test authentication with a valid user and api key. """

        auth_result = self.ctrl.authenticate()
        self.assertEqual(auth_result, True)
        self.assertIsNotNone(self.ctrl.token)

    def test_authenticate_empty_user(self):
        """ Ensure authentication with empty string as username fails. """

        ctrl = RackspaceCtrl('', 'valid_api_key', 'http://foo.bar:8888')
        ctrl.post_fn = stub_rackspace_identity_post

        auth_result = ctrl.authenticate()
        self.assertEqual(auth_result, False)
        self.assertIsNone(ctrl.token)

    def test_authenticate_empty_apikey(self):
        """ Ensure authentication with empty string as api_key fails. """

        ctrl = RackspaceCtrl('valid_user', '', 'http://foo.bar:8888')
        ctrl.post_fn = stub_rackspace_identity_post

        auth_result = ctrl.authenticate()
        self.assertEqual(auth_result, False)
        self.assertIsNone(ctrl.token)

    def test_authenticate_invalid_user(self):
        """  Ensure authentication with invalid user credentials fails. """

        ctrl = RackspaceCtrl('invalid_user', 'invalid_api_key', 'http://foo.bar:8888')
        ctrl.post_fn = stub_rackspace_identity_post

        auth_result = ctrl.authenticate()
        self.assertEqual(auth_result, False)
        self.assertIsNone(ctrl.token)

    def test_list_regions(self):
        """ Ensure that list_regions returns the correct result. """

        self.ctrl.authenticate()
        regions = self.ctrl.list_regions()

        expected_regions = [
            {'IAD': 'iad'},
            {'DFW': 'dfw'},
            {'SYD': 'syd'},
            {'ORD': 'ord'}
        ]

        self.assertCountEqual(regions, expected_regions)

    def test_set_region(self):
        """ Ensure that set_region sets 'region' and 'driver'. """

        self.ctrl.authenticate()

        result = self.ctrl.set_region('iad')

        self.assertEqual(result, True)
        self.assertEqual(self.ctrl.region, 'iad')
        self.assertIsNotNone(self.ctrl.driver)

    def test_set_invalid_region(self):
        """ Ensure that calling 'set_region' with an invalid param fails. """

        self.ctrl.authenticate()

        result = self.ctrl.set_region('invalid')

        self.assertEqual(result, False)
        self.assertIsNone(self.ctrl.region)
        self.assertIsNone(self.ctrl.driver)

    def test_token_parsed(self):
        """ Ensure that the token is set. """

        ctrl = RackspaceCtrl('valid_user', 'valid_api_key', 'http://foo.bar:8888')
        ctrl.post_fn = stub_rackspace_identity_post

        ctrl.authenticate()

        self.assertEqual('abcdefgh0123456789', ctrl.token)
開發者ID:avdoshkin,項目名稱:gns3-gui,代碼行數:94,代碼來源:test_cloud_unit.py

示例2: TestRackspaceCtrl

# 需要導入模塊: from gns3.cloud.rackspace_ctrl import RackspaceCtrl [as 別名]
# 或者: from gns3.cloud.rackspace_ctrl.RackspaceCtrl import list_regions [as 別名]

#.........這裏部分代碼省略.........

        response = self.ctrl.delete_key_pair(key_pair)

        self.assertEqual(response, True)

    def test_create_key_pair_existing_name(self):
        """ Test creating a key pair with an existing name. """

        name = "%screate_key_pair_existing_name" % self.object_prefix
        # Create the first instance
        self.ctrl.create_key_pair(name)

        self.assertRaises(KeyPairExists, self.ctrl.create_key_pair, name)

    def test_delete_key_pair(self):
        """ Test deleting a key pair. """

        name = "%sdelete_key_pair" % self.object_prefix

        key_pair = self.ctrl.create_key_pair(name)

        result = self.ctrl.delete_key_pair(key_pair)

        self.assertEqual(result, True)

    def test_delete_nonexistant_key_pair(self):
        """ Test deleting a key pair that doesn't exist. """

        fake_key_pair = StubObject(name='invalid_name')

        self.assertRaises(ItemNotFound, self.ctrl.delete_key_pair,
                          fake_key_pair)

    def test_list_regions(self):
        """ Ensure that list_regions returns the correct result. """

        regions = self.ctrl.list_regions()

        expected_regions = [
            {'IAD': 'iad'},
            {'DFW': 'dfw'},
            {'SYD': 'syd'},
            {'ORD': 'ord'},
            {'HKG': 'hkg'}
        ]

        self.assertCountEqual(regions, expected_regions)

    def test_list_instances(self):

        name = "%slist_instances" % self.object_prefix

        image = self.ctrl.driver.list_images()[0]
        size = self.ctrl.driver.list_sizes()[0]
        key_pair = self.ctrl.create_key_pair(name)

        instance = self.ctrl.create_instance(name, size, image, key_pair)
        if self.run_instances:
            self.ctrl.driver.wait_until_running([instance])

        instances = self.ctrl.list_instances()

        self.assertIsInstance(instances, list)
        self.assertIsInstance(instances[0], Node)

    def test_list_sizes(self):
開發者ID:avdoshkin,項目名稱:gns3-gui,代碼行數:70,代碼來源:test_cloud_integration.py

示例3: TestRackspaceCtrl

# 需要導入模塊: from gns3.cloud.rackspace_ctrl import RackspaceCtrl [as 別名]
# 或者: from gns3.cloud.rackspace_ctrl.RackspaceCtrl import list_regions [as 別名]

#.........這裏部分代碼省略.........
        image = self.ctrl.driver.list_images()[0]
        size = self.ctrl.driver.list_sizes()[0]
        key_pair = self.ctrl.create_key_pair(name)

        instance = self.ctrl.create_instance(name, size, image, key_pair)
        self.ctrl.driver.wait_until_running([instance])

        response = self.ctrl.delete_instance(instance)

        self.assertEqual(response, True)

    def test_delete_invalid_instance_id(self):

        fake_instance = StubObject(id='invalid_id')

        self.assertRaises(ItemNotFound, self.ctrl.delete_instance,
                          fake_instance)

    def test_create_key_pair(self):
        """ Test creating a key pair. """

        name = "%screate_key_pair" % self.object_prefix
        key_pair = self.ctrl.create_key_pair(name)

        self.assertIsInstance(key_pair, KeyPair)

        response = self.ctrl.delete_key_pair(key_pair)

        self.assertEqual(response, True)

    def test_create_key_pair_existing_name(self):
        """ Test creating a key pair with an existing name. """

        name = "%screate_key_pair_existing_name" % self.object_prefix
        # Create the first instance
        self.ctrl.create_key_pair(name)

        self.assertRaises(KeyPairExists, self.ctrl.create_key_pair, name)

    def test_delete_key_pair(self):
        """ Test deleting a key pair. """

        name = "%sdelete_key_pair" % self.object_prefix

        key_pair = self.ctrl.create_key_pair(name)

        result = self.ctrl.delete_key_pair(key_pair)

        self.assertEqual(result, True)

    def test_delete_nonexistant_key_pair(self):
        """ Test deleting a key pair that doesn't exist. """

        fake_key_pair = StubObject(name='invalid_name')

        self.assertRaises(ItemNotFound, self.ctrl.delete_key_pair,
                          fake_key_pair)

    def test_list_regions(self):
        """ Ensure that list_regions returns the correct result. """

        regions = self.ctrl.list_regions()

        expected_regions = [
            {'IAD': 'iad'},
            {'DFW': 'dfw'},
            {'SYD': 'syd'},
            {'ORD': 'ord'},
            {'HKG': 'hkg'}
        ]

        self.assertCountEqual(regions, expected_regions)

    def test_list_instances(self):

        name = "%slist_instances" % self.object_prefix

        image = self.ctrl.driver.list_images()[0]
        size = self.ctrl.driver.list_sizes()[0]
        key_pair = self.ctrl.create_key_pair(name)

        instance = self.ctrl.create_instance(name, size, image, key_pair)
        self.ctrl.driver.wait_until_running([instance])

        instances = self.ctrl.list_instances()

        self.assertIsInstance(instances, list)
        self.assertIsInstance(instances[0], Node)

    def test_list_sizes(self):

        sizes = self.ctrl.list_sizes()

        self.assertIsInstance(sizes, list)
        self.assertIsInstance(sizes[0], NodeSize)

    def test_token_parsed(self):
        """ Ensure that the token is set. """

        self.assertIsNotNone(self.ctrl.token)
開發者ID:madkrell,項目名稱:gns3-gui,代碼行數:104,代碼來源:test_cloud_integration.py

示例4: TestRackspaceCtrl

# 需要導入模塊: from gns3.cloud.rackspace_ctrl import RackspaceCtrl [as 別名]
# 或者: from gns3.cloud.rackspace_ctrl.RackspaceCtrl import list_regions [as 別名]

#.........這裏部分代碼省略.........
        self.assertIsInstance(key_pair, KeyPair)

        response = self.ctrl.delete_key_pair(key_pair)

        self.assertEqual(response, True)

    def test_create_key_pair_existing_name(self):
        """ Test creating a key pair with an existing name. """

        name = "%screate_key_pair_existing_name" % self.object_prefix
        # Create the first instance
        self.ctrl.create_key_pair(name)

        self.assertRaises(KeyPairExists, self.ctrl.create_key_pair, name)

    def test_delete_key_pair(self):
        """ Test deleting a key pair. """

        name = "%sdelete_key_pair" % self.object_prefix

        key_pair = self.ctrl.create_key_pair(name)

        result = self.ctrl.delete_key_pair(key_pair)

        self.assertEqual(result, True)

    def test_delete_nonexistant_key_pair(self):
        """ Test deleting a key pair that doesn't exist. """

        fake_key_pair = StubObject(name="invalid_name")

        self.assertRaises(ItemNotFound, self.ctrl.delete_key_pair, fake_key_pair)

    def test_list_regions(self):
        """ Ensure that list_regions returns the correct result. """

        regions = self.ctrl.list_regions()

        expected_regions = [{"IAD": "iad"}, {"DFW": "dfw"}, {"SYD": "syd"}, {"ORD": "ord"}, {"HKG": "hkg"}]

        self.assertCountEqual(regions, expected_regions)

    def test_list_instances(self):

        name = "%slist_instances" % self.object_prefix

        image = self.ctrl.driver.list_images()[0]
        size = self.ctrl.driver.list_sizes()[0]
        key_pair = self.ctrl.create_key_pair(name)

        instance = self.ctrl.create_instance(name, size, image, key_pair)
        if self.run_instances:
            self.ctrl.driver.wait_until_running([instance])

        instances = self.ctrl.list_instances()

        self.assertIsInstance(instances, list)
        self.assertIsInstance(instances[0], Node)

    def test_list_sizes(self):

        sizes = self.ctrl.list_sizes()

        self.assertIsInstance(sizes, list)
        self.assertIsInstance(sizes[0], NodeSize)
開發者ID:planctechnologies,項目名稱:gns3-gui,代碼行數:69,代碼來源:test_cloud_integration.py

示例5: TestRackspaceCtrl

# 需要導入模塊: from gns3.cloud.rackspace_ctrl import RackspaceCtrl [as 別名]
# 或者: from gns3.cloud.rackspace_ctrl.RackspaceCtrl import list_regions [as 別名]
class TestRackspaceCtrl(unittest.TestCase):
    def setUp(self):
        """ Set up the objects used by most of the tests. """

        self.ctrl = RackspaceCtrl("valid_user", "valid_api_key", "http://foo.bar:8888")
        self.ctrl.post_fn = stub_rackspace_identity_post
        self.driver_cls = MockLibCloudDriver

    def test_authenticate_valid_user(self):
        """ Test authentication with a valid user and api key. """

        auth_result = self.ctrl.authenticate()
        self.assertEqual(auth_result, True)
        self.assertIsNotNone(self.ctrl.token)

    def test_authenticate_empty_user(self):
        """ Ensure authentication with empty string as username fails. """

        ctrl = RackspaceCtrl("", "valid_api_key", "http://foo.bar:8888")
        ctrl.post_fn = stub_rackspace_identity_post

        auth_result = ctrl.authenticate()
        self.assertEqual(auth_result, False)
        self.assertIsNone(ctrl.token)

    def test_authenticate_empty_apikey(self):
        """ Ensure authentication with empty string as api_key fails. """

        ctrl = RackspaceCtrl("valid_user", "", "http://foo.bar:8888")
        ctrl.post_fn = stub_rackspace_identity_post

        auth_result = ctrl.authenticate()
        self.assertEqual(auth_result, False)
        self.assertIsNone(ctrl.token)

    def test_authenticate_invalid_user(self):
        """  Ensure authentication with invalid user credentials fails. """

        ctrl = RackspaceCtrl("invalid_user", "invalid_api_key", "http://foo.bar:8888")
        ctrl.post_fn = stub_rackspace_identity_post

        auth_result = ctrl.authenticate()
        self.assertEqual(auth_result, False)
        self.assertIsNone(ctrl.token)

    def test_list_regions(self):
        """ Ensure that list_regions returns the correct result. """

        self.ctrl.authenticate()
        regions = self.ctrl.list_regions()

        expected_regions = [{"IAD": "iad"}, {"DFW": "dfw"}, {"SYD": "syd"}, {"ORD": "ord"}]

        self.assertCountEqual(regions, expected_regions)

    def test_set_region(self):
        """ Ensure that set_region sets 'region' and 'driver'. """

        self.ctrl.authenticate()

        result = self.ctrl.set_region("iad")

        self.assertEqual(result, True)
        self.assertEqual(self.ctrl.region, "iad")
        self.assertIsNotNone(self.ctrl.driver)

    def test_set_invalid_region(self):
        """ Ensure that calling 'set_region' with an invalid param fails. """

        self.ctrl.authenticate()

        result = self.ctrl.set_region("invalid")

        self.assertEqual(result, False)
        self.assertIsNone(self.ctrl.region)
        self.assertIsNone(self.ctrl.driver)

    def test_token_parsed(self):
        """ Ensure that the token is set. """

        ctrl = RackspaceCtrl("valid_user", "valid_api_key", "http://foo.bar:8888")
        ctrl.post_fn = stub_rackspace_identity_post

        ctrl.authenticate()

        self.assertEqual("abcdefgh0123456789", ctrl.token)

    def test_upload_file(self):
        self.ctrl.storage_driver = mock.MagicMock()
        mock_container = mock.MagicMock()
        mock_container.list_objects = mock.MagicMock(return_value=[])
        self.ctrl.storage_driver.create_container = mock.MagicMock(return_value=mock_container)
        test_data = b"abcdef"
        test_data_hash = hashlib.md5(test_data).hexdigest()

        test_file = tempfile.NamedTemporaryFile()
        with test_file.file as f:
            f.write(test_data)

        return_value = self.ctrl.upload_file(test_file.name, "test_folder/test.txt")
#.........這裏部分代碼省略.........
開發者ID:planctechnologies,項目名稱:gns3-gui,代碼行數:103,代碼來源:test_cloud_unit.py


注:本文中的gns3.cloud.rackspace_ctrl.RackspaceCtrl.list_regions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。