Sha256: afa6afe8630da8b3bdca61de4452930371daaf48c81194ae997dfeee57617a8e

Contents?: true

Size: 1.94 KB

Versions: 27

Compression:

Stored size: 1.94 KB

Contents

class SshKeyPair < CloudstackCli::Base

  desc "list", 'list ssh key pairs'
  option :listall, default: true
  option :account
  option :project
  def list
    resolve_account
    resolve_project
    pairs = client.list_ssh_key_pairs(options)
    if pairs.size < 1
      say "No ssh key pairs found."
    else
      table = [["Name", "Fingerprint"]]
      pairs.each do |pair|
        table << [pair['name'], pair['fingerprint']]
      end
      print_table table
    end
  end

  desc 'create NAME', 'create ssh key pair'
  option :account
  option :project
  def create(name)
    resolve_account
    resolve_project
    options[:name] = name
    pair = client.create_ssh_key_pair(options)
    say "Name : #{pair['name']}"
    say "Fingerprint : #{pair['fingerprint']}"
    say "Privatekey:"
    say pair['privatekey']
  end

  desc 'register NAME', 'register ssh key pair'
  option :account
  option :project
  option :public_key, required: true, desc: "path to public_key file"
  def register(name)
    resolve_account
    resolve_project
    options[:name] = name
    if File.exist?(options[:public_key])
      public_key = IO.read(options[:public_key])
    else
      say("Can't open public key #{options[:public_key]}", :red)
      exit 1
    end
    pair = client.register_ssh_key_pair(options)
    say "Name : #{pair['name']}"
    say "Fingerprint : #{pair['fingerprint']}"
    say "Privatekey:"
    say pair['privatekey']
  rescue => e
    say "Failed to register key: #{e.message}", :red
    exit 1
  end

  desc 'delete NAME', 'delete ssh key pair'
  option :account
  option :project
  option :force, aliases: '-f', desc: "delete without asking"
  def delete(name)
    resolve_account
    resolve_project
    options[:name] = name
    if options[:force] || yes?("Delete ssh key pair #{name}?", :yellow)
      if client.delete_ssh_key_pair(options)['success'] == "true"
        say("OK", :green)
      else
        say("Failed", :red)
        exit 1
      end
    end
  end

end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
cloudstack-cli-1.4.1 lib/cloudstack-cli/commands/ssh_key_pair.rb
cloudstack-cli-1.4.0 lib/cloudstack-cli/commands/ssh_key_pair.rb
cloudstack-cli-1.3.3 lib/cloudstack-cli/commands/ssh_key_pair.rb
cloudstack-cli-1.3.2 lib/cloudstack-cli/commands/ssh_key_pair.rb
cloudstack-cli-1.3.1 lib/cloudstack-cli/commands/ssh_key_pair.rb
cloudstack-cli-1.3.0 lib/cloudstack-cli/commands/ssh_key_pair.rb
cloudstack-cli-1.2.7 lib/cloudstack-cli/commands/ssh_key_pair.rb
cloudstack-cli-1.2.6 lib/cloudstack-cli/commands/ssh_key_pair.rb
cloudstack-cli-1.2.5 lib/cloudstack-cli/commands/ssh_key_pair.rb
cloudstack-cli-1.2.4 lib/cloudstack-cli/commands/ssh_key_pair.rb
cloudstack-cli-1.2.3 lib/cloudstack-cli/commands/ssh_key_pair.rb
cloudstack-cli-1.2.1 lib/cloudstack-cli/commands/ssh_key_pair.rb
cloudstack-cli-1.2.0 lib/cloudstack-cli/commands/ssh_key_pair.rb
cloudstack-cli-1.1.0 lib/cloudstack-cli/commands/ssh_key_pair.rb
cloudstack-cli-1.0.8 lib/cloudstack-cli/commands/ssh_key_pair.rb
cloudstack-cli-1.0.7 lib/cloudstack-cli/commands/ssh_key_pair.rb
cloudstack-cli-1.0.6 lib/cloudstack-cli/commands/ssh_key_pair.rb
cloudstack-cli-1.0.5 lib/cloudstack-cli/commands/ssh_key_pair.rb
cloudstack-cli-1.0.4 lib/cloudstack-cli/commands/ssh_key_pair.rb
cloudstack-cli-1.0.3 lib/cloudstack-cli/commands/ssh_key_pair.rb