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


Python RackspaceCtrl.list_sizes方法代码示例

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


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

示例1: TestRackspaceCtrl

# 需要导入模块: from gns3.cloud.rackspace_ctrl import RackspaceCtrl [as 别名]
# 或者: from gns3.cloud.rackspace_ctrl.RackspaceCtrl import list_sizes [as 别名]
class TestRackspaceCtrl(unittest.TestCase):

    def setUp(self):
        self.username = username
        self.api_key = api_key
        # prefix to identify created objects
        self.object_prefix = "int_test_"
        self.prefix_length = len(self.object_prefix)
        self.ctrl = RackspaceCtrl(self.username, self.api_key)
        self.ctrl.authenticate()
        self.ctrl.set_region('ord')

    def tearDown(self):
        self._remove_instances()
        self._remove_key_pairs()

    def _remove_instances(self):
        """ Remove any instances that were created. """

        for instance in self.ctrl.driver.list_nodes():
            if instance.name[0:self.prefix_length] == self.object_prefix:
                self.ctrl.driver.destroy_node(instance)

    def _remove_key_pairs(self):
        """ Remove any key pairs that were created. """

        for key_pair in self.ctrl.driver.list_key_pairs():
            if key_pair.name[0:self.prefix_length] == self.object_prefix:
                self.ctrl.driver.delete_key_pair(key_pair)

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

        ctrl = RackspaceCtrl(self.username, self.api_key)

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

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

        ctrl = RackspaceCtrl('', self.api_key)

        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(self.username, '')

        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')

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

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

        ctrl = RackspaceCtrl(self.username, self.api_key)
        ctrl.authenticate()

        result = ctrl.set_region('iad')

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

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

        ctrl = RackspaceCtrl(self.username, self.api_key)
        ctrl.authenticate()

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

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

    def test_create_instance(self):
        """ Test creating an instance. """

        name = "%screate_instance" % 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)
#.........这里部分代码省略.........
开发者ID:madkrell,项目名称:gns3-gui,代码行数:103,代码来源:test_cloud_integration.py

示例2: TestRackspaceCtrl

# 需要导入模块: from gns3.cloud.rackspace_ctrl import RackspaceCtrl [as 别名]
# 或者: from gns3.cloud.rackspace_ctrl.RackspaceCtrl import list_sizes [as 别名]
class TestRackspaceCtrl(unittest.TestCase):
    def setUp(self):
        # prefix to identify created objects
        self.object_prefix = "int_test_"
        self.prefix_length = len(self.object_prefix)
        self.ctrl = RackspaceCtrl(self.username, self.api_key, 'http://foo.bar:8888')
        self.ctrl.authenticate()
        self.ctrl.set_region('ord')
        self.gns3_image = None

    def tearDown(self):
        self._remove_instances()
        self._remove_key_pairs()
        if self.gns3_image is not None:
            self.ctrl.driver.ex_delete_image(self.gns3_image)

    def _remove_instances(self):
        """ Remove any instances that were created. """

        for instance in self.ctrl.driver.list_nodes():
            if instance.name[0:self.prefix_length] == self.object_prefix:
                self.ctrl.driver.destroy_node(instance)

    def _remove_key_pairs(self):
        """ Remove any key pairs that were created. """

        for key_pair in self.ctrl.driver.list_key_pairs():
            if key_pair.name[0:self.prefix_length] == self.object_prefix:
                self.ctrl.driver.delete_key_pair(key_pair)

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

        ctrl = RackspaceCtrl(self.username, self.api_key, 'http://foo.bar:8888')

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

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

        ctrl = RackspaceCtrl('', self.api_key, 'http://foo.bar:8888')

        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(self.username, '', 'http://foo.bar:8888')

        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')

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

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

        ctrl = RackspaceCtrl(self.username, self.api_key, 'http://foo.bar:8888')
        ctrl.authenticate()

        result = ctrl.set_region('iad')

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

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

        ctrl = RackspaceCtrl(self.username, self.api_key, 'http://foo.bar:8888')
        ctrl.authenticate()

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

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

    def test_create_instance(self):
        """ Test creating an instance. """

        name = "%screate_instance" % 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)
#.........这里部分代码省略.........
开发者ID:avdoshkin,项目名称:gns3-gui,代码行数:103,代码来源:test_cloud_integration.py

示例3: TestRackspaceCtrl

# 需要导入模块: from gns3.cloud.rackspace_ctrl import RackspaceCtrl [as 别名]
# 或者: from gns3.cloud.rackspace_ctrl.RackspaceCtrl import list_sizes [as 别名]

#.........这里部分代码省略.........
        self.assertEqual(auth_result, False)
        self.assertIsNone(ctrl.token)

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

        ctrl = RackspaceCtrl(self.username, self.api_key, "http://foo.bar:8888")
        ctrl.authenticate()

        result = ctrl.set_region("iad")

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

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

        ctrl = RackspaceCtrl(self.username, self.api_key, "http://foo.bar:8888")
        ctrl.authenticate()

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

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

    def test_create_instance(self):
        """ Test creating an instance. """

        name = "%screate_instance" % 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])
        self.assertIsInstance(instance, Node)

    def test_delete_instance(self):
        """ Test deleting an instance. """

        name = "%sdelete_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])

        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. """
开发者ID:planctechnologies,项目名称:gns3-gui,代码行数:70,代码来源:test_cloud_integration.py


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