63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# File 'lib/ec2-instance-manager/launch.rb', line 63
def start_launch_plan
ami_ids_to_launch = []; detailed_ami_ids_to_launch = []
puts
puts "Your Launch Plan:"
if config[@customer_key]["launch_plan"] and config[@customer_key]["launch_plan"].any?
launch_plan_groups = config[@customer_key]["launch_plan"].keys.sort
if self.options[:group]
puts
puts "Existing groups: #{launch_plan_groups.join(", ")}"
if launch_plan_groups.include?(self.options[:group])
puts "Targeted Group: #{self.options[:group]}"
config[@customer_key]["launch_plan"][self.options[:group]].each do |ami_id|
if (ami_id[1].is_a?(Fixnum))
puts "#{ami_id[0]} => #{ami_id[1]} Instances to launch"
ami_ids_to_launch << [ami_id[0], ami_id[1]]
else
puts "#{ami_id[0]} => Detailed launch: #{ami_id[1]}"
detailed_ami_ids_to_launch << [ami_id[0], ami_id[1]]
end
end
else
puts white("Targeted Launch plan group '#{self.options[:group]}' not found.")
end
else
launch_plan_groups.each do |launch_plan_group|
puts
puts "Group: #{launch_plan_group}"
if config[@customer_key]["launch_plan"][launch_plan_group] and config[@customer_key]["launch_plan"][launch_plan_group].any?
config[@customer_key]["launch_plan"][launch_plan_group].keys.each do |ami_id|
if (config[@customer_key]["launch_plan"][launch_plan_group][ami_id].is_a?(Fixnum))
puts "#{ami_id} => #{config[@customer_key]["launch_plan"][launch_plan_group][ami_id]} Instances to launch"
ami_ids_to_launch << [ami_id, config[@customer_key]["launch_plan"][launch_plan_group][ami_id]]
else
puts "#{ami_id} => Detailed launch: #{config[@customer_key]["launch_plan"][launch_plan_group][ami_id]}"
detailed_ami_ids_to_launch << [ami_id, config[@customer_key]["launch_plan"][launch_plan_group][ami_id]]
end
end
else
puts white("No Ami Id's to launch defined.")
end
end
end
puts
puts red("Warning: Now launching your plan...")
puts red("Please press CTRL-C to cancel within the next 5 seconds if this isn't what you want...")
puts
sleep 5
ami_ids_to_launch.each do |group_ami_id_pair|
group_ami_id_pair[1].times {
puts "Launching #{group_ami_id_pair[0]}..."
result = launch_ami(group_ami_id_pair[0])
}
end
puts if ami_ids_to_launch.any?
detailed_ami_ids_to_launch.each do |group_ami_id_pair|
your_instance_name = group_ami_id_pair[0]
instance_assignments = group_ami_id_pair[1].split(";")
ami_id = instance_assignments[0]
raise "Incomplete detailed launchplan definition." if instance_assignments.size < 3
puts "Launching '#{your_instance_name}'..."
architecture = instance_assignments[1]; instance_type = instance_assignments[2]
result = launch_ami(ami_id, {:instance_type => instance_type, :architecture => architecture})
if result and result["instancesSet"]["item"] and (instance_id = result["instancesSet"]["item"][0]["instanceId"])
instance_state = ''
while(instance_state != 'running') do
instance_state, dns_name = get_instance_state(instance_id)
puts "Running state of instance #{instance_id}: #{output_running_state(instance_state)}"
sleep 5
end
if instance_assignments[3] and not instance_assignments[3].empty?
puts "Associating IP #{instance_assignments[3]}..."
result = ec2.associate_address(:instance_id => instance_id, :public_ip => instance_assignments[3])
end
if instance_assignments[4] and not instance_assignments[4].empty?
volumes = instance_assignments[4].split(",")
volumes.each do |volume_pair|
volume = volume_pair.split("@")
puts "Attaching volume #{volume[0]} at mount point #{volume[1]}..."
result = ec2.attach_volume(:volume_id => volume[0], :instance_id => instance_id, :device => volume[1])
end
end
end
puts
end
puts white("Launchplan executed!")
else
puts white("No launch plan groups defined.")
end
end
|