lib/cloudstack-cli/commands/volume.rb in cloudstack-cli-1.2.7 vs lib/cloudstack-cli/commands/volume.rb in cloudstack-cli-1.3.0

- old
+ new

@@ -80,19 +80,29 @@ say "Zone is required when deploying with disk-offering.", :yellow exit 1 end say "Creating volume #{name} " - client.create_volume(options) + job = client.create_volume(options).merge(sync: true) say " OK.", :green - sleep 2 - invoke "volume:show", [name], options + + # attach the new volume if a vm is profided and not a sapshot + if options[:virtual_machine] && options[:snapshot] == nil + sleep 2 + say "Attach volume #{name} to VM #{options[:virtual_machine]} " + client.attach_volume( + id: job['volume']['id'], + virtualmachineid: options[:virtual_machine_id], + sync: true + ) + say " OK.", :green + end end desc "attach NAME", "attach volume to VM" option :project, desc: 'project of volume' - option :virtual_machine, desc: 'project of volume' + option :virtual_machine, desc: 'virtual machine of volume' def attach(name) resolve_project resolve_virtual_machine volume = client.list_volumes( @@ -110,16 +120,16 @@ end say "Attach volume #{name} to VM #{options[:virtual_machine]} " client.attach_volume( id: volume['id'], - virtualmachine_id: options[:virtual_machine_id] + virtualmachineid: options[:virtual_machine_id] ) say " OK.", :green end - desc "detach NAME", "attach volume to VM" + desc "detach NAME", "detach volume from VM" option :project, desc: 'project of volume' def detach(name) resolve_project volume = client.list_volumes( @@ -139,10 +149,10 @@ say "Detach volume #{name} from VM #{volume["vmname"]} " client.detach_volume id: volume['id'] say " OK.", :green end - desc "delete NAME", "attach volume to VM" + desc "delete NAME", "delete volume to VM" option :project, desc: 'project of volume' def delete(name) resolve_project volume = client.list_volumes(