lib/cloudstack-cli/commands/stack.rb in cloudstack-cli-1.5.1 vs lib/cloudstack-cli/commands/stack.rb in cloudstack-cli-1.5.2
- old
+ new
@@ -1,8 +1,11 @@
class Stack < CloudstackCli::Base
desc "create STACKFILE", "create a stack of VMs"
+ option :skip_forwarding_rules, default: false,
+ type: :boolean, aliases: '-s',
+ desc: "Skip creation of port forwarding rules."
def create(stackfile)
stack = parse_file(stackfile)
project_id = find_project_by_name(stack["project"])
say "Create stack #{stack["name"]}...", :green
@@ -32,11 +35,10 @@
size: instance["disk_size"],
group: instance["group"] || stack["group"],
keypair: instance["keypair"] || stack["keypair"],
ip_address: instance["ip_address"]
})
-
jobs << {
id: client.deploy_virtual_machine(
vm_options_to_params,
{sync: true}
)['jobid'],
@@ -45,26 +47,29 @@
end
end
end
watch_jobs(jobs)
- say "Check for port forwarding rules...", :green
- jobs = []
- stack["servers"].each do |instance|
- string_to_array(instance["name"]).each do |name|
- if port_rules = string_to_array(instance["port_rules"])
- server = client.list_virtual_machines(name: name, project_id: project_id).first
- create_port_rules(server, port_rules, false).each_with_index do |job_id, index|
- jobs << {
- id: job_id,
- name: "Create port forwarding rules (#{port_rules[index]}) for VM #{name}"
- }
+ unless options[:skip_forwarding_rules]
+ say "Check for port forwarding rules...", :green
+ jobs = []
+ stack["servers"].each do |instance|
+ string_to_array(instance["name"]).each do |name|
+ if port_rules = string_to_array(instance["port_rules"])
+ server = client.list_virtual_machines(name: name, project_id: project_id).first
+ create_port_rules(server, port_rules, false).each_with_index do |job_id, index|
+ jobs << {
+ id: job_id,
+ name: "Create port forwarding rules (#{port_rules[index]}) for VM #{name}"
+ }
+ end
end
end
end
+ watch_jobs(jobs)
end
- watch_jobs(jobs)
+
say "Finished.", :green
end
desc "destroy STACKFILE", "destroy a stack of VMs"
option :force,
@@ -116,10 +121,11 @@
end
project_id
end
def load_string_or_array(item)
- item.is_a?(Array) ? item : [item]
+ return nil if item == nil
+ item.is_a?(Array) ? item : [item]
end
def string_to_array(string)
string ? string.gsub(', ', ',').split(',') : nil
end