Class: Chef::Knife::CloudstackKeypairDelete

Inherits:
Chef::Knife
  • Object
show all
Includes:
CloudstackBase
Defined in:
lib/chef/knife/cloudstack_keypair_delete.rb

Instance Method Summary collapse

Methods included from CloudstackBase

#connection, included, #locate_config_value, #msg_pair, #validate!

Instance Method Details

#runObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/chef/knife/cloudstack_keypair_delete.rb', line 30

def run
  if @name_args.nil? || @name_args.empty?
    puts "#{ui.color("Please provide a keypair name.", :red)}"
  end

  @name_args.each do |keypair_name|
    response = connection.list_ssh_key_pairs('name' => keypair_name)
    fingerprint = response['listsshkeypairsresponse']['sshkeypair'].first['fingerprint']
    real_keypair_name = response['listsshkeypairsresponse']['sshkeypair'].first['name']
    puts "#{ui.color("Name", :red)}: #{real_keypair_name}"
    puts "#{ui.color("Fingerprint", :red)}: #{fingerprint}"
    puts "\n"
    confirm("#{ui.color("Do you really want to delete this keypair?", :red)}")
    connection.delete_ssh_key_pair(real_keypair_name)
    ui.warn("Deleted SSH keypair #{real_keypair_name}")
  end
end