diff options
author | Dan Smith <dansmith@redhat.com> | 2019-10-07 11:23:28 -0700 |
---|---|---|
committer | Dan Smith <dansmith@redhat.com> | 2019-10-18 10:50:01 -0700 |
commit | 71c29a184b388b38d81dc609b9883c5e8f7166cf (patch) | |
tree | aaf16b08bcc3c555f2acae95db03c0f565065131 /novaclient/v2 | |
parent | e1bb4378db1e5be85a59861c2d473388fa336da8 (diff) | |
download | python-novaclient-71c29a184b388b38d81dc609b9883c5e8f7166cf.tar.gz |
Add aggregate-cache-images command and client routines
This adds the ability to request image precache support for an aggregate
in support of the matching server feature.
Related to blueprint image-precache-support
Depends-On: https://review.opendev.org/#/c/687140
Change-Id: Id354ccfa99e500a598685e6b794c12160ea2a990
Diffstat (limited to 'novaclient/v2')
-rw-r--r-- | novaclient/v2/aggregates.py | 22 | ||||
-rw-r--r-- | novaclient/v2/shell.py | 15 |
2 files changed, 37 insertions, 0 deletions
diff --git a/novaclient/v2/aggregates.py b/novaclient/v2/aggregates.py index 9d4dff82..d2cbaa85 100644 --- a/novaclient/v2/aggregates.py +++ b/novaclient/v2/aggregates.py @@ -15,6 +15,7 @@ """Aggregate interface.""" +from novaclient import api_versions from novaclient import base @@ -45,6 +46,10 @@ class Aggregate(base.Resource): """ return self.manager.delete(self) + @api_versions.wraps("2.81") + def cache_images(self, images): + return self.manager.cache_images(self, images) + class AggregateManager(base.ManagerWithFind): resource_class = Aggregate @@ -103,3 +108,20 @@ class AggregateManager(base.ManagerWithFind): :returns: An instance of novaclient.base.TupleWithMeta """ return self._delete('/os-aggregates/%s' % (base.getid(aggregate))) + + @api_versions.wraps("2.81") + def cache_images(self, aggregate, images): + """ + Request images be cached on a given aggregate. + + :param aggregate: The aggregate to target + :param images: A list of image IDs to request caching + :returns: An instance of novaclient.base.TupleWithMeta + """ + body = { + 'cache': [{'id': base.getid(image)} for image in images], + } + resp, body = self.api.client.post( + "/os-aggregates/%s/images" % base.getid(aggregate), + body=body) + return self.convert_into_with_meta(body, resp) diff --git a/novaclient/v2/shell.py b/novaclient/v2/shell.py index 818006b9..0f8b5ce6 100644 --- a/novaclient/v2/shell.py +++ b/novaclient/v2/shell.py @@ -3526,6 +3526,21 @@ def _print_aggregate_details(cs, aggregate): utils.print_list([aggregate], columns, formatters=formatters) +@api_versions.wraps("2.81") +@utils.arg( + 'aggregate', metavar='<aggregate>', + help=_('Name or ID of the aggregate.')) +@utils.arg( + 'images', metavar='<image>', nargs='+', + help=_('Name or ID of image(s) to cache on the hosts within ' + 'the aggregate.')) +def do_aggregate_cache_images(cs, args): + """Request images be cached.""" + aggregate = _find_aggregate(cs, args.aggregate) + images = _find_images(cs, args.images) + cs.aggregates.cache_images(aggregate, images) + + @utils.arg('server', metavar='<server>', help=_('Name or ID of server.')) @utils.arg( 'host', metavar='<host>', default=None, nargs='?', |