Permalink
Browse files

Move Launcher files to their own directory

This only moves the lib files, not the spec files, so as not to make this commit too complex. All tests still pass at this point.
  • Loading branch information...
annashipman committed Apr 1, 2014
1 parent 95d6d77 commit c09090668acfef26df713110d05d0f4850c22163
@@ -5,7 +5,7 @@ require 'bundler/setup'
require 'optparse'
require 'methadone'
require 'vcloud/launch'
require 'vcloud/launcher/launch'
class App
include Methadone::Main
@@ -11,9 +11,9 @@
require 'vcloud/fog'
require 'vcloud/core'
require 'vcloud/launch'
require 'vcloud/vm_orchestrator'
require 'vcloud/vapp_orchestrator'
require 'vcloud/launcher/launch'
require 'vcloud/launcher/vm_orchestrator'
require 'vcloud/launcher/vapp_orchestrator'
module Vcloud

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,48 @@
require 'vcloud'
module Vcloud
module Launcher
class Launch
def initialize
@config_loader = Vcloud::Core::ConfigLoader.new
end
def run(config_file = nil, cli_options = {})
config = @config_loader.load_config(config_file, config_schema)
config[:vapps].each do |vapp_config|
Vcloud.logger.info("\n")
Vcloud.logger.info("Provisioning vApp #{vapp_config[:name]}.")
begin
vapp = ::Vcloud::Launcher::VappOrchestrator.provision(vapp_config)
#methadone sends option starting with 'no' as false.
vapp.power_on unless cli_options["dont-power-on"]
Vcloud.logger.info("Done! Provisioned vApp #{vapp_config[:name]} successfully.")
Vcloud.logger.info("=" * 70)
rescue RuntimeError => e
Vcloud.logger.error("Failure : Could not provision vApp: #{e.message}")
Vcloud.logger.info("=" * 70)
break unless cli_options["continue-on-error"]
end
end
end
def config_schema
{
type: 'hash',
allowed_empty: false,
permit_unknown_parameters: true,
internals: {
vapps: {
type: 'array',
required: false,
allowed_empty: true,
each_element_is: ::Vcloud::Launcher::VappOrchestrator.provision_schema
},
}
}
end
end
end
end
@@ -0,0 +1,44 @@
module Vcloud
module Launcher
class VappOrchestrator
def self.provision(vapp_config)
name, vdc_name = vapp_config[:name], vapp_config[:vdc_name]
if vapp = Vcloud::Core::Vapp.get_by_name_and_vdc_name(name, vdc_name)
Vcloud.logger.info("Found existing vApp #{name} in vDC '#{vdc_name}'. Skipping.")
else
template = Vcloud::Core::VappTemplate.get(vapp_config[:catalog], vapp_config[:catalog_item])
template_id = template.id
network_names = extract_vm_networks(vapp_config)
vapp = Vcloud::Core::Vapp.instantiate(name, network_names, template_id, vdc_name)
Vcloud::Launcher::VmOrchestrator.new(vapp.fog_vms.first, vapp).customize(vapp_config[:vm]) if vapp_config[:vm]
end
vapp
end
def self.provision_schema
{
type: 'hash',
required: true,
allowed_empty: false,
internals: {
name: { type: 'string', required: true, allowed_empty: false },
vdc_name: { type: 'string', required: true, allowed_empty: false },
catalog: { type: 'string', required: true, allowed_empty: false },
catalog_item: { type: 'string', required: true, allowed_empty: false },
vm: Vcloud::Launcher::VmOrchestrator.customize_schema,
}
}
end
def self.extract_vm_networks(config)
if (config[:vm] && config[:vm][:network_connections])
config[:vm][:network_connections].collect { |h| h[:name] }
end
end
end
end
end
@@ -0,0 +1,85 @@
module Vcloud
module Launcher
class VmOrchestrator
def initialize fog_vm, vapp
vm_id = fog_vm[:href].split('/').last
@vm = Core::Vm.new(vm_id, vapp)
end
def customize(vm_config)
@vm.update_name(@vm.vapp_name)
@vm.configure_network_interfaces vm_config[:network_connections]
@vm.update_storage_profile(vm_config[:storage_profile]) if vm_config[:storage_profile]
if hardware_config = vm_config[:hardware_config]
@vm.update_cpu_count(hardware_config[:cpu])
@vm.update_memory_size_in_mb(hardware_config[:memory])
end
@vm.add_extra_disks(vm_config[:extra_disks])
@vm.update_metadata(vm_config[:metadata])
@vm.configure_guest_customization_section(
@vm.vapp_name,
vm_config[:bootstrap],
vm_config[:extra_disks]
)
end
def self.customize_schema
{
type: 'hash',
required: false,
allowed_empty: false,
internals: {
network_connections: {
type: 'array',
required: false,
each_element_is: {
type: 'hash',
internals: {
name: { type: 'string', required: true },
ip_address: { type: 'ip_address', required: false },
},
},
},
storage_profile: { type: 'string', required: false },
hardware_config: {
type: 'hash',
required: false,
internals: {
cpu: { type: 'string_or_number', required: false },
memory: { type: 'string_or_number', required: false },
},
},
extra_disks: {
type: 'array',
required: false,
allowed_empty: false,
each_element_is: {
type: 'hash',
internals: {
name: { type: 'string', required: false },
size: { type: 'string_or_number', required: false },
},
},
},
bootstrap: {
type: 'hash',
required: false,
allowed_empty: false,
internals: {
script_path: { type: 'string', required: false },
script_post_processor: { type: 'string', required: false },
vars: { type: 'hash', required: false, allowed_empty: true },
},
},
metadata: {
type: 'hash',
required: false,
allowed_empty: true,
},
},
}
end
end
end
end

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -1,12 +1,12 @@
require 'spec_helper'
describe Vcloud::Launch do
describe Vcloud::Launcher::Launch do
context "storage profile", :take_too_long => true do
before(:all) do
@test_data = define_test_data
@config_yaml = ErbHelper.convert_erb_template_to_yaml(@test_data, File.join(File.dirname(__FILE__), 'data/storage_profile.yaml.erb'))
@fog_interface = Vcloud::Fog::ServiceInterface.new
Vcloud::Launch.new.run(@config_yaml, {'dont-power-on' => true})
Vcloud::Launcher::Launch.new.run(@config_yaml, {'dont-power-on' => true})
@vapp_query_result_1 = @fog_interface.get_vapp_by_name_and_vdc_name(@test_data[:vapp_name_1], @test_data[:vdc_name_1])
@vapp_id_1 = @vapp_query_result_1[:href].split('/').last
Oops, something went wrong.

0 comments on commit c090906

Please sign in to comment.