def list_volumes(self, volume_id=None, status=None, attach_status=None, size=None, zone=None, snapshot_id=None, show_deleted=False): """ Print a list of volumes to the screen """ filters = {} if status: filters['status'] = status else: filters['status'] = ['creating', 'available', 'in-use', 'error'] if show_deleted: filters['status'] += ['deleting', 'deleted'] if attach_status: filters['attachment.status'] = attach_status if volume_id: filters['volume-id'] = volume_id if size: filters['size'] = size if zone: filters['availability-zone'] = zone if snapshot_id: filters['snapshot-id'] = snapshot_id vols = self.get_volumes(filters=filters) vols.sort(key=lambda x: x.create_time) if vols: for vol in vols: print "volume_id: %s" % vol.id print "size: %sGB" % vol.size print "status: %s" % vol.status if vol.attachment_state(): print "attachment_status: %s" % vol.attachment_state() print "availability_zone: %s" % vol.zone if vol.snapshot_id: print "snapshot_id: %s" % vol.snapshot_id snapshots = self.get_snapshots(volume_ids=[vol.id]) if snapshots: snap_list = ' '.join([snap.id for snap in snapshots]) print 'snapshots: %s' % snap_list if vol.create_time: lt = utils.iso_to_localtime_tuple(vol.create_time) print "create_time: %s" % lt print print 'Total: %s' % len(vols)
def local_launch_time(self): ltime = utils.iso_to_localtime_tuple(self.launch_time) return time.strftime("%Y-%m-%d %H:%M:%S", ltime.timetuple())
def list_volumes(self, volume_id=None, status=None, attach_status=None, size=None, zone=None, snapshot_id=None, show_deleted=False, tags=None, name=None): """ Print a list of volumes to the screen """ filters = {} if status: filters['status'] = status else: filters['status'] = ['creating', 'available', 'in-use', 'error'] if show_deleted: filters['status'] += ['deleting', 'deleted'] if attach_status: filters['attachment.status'] = attach_status if volume_id: filters['volume-id'] = volume_id if size: filters['size'] = size if zone: filters['availability-zone'] = zone if snapshot_id: filters['snapshot-id'] = snapshot_id if tags: tagkeys = [] for tag in tags: val = tags.get(tag) if val: filters["tag:%s" % tag] = val elif tag: tagkeys.append(tag) if tagkeys: filters['tag-key'] = tagkeys if name: filters['tag:Name'] = name vols = self.get_volumes(filters=filters) vols.sort(key=lambda x: x.create_time) if vols: for vol in vols: print "volume_id: %s" % vol.id print "size: %sGB" % vol.size print "status: %s" % vol.status if vol.attachment_state(): print "attachment_status: %s" % vol.attachment_state() print "availability_zone: %s" % vol.zone if vol.snapshot_id: print "snapshot_id: %s" % vol.snapshot_id snapshots = self.get_snapshots(volume_ids=[vol.id]) if snapshots: snap_list = ' '.join([snap.id for snap in snapshots]) print 'snapshots: %s' % snap_list if vol.create_time: lt = utils.iso_to_localtime_tuple(vol.create_time) print "create_time: %s" % lt tags = [] for tag in vol.tags: val = vol.tags.get(tag) if val: tags.append("%s=%s" % (tag, val)) else: tags.append(tag) if tags: print "tags: %s" % ', '.join(tags) print print 'Total: %s' % len(vols)