def create_server(name, image_id, flavor_id, min_count, max_count, options = {})
data = {
'server' => {
'name' => name,
'imageRef' => image_id,
'flavorRef' => flavor_id,
'minCount' => min_count,
'maxCount' => max_count
}
}
data['server']['adminPass'] = options[:password] unless options[:password].nil?
data['server']['OS-DCF:diskConfig'] = options[:disk_config] unless options[:disk_config].nil?
data['server']['metadata'] = options[:metadata] unless options[:metadata].nil?
data['server']['personality'] = options[:personality] unless options[:personality].nil?
data['server']['config_drive'] = options[:config_drive] unless options[:config_drive].nil?
data['server']['user_data'] = options[:user_data] unless options[:user_data].nil?
data['server']['networks'] = options[:networks] || [
{ :uuid => '00000000-0000-0000-0000-000000000000' },
{ :uuid => '11111111-1111-1111-1111-111111111111' }
]
if options[:keypair]
Fog::Logger.deprecation(":keypair has been depreciated. Please use :key_name instead.")
options[:key_name] = options[:keypair]
end
data['server']['key_name'] = options[:key_name] unless options[:key_name].nil?
if options[:block_device_mapping]
if options[:boot_volume_id]
Fog::Logger.warning("Manual :block_device_mapping overrides :boot_volume_id in #create_server!")
end
if options[:boot_image_id]
Fog::Logger.warning("Manual :block_device_mapping overrides :boot_image_id in #create_server!")
end
data['server']['block_device_mapping_v2'] = options[:block_device_mapping]
else
if options[:boot_volume_id]
if options[:boot_image_id]
Fog::Logger.warning(":boot_volume_id overrides :boot_image_id!")
end
if options[:boot_volume_size]
Fog::Logger.warning("Boot volume size: " + options[:boot_volume_size] + "GB")
end
data['server']['block_device_mapping_v2'] = [{
'boot_index' => '0',
'uuid' => options[:boot_volume_id],
'source_type' => 'volume',
'destination_type' => 'volume',
'volume_size' => options[:boot_volume_size] ? options[:boot_volume_size] : 100
}]
end
if options[:boot_image_id]
data['server']['block_device_mapping_v2'] = [{
'boot_index' => '0',
'uuid' => options[:boot_image_id],
'source_type' => 'image',
'destination_type' => 'volume',
'volume_size' => options[:boot_volume_size] ? options[:boot_volume_size] : 100
}]
end
end
request(
:body => Fog::JSON.encode(data),
:expects => [202],
:method => 'POST',
:path => "servers"
)
end