diff --git a/src/vmm_mad/remotes/az/az_driver.rb b/src/vmm_mad/remotes/az/az_driver.rb index 7d300506be..6ee703f9fd 100755 --- a/src/vmm_mad/remotes/az/az_driver.rb +++ b/src/vmm_mad/remotes/az/az_driver.rb @@ -162,7 +162,6 @@ class AzureDriver end Azure.configure do |config| - # Configure these 3 properties to use Storage config.management_certificate = @region['pem_management_cert'] config.subscription_id = @region['subscription_id'] config.management_endpoint = @region['management_endpoint'] @@ -172,14 +171,14 @@ class AzureDriver end # DEPLOY action - def deploy(id, host, xml_text) + def deploy(id, host, xml_text, lcm_state, deploy_id) + if lcm_state == "BOOT" || lcm_state == "BOOT_FAILURE" load_default_template_values az_info = get_deployment_info(host, xml_text) if !az_value(az_info, 'IMAGE') STDERR.puts("Cannot find IMAGE in deployment file") - exit(-1) end csn = az_value(az_info, 'CLOUD_SERVICE') @@ -197,21 +196,28 @@ class AzureDriver end rescue => e STDERR.puts(e.message) - exit(-1) end if instance.class == Azure::VirtualMachineManagement::VirtualMachine puts(instance.vm_name) else STDERR.puts(instance) - exit (-1) end + else + restore(deploy_id) + deploy_id + end end # Shutdown an Azure instance - def shutdown(deploy_id) - az_action(deploy_id, :shutdown) - az_action(deploy_id, :delete) + def shutdown(deploy_id, lcm_state) + case lcm_state + when "SHUTDOWN" + az_action(deploy_id, :shutdown) + az_action(deploy_id, :delete) + when "SHUTDOWN_POWEROFF", "SHUTDOWN_UNDEPLOY" + az_action(deploy_id, :shutdown) + end end # Reboot an Azure instance @@ -229,7 +235,7 @@ class AzureDriver az_action(deploy_id, :shutdown) end - # Cancel an Azure instance + # Resume an Azure instance def restore(deploy_id) az_action(deploy_id, :start) end @@ -557,7 +563,7 @@ private def get_instance(vm_name) begin csn = vm_name.match(/([^_]+)-(.+)/)[-1] - + instance = @azure_vms.get_virtual_machine(vm_name,csn) if instance return instance diff --git a/src/vmm_mad/remotes/az/deploy b/src/vmm_mad/remotes/az/deploy index 3036f6a7bc..92f9e0bdab 100755 --- a/src/vmm_mad/remotes/az/deploy +++ b/src/vmm_mad/remotes/az/deploy @@ -28,16 +28,23 @@ $: << RUBY_LIB_LOCATION $: << File.dirname(__FILE__) require 'az_driver' +require 'opennebula' dfile = ARGV[0] host = ARGV[1] id = ARGV[2] +vm = OpenNebula::VirtualMachine.new_with_id(id, OpenNebula::Client.new) +vm.info + +lcm_state = vm.lcm_state_str +deploy_id = vm.deploy_id + az_drv = AzureDriver.new(host) text=File.read(dfile) -puts az_drv.deploy(id, host, text) +puts az_drv.deploy(id, host, text, lcm_state, deploy_id) exit 0 diff --git a/src/vmm_mad/remotes/az/shutdown b/src/vmm_mad/remotes/az/shutdown index 3261d702ed..a247e9c6e0 100755 --- a/src/vmm_mad/remotes/az/shutdown +++ b/src/vmm_mad/remotes/az/shutdown @@ -28,11 +28,18 @@ $: << RUBY_LIB_LOCATION $: << File.dirname(__FILE__) require 'az_driver' +require 'opennebula' deploy_id = ARGV[0] host = ARGV[1] +vm_id = ARGV[-2] az_drv = AzureDriver.new(host) -az_drv.shutdown(deploy_id) +vm = OpenNebula::VirtualMachine.new_with_id(vm_id, OpenNebula::Client.new) +vm.info + +lcm_state = vm.lcm_state_str + +az_drv.shutdown(deploy_id, lcm_state) diff --git a/src/vmm_mad/remotes/ec2/deploy b/src/vmm_mad/remotes/ec2/deploy index 7122f1b317..3aa8d99bf7 100755 --- a/src/vmm_mad/remotes/ec2/deploy +++ b/src/vmm_mad/remotes/ec2/deploy @@ -28,16 +28,26 @@ $: << RUBY_LIB_LOCATION $: << File.dirname(__FILE__) require 'ec2_driver' +require 'opennebula' dfile = ARGV[0] host = ARGV[1] id = ARGV[2] +vm = OpenNebula::VirtualMachine.new_with_id(id, OpenNebula::Client.new) +vm.info + +lcm_state = vm.lcm_state_str +deploy_id = vm.deploy_id + ec2_drv = EC2Driver.new(host) text=File.read(dfile) -puts ec2_drv.deploy(id, host, text) - -exit 0 - +begin + puts ec2_drv.deploy(id, host, text, lcm_state, deploy_id) +rescue Exception => e + STDERR.puts "Deploy of VM #{id} on host #{host} with #{dfile} failed " + + "due to \"#{e.message}\"" + exit -1 +end diff --git a/src/vmm_mad/remotes/ec2/ec2_driver.rb b/src/vmm_mad/remotes/ec2/ec2_driver.rb index 2213c20849..401b8c2bfb 100755 --- a/src/vmm_mad/remotes/ec2/ec2_driver.rb +++ b/src/vmm_mad/remotes/ec2/ec2_driver.rb @@ -231,7 +231,8 @@ class EC2Driver end # DEPLOY action, also sets ports and ip if needed - def deploy(id, host, xml_text) + def deploy(id, host, xml_text, lcm_state, deploy_id) + if lcm_state == "BOOT" || lcm_state == "BOOT_FAILURE" ec2_info = get_deployment_info(host, xml_text) load_default_template_values @@ -274,11 +275,20 @@ class EC2Driver end puts(instance.id) + else + restore(deploy_id) + deploy_id + end end # Shutdown a EC2 instance - def shutdown(deploy_id) - ec2_action(deploy_id, :terminate) + def shutdown(deploy_id, lcm_state) + case lcm_state + when "SHUTDOWN" + ec2_action(deploy_id, :terminate) + when "SHUTDOWN_POWEROFF", "SHUTDOWN_UNDEPLOY" + ec2_action(deploy_id, :stop) + end end # Reboot a EC2 instance @@ -291,12 +301,12 @@ class EC2Driver ec2_action(deploy_id, :terminate) end - # Stop a EC2 instance + # Save a EC2 instance def save(deploy_id) ec2_action(deploy_id, :stop) end - # Cancel a EC2 instance + # Resumes a EC2 instance def restore(deploy_id) ec2_action(deploy_id, :start) end diff --git a/src/vmm_mad/remotes/ec2/shutdown b/src/vmm_mad/remotes/ec2/shutdown index 9c2e338be6..3f30425502 100755 --- a/src/vmm_mad/remotes/ec2/shutdown +++ b/src/vmm_mad/remotes/ec2/shutdown @@ -28,11 +28,18 @@ $: << RUBY_LIB_LOCATION $: << File.dirname(__FILE__) require 'ec2_driver' +require 'opennebula' deploy_id = ARGV[0] host = ARGV[1] +vm_id = ARGV[2] + +vm = OpenNebula::VirtualMachine.new_with_id(vm_id, OpenNebula::Client.new) +vm.info + +lcm_state = vm.lcm_state_str ec2_drv = EC2Driver.new(host) -ec2_drv.shutdown(deploy_id) +ec2_drv.shutdown(deploy_id, lcm_state) diff --git a/src/vmm_mad/remotes/sl/deploy b/src/vmm_mad/remotes/sl/deploy index 253ddb8e45..91bbba907b 100755 --- a/src/vmm_mad/remotes/sl/deploy +++ b/src/vmm_mad/remotes/sl/deploy @@ -28,15 +28,26 @@ $: << RUBY_LIB_LOCATION $: << File.dirname(__FILE__) require 'sl_driver' +require 'opennebula' dfile = ARGV[0] host = ARGV[1] id = ARGV[2] +vm = OpenNebula::VirtualMachine.new_with_id(id, OpenNebula::Client.new) +vm.info + +lcm_state = vm.lcm_state_str +deploy_id = vm.deploy_id + sl_drv = SLDriver.new(host) text=File.read(dfile) -puts sl_drv.deploy(id, host, text) - -exit 0 +begin + puts sl_drv.deploy(id, host, text, lcm_state, deploy_id) +rescue Exception => e + STDERR.puts "Deploy of VM #{id} on host #{host} with #{dfile} failed " + + "due to \"#{e.message}\"" + exit -1 +end diff --git a/src/vmm_mad/remotes/sl/shutdown b/src/vmm_mad/remotes/sl/shutdown index 70b2deff42..ffe282cbf5 100755 --- a/src/vmm_mad/remotes/sl/shutdown +++ b/src/vmm_mad/remotes/sl/shutdown @@ -28,10 +28,17 @@ $: << RUBY_LIB_LOCATION $: << File.dirname(__FILE__) require 'sl_driver' +require 'opennebula' deploy_id = ARGV[0] host = ARGV[1] +vm_id = ARGV[-2] + +vm = OpenNebula::VirtualMachine.new_with_id(vm_id, OpenNebula::Client.new) +vm.info + +lcm_state = vm.lcm_state_str sl_drv = SLDriver.new(host) -sl_drv.shutdown(deploy_id) +sl_drv.shutdown(deploy_id, lcm_state) diff --git a/src/vmm_mad/remotes/sl/sl_driver.rb b/src/vmm_mad/remotes/sl/sl_driver.rb index dad30f992b..be29bf1f8c 100644 --- a/src/vmm_mad/remotes/sl/sl_driver.rb +++ b/src/vmm_mad/remotes/sl/sl_driver.rb @@ -178,7 +178,8 @@ class SLDriver end # DEPLOY action - def deploy(id, host, xml_text) + def deploy(id, host, xml_text, lcm_state, deploy_id) + if lcm_state == "BOOT" || lcm_state == "BOOT_FAILURE" load_default_template_values sl_info = get_deployment_info(host, xml_text) @@ -212,11 +213,20 @@ class SLDriver end puts(vgid) + else + restore(deploy_id) + deploy_id + end end # Shutdown a SoftLayer instance - def shutdown(deploy_id) - sl_action(deploy_id, :terminate) + def shutdown(deploy_id, lcm_state) + case lcm_state + when "SHUTDOWN" + sl_action(deploy_id, :terminate) + when "SHUTDOWN_POWEROFF", "SHUTDOWN_UNDEPLOY" + sl_action(deploy_id, :stop) + end end # Reboot a SoftLayer instance @@ -235,7 +245,7 @@ class SLDriver end # Start a SoftLayer instance - def restore(deploy_id)0 + def restore(deploy_id) sl_action(deploy_id, :start) end