lib/cloudstack-cli/option_resolver.rb in cloudstack-cli-1.0.2 vs lib/cloudstack-cli/option_resolver.rb in cloudstack-cli-1.0.3

- old
+ new

@@ -1,9 +1,9 @@ module CloudstackCli module OptionResolver - def vm_options_to_params(options = options) + def vm_options_to_params resolve_zone(options) resolve_project(options) resolve_compute_offering(options) resolve_template(options) resolve_disk_offering(options) @@ -13,11 +13,11 @@ exit 1 end resolve_networks(options) end - def resolve_zone(options = options) + def resolve_zone if options[:zone] zones = client.list_zones zone = zones.find {|z| z['name'] == options[:zone] } if !zone msg = options[:zone] ? "Zone '#{options[:zone]}' is invalid." : "No zone found." @@ -27,11 +27,11 @@ options[:zone_id] = zone['id'] end options end - def resolve_domain(options = options) + def resolve_domain if options[:domain] if domain = client.list_domains(name: options[:domain]).first options[:domain_id] = domain['id'] else say "Error: Domain #{options[:domain]} not found.", :red @@ -39,11 +39,11 @@ end end options end - def resolve_project(options = options) + def resolve_project if options[:project] if %w(ALL -1).include? options[:project] options[:project_id] = "-1" elsif project = client.list_projects(name: options[:project], listall: true).first options[:project_id] = project['id'] @@ -53,11 +53,11 @@ end end options end - def resolve_account(options = options) + def resolve_account if options[:account] if account = client.list_accounts(name: options[:account], listall: true).first options[:account_id] = account['id'] options[:domain_id] = account['domainid'] else @@ -66,11 +66,11 @@ end end options end - def resolve_networks(options = options) + def resolve_networks networks = [] available_networks = network = client.list_networks( zone_id: options[:zone_id], project_id: options[:project_id] ) @@ -95,11 +95,11 @@ end options[:network_ids] = networks.join(',') options end - def resolve_iso(options = options) + def resolve_iso if options[:iso] unless iso = client.list_isos( name: options[:iso], project_id: options[:project_id] ).first @@ -114,11 +114,11 @@ options['hypervisor'] = (options[:hypervisor] || 'vmware') end options end - def resolve_template(options = options) + def resolve_template if options[:template] if template = client.list_templates( name: options[:template], template_filter: "executable", project_id: options[:project_id] @@ -130,32 +130,32 @@ end end options end - def resolve_compute_offering(options = options) + def resolve_compute_offering if offering = client.list_service_offerings(name: options[:offering]).first options[:service_offering_id] = offering['id'] else say "Error: Offering #{options[:offering]} not found.", :red exit 1 end options end - def resolve_disk_offering(options = options) + def resolve_disk_offering if options[:disk_offering] unless disk_offering = client.list_disk_offerings(name: options[:disk_offering]).first say "Error: Disk offering '#{options[:disk_offering]}' not found.", :red exit 1 end options[:disk_offering_id] = disk_offering['id'] end options end - def resolve_virtual_machine(options = options) + def resolve_virtual_machine if options[:virtual_machine] args = { name: options[:virtual_machine], listall: true } args[:project_id] = options[:project_id] unless vm = client.list_virtual_machines(args).first say "Error: VM '#{options[:virtual_machine]}' not found.", :red @@ -164,10 +164,10 @@ options[:virtual_machine_id] = vm['id'] end options end - def resolve_snapshot(options = options) + def resolve_snapshot if options[:snapshot] args = { name: options[:snapshot], listall: true } args[:project_id] = options[:project_id] unless snapshot = client.list_snapshots(args).first say "Error: Snapshot '#{options[:snapshot]}' not found.", :red