Class: Fog::AWS::Compute::Servers
- Inherits:
-
Collection
- Object
- Array
- Collection
- Fog::AWS::Compute::Servers
- Defined in:
- lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/servers.rb
Instance Attribute Summary
Attributes inherited from Collection
Instance Method Summary collapse
- #all(filters = self.filters) ⇒ 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.
14 15 16 17 |
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/servers.rb', line 14 def initialize(attributes) self.filters ||= {} super end |
Instance Method Details
#all(filters = self.filters) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/servers.rb', line 19 def all(filters = self.filters) unless filters.is_a?(Hash) Formatador.display_line("[yellow][WARN] all with #{filters.class} param is deprecated, use all('instance-id' => []) instead[/] [light_black](#{caller.first})[/]") filters = {'instance-id' => [*filters]} end self.filters = filters data = connection.describe_instances(filters).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
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/servers.rb', line 35 def bootstrap(new_attributes = {}) server = connection.servers.new(new_attributes) unless new_attributes[:key_name] # first or create fog_#{credential} keypair name = Fog.respond_to?(:credential) && Fog.credential || :default unless server.key_pair = connection.key_pairs.get("fog_#{name}") server.key_pair = connection.key_pairs.create( :name => "fog_#{name}", :public_key => server.public_key ) end 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.save server.wait_for { ready? } server.setup(:key_data => [server.private_key]) server end |
#get(server_id) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/servers.rb', line 67 def get(server_id) if server_id self.class.new(:connection => connection).all('instance-id' => server_id).first end rescue Fog::Errors::NotFound nil end |