lib/cloudstack-cli/option_resolver.rb in cloudstack-cli-1.5.0 vs lib/cloudstack-cli/option_resolver.rb in cloudstack-cli-1.5.1

- old
+ new

@@ -11,11 +11,15 @@ options[:size] = options[:disk_size] if options[:disk_size] unless options[:template_id] say "Error: Template or ISO is required.", :red exit 1 end - resolve_networks + if options[:ip_network_list] + resolve_ip_network_list + else + resolve_networks + end end def resolve_zone if options[:zone] zones = client.list_zones @@ -84,18 +88,41 @@ networks << network['id'] rescue nil end end networks.compact! if networks.empty? - #unless default_network = client.list_networks(project_id: options[:project_id]).find { - # |n| n['isdefault'] == true } unless default_network = client.list_networks(project_id: options[:project_id]).first say "Error: No default network found.", :red exit 1 end networks << available_networks.first['id'] rescue nil end options[:network_ids] = networks.join(',') + options + end + + def resolve_ip_network_list + network_list = [] + available_networks = network = client.list_networks( + zone_id: options[:zone_id], + project_id: options[:project_id] + ) + if options[:ip_network_list] + options[:ip_network_list].each do |item| + unless network = available_networks.find { |n| n['name'] == item["name"] } + say "Error: Network '#{name}' not found.", :red + exit 1 + end + item.delete("name") + network_list << {networkid: network["id"]}.merge(item) # rescue nil + end + end + network_list.compact! + if network_list.empty? + say "Error: IP network list can't be empty.", :red + exit 1 + end + options[:ip_to_network_list] = network_list options end def resolve_iso if options[:iso]