Class: AWS::EC2::KeyPair

Inherits:
Resource
  • Object
show all
Defined in:
lib/aws/ec2/key_pair.rb

Overview

Represents an EC2 key pair.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ KeyPair



22
23
24
25
26
27
# File 'lib/aws/ec2/key_pair.rb', line 22

def initialize name, options = {}
  @name = name.to_s
  @fingerprint = options[:fingerprint]
  @private_key = options[:private_key]
  super
end

Instance Attribute Details

#nameString (readonly)



30
31
32
# File 'lib/aws/ec2/key_pair.rb', line 30

def name
  @name
end

Instance Method Details

#deletetrue

Deletes this key pair from EC2.



61
62
63
64
# File 'lib/aws/ec2/key_pair.rb', line 61

def delete
  client.delete_key_pair(:key_name => name)  
  true
end

#exists?Boolean



33
34
35
36
37
# File 'lib/aws/ec2/key_pair.rb', line 33

def exists?
  !client.describe_key_pairs(:filters => [{ :name => "key-name",
                                          :values => [name] }]).
    key_set.empty?
end

#fingerprintString



40
# File 'lib/aws/ec2/key_pair.rb', line 40

def fingerprint; end

#private_keyString

Note:

Only call this method on newly created keys.

Returns the private key. Raises an exception if called against an existing key. You can only get the private key at the time of creation.



52
53
54
55
56
57
# File 'lib/aws/ec2/key_pair.rb', line 52

def private_key
  unless @private_key
    raise 'you can only get the private key for just-created keypairs'
  end
  @private_key
end