Class: Knifecosmic::CosmicVolumeCreate

Inherits:
Chef::Knife show all
Includes:
Chef::Knife::KnifecosmicBase
Defined in:
lib/chef/knife/cosmic_volume_create.rb

Instance Method Summary collapse

Methods included from Chef::Knife::KnifecosmicBase

included

Instance Method Details

#runObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/chef/knife/cosmic_volume_create.rb', line 66

def run
    validate_base_options

    Chef::Log.debug("Validate hostname and options")
    if  locate_config_value(:name)
	volumename = locate_config_value(:name)
    else
	volumename = @name_args.first
	unless /^[a-zA-Z0-9][a-zA-Z0-9_\-#]*$/.match volumename then
	    ui.error "Invalid volumename. Please specify a simple name without any spaces"
	    exit 1
	end
    end

    print "#{ui.color("Creating volume: #{volumename}", :magenta)}\n"

    params = {
	'command' => 'createVolume',
	'name' => volumename,
    }

    params['account'] = locate_config_value(:account) if locate_config_value(:account)
    params['diskofferingid'] = locate_config_value(:diskofferingid) if locate_config_value(:diskofferingid)
    params['domainid'] = locate_config_value(:domainid) if locate_config_value(:domainid)
    params['projectid'] = locate_config_value(:projectid) if locate_config_value(:projectid)
    params['size'] = locate_config_value(:size) if locate_config_value(:size)
    params['snapshotid'] = locate_config_value(:snapshotid) if locate_config_value(:snapshotid)
    params['zoneid'] = locate_config_value(:zoneid) if locate_config_value(:zoneid)

    json = connection.send_request(params)

    if ! json then
	ui.error("Unable to create volume")
	exit 1
    end

    print "Volume #{json['id']} is being created in the background\n";

    return json['id']
end