Class: Capistrano::Elobuff::Ec2::Compute
- Inherits:
-
Object
- Object
- Capistrano::Elobuff::Ec2::Compute
- Defined in:
- lib/capistrano/elobuff/ec2/compute.rb
Instance Method Summary collapse
- #available_servers ⇒ Object
- #available_servers_in_role(role) ⇒ Object
- #available_servers_in_zone(zone) ⇒ Object
- #connection ⇒ Object
- #create_server(ami, type, security_groups, availability_zone, name, roles) ⇒ Object
- #find_server(id) ⇒ Object
-
#initialize(application, access_key_id, secret_access_key) ⇒ Compute
constructor
A new instance of Compute.
- #roles ⇒ Object
- #servers ⇒ Object
- #update_server_tags(server) ⇒ Object
- #zones ⇒ Object
Constructor Details
#initialize(application, access_key_id, secret_access_key) ⇒ Compute
Returns a new instance of Compute.
7 8 9 10 11 |
# File 'lib/capistrano/elobuff/ec2/compute.rb', line 7 def initialize(application, access_key_id, secret_access_key) @application = application @access_key_id = access_key_id @secret_access_key = secret_access_key end |
Instance Method Details
#available_servers ⇒ Object
25 26 27 |
# File 'lib/capistrano/elobuff/ec2/compute.rb', line 25 def available_servers servers.select {|s| s.available? } end |
#available_servers_in_role(role) ⇒ Object
37 38 39 |
# File 'lib/capistrano/elobuff/ec2/compute.rb', line 37 def available_servers_in_role(role) available_servers.select {|s| s.roles.include? role } end |
#available_servers_in_zone(zone) ⇒ Object
41 42 43 |
# File 'lib/capistrano/elobuff/ec2/compute.rb', line 41 def available_servers_in_zone(zone) available_servers.select {|s| s.zone == zone } end |
#connection ⇒ Object
13 14 15 |
# File 'lib/capistrano/elobuff/ec2/compute.rb', line 13 def connection @connection ||= Fog::Compute.new provider: "AWS", aws_access_key_id: @access_key_id, aws_secret_access_key: @secret_access_key end |
#create_server(ami, type, security_groups, availability_zone, name, roles) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/capistrano/elobuff/ec2/compute.rb', line 45 def create_server(ami, type, security_groups, availability_zone, name, roles) puts "Creating server" server = connection.servers.create( image_id: ami, flavor_id: type, groups: security_groups, availability_zone: availability_zone, tags: { "Name" => name, "#{@application}" => roles }) server.wait_for { ready? } Server.new(server, @application) end |
#find_server(id) ⇒ Object
21 22 23 |
# File 'lib/capistrano/elobuff/ec2/compute.rb', line 21 def find_server(id) servers.select {|s| (s.id == id) || (s.name == id) || (s.address == id) }.first || die("Could not find server with id, name or address: #{id}") end |
#roles ⇒ Object
29 30 31 |
# File 'lib/capistrano/elobuff/ec2/compute.rb', line 29 def roles available_servers.map {|s| s.roles }.flatten.uniq end |
#servers ⇒ Object
17 18 19 |
# File 'lib/capistrano/elobuff/ec2/compute.rb', line 17 def servers @servers ||= connection.servers.select {|s| s..keys.include? @application.to_s }.map {|s| Server.new s, @application } end |
#update_server_tags(server) ⇒ Object
57 58 59 |
# File 'lib/capistrano/elobuff/ec2/compute.rb', line 57 def (server) connection. server.id, server. end |
#zones ⇒ Object
33 34 35 |
# File 'lib/capistrano/elobuff/ec2/compute.rb', line 33 def zones available_servers.map {|s| s.zone }.flatten.uniq end |