awsome 0.0.17 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/awsome +2 -1
- data/lib/awsome/ec2.rb +6 -0
- data/lib/awsome/ec2/instance.rb +4 -0
- data/lib/awsome/executor.rb +7 -0
- data/lib/awsome/instance_requirement.rb +4 -0
- data/lib/awsome/requirements.rb +42 -2
- metadata +1 -1
data/bin/awsome
CHANGED
@@ -20,8 +20,9 @@ OptionParser.new do |opts|
|
|
20
20
|
end
|
21
21
|
end.parse!
|
22
22
|
|
23
|
-
instances = Awsome::Ec2.describe_instances('instance-state-name' => 'running')
|
24
23
|
requirements = Awsome::Requirements.from_yaml_file(requirements_file)
|
24
|
+
filters = {'instance-state-name' => 'running'}.merge(requirements.filters)
|
25
|
+
instances = Awsome::Ec2.describe_instances(filters)
|
25
26
|
matchmaker = Awsome::Matchmaker.new(instances, requirements)
|
26
27
|
executor = Awsome::Executor.new(matchmaker.matches)
|
27
28
|
|
data/lib/awsome/ec2.rb
CHANGED
@@ -47,6 +47,12 @@ module Awsome
|
|
47
47
|
Awsome::Ec2::Instance.new(Awsome.execute(cmd, columns: @@run_instance_fields, filter: /^INSTANCE/).first)
|
48
48
|
end
|
49
49
|
|
50
|
+
def self.create_tags(resource_id, tags)
|
51
|
+
tags = tags.collect { |k, v| v ? "--tag #{k}=#{v}" : "--tag #{k}" }
|
52
|
+
cmd = command('ec2-create-tags', resource_id, *tags)
|
53
|
+
Awsome.execute(cmd)
|
54
|
+
end
|
55
|
+
|
50
56
|
@@describe_instance_fields = %w(
|
51
57
|
reservation_identifier
|
52
58
|
reservation_id
|
data/lib/awsome/ec2/instance.rb
CHANGED
@@ -76,6 +76,10 @@ module Awsome
|
|
76
76
|
Awsome::Ec2.terminate_instances(@properties['instance_id'])
|
77
77
|
end
|
78
78
|
|
79
|
+
def create_tags(tags)
|
80
|
+
Awsome::Ec2.create_tags(@properties['instance_id'], tags)
|
81
|
+
end
|
82
|
+
|
79
83
|
private
|
80
84
|
def reload!
|
81
85
|
instance = Awsome::Ec2.describe_instances('instance-id' => @properties['instance_id']).first
|
data/lib/awsome/executor.rb
CHANGED
@@ -16,6 +16,7 @@ module Awsome
|
|
16
16
|
|
17
17
|
run
|
18
18
|
wait_for_ssh
|
19
|
+
tag_instances
|
19
20
|
reattach_volumes
|
20
21
|
deploy
|
21
22
|
terminate
|
@@ -46,6 +47,12 @@ module Awsome
|
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
50
|
+
def tag_instances
|
51
|
+
instances_to_use do |instance, requirement|
|
52
|
+
instance.create_tags(requirement.tags)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
49
56
|
def reattach_volumes
|
50
57
|
instances_to_use do |instance, requirement|
|
51
58
|
instance.reattach_volumes(*requirement.volumes_to_attach(instance))
|
data/lib/awsome/requirements.rb
CHANGED
@@ -3,18 +3,58 @@ require 'yaml'
|
|
3
3
|
module Awsome
|
4
4
|
class Requirements
|
5
5
|
attr_reader :options
|
6
|
+
|
6
7
|
def initialize(requirements_hash)
|
7
8
|
@requirements = requirements_hash.clone
|
8
9
|
@options = Awsome::RequirementsOptions.new(@requirements)
|
9
10
|
end
|
11
|
+
|
10
12
|
def self.from_yaml_file(filename)
|
11
13
|
new(YAML::load(File.open(filename, 'r').read))
|
12
14
|
end
|
15
|
+
|
13
16
|
def instances
|
14
|
-
@requirements['instances'].collect do |
|
15
|
-
|
17
|
+
@requirements['instances'].collect do |req|
|
18
|
+
instance = req.clone
|
19
|
+
inflate!(instance, instance.delete('traits'))
|
20
|
+
Awsome::InstanceRequirement.new(instance, @options)
|
16
21
|
end
|
17
22
|
end
|
23
|
+
|
24
|
+
def filters
|
25
|
+
@requirements['filters'] || {}
|
26
|
+
end
|
27
|
+
|
28
|
+
def traits
|
29
|
+
@requirements['traits'] || {}
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def find_trait(name)
|
35
|
+
traits[name] || raise "no trait called #{name}"
|
36
|
+
end
|
37
|
+
|
38
|
+
# implements trait inheritance
|
39
|
+
def inflate!(instance, names)
|
40
|
+
inflated = req.clone
|
41
|
+
|
42
|
+
# prevents loops
|
43
|
+
merged = Set[]
|
44
|
+
while names && names.any?
|
45
|
+
name = names.shift
|
46
|
+
if merged.add?(name)
|
47
|
+
trait = find_trait(name).clone
|
48
|
+
|
49
|
+
# extract trait supertraits for merging
|
50
|
+
names += trait.delete('traits') || []
|
51
|
+
|
52
|
+
inflated = trait.merge(inflated)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
inflated
|
57
|
+
end
|
18
58
|
end
|
19
59
|
end
|
20
60
|
|