2010-10-04 17:02:08 -04:00
require 'fog/core/collection'
2011-01-14 05:20:52 -05:00
require 'fog/compute/models/aws/key_pair'
2010-03-16 18:46:21 -04:00
2009-08-13 01:33:35 -04:00
module Fog
module AWS
2010-09-08 17:40:02 -04:00
class Compute
2009-08-13 01:33:35 -04:00
class KeyPairs < Fog :: Collection
2010-11-19 16:45:45 -05:00
attribute :filters
2009-09-25 12:01:51 -04:00
attribute :key_name
2010-09-08 17:40:02 -04:00
model Fog :: AWS :: Compute :: KeyPair
2009-10-30 02:35:28 -04:00
2010-11-21 09:02:34 -05:00
# Used to create a key pair. There are 3 arguments and only name is required. You can generate a new key_pair as follows:
# AWS.key_pairs.create(:name => "test", :fingerprint => "123", :private_key => '234234')
#
# ==== Returns
#
#<Fog::AWS::Compute::KeyPair
# name="test",
# fingerprint="3a:d3:e5:17:e5:e7:f7:de:fe:db:1b:c2:55:7d:94:0b:07:2e:05:aa",
# private_key="-----BEGIN RSA PRIVATE KEY-----\nf/VtfXJ/ekTSlRS2GSItBSzMrEGoZ+EXeMOuiA7HFkDcgKt6aBiOX9Bysiyfc1rIrgWdFKqXBRJA\nrtvBPa3/32koMPV4FxG7RZrPuKLITmFoEV86M0DSLo+ErlOPuDChfrR9dk6eI17/o1VmSvYsIpDc\njvbgx+tt7ZEPvduoUag7YdnUI0f20fttsdXjMlyDg9pPOVF3/hqucqOb3t5y9lvVJJxdTnEDFSjb\nvodpaDT9+ssw4IsQsZEIvfL0hK+Lt4phbclUWfG7JVnYfdd2u4zU6Nqe0+3qoR0ZOH4/zaUko7z8\n7JMbJqs5bmdWfnQTrvbJ13545FRI/W48ZRJxqPcj0t2MzasbT4gMgtNJrSadq78RkRJjNTu4lZmK\nvJejkBZPicHvo5IRSEbDc90Rhdh0aZNifXn0d0DSV2N6Ywo2o1lwRAi3/l6XSjukyRpTPcMr14MP\ntGwS1Tvez41Oa7Y96VfsJB2xtKc6LGRFiPUg2ZAEHU15Q9bIISVzHXgdAcef1bsh8UN/fDBrT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ed6LMoCXoaQV8BdMX4xh=\n-----END RSA PRIVATE KEY-----"
#>
#
# The key_pair can be retreived by running AWS.key_pairs.get("test"). See get method below.
#
2009-09-28 00:31:15 -04:00
def initialize ( attributes )
2010-11-19 16:45:45 -05:00
self . filters || = { }
2009-09-28 00:31:15 -04:00
super
end
2010-11-21 09:02:34 -05:00
# Returns an array of all key pairs that have been created
#
# AWS.key_pairs.all
#
# ==== Returns
#
# <Fog::AWS::Compute::KeyPairs
# key_name=nil
# [
# <Fog::AWS::Compute::KeyPair
# name="test",
# fingerprint="1f:26:3d:83:e7:4f:48:74:c3:1c:e6:b3:c7:f6:ec:d8:cb:09:b3:7f",
# private_key=nil
# >
# ]
#>
#
2010-11-19 16:45:45 -05:00
def all ( filters = filters )
2010-10-11 16:45:26 -04:00
unless filters . is_a? ( Hash )
Formatador . display_line ( " [yellow][WARN] all with #{ filters . class } param is deprecated, use all('key-name' => []) instead[/] [light_black]( #{ caller . first } )[/] " )
filters = { 'key-name' = > [ * filters ] }
end
2010-11-19 16:45:45 -05:00
self . filters = filters
2010-10-04 18:46:12 -04:00
data = connection . describe_key_pairs ( filters ) . body
2010-03-06 23:02:10 -05:00
load ( data [ 'keySet' ] )
2009-08-13 01:33:35 -04:00
end
2010-11-21 09:02:34 -05:00
# Used to retreive a key pair that was created with the AWS.key_pairs.create method.
# The name is required to get the associated key_pair information.
#
# You can run the following command to get the details:
# AWS.key_pairs.get("test")
#
# ==== Returns
#
#>> AWS.key_pairs.get("test")
# <Fog::AWS::Compute::KeyPair
# name="test",
# fingerprint="1f:26:3d:83:e7:4f:48:74:c3:1c:e6:b3:c7:f6:ec:d8:cb:09:b3:7f",
# private_key=nil
# >
#
2009-09-25 12:01:51 -04:00
def get ( key_name )
2009-10-22 23:46:15 -04:00
if key_name
2010-10-04 18:46:12 -04:00
self . class . new ( :connection = > connection ) . all ( 'key-name' = > key_name ) . first
2009-10-22 23:46:15 -04:00
end
2009-09-25 12:01:51 -04:00
end
2009-08-13 01:33:35 -04:00
end
end
end
end