Class: Fog::Compute::OpenStack::KeyPair
- Defined in:
- lib/fog/openstack/models/compute/key_pair.rb
Instance Attribute Summary collapse
-
#public_key ⇒ Object
Returns the value of attribute public_key.
Attributes inherited from Model
Instance Method Summary collapse
- #destroy ⇒ Object
- #save ⇒ Object
- #writable? ⇒ Boolean
- #write(path = "#{ENV['HOME']}/.ssh/fog_#{Fog.credential.to_s}_#{name}.pem") ⇒ Object
Methods inherited from Model
#initialize, #inspect, #reload, #symbolize_keys, #to_json, #wait_for
Methods included from Attributes::ClassMethods
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
Methods included from Attributes::InstanceMethods
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires, #requires_one
Constructor Details
This class inherits a constructor from Fog::Model
Instance Attribute Details
#public_key ⇒ Object
Returns the value of attribute public_key.
17 18 19 |
# File 'lib/fog/openstack/models/compute/key_pair.rb', line 17 def public_key @public_key end |
Instance Method Details
#destroy ⇒ Object
19 20 21 22 23 24 |
# File 'lib/fog/openstack/models/compute/key_pair.rb', line 19 def destroy requires :name connection.delete_key_pair(name) true end |
#save ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fog/openstack/models/compute/key_pair.rb', line 26 def save requires :name data = if public_key connection.create_key_pair(name, public_key).body['keypair'] else connection.create_key_pair(name).body['keypair'] end new_attributes = data.reject {|key,value| !['fingerprint', 'public_key', 'name', 'private_key', 'user_id'].include?(key)} merge_attributes(new_attributes) true end |
#writable? ⇒ Boolean
53 54 55 |
# File 'lib/fog/openstack/models/compute/key_pair.rb', line 53 def writable? !!(private_key && ENV.has_key?('HOME')) end |
#write(path = "#{ENV['HOME']}/.ssh/fog_#{Fog.credential.to_s}_#{name}.pem") ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fog/openstack/models/compute/key_pair.rb', line 39 def write(path="#{ENV['HOME']}/.ssh/fog_#{Fog.credential.to_s}_#{name}.pem") if writable? split_private_key = private_key.split(/\n/) File.open(path, "w") do |f| split_private_key.each {|line| f.puts line} f.chmod 0600 end "Key file built: #{path}" else "Invalid private key" end end |