Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request CloudStack-extras#72 from voroniys/master
Nice option to create extra data disks on the new instances.
  • Loading branch information
sbotman committed Jun 13, 2013
2 parents 528a938 + 8cf8d44 commit 440c020
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/chef/knife/cs_server_create.rb
Expand Up @@ -81,6 +81,11 @@ class CsServerCreate < Chef::Knife
:proc => lambda { |n| n.split(',').map {|sn| sn.strip}} ,
:default => []

option :cloudstack_disk,
:short => "-D DISK",
:long => "--disk DISK",
:description => "The name of CloudStack disk oferring"

option :cloudstack_hypervisor,
:long => '--cloudstack-hypervisor HYPERVISOR',
:description => "The CloudStack hypervisor type for the server"
Expand Down Expand Up @@ -224,6 +229,7 @@ def run
template : #{locate_config_value(:cloudstack_template)}
zone : #{locate_config_value(:cloudstack_zone)}
project: #{locate_config_value(:cloudstack_project)}
disk: #{locate_config_value(:cloudstack_disk)}
network: #{locate_config_value(:cloudstack_networks)}")

print "\n#{ui.color("Waiting for Server to be created", :magenta)}"
Expand All @@ -236,6 +242,7 @@ def run
locate_config_value(:cloudstack_template),
locate_config_value(:cloudstack_zone),
locate_config_value(:cloudstack_networks),
locate_config_value(:cloudstack_disk),
params
)

Expand Down
38 changes: 37 additions & 1 deletion lib/knife-cloudstack/connection.rb
Expand Up @@ -155,7 +155,7 @@ def list_servers
##
# Deploys a new server using the specified parameters.

def create_server(host_name, service_name, template_name, zone_name=nil, network_names=[], extra_params)
def create_server(host_name, service_name, template_name, zone_name=nil, network_names=[], disk_name=nil, extra_params)

if host_name then
if get_server(host_name) then
Expand All @@ -176,6 +176,23 @@ def create_server(host_name, service_name, template_name, zone_name=nil, network
exit 1
end

if (!!disk_name) then
if ( disk_name =~ /(\D+):(\d+)/) then
disk_size = $2
disk_name = $1
end
disk = get_disk(disk_name)
if !disk then
puts "Error: Disk '#{disk_name}' is invalid"
exit 1
end
if !disk_size.empty? && !disk['iscustomized'] then
puts "Error: You may not provide size for disk '#{disk_name}'"
exit 1
end
end


zone = zone_name ? get_zone(zone_name) : get_default_zone
if !zone then
msg = zone_name ? "Zone '#{zone_name}' is invalid" : "No default zone found"
Expand Down Expand Up @@ -229,6 +246,9 @@ def create_server(host_name, service_name, template_name, zone_name=nil, network

params['name'] = host_name if host_name

params['diskOfferingId'] = disk['id'] if !!disk && !disk.empty?
params['size'] = disk_size if !!disk_size && !disk_size.empty?

json = send_async_request(params)
json['virtualmachine']
end
Expand Down Expand Up @@ -360,6 +380,22 @@ def list_security_groups
end


def get_disk(name)
params = {
'command' => 'listDiskOfferings',
'name' => name
}
json = send_request(params)
disk = json['diskoffering']

if !disk || disk.empty? then
return nil
end

disk.first
end


##
# Finds the template with the specified name.

Expand Down

0 comments on commit 440c020

Please sign in to comment.