1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

Bug #3774: Change poweroff behaviour for hybrids

This commit is contained in:
Tino Vazquez 2015-07-31 19:09:52 +02:00
parent 81dcc96f20
commit 755ea38c81
9 changed files with 105 additions and 30 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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