Merge "Fix troveclient to support Mistral"
This commit is contained in:
@@ -40,33 +40,9 @@ def quote_user_host(user, host):
|
|||||||
return quoted.replace('.', '%2e')
|
return quoted.replace('.', '%2e')
|
||||||
|
|
||||||
|
|
||||||
class Paginated(object):
|
class Paginated(list):
|
||||||
"""Pretends to be a list if you iterate over it, but also keeps a
|
|
||||||
next property you can use to get the next page of data.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, items=[], next_marker=None, links=[]):
|
def __init__(self, items=[], next_marker=None, links=[]):
|
||||||
self.items = items
|
super(Paginated, self).__init__(items)
|
||||||
self.next = next_marker
|
self.next = next_marker
|
||||||
self.links = links
|
self.links = links
|
||||||
|
|
||||||
def __len__(self):
|
|
||||||
return len(self.items)
|
|
||||||
|
|
||||||
def __iter__(self):
|
|
||||||
return self.items.__iter__()
|
|
||||||
|
|
||||||
def __getitem__(self, key):
|
|
||||||
return self.items[key]
|
|
||||||
|
|
||||||
def __setitem__(self, key, value):
|
|
||||||
self.items[key] = value
|
|
||||||
|
|
||||||
def __delitem__(self, key):
|
|
||||||
del self.items[key]
|
|
||||||
|
|
||||||
def __reversed__(self):
|
|
||||||
return reversed(self.items)
|
|
||||||
|
|
||||||
def __contains__(self, needle):
|
|
||||||
return needle in self.items
|
|
||||||
|
@@ -87,7 +87,8 @@ class BackupManagerTest(testtools.TestCase):
|
|||||||
def test_copy(self):
|
def test_copy(self):
|
||||||
create_mock = mock.Mock()
|
create_mock = mock.Mock()
|
||||||
self.backups._create = create_mock
|
self.backups._create = create_mock
|
||||||
args = {'name': 'test_backup', 'backup': '1'}
|
args = {'name': 'test_backup', 'instance': 'foo',
|
||||||
|
'backup': '1'}
|
||||||
body = {'backup': args}
|
body = {'backup': args}
|
||||||
self.backups.create(**args)
|
self.backups.create(**args)
|
||||||
create_mock.assert_called_with('/backups', body, 'backup')
|
create_mock.assert_called_with('/backups', body, 'backup')
|
||||||
|
@@ -289,8 +289,8 @@ class MangerPaginationTests(ManagerTest):
|
|||||||
def test_pagination(self):
|
def test_pagination(self):
|
||||||
resp = self.manager._paginated(self.url, self.response_key)
|
resp = self.manager._paginated(self.url, self.response_key)
|
||||||
self.manager.api.client.get.assert_called_with(self.url)
|
self.manager.api.client.get.assert_called_with(self.url)
|
||||||
self.assertEqual('p1', resp.items[0].foo)
|
self.assertEqual('p1', resp[0].foo)
|
||||||
self.assertEqual('p2', resp.items[1].foo)
|
self.assertEqual('p2', resp[1].foo)
|
||||||
self.assertEqual(self.marker, resp.next)
|
self.assertEqual(self.marker, resp.next)
|
||||||
self.assertEqual(self.links, resp.links)
|
self.assertEqual(self.links, resp.links)
|
||||||
self.assertIsInstance(resp, common.Paginated)
|
self.assertIsInstance(resp, common.Paginated)
|
||||||
@@ -299,8 +299,8 @@ class MangerPaginationTests(ManagerTest):
|
|||||||
resp = self.manager._paginated(self.url, self.response_key,
|
resp = self.manager._paginated(self.url, self.response_key,
|
||||||
limit=self.limit, marker=self.marker)
|
limit=self.limit, marker=self.marker)
|
||||||
self.manager.api.client.get.assert_called_with(self.next_url)
|
self.manager.api.client.get.assert_called_with(self.next_url)
|
||||||
self.assertEqual('p3', resp.items[0].foo)
|
self.assertEqual('p3', resp[0].foo)
|
||||||
self.assertEqual('p4', resp.items[1].foo)
|
self.assertEqual('p4', resp[1].foo)
|
||||||
self.assertIsNone(resp.next)
|
self.assertIsNone(resp.next)
|
||||||
self.assertEqual([], resp.links)
|
self.assertEqual([], resp.links)
|
||||||
self.assertIsInstance(resp, common.Paginated)
|
self.assertIsInstance(resp, common.Paginated)
|
||||||
|
@@ -75,39 +75,6 @@ class PaginatedTest(testtools.TestCase):
|
|||||||
super(PaginatedTest, self).tearDown()
|
super(PaginatedTest, self).tearDown()
|
||||||
|
|
||||||
def test___init__(self):
|
def test___init__(self):
|
||||||
self.assertEqual(self.items_, self.pgn.items)
|
self.assertEqual(self.items_, self.pgn)
|
||||||
self.assertEqual(self.next_marker_, self.pgn.next)
|
self.assertEqual(self.next_marker_, self.pgn.next)
|
||||||
self.assertEqual(self.links_, self.pgn.links)
|
self.assertEqual(self.links_, self.pgn.links)
|
||||||
|
|
||||||
def test___len__(self):
|
|
||||||
self.assertEqual(len(self.items_), self.pgn.__len__())
|
|
||||||
|
|
||||||
def test___iter__(self):
|
|
||||||
itr_expected = self.items_.__iter__()
|
|
||||||
itr = self.pgn.__iter__()
|
|
||||||
self.assertEqual(next(itr_expected), next(itr))
|
|
||||||
self.assertEqual(next(itr_expected), next(itr))
|
|
||||||
self.assertRaises(StopIteration, next, itr_expected)
|
|
||||||
self.assertRaises(StopIteration, next, itr)
|
|
||||||
|
|
||||||
def test___getitem__(self):
|
|
||||||
self.assertEqual(self.items_[0], self.pgn.__getitem__(0))
|
|
||||||
|
|
||||||
def test___setitem__(self):
|
|
||||||
self.pgn.__setitem__(0, "new-item")
|
|
||||||
self.assertEqual("new-item", self.pgn.items[0])
|
|
||||||
|
|
||||||
def test___delitem(self):
|
|
||||||
del self.pgn[0]
|
|
||||||
self.assertEqual(1, self.pgn.__len__())
|
|
||||||
|
|
||||||
def test___reversed__(self):
|
|
||||||
itr = self.pgn.__reversed__()
|
|
||||||
self.assertEqual("item2", next(itr))
|
|
||||||
self.assertEqual("item1", next(itr))
|
|
||||||
self.assertRaises(StopIteration, next, itr)
|
|
||||||
|
|
||||||
def test___contains__(self):
|
|
||||||
self.assertTrue(self.pgn.__contains__("item1"))
|
|
||||||
self.assertTrue(self.pgn.__contains__("item2"))
|
|
||||||
self.assertFalse(self.pgn.__contains__("item3"))
|
|
||||||
|
@@ -39,10 +39,6 @@ class InstanceTest(testtools.TestCase):
|
|||||||
super(InstanceTest, self).tearDown()
|
super(InstanceTest, self).tearDown()
|
||||||
instances.Instance.__init__ = self.orig__init
|
instances.Instance.__init__ = self.orig__init
|
||||||
|
|
||||||
def test___repr__(self):
|
|
||||||
self.instance.name = "instance-1"
|
|
||||||
self.assertEqual('<Instance: instance-1>', self.instance.__repr__())
|
|
||||||
|
|
||||||
def test_list_databases(self):
|
def test_list_databases(self):
|
||||||
db_list = ['database1', 'database2']
|
db_list = ['database1', 'database2']
|
||||||
self.instance.manager.databases = mock.Mock()
|
self.instance.manager.databases = mock.Mock()
|
||||||
|
@@ -50,9 +50,16 @@ class Backups(base.ManagerWithFind):
|
|||||||
return self._paginated("/backups", "backups", limit, marker,
|
return self._paginated("/backups", "backups", limit, marker,
|
||||||
query_strings)
|
query_strings)
|
||||||
|
|
||||||
def create(self, name, instance=None, description=None, parent_id=None,
|
def create(self, name, instance, description=None, parent_id=None,
|
||||||
backup=None,):
|
backup=None,):
|
||||||
"""Create a new backup from the given instance."""
|
"""Create a new backup from the given instance.
|
||||||
|
|
||||||
|
:param name: name for backup.
|
||||||
|
:param instance: instance to backup.
|
||||||
|
:param description: (optional).
|
||||||
|
:param parent_id: base for incremental backup (optional).
|
||||||
|
:returns: :class:`Backups`
|
||||||
|
"""
|
||||||
body = {
|
body = {
|
||||||
"backup": {
|
"backup": {
|
||||||
"name": name
|
"name": name
|
||||||
|
@@ -33,8 +33,6 @@ REBOOT_HARD = 'HARD'
|
|||||||
|
|
||||||
class Instance(base.Resource):
|
class Instance(base.Resource):
|
||||||
"""An Instance is an opaque instance used to store Database instances."""
|
"""An Instance is an opaque instance used to store Database instances."""
|
||||||
def __repr__(self):
|
|
||||||
return "<Instance: %s>" % self.name
|
|
||||||
|
|
||||||
def list_databases(self):
|
def list_databases(self):
|
||||||
return self.manager.databases.list(self)
|
return self.manager.databases.list(self)
|
||||||
@@ -186,6 +184,9 @@ class Instances(base.ManagerWithFind):
|
|||||||
def backups(self, instance, limit=None, marker=None):
|
def backups(self, instance, limit=None, marker=None):
|
||||||
"""Get the list of backups for a specific instance.
|
"""Get the list of backups for a specific instance.
|
||||||
|
|
||||||
|
:param instance: instance for which to list backups
|
||||||
|
:param limit: max items to return
|
||||||
|
:param marker: marker start point
|
||||||
:rtype: list of :class:`Backups`.
|
:rtype: list of :class:`Backups`.
|
||||||
"""
|
"""
|
||||||
url = "/instances/%s/backups" % base.getid(instance)
|
url = "/instances/%s/backups" % base.getid(instance)
|
||||||
|
@@ -810,12 +810,12 @@ def do_backup_show(cs, args):
|
|||||||
def do_backup_list_instance(cs, args):
|
def do_backup_list_instance(cs, args):
|
||||||
"""Lists available backups for an instance."""
|
"""Lists available backups for an instance."""
|
||||||
instance = _find_instance(cs, args.instance)
|
instance = _find_instance(cs, args.instance)
|
||||||
wrapper = cs.instances.backups(instance, limit=args.limit,
|
items = cs.instances.backups(instance, limit=args.limit,
|
||||||
marker=args.marker)
|
marker=args.marker)
|
||||||
backups = wrapper.items
|
backups = items
|
||||||
while wrapper.next and not args.limit:
|
while items.next and not args.limit:
|
||||||
wrapper = cs.instances.backups(instance, marker=wrapper.next)
|
items = cs.instances.backups(instance, marker=items.next)
|
||||||
backups += wrapper.items
|
backups += items
|
||||||
utils.print_list(backups, ['id', 'name', 'status',
|
utils.print_list(backups, ['id', 'name', 'status',
|
||||||
'parent_id', 'updated'],
|
'parent_id', 'updated'],
|
||||||
order_by='updated')
|
order_by='updated')
|
||||||
@@ -834,12 +834,12 @@ def do_backup_list_instance(cs, args):
|
|||||||
@utils.service_type('database')
|
@utils.service_type('database')
|
||||||
def do_backup_list(cs, args):
|
def do_backup_list(cs, args):
|
||||||
"""Lists available backups."""
|
"""Lists available backups."""
|
||||||
wrapper = cs.backups.list(limit=args.limit, datastore=args.datastore,
|
items = cs.backups.list(limit=args.limit, datastore=args.datastore,
|
||||||
marker=args.marker)
|
marker=args.marker)
|
||||||
backups = wrapper.items
|
backups = items
|
||||||
while wrapper.next and not args.limit:
|
while items.next and not args.limit:
|
||||||
wrapper = cs.backups.list(marker=wrapper.next)
|
items = cs.backups.list(marker=items.next)
|
||||||
backups += wrapper.items
|
backups += items
|
||||||
utils.print_list(backups, ['id', 'instance_id', 'name',
|
utils.print_list(backups, ['id', 'instance_id', 'name',
|
||||||
'status', 'parent_id', 'updated'],
|
'status', 'parent_id', 'updated'],
|
||||||
order_by='updated')
|
order_by='updated')
|
||||||
@@ -925,11 +925,11 @@ def do_database_create(cs, args):
|
|||||||
def do_database_list(cs, args):
|
def do_database_list(cs, args):
|
||||||
"""Lists available databases on an instance."""
|
"""Lists available databases on an instance."""
|
||||||
instance = _find_instance(cs, args.instance)
|
instance = _find_instance(cs, args.instance)
|
||||||
wrapper = cs.databases.list(instance)
|
items = cs.databases.list(instance)
|
||||||
databases = wrapper.items
|
databases = items
|
||||||
while (wrapper.next):
|
while (items.next):
|
||||||
wrapper = cs.databases.list(instance, marker=wrapper.next)
|
items = cs.databases.list(instance, marker=items.next)
|
||||||
databases += wrapper.items
|
databases += items
|
||||||
|
|
||||||
utils.print_list(databases, ['name'])
|
utils.print_list(databases, ['name'])
|
||||||
|
|
||||||
@@ -973,11 +973,11 @@ def do_user_create(cs, args):
|
|||||||
def do_user_list(cs, args):
|
def do_user_list(cs, args):
|
||||||
"""Lists the users for an instance."""
|
"""Lists the users for an instance."""
|
||||||
instance = _find_instance(cs, args.instance)
|
instance = _find_instance(cs, args.instance)
|
||||||
wrapper = cs.users.list(instance)
|
items = cs.users.list(instance)
|
||||||
users = wrapper.items
|
users = items
|
||||||
while (wrapper.next):
|
while (items.next):
|
||||||
wrapper = cs.users.list(instance, marker=wrapper.next)
|
items = cs.users.list(instance, marker=items.next)
|
||||||
users += wrapper.items
|
users += items
|
||||||
for user in users:
|
for user in users:
|
||||||
db_names = [db['name'] for db in user.databases]
|
db_names = [db['name'] for db in user.databases]
|
||||||
user.databases = ', '.join(db_names)
|
user.databases = ', '.join(db_names)
|
||||||
@@ -1142,11 +1142,11 @@ def do_root_show(cs, args):
|
|||||||
@utils.service_type('database')
|
@utils.service_type('database')
|
||||||
def do_secgroup_list(cs, args):
|
def do_secgroup_list(cs, args):
|
||||||
"""Lists all security groups."""
|
"""Lists all security groups."""
|
||||||
wrapper = cs.security_groups.list()
|
items = cs.security_groups.list()
|
||||||
sec_grps = wrapper.items
|
sec_grps = items
|
||||||
while (wrapper.next):
|
while (items.next):
|
||||||
wrapper = cs.security_groups.list()
|
items = cs.security_groups.list()
|
||||||
sec_grps += wrapper.items
|
sec_grps += items
|
||||||
|
|
||||||
utils.print_list(sec_grps, ['id', 'name', 'instance_id'])
|
utils.print_list(sec_grps, ['id', 'name', 'instance_id'])
|
||||||
|
|
||||||
@@ -1682,13 +1682,13 @@ def do_module_list_instance(cs, args):
|
|||||||
def do_module_instances(cs, args):
|
def do_module_instances(cs, args):
|
||||||
"""Lists the instances that have a particular module applied."""
|
"""Lists the instances that have a particular module applied."""
|
||||||
module = _find_module(cs, args.module)
|
module = _find_module(cs, args.module)
|
||||||
wrapper = cs.modules.instances(
|
items = cs.modules.instances(
|
||||||
module, limit=args.limit, marker=args.marker,
|
module, limit=args.limit, marker=args.marker,
|
||||||
include_clustered=args.include_clustered)
|
include_clustered=args.include_clustered)
|
||||||
instance_list = wrapper.items
|
instance_list = items
|
||||||
while not args.limit and wrapper.next:
|
while not args.limit and items.next:
|
||||||
wrapper = cs.modules.instances(module, marker=wrapper.next)
|
items = cs.modules.instances(module, marker=items.next)
|
||||||
instance_list += wrapper.items
|
instance_list += items
|
||||||
_print_instances(instance_list)
|
_print_instances(instance_list)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user