lib/chef/knife/google_disk_create.rb in knife-google-1.1.0 vs lib/chef/knife/google_disk_create.rb in knife-google-1.2.0
- old
+ new
@@ -18,27 +18,26 @@
class Knife
class GoogleDiskCreate < Knife
include Knife::GoogleBase
- banner "knife google disk create NAME --google-disk-sizeGb N --google-compute-zone ZONE (options)"
+ banner "knife google disk create NAME --gce-disk-size N -Z ZONE (options)"
deps do
require 'google/compute'
end
option :zone,
:short => "-Z ZONE",
- :long => "--google-compute-zone ZONE",
+ :long => "--gce-zone ZONE",
:description => "The Zone for this disk",
:required => true
- option :sizeGb,
- :short => "-s SIZE",
- :long => "--google-disk-sizeGb SIZE",
- :description => "Disk size in GB",
- :required => true
+ option :disk_size,
+ :long => "--gce-disk-size SIZE",
+ :description => "Size of the persistent disk between 1 and 10000 GB, specified in GB; default is '1' GB",
+ :default => "1"
def run
$stdout.sync = true
unless @name_args.size > 0
ui.error("Please provide the name of the new disk")
@@ -50,11 +49,20 @@
rescue Google::Compute::ResourceNotFound
ui.error("Zone '#{config[:zone]}' not found")
exit 1
end
- zone_operation = client.disks.create(:name=>@name_args.first,
- :sizeGb=>config[:sizeGb], :zone=>zone.name)
+ begin
+ disk_size = config[:disk_size].to_i
+ raise if !disk_size.between?(1, 10000)
+ rescue
+ ui.error("Size of the persistent disk must be between 1 and 10000 GB.")
+ exit 1
+ end
+
+ zone_operation = client.disks.create(:name => @name_args.first,
+ :sizeGb => config[:disk_size],
+ :zone => zone.name)
end
end
end
end