Class: Knifecosmic::CosmicVolumeDelete
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Knifecosmic::CosmicVolumeDelete
- Includes:
- Chef::Knife::KnifecosmicBase
- Defined in:
- lib/chef/knife/cosmic_volume_delete.rb
Instance Method Summary collapse
Methods included from Chef::Knife::KnifecosmicBase
Instance Method Details
#confirm_action(question) ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/chef/knife/cosmic_volume_delete.rb', line 86 def confirm_action(question) return true if locate_config_value(:yes) result = ui.ask_question(question, :default => "Y" ) if result == "Y" || result == "y" then return true else return false end end |
#run ⇒ Object
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 |
# File 'lib/chef/knife/cosmic_volume_delete.rb', line 35 def run @name_args.each do |volume_name| volume = connection.get_volume(volume_name) if !volume then ui.error("Volume '#{volume_name}' not found") next end if vmn = volume['vmname'] ui.error("Volume '#{volume_name}' attached to VM '#{vmn}'") ui.error("You should detach it from VM to delete the volume.") next end show_object_details(volume) result = confirm_action("Do you really want to delete this volume") if result print "#{ui.color("Waiting for deletion", :magenta)}" connection.delete_volume(volume_name) puts "\n" ui.msg("Deleted volume #{volume_name}") end end end |
#show_object_details(v) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/chef/knife/cosmic_volume_delete.rb', line 64 def show_object_details(v) return if locate_config_value(:yes) object_fields = [] object_fields << ui.color("Name:", :cyan) object_fields << v['name'].to_s object_fields << ui.color("Account:", :cyan) object_fields << v['account'] object_fields << ui.color("Domain:", :cyan) object_fields << v['domain'] object_fields << ui.color("State:", :cyan) object_fields << v['state'] object_fields << ui.color("VMName:", :cyan) object_fields << v['vmname'] object_fields << ui.color("VMState:", :cyan) object_fields << v['vmstate'] puts "\n" puts ui.list(object_fields, :uneven_columns_across, 2) puts "\n" end |