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
33
import euca2ools.commands.eucacommand
34
from boto.roboto.param import Param
36
class DescribeVolumes(euca2ools.commands.eucacommand.EucaCommand):
38
APIVersion = '2010-08-31'
39
Description = 'Shows information about volumes.'
40
Args = [Param(name='volume_id', ptype='string',
41
doc='volumes to describe',
42
cardinality='+', optional=True)]
43
Filters = [Param(name='attachment.attach-time', ptype='string',
44
doc='Time stamp when the attachment initiated.'),
45
Param(name='attachment.delete-on-termination', ptype='string',
46
doc="""Whether the volume will be deleted on
47
instance termination."""),
48
Param(name='attachment.device', ptype='string',
49
doc="""How the volume is exposed to the
50
instance (e.g., /dev/sda1)."""),
51
Param(name='attachment.instance-id', ptype='string',
52
doc='ID of the instance the volume is attached to.'),
53
Param(name='attachment.status', ptype='datetime',
54
doc="""Attachment state.
55
Valid Values: attaching | attached | detaching | detached"""),
56
Param(name='availability-zone', ptype='string',
57
doc='Availability Zone in which the volume was created.'),
58
Param(name='create-time', ptype='datetime',
59
doc='Time stamp when the volume was created.'),
60
Param(name='size', ptype='integer',
61
doc='Size of the volume, in GiB (e.g., 20).'),
62
Param(name='snapshot-id', ptype='string',
63
doc='Snapshot from which the volume was created.'),
64
Param(name='status', ptype='string',
65
doc="""Status of the volume.
66
Valid values: pending | completed | error."""),
67
Param(name='tag-key', ptype='string',
68
doc='Key of a tag assigned to the resource.'),
69
Param(name='tag-value', ptype='string',
70
doc='Value of a tag assigned to the resource.'),
71
Param(name='tag:key', ptype='string',
72
doc="""Filters the results based on a specific
73
tag/value combination."""),
74
Param(name='volume-id', ptype='string',
75
doc='ID of the volume the snapshot is for')]
77
def display_volumes(self, volumes):
78
for volume in volumes:
79
volume_string = '%s\t ' % volume.id
81
volume_string += '%d' % volume.size
82
if volume.snapshot_id:
83
volume_string += '\t%s' % volume.snapshot_id
87
az = getattr(volume, 'availabilityZone', object)
91
volume_string += '\t%s' % az
93
volume_string += '\t%s\t%s' % (volume.status,
95
print 'VOLUME\t%s' % volume_string
96
if volume.status == 'in-use':
97
attachment_string = '%s\t%s\t%s\t%s' % (volume.id,
98
volume.attach_data.instance_id,
99
volume.attach_data.device,
100
volume.attach_data.attach_time)
101
print 'ATTACHMENT\t%s' % attachment_string
104
conn = self.make_connection_cli()
105
return self.make_request_cli(conn, 'get_all_volumes',
106
volume_ids=self.volume_id)
109
volumes = self.main()
110
self.display_volumes(volumes)