class Awscli::EC2::KeyPairs
Public Class Methods
new(connection)
click to toggle source
# File lib/awscli/ec2.rb, line 243 def initialize(connection) @conn = connection end
Public Instance Methods
create_keypair(options)
click to toggle source
# File lib/awscli/ec2.rb, line 251 def create_keypair(options) #validate keypair Fog.credential = 'awscli' abort "KeyPair '#{options[:name]}' already exists" if @conn.key_pairs.get(options[:name]) kp = @conn.key_pairs.create(options) puts "Created keypair: #{options[:name]}" p kp.write #save the key to disk end
delete_keypair(keypair)
click to toggle source
# File lib/awscli/ec2.rb, line 260 def delete_keypair(keypair) abort "KeyPair '#{keypair}' does not exist" unless @conn.key_pairs.get(keypair) @conn.key_pairs.get(keypair).destroy puts "Deleted Keypair: #{keypair}" end
fingerprint(keypair)
click to toggle source
# File lib/awscli/ec2.rb, line 266 def fingerprint(keypair) response = @conn.key_pairs.get(keypair) abort "Cannot find key pair: #{keypair}" unless response puts "Fingerprint for the key (#{keypair}): #{response.fingerprint}" end
import_keypair(options)
click to toggle source
# File lib/awscli/ec2.rb, line 272 def import_keypair(options) #validate if the file exists private_key_path = if options[:private_key_path] File.expand_path(options[:private_key_path]) else File.expand_path("~/.ssh/#{options[:name]}") end public_key_path = if options[:public_key_path] File.expand_path(options[:public_key_path]) else File.expand_path("~/.ssh/#{options[:name]}.pub") end abort "Cannot find private_key_path: #{private_key_path}" unless File.exist?(private_key_path) abort "Cannot find public_key_path: #{public_key_path}" unless File.exist?(public_key_path) #validate if the key pair name exists Fog.credentials = Fog.credentials.merge({ :private_key_path => private_key_path, :public_key_path => public_key_path }) @conn.import_key_pair(options[:name], IO.read(public_key_path)) if @conn.key_pairs.get(options[:name]).nil? puts "Imported KeyPair with name: #{options[:name]} sucessfully, using public_key: #{public_key_path} and private_key: #{private_key_path}" end
list_keypairs()
click to toggle source
# File lib/awscli/ec2.rb, line 247 def list_keypairs @conn.key_pairs.table end