Class: CapAwsEc2

Inherits:
Object
  • Object
show all
Defined in:
lib/cap-aws-ec2.rb,
lib/cap-aws-ec2/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Instance Method Summary collapse

Constructor Details

#initialize(key, secret, aws_region, project, environment) ⇒ CapAwsEc2

Returns a new instance of CapAwsEc2.



13
14
15
16
17
18
19
# File 'lib/cap-aws-ec2.rb', line 13

def initialize(key, secret, aws_region, project, environment)
  @key = key
  @secret = secret
  @region = aws_region
  @project = project.to_s
  @environment = environment.to_s
end

Instance Method Details

#executeObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cap-aws-ec2.rb', line 21

def execute
  instances = ec2.describe_instances(instance_ids: tagged_instances,
                                     filters: [
                                       {name: "instance-state-name", values: ["running"]},
                                       {name: "tag:Env", values: [@environment]},
                                       {name: "tag:Project", values: [@project]},
                                       {name: "tag-key", values: ["Roles"]}
                                      ]
                                    )
  instances = instances.reservations.map {|r| r.instances }.flatten

  server_definitions(instances)
end