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


Python RackspaceCtrl.list_images方法代碼示例

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


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

示例1: TestRackspaceCtrlDriver

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

    """ Test the libcloud Rackspace driver. """

    class StubObject(object):

        def __init__(self, **kwargs):

            for arg in kwargs:
                setattr(self, arg, kwargs[arg])

    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.ctrl.driver_cls = MockLibCloudDriver
        self.ctrl.authenticate()
        self.ctrl.set_region('iad')
        self.ctrl.get_image = mock.MagicMock()
        self.ctrl.get_image.return_value = ''
        self.key_pair = TestRackspaceCtrlDriver.StubObject(public_key='keystr')

    def test_create_instance_over_limit(self):
        """ Ensure '413 Over Limit' error is handled properly. """

        self.assertRaises(OverLimit, self.ctrl.create_instance,
                          'over_limit', 'size', 'image', self.key_pair)

    def test_create_instance_bad_request(self):
        """ Ensure '400 Bad Request' error is handled properly. """

        self.assertRaises(BadRequest, self.ctrl.create_instance,
                          'bad_request', 'size', 'image', self.key_pair)

    def test_delete_instance_nonexistant(self):
        """ Ensure '404 Instance not found' error is handled properly. """

        instance = TestRackspaceCtrlDriver.StubObject(name='nonexistant')

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

    def test_create_key_pair_duplicate_name(self):
        """ Ensure '409 Key Pair exists' error is handled properly. """

        self.assertRaises(KeyPairExists, self.ctrl.create_key_pair,
                          'duplicate_name')

    def test_service_uavailable(self):
        """ Ensure '503 Service Unavailable' error is handled properly. """

        self.assertRaises(ServiceUnavailable, self.ctrl.create_instance,
                          'service_unavailable', 'size', 'image',
                          self.key_pair)

    def test_unauthorized(self):
        """ Ensure '401 Unauthroized' error is handled properly. """

        self.assertRaises(Unauthorized, self.ctrl.create_instance,
                          'unauthorized', 'size', 'image', self.key_pair)

    def test_api_error(self):
        """ Ensure '500 ...' error is handled properly. """

        self.assertRaises(ApiError, self.ctrl.create_instance, 'api_error',
                          'size', 'image', self.key_pair)

    def test_list_images(self):
        self.ctrl.tenant_id = '1234567890'
        self.ctrl._get_shared_images = mock.MagicMock()
        self.ctrl._get_shared_images.return_value = [
            {
                "image_name": "foo",
                "schema": "/v2/schemas/member",
                "status": "pending",
                "image_id": "1c6ba38d-5960-4cc1-a3db-bab521e99afa",
                "member_id": "user_foo",
                "created_at": "2014-06-25T13:49:56Z",
                "updated_at": "2014-06-25T13:49:56Z"
            },
            {
                "image_name": "foo2",
                "schema": "/v2/schemas/member",
                "status": "pending",
                "image_id": "a44a6c31-a437-498e-b4e4-3a6cb9d1d733",
                "member_id": "user_foo",
                "created_at": "2014-06-25T13:49:59Z",
                "updated_at": "2014-06-25T13:49:59Z"
            },
            {
                "image_name": "foo3",
                "member_id": "user_foo",
                "image_id": "64c3b6e5-05c1-4407-82b9-5690cdfaa887",
                "status": "ALREADYREQUESTED"
            },
            {
                "image_name": "foo4",
                "member_id": "user_foo",
                "image_id": "a6893756-b108-4667-9bf3-7a02d076b3e2",
#.........這裏部分代碼省略.........
開發者ID:avdoshkin,項目名稱:gns3-gui,代碼行數:103,代碼來源:test_cloud_unit.py


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