lib/cloudstack-cli/commands/stack.rb in cloudstack-cli-0.12.1 vs lib/cloudstack-cli/commands/stack.rb in cloudstack-cli-0.12.2

- old
+ new

@@ -1,16 +1,18 @@ +require 'open-uri' + class Stack < CloudstackCli::Base desc "create STACKFILE", "create a stack of servers" def create(stackfile) stack = parse_stackfile(stackfile) say "Create stack #{stack["name"]}...", :green projectid = find_project(stack["project"])['id'] if stack["project"] jobs = [] client.verbose = false stack["servers"].each do |instance| - instance["name"].gsub(', ', ',').split(',').each do |name| + string_to_array(instance["name"]).each do |name| server = client.get_server(name, project_id: projectid) if server say "Server #{name} (#{server["state"]}) already exists.", :yellow jobs << { id: 0, @@ -44,17 +46,17 @@ watch_jobs(jobs) say "Check for port forwarding rules...", :green jobs = [] stack["servers"].each do |instance| - instance["name"].gsub(', ', ',').split(',').each do |name| + string_to_array(instance["name"]).each do |name| if port_rules = string_to_array(instance["port_rules"]) server = client(quiet: true).get_server(name, project_id: projectid) create_port_rules(server, port_rules, false).each_with_index do |job_id, index| jobs << { id: job_id, - name: "Create port forwarding ##{index + 1} rules for server #{name}" + name: "Create port forwarding rules (#{port_rules[index]}) for server #{name}" } end end end end @@ -77,11 +79,11 @@ stack = parse_stackfile(stackfile) projectid = find_project(stack["project"])['id'] if stack["project"] client.verbose = false servers = [] stack["servers"].each do |server| - server["name"].gsub(', ', ',').split(',').each {|name| servers << name} + string_to_array(server["name"]).each {|name| servers << name} end if options[:force] || yes?("Destroy the following servers #{servers.join(', ')}? [y/N]:", :yellow) jobs = [] servers.each do |name| @@ -113,10 +115,10 @@ else say "File extension #{File.extname(stackfile)} not supported. Supported extensions are .json, .yaml or .yml", :red exit end begin - return handler.load File.read(stackfile) + return handler.load open(stackfile){|f| f.read} rescue SystemCallError say "Can't find the stack file #{stackfile}.", :red exit 1 rescue => e say "Error parsing #{File.extname(stackfile)} file:", :red