Modified as per code-review comments:
- Renaned snapshot to volume-snapshot - Created a new file for volume snapshots Review: https://github.com/rackspace/python-novaclient/pull/136#issuecomment-2623509
This commit is contained in:
parent
98cbe4620e
commit
3d03a25363
12
README.rst
12
README.rst
@ -124,10 +124,6 @@ You'll find complete documentation on the shell by running
|
||||
secgroup-list List security groups for the curent tenant.
|
||||
secgroup-list-rules List rules for a security group.
|
||||
show Show details about the given server.
|
||||
snapshot-create Add a new snapshot.
|
||||
snapshot-delete Remove a snapshot.
|
||||
snapshot-list List all the snapshots.
|
||||
snapshot-show Show details about a snapshot.
|
||||
suspend Suspend a server.
|
||||
unpause Unpause a server.
|
||||
unrescue Unrescue a server.
|
||||
@ -137,6 +133,14 @@ You'll find complete documentation on the shell by running
|
||||
volume-detach Detach a volume from a server.
|
||||
volume-list List all the volumes.
|
||||
volume-show Show details about a volume.
|
||||
volume-snapshot-create
|
||||
Add a new snapshot.
|
||||
volume-snapshot-delete
|
||||
Remove a snapshot.
|
||||
volume-snapshot-list
|
||||
List all the snapshots.
|
||||
volume-snapshot-show
|
||||
Show details about a snapshot.
|
||||
zone Show or edit a Child Zone
|
||||
zone-add Add a Child Zone.
|
||||
zone-boot Boot a server, considering Zones.
|
||||
|
@ -8,6 +8,7 @@ from novaclient.v1_1 import security_groups
|
||||
from novaclient.v1_1 import servers
|
||||
from novaclient.v1_1 import quotas
|
||||
from novaclient.v1_1 import volumes
|
||||
from novaclient.v1_1 import volume_snapshots
|
||||
from novaclient.v1_1 import zones
|
||||
|
||||
|
||||
@ -38,7 +39,7 @@ class Client(object):
|
||||
|
||||
# extensions
|
||||
self.volumes = volumes.VolumeManager(self)
|
||||
self.snapshots = volumes.SnapshotManager(self)
|
||||
self.volume_snapshots = volume_snapshots.SnapshotManager(self)
|
||||
self.keypairs = keypairs.KeypairManager(self)
|
||||
self.zones = zones.ZoneManager(self)
|
||||
self.quotas = quotas.QuotaSetManager(self)
|
||||
|
@ -105,12 +105,12 @@ def _boot(cs, args, reservation_id=None, min_count=None, max_count=None):
|
||||
security_groups = args.security_groups.split(',')
|
||||
else:
|
||||
security_groups = None
|
||||
|
||||
|
||||
block_device_mapping = {}
|
||||
for bdm in args.block_device_mapping:
|
||||
device_name, mapping = bdm.split('=', 1)
|
||||
block_device_mapping[device_name] = mapping
|
||||
|
||||
|
||||
return (args.name, image, flavor, metadata, files, key_name,
|
||||
reservation_id, min_count, max_count, user_data, \
|
||||
availability_zone, security_groups, block_device_mapping)
|
||||
@ -773,15 +773,17 @@ def _find_volume(cs, volume):
|
||||
"""Get a volume by ID."""
|
||||
return utils.find_resource(cs.volumes, volume)
|
||||
|
||||
def _find_snapshot(cs, snapshot):
|
||||
"""Get a snapshot by ID."""
|
||||
return utils.find_resource(cs.snapshots, snapshot)
|
||||
|
||||
def _find_volume_snapshot(cs, snapshot):
|
||||
"""Get a volume snapshot by ID."""
|
||||
return utils.find_resource(cs.volume_snapshots, snapshot)
|
||||
|
||||
|
||||
def _print_volume(cs, volume):
|
||||
utils.print_dict(volume._info)
|
||||
|
||||
|
||||
def _print_snapshot(cs, snapshot):
|
||||
def _print_volume_snapshot(cs, snapshot):
|
||||
utils.print_dict(snapshot._info)
|
||||
|
||||
|
||||
@ -794,7 +796,7 @@ def _translate_volume_keys(collection):
|
||||
setattr(item, to_key, item._info[from_key])
|
||||
|
||||
|
||||
def _translate_snapshot_keys(collection):
|
||||
def _translate_volume_snapshot_keys(collection):
|
||||
convert = [('displayName', 'display_name'), ('volumeId', 'volume_id')]
|
||||
for item in collection:
|
||||
keys = item.__dict__.keys()
|
||||
@ -880,19 +882,19 @@ def do_volume_detach(cs, args):
|
||||
cs.volumes.delete_server_volume(_find_server(cs, args.server).id,
|
||||
args.attachment_id)
|
||||
|
||||
def do_snapshot_list(cs, args):
|
||||
def do_volume_snapshot_list(cs, args):
|
||||
"""List all the snapshots."""
|
||||
snapshots = cs.snapshots.list()
|
||||
_translate_snapshot_keys(snapshots)
|
||||
snapshots = cs.volume_snapshots.list()
|
||||
_translate_volume_snapshot_keys(snapshots)
|
||||
utils.print_list(snapshots, ['ID', 'Volume ID', 'Status', 'Display Name',
|
||||
'Size'])
|
||||
|
||||
|
||||
@utils.arg('snapshot', metavar='<snapshot>', help='ID of the snapshot.')
|
||||
def do_snapshot_show(cs, args):
|
||||
def do_volume_snapshot_show(cs, args):
|
||||
"""Show details about a snapshot."""
|
||||
snapshot = _find_snapshot(cs, args.snapshot)
|
||||
_print_snapshot(cs, snapshot)
|
||||
snapshot = _find_volume_snapshot(cs, args.snapshot)
|
||||
_print_volume_snapshot(cs, snapshot)
|
||||
|
||||
|
||||
@utils.arg('volume_id',
|
||||
@ -900,7 +902,7 @@ def do_snapshot_show(cs, args):
|
||||
type=int,
|
||||
help='ID of the volume to snapshot')
|
||||
@utils.arg('--force',
|
||||
metavar='<force>',
|
||||
metavar='<True|False>',
|
||||
help='Optional flag to indicate whether to snapshot a volume even if its '
|
||||
'attached to an instance. (Default=False)',
|
||||
default=False)
|
||||
@ -910,9 +912,9 @@ def do_snapshot_show(cs, args):
|
||||
@utils.arg('--display_description', metavar='<display_description>',
|
||||
help='Optional snapshot description. (Default=None)',
|
||||
default=None)
|
||||
def do_snapshot_create(cs, args):
|
||||
def do_volume_snapshot_create(cs, args):
|
||||
"""Add a new snapshot."""
|
||||
cs.snapshots.create(args.volume_id,
|
||||
cs.volume_snapshots.create(args.volume_id,
|
||||
args.force,
|
||||
args.display_name,
|
||||
args.display_description)
|
||||
@ -921,9 +923,9 @@ def do_snapshot_create(cs, args):
|
||||
@utils.arg('snapshot_id',
|
||||
metavar='<snapshot_id>',
|
||||
help='ID of the snapshot to delete.')
|
||||
def do_snapshot_delete(cs, args):
|
||||
def do_volume_snapshot_delete(cs, args):
|
||||
"""Remove a snapshot."""
|
||||
snapshot = _find_snapshot(cs, args.snapshot_id)
|
||||
snapshot = _find_volume_snapshot(cs, args.snapshot_id)
|
||||
snapshot.delete()
|
||||
|
||||
|
||||
|
88
novaclient/v1_1/volume_snapshots.py
Normal file
88
novaclient/v1_1/volume_snapshots.py
Normal file
@ -0,0 +1,88 @@
|
||||
# Copyright 2011 Denali Systems, 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.
|
||||
|
||||
"""
|
||||
Volume snapshot interface (1.1 extension).
|
||||
"""
|
||||
|
||||
from novaclient import base
|
||||
|
||||
|
||||
class Snapshot(base.Resource):
|
||||
"""
|
||||
A Snapshot is a point-in-time snapshot of an openstack volume.
|
||||
"""
|
||||
def __repr__(self):
|
||||
return "<Snapshot: %s>" % self.id
|
||||
|
||||
def delete(self):
|
||||
"""
|
||||
Delete this snapshot.
|
||||
"""
|
||||
return self.manager.delete(self)
|
||||
|
||||
|
||||
class SnapshotManager(base.ManagerWithFind):
|
||||
"""
|
||||
Manage :class:`Snapshot` resources.
|
||||
"""
|
||||
resource_class = Snapshot
|
||||
|
||||
def create(self, volume_id, force=False,
|
||||
display_name=None, display_description=None):
|
||||
|
||||
"""
|
||||
Create a snapshot of the given volume.
|
||||
|
||||
:param volume_id: The ID of the volume to snapshot.
|
||||
:param force: If force is True, create a snapshot even if the volume is
|
||||
attached to an instance. Default is False.
|
||||
:param display_name: Name of the snapshot
|
||||
:param display_description: Description of the snapshot
|
||||
:rtype: :class:`Snapshot`
|
||||
"""
|
||||
body = {'snapshot': {'volume_id': volume_id,
|
||||
'force': force,
|
||||
'display_name': display_name,
|
||||
'display_description': display_description}}
|
||||
return self._create('/os-snapshots', body, 'snapshot')
|
||||
|
||||
def get(self, snapshot_id):
|
||||
"""
|
||||
Get a snapshot.
|
||||
|
||||
:param snapshot_id: The ID of the snapshot to get.
|
||||
:rtype: :class:`Snapshot`
|
||||
"""
|
||||
return self._get("/os-snapshots/%s" % snapshot_id, "snapshot")
|
||||
|
||||
def list(self, detailed=True):
|
||||
"""
|
||||
Get a list of all snapshots.
|
||||
|
||||
:rtype: list of :class:`Snapshot`
|
||||
"""
|
||||
if detailed is True:
|
||||
return self._list("/os-snapshots/detail", "snapshots")
|
||||
else:
|
||||
return self._list("/os-snapshots", "snapshots")
|
||||
|
||||
def delete(self, snapshot):
|
||||
"""
|
||||
Delete a snapshot.
|
||||
|
||||
:param snapshot: The :class:`Snapshot` to delete.
|
||||
"""
|
||||
self._delete("/os-snapshots/%s" % base.getid(snapshot))
|
@ -33,19 +33,6 @@ class Volume(base.Resource):
|
||||
"""
|
||||
return self.manager.delete(self)
|
||||
|
||||
class Snapshot(base.Resource):
|
||||
"""
|
||||
A Snapshot is a point-in-time snapshot of an openstack volume.
|
||||
"""
|
||||
def __repr__(self):
|
||||
return "<Snapshot: %s>" % self.id
|
||||
|
||||
def delete(self):
|
||||
"""
|
||||
Delete this snapshot.
|
||||
"""
|
||||
return self.manager.delete(self)
|
||||
|
||||
|
||||
class VolumeManager(base.ManagerWithFind):
|
||||
"""
|
||||
@ -143,57 +130,3 @@ class VolumeManager(base.ManagerWithFind):
|
||||
"""
|
||||
return self._delete("/servers/%s/os-volume_attachments/%s" % (server_id,
|
||||
attachment_id,))
|
||||
|
||||
|
||||
class SnapshotManager(base.ManagerWithFind):
|
||||
"""
|
||||
Manage :class:`Snapshot` resources.
|
||||
"""
|
||||
resource_class = Snapshot
|
||||
|
||||
def create(self, volume_id, force=False,
|
||||
display_name=None, display_description=None):
|
||||
|
||||
"""
|
||||
Create a snapshot of the given volume.
|
||||
|
||||
:param volume_id: The ID of the volume to snapshot.
|
||||
:param force: If force is True, create a snapshot even if the volume is
|
||||
attached to an instance. Default is False.
|
||||
:param display_name: Name of the snapshot
|
||||
:param display_description: Description of the snapshot
|
||||
:rtype: :class:`Snapshot`
|
||||
"""
|
||||
body = {'snapshot': {'volume_id': volume_id,
|
||||
'force': force,
|
||||
'display_name': display_name,
|
||||
'display_description': display_description}}
|
||||
return self._create('/os-snapshots', body, 'snapshot')
|
||||
|
||||
def get(self, snapshot_id):
|
||||
"""
|
||||
Get a snapshot.
|
||||
|
||||
:param snapshot_id: The ID of the snapshot to get.
|
||||
:rtype: :class:`Snapshot`
|
||||
"""
|
||||
return self._get("/os-snapshots/%s" % snapshot_id, "snapshot")
|
||||
|
||||
def list(self, detailed=True):
|
||||
"""
|
||||
Get a list of all snapshots.
|
||||
|
||||
:rtype: list of :class:`Snapshot`
|
||||
"""
|
||||
if detailed is True:
|
||||
return self._list("/os-snapshots/detail", "snapshots")
|
||||
else:
|
||||
return self._list("/os-snapshots", "snapshots")
|
||||
|
||||
def delete(self, snapshot):
|
||||
"""
|
||||
Delete a snapshot.
|
||||
|
||||
:param snapshot: The :class:`Snapshot` to delete.
|
||||
"""
|
||||
self._delete("/os-snapshots/%s" % base.getid(snapshot))
|
||||
|
Loading…
x
Reference in New Issue
Block a user