1
# Software License Agreement (BSD License)
3
# Copyright (c) 2009-2011, Eucalyptus Systems, Inc.
6
# Redistribution and use of this software in source and binary forms, with or
7
# without modification, are permitted provided that the following conditions
10
# Redistributions of source code must retain the above
11
# copyright notice, this list of conditions and the
12
# following disclaimer.
14
# Redistributions in binary form must reproduce the above
15
# copyright notice, this list of conditions and the
16
# following disclaimer in the documentation and/or other
17
# materials provided with the distribution.
19
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
# POSSIBILITY OF SUCH DAMAGE.
31
# Author: Neil Soman neil@eucalyptus.com
32
# Mitch Garnaat mgarnaat@eucalyptus.com
34
import euca2ools.commands.eucacommand
35
from boto.roboto.param import Param
37
class DescribeSnapshots(euca2ools.commands.eucacommand.EucaCommand):
39
APIVersion = '2010-08-31'
40
Description = 'Shows information about snapshots.'
41
Options = [Param(name='owner', short_name='o', long_name='owner',
42
optional=True, ptype='string',
43
doc='ID of the user who owns the snapshot.'),
44
Param(name='restorable_by',
45
short_name='r', long_name='restorable-by',
46
optional=True, ptype='string',
47
doc="""restorable by (user id of the user that can
48
create volumes from the snapshot).""")]
49
Args = [Param(name='snapshot', ptype='string',
50
doc='snapshots to describe',
51
cardinality='+', optional=True)]
52
Filters = [Param(name='description', ptype='string',
53
doc='Description of the snapshot'),
54
Param(name='owner-alias', ptype='string',
55
doc="""AWS account alias (e.g., amazon or self) or
56
AWS account ID that owns the snapshot."""),
57
Param(name='owner-id', ptype='string',
58
doc='AWS account ID of the snapshot owner.'),
59
Param(name='progress', ptype='string',
60
doc='The progress of the snapshot, in percentage.'),
61
Param(name='snapshot-id', ptype='string',
62
doc='The ID of the snapshot.'),
63
Param(name='start-time', ptype='datetime',
64
doc='Time stamp when the snapshot was initiated.'),
65
Param(name='status', ptype='string',
66
doc="""Status of the snapshost.
67
Valid values: pending | completed | error."""),
68
Param(name='tag-key', ptype='string',
69
doc='Key of a tag assigned to the resource.'),
70
Param(name='tag-value', ptype='string',
71
doc='Value of a tag assigned to the resource.'),
72
Param(name='tag:key', ptype='string',
73
doc="""Filters the results based on a specific
74
tag/value combination."""),
75
Param(name='volume-id', ptype='string',
76
doc='ID of the volume the snapshot is for'),
77
Param(name='volume-size', ptype='integer',
78
doc='The size of the volume, in GiB.')]
80
def display_snapshots(self, snapshots):
81
for snapshot in snapshots:
82
snapshot_string = '%s\t%s\t%s\t%s\t%s' % (snapshot.id,
83
snapshot.volume_id, snapshot.status,
84
snapshot.start_time, snapshot.progress)
85
print 'SNAPSHOT\t%s' % snapshot_string
88
conn = self.make_connection_cli()
89
return self.make_request_cli(conn, 'get_all_snapshots',
90
snapshot_ids=self.snapshot,
92
restorable_by=self.restorable_by)
95
snapshots = self.main()
96
self.display_snapshots(snapshots)