Class: Chef::Knife::CloudstackVolumeList
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::CloudstackVolumeList
- Includes:
- CloudstackBase
- Defined in:
- lib/chef/knife/cloudstack_volumes_list.rb
Instance Method Summary collapse
Methods included from CloudstackBase
#connection, included, #locate_config_value, #msg_pair, #validate!
Instance Method Details
#run ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/chef/knife/cloudstack_volumes_list.rb', line 29 def run $stdout.sync = true validate! volume_list = [ ui.color('ID', :bold), ui.color('Name', :bold), ui.color('Size (in GB)', :bold), ui.color('Type', :bold), ui.color('Virtual Machine', :bold), ui.color('State', :bold) ] response = connection.list_volumes['listvolumesresponse'] if volumes = response['volume'] volumes.each do |volume| volume_list << volume['id'].to_s volume_list << volume['name'].to_s volume_size = volume['size'] volume_size = (volume_size/1024/1024/1024) volume_list << volume_size.to_s volume_list << volume['type'] if (volume['vmdisplayname'].nil?) volume_list << ' ' else volume_list << volume['vmdisplayname'] end volume_list << begin state = volume['state'].to_s.downcase case state when 'allocated' ui.color(state, :red) when 'pending' ui.color(state, :yellow) else ui.color(state, :green) end end end puts ui.list(volume_list, :uneven_columns_across, 6) end end |