Class: Fog::AWS::Compute::Servers
- Inherits:
-
Collection
- Object
- Array
- Collection
- Fog::AWS::Compute::Servers
- Defined in:
- lib/fog/aws/models/compute/servers.rb
Instance Attribute Summary collapse
Attributes inherited from Collection
Instance Method Summary collapse
- #all(server_id = @server_id) ⇒ Object
- #bootstrap(new_attributes = {}) ⇒ Object
- #get(server_id) ⇒ Object
-
#initialize(attributes) ⇒ Servers
constructor
A new instance of Servers.
Methods inherited from Collection
#clear, #create, #inspect, #load, model, #model, #new, #reload, #table, #to_json
Methods included from Fog::Attributes::ClassMethods
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
Methods included from Fog::Attributes::InstanceMethods
#_dump, #attributes, #identity, #identity=, #merge_attributes, #new_record?, #requires
Constructor Details
#initialize(attributes) ⇒ Servers
Returns a new instance of Servers.
16 17 18 19 |
# File 'lib/fog/aws/models/compute/servers.rb', line 16 def initialize(attributes) @server_id ||= [] super end |
Instance Attribute Details
#private_key_path ⇒ Object
68 69 70 |
# File 'lib/fog/aws/models/compute/servers.rb', line 68 def private_key_path @private_key_path ||= Fog.credentials[:private_key_path] end |
#public_key_path ⇒ Object
72 73 74 |
# File 'lib/fog/aws/models/compute/servers.rb', line 72 def public_key_path @public_key_path ||= Fog.credentials[:public_key_path] end |
Instance Method Details
#all(server_id = @server_id) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fog/aws/models/compute/servers.rb', line 21 def all(server_id = @server_id) @server_id = server_id data = connection.describe_instances(server_id).body load( data['reservationSet'].map do |reservation| reservation['instancesSet'].map do |instance| instance.merge(:groups => reservation['groupSet']) end end.flatten ) end |
#bootstrap(new_attributes = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/fog/aws/models/compute/servers.rb', line 33 def bootstrap(new_attributes = {}) # first or create fog_#{credential} keypair unless key_pair = connection.key_pairs.get("fog_#{Fog.credential}") public_key = File.read(public_key_path) key_pair = connection.key_pairs.create(:name => "fog_#{Fog.credential}", :public_key => public_key) end # make sure port 22 is open in the first security group security_group = connection.security_groups.get(server.groups.first) = security_group..detect do || ['ipRanges'].first && ['ipRanges'].first['cidrIp'] == '0.0.0.0/0' && ['fromPort'] == 22 && ['ipProtocol'] == 'tcp' && ['toPort'] == 22 end unless security_group.(22..22) end server.wait_for { ready? } private_key = File.read(private_key_path) server.setup(:key_data => [private_key]) server.merge_attributes(:private_key_path => private_key_path, :public_key_path => public_key_path) server end |