From 6346f13bf5e54fd780dbf17f21846e91f4c933a6 Mon Sep 17 00:00:00 2001 From: eddie-sheffield Date: Wed, 27 Feb 2013 14:31:30 -0500 Subject: [PATCH] Added support for scheduled images extension --- novaclient/v1_1/client.py | 2 + novaclient/v1_1/scheduled_images.py | 63 +++++++++++++++++++++++++++++ novaclient/v1_1/shell.py | 22 ++++++++++ 3 files changed, 87 insertions(+) create mode 100644 novaclient/v1_1/scheduled_images.py diff --git a/novaclient/v1_1/client.py b/novaclient/v1_1/client.py index 383ae19fc..b9c07c9f7 100644 --- a/novaclient/v1_1/client.py +++ b/novaclient/v1_1/client.py @@ -46,6 +46,7 @@ from novaclient.v1_1 import services from novaclient.v1_1 import fixed_ips from novaclient.v1_1 import floating_ips_bulk +from novaclient.v1_1 import scheduled_images class Client(object): @@ -117,6 +118,7 @@ def __init__(self, username, api_key, project_id, auth_url=None, self.coverage = coverage_ext.CoverageManager(self) self.availability_zones = \ availability_zones.AvailabilityZoneManager(self) + self.scheduled_images = scheduled_images.ScheduledImageManager(self) # Add in any extensions... if extensions: diff --git a/novaclient/v1_1/scheduled_images.py b/novaclient/v1_1/scheduled_images.py new file mode 100644 index 000000000..9d28625d4 --- /dev/null +++ b/novaclient/v1_1/scheduled_images.py @@ -0,0 +1,63 @@ +# Copyright 2013 Rackspace, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +""" +Scheduled Images interface (1.1 extension). +""" + +import urllib + +from novaclient import base +from novaclient import exceptions + +class ScheduledImage(base.Resource): + def __repr__(self): + return "" + +class ScheduledImageManager(base.Manager): + resource_class = ScheduledImage + + def get(self, server_id): + """ + Get the scheduled image information for the server. + + :param server_id: The ID of the server to query for. + :rtype: :class:`ScheduledImage` + """ + try: + return self._get("/servers/%s/os-si-image-schedule" % server_id, "image_schedule") + except exceptions.NotFound: + msg = "Scheduled images not enabled for server %s" % server_id + raise exceptions.NotFound(404, msg) + + def disable(self, server_id): + """ + Disable the creation of scheduled images for the server. + + :param server_id: The ID of the server to disable scheduled images for. + """ + self._delete("/servers/%s/os-si-image-schedule" % server_id) + + def enable(self, server_id, retention): + """ + Enable the creation of scheduled images for the server. + + :param server_id: The ID of the server to enable scheduled images for. + :param retention: The number of scheduled images to retain. + :rtype: :class:`ScheduledImage` + """ + body = {'image_schedule': {'retention': retention}} + return self._create("/servers/%s/os-si-image-schedule" % server_id, + body, "image_schedule") diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py index a6518077b..2242020b8 100644 --- a/novaclient/v1_1/shell.py +++ b/novaclient/v1_1/shell.py @@ -3024,3 +3024,25 @@ def do_availability_zone_list(cs, _args): _translate_availability_zone_keys(result) utils.print_list(result, ['Name', 'Status'], sortby_index=None) + + +@utils.arg('server', metavar='', help='Name or ID of server.') +def do_scheduled_images_show(cs, args): + """Show the scheduled image settings for a server""" + server_id = _find_server(cs, args.server).id + result = cs.scheduled_images.get(server_id) + print "Retention: %d" % result['retention'] + +@utils.arg('server', metavar='', help='Name or ID of server.') +@utils.arg('retention', metavar='', + help='Number of scheduled images to retain') +def do_scheduled_images_enable(cs, args): + """Enable scheduled images for a server""" + server_id = _find_server(cs, args.server).id + result = cs.scheduled_images.enable(server_id, args.retention) + +@utils.arg('server', metavar='', help='Name or ID of server.') +def do_scheduled_images_disable(cs, args): + """Enable scheduled images for a server""" + server_id = _find_server(cs, args.server).id + result = cs.scheduled_images.disable(server_id)