Class: Opsicle::ExecuteRecipes
- Inherits:
-
Object
- Object
- Opsicle::ExecuteRecipes
show all
- Includes:
- DeployHelper
- Defined in:
- lib/opsicle/commands/execute_recipes.rb
Constant Summary
collapse
- NoInstanceError =
Class.new(StandardError)
Instance Attribute Summary collapse
Instance Method Summary
collapse
#launch_stack_monitor, #open_deploy
Constructor Details
Returns a new instance of ExecuteRecipes.
8
9
10
11
|
# File 'lib/opsicle/commands/execute_recipes.rb', line 8
def initialize(environment)
@environment = environment
@client = Client.new(environment)
end
|
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
6
7
8
|
# File 'lib/opsicle/commands/execute_recipes.rb', line 6
def client
@client
end
|
#recipes ⇒ Object
Returns the value of attribute recipes.
6
7
8
|
# File 'lib/opsicle/commands/execute_recipes.rb', line 6
def recipes
@recipes
end
|
Instance Method Details
#determine_from_eip ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/opsicle/commands/execute_recipes.rb', line 49
def determine_from_eip
if instance = Opsicle::Instances.find_by_eip(client).first
Array(instance[:instance_id])
else
raise NoInstanceError, "Unable to find instances with elastic IPs"
end
end
|
#determine_from_ips(ips) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/opsicle/commands/execute_recipes.rb', line 41
def determine_from_ips(ips)
if instances = Opsicle::Instances.find_by_ip(client, ips)
instances.map { |instance| instance[:instance_id] }
else
raise NoInstanceError, "Unable to find instances with given IP"
end
end
|
#determine_from_layers(layers) ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/opsicle/commands/execute_recipes.rb', line 57
def determine_from_layers(layers)
if instances = Opsicle::Layer.instance_ids(client, layers)
instances
else
raise NoInstanceError, "Unable to find instances in specified layers"
end
end
|
#determine_instance_ids(options) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/opsicle/commands/execute_recipes.rb', line 29
def determine_instance_ids(options)
if options[:instance_ids]
options[:instance_ids]
elsif options[:layers]
determine_from_layers(options[:layers])
elsif options[:ip_addresses]
determine_from_ips(options[:ip_addresses])
elsif options[:eip]
determine_from_eip
end
end
|
#execute(options = { monitor: true }) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/opsicle/commands/execute_recipes.rb', line 13
def execute(options={ monitor: true })
Output.say "Starting OpsWorks chef run..."
command_args = {}
command_args["recipes"] = options[:recipes]
command_opts = {}
command_opts["instance_ids"] = determine_instance_ids(options)
command_opts["custom_json"] = options.delete(:json) if options[:json]
command_opts.reject! {|key,value| value.nil?}
response = client.run_command('execute_recipes', command_args, command_opts)
launch_stack_monitor(response, options)
end
|