mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-24 21:34:01 +03:00
feature #1020: Improved actions for vmm and im vmware drivers
This commit is contained in:
parent
d50c9fd86c
commit
ccd099c957
@ -19,18 +19,18 @@
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
|
||||
|
||||
if !ONE_LOCATION
|
||||
ETC_LOCATION = "/etc/one" if !defined?(ETC_LOCATION)
|
||||
RUBY_LIB_LOCATION = "/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
else
|
||||
ETC_LOCATION = ONE_LOCATION+"/etc" if !defined?(ETC_LOCATION)
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
|
||||
require "scripts_common"
|
||||
require 'yaml'
|
||||
require "CommandManager"
|
||||
require 'OpenNebula'
|
||||
include OpenNebula
|
||||
require 'vmwarelib'
|
||||
|
||||
begin
|
||||
client = Client.new()
|
||||
@ -39,6 +39,28 @@ rescue Exception => e
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
# ######################################################################## #
|
||||
# DRIVER HELPER FUNCTIONS #
|
||||
# ######################################################################## #
|
||||
|
||||
#Generates an ESX command using ttyexpect
|
||||
def esx_cmd(command)
|
||||
cmd = "#{BIN_LOCATION}/tty_expect -u #{@user} -p #{@pass} #{command}"
|
||||
end
|
||||
|
||||
#Performs a action usgin libvirt
|
||||
def do_action(cmd)
|
||||
rc = LocalCommand.run(esx_cmd(cmd))
|
||||
|
||||
if rc.code == 0
|
||||
return [true, rc.stdout]
|
||||
else
|
||||
err = "Error executing: #{cmd} err: #{rc.stderr} out: #{rc.stdout}"
|
||||
OpenNebula.log_error(err)
|
||||
return [false, rc.code]
|
||||
end
|
||||
end
|
||||
|
||||
def add_info(name, value)
|
||||
value = "0" if value.nil? or value.to_s.empty?
|
||||
result_str << "#{name}=#{value} "
|
||||
@ -48,17 +70,25 @@ def print_info
|
||||
puts result_str
|
||||
end
|
||||
|
||||
# ######################################################################## #
|
||||
# Main Procedure #
|
||||
# ######################################################################## #
|
||||
|
||||
result_str = ""
|
||||
|
||||
host = ARGV[2]
|
||||
|
||||
if !@host
|
||||
if !host
|
||||
exit -1
|
||||
end
|
||||
|
||||
vmware_drv = VMWareDriver.new(host)
|
||||
# Poll the VMware hypervisor
|
||||
|
||||
data = vmware_drv.poll_hypervisor
|
||||
rc, data = do_action("virsh -c #{@uri} --readonly nodeinfo")
|
||||
|
||||
if rc == false
|
||||
exit info
|
||||
end
|
||||
|
||||
data.split(/\n/).each{|line|
|
||||
if line.match('^CPU\(s\)')
|
||||
|
@ -18,7 +18,7 @@ require "scripts_common"
|
||||
require 'yaml'
|
||||
require "CommandManager"
|
||||
|
||||
class VmWareDriver
|
||||
class VMwareDriver
|
||||
# -------------------------------------------------------------------------#
|
||||
# Set up the environment for the driver #
|
||||
# -------------------------------------------------------------------------#
|
||||
@ -66,7 +66,7 @@ class VmWareDriver
|
||||
|
||||
exit -1 if deploy_id.nil?
|
||||
|
||||
OpenNebula.log_debug("Successfully defined domain #{deploy_id}.")
|
||||
OpenNebula.log_debug("Successfully defined domain #{deploy_id}.")
|
||||
|
||||
# Start the VM
|
||||
rc, info = do_action("virsh -c #{@uri} start #{deploy_id}")
|
||||
@ -90,6 +90,8 @@ class VmWareDriver
|
||||
exit info
|
||||
end
|
||||
|
||||
OpenNebula.log_debug("Successfully canceled domain #{deploy_id}.")
|
||||
|
||||
# Undefine the VM
|
||||
undefine_domain(deploy_id)
|
||||
end
|
||||
@ -98,7 +100,7 @@ class VmWareDriver
|
||||
# Migrate #
|
||||
# ------------------------------------------------------------------------ #
|
||||
def migrate
|
||||
OpenNebula.log_error("TBD")
|
||||
OpenNebula.log_error("Migration action is currently not supported")
|
||||
exit -1
|
||||
end
|
||||
|
||||
@ -109,8 +111,7 @@ class VmWareDriver
|
||||
rc, info = do_action("virsh -c #{@uri} --readonly dominfo #{deploy_id}")
|
||||
|
||||
if rc == false
|
||||
puts "STATE=d"
|
||||
exit 0
|
||||
return "STATE=d"
|
||||
end
|
||||
|
||||
state = ""
|
||||
@ -219,20 +220,6 @@ class VmWareDriver
|
||||
undefine_domain(deploy_id)
|
||||
end
|
||||
|
||||
# ------------------------------------------------------------------------ #
|
||||
# Poll a VMware hypervisor #
|
||||
# ------------------------------------------------------------------------ #
|
||||
def poll_hypervisor
|
||||
# Destroy the VM
|
||||
rc, info = perform_action("virsh -c #{@uri} --readonly nodeinfo")
|
||||
|
||||
if rc == false
|
||||
exit info
|
||||
end
|
||||
|
||||
return info
|
||||
end
|
||||
|
||||
# ######################################################################## #
|
||||
# DRIVER HELPER FUNCTIONS #
|
||||
# ######################################################################## #
|
||||
|
@ -32,45 +32,6 @@ require 'vmwarelib'
|
||||
dfile = ARGV[0]
|
||||
host = ARGV[1]
|
||||
|
||||
vmware_drv = VMWareDriver.new(host)
|
||||
|
||||
puts vmware_drv.deploy(dfile)
|
||||
|
||||
exit 0
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
|
||||
|
||||
if !ONE_LOCATION
|
||||
ETC_LOCATION="/etc/one" if !defined?(ETC_LOCATION)
|
||||
else
|
||||
ETC_LOCATION=ONE_LOCATION+"/etc" if !defined?(ETC_LOCATION)
|
||||
end
|
||||
|
||||
deploy_id = ARGV[0]
|
||||
@host = ARGV[1]
|
||||
|
||||
if !@host or !deploy_id
|
||||
exit -1
|
||||
end
|
||||
|
||||
load ETC_LOCATION + "/vmwarerc"
|
||||
|
||||
if USERNAME.class!=String || PASSWORD.class!=String
|
||||
warn "Bad ESX credentials, aborting"
|
||||
exit -1
|
||||
end
|
||||
|
||||
# Destroy the VM
|
||||
data = perform_action("virsh -c #{LIBVIRT_URI} destroy #{deploy_id}")
|
||||
|
||||
if data.class == Fixnum
|
||||
exit data
|
||||
end
|
||||
|
||||
# Undefine the VM
|
||||
data = perform_action("virsh -c #{LIBVIRT_URI} undefine #{deploy_id}")
|
||||
|
||||
if data.class == Fixnum
|
||||
exit data
|
||||
end
|
||||
vmware_drv = VMwareDriver.new(host)
|
||||
|
||||
vmware_drv.cancel(dfile)
|
||||
|
@ -32,7 +32,7 @@ require 'vmwarelib'
|
||||
dfile = ARGV[0]
|
||||
host = ARGV[1]
|
||||
|
||||
vmware_drv = VmWareDriver.new(host)
|
||||
vmware_drv = VMwareDriver.new(host)
|
||||
|
||||
puts vmware_drv.deploy(dfile)
|
||||
|
||||
|
@ -16,62 +16,23 @@
|
||||
# limitations under the License. #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
|
||||
|
||||
if !ONE_LOCATION
|
||||
ETC_LOCATION="/etc/one" if !defined?(ETC_LOCATION)
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
else
|
||||
ETC_LOCATION=ONE_LOCATION+"/etc" if !defined?(ETC_LOCATION)
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << File.dirname(__FILE__)
|
||||
|
||||
require 'vmwarelib'
|
||||
|
||||
deploy_id = ARGV[0]
|
||||
@host = ARGV[1]
|
||||
|
||||
if !@host or !deploy_id
|
||||
exit -1
|
||||
end
|
||||
|
||||
load ETC_LOCATION + "/vmwarerc"
|
||||
|
||||
if USERNAME.class!=String || PASSWORD.class!=String
|
||||
warn "Bad ESX credentials, aborting"
|
||||
exit -1
|
||||
end
|
||||
|
||||
data = perform_action(
|
||||
"virsh -c #{LIBVIRT_URI} --readonly dominfo #{deploy_id}")
|
||||
|
||||
if data.class == Fixnum
|
||||
puts "STATE=d"
|
||||
exit 0
|
||||
end
|
||||
|
||||
state = ""
|
||||
|
||||
data.split('\n').each{ |line|
|
||||
state = line.match("^State: (.*)")
|
||||
|
||||
if state
|
||||
state = state[1].strip
|
||||
break
|
||||
end
|
||||
}
|
||||
|
||||
state_short = ""
|
||||
|
||||
case state
|
||||
when "running","blocked","shutdown","dying"
|
||||
state_short = 'a'
|
||||
when "paused"
|
||||
state_short = 'p'
|
||||
when "crashed"
|
||||
state_short = 'c'
|
||||
else
|
||||
state_short = 'd'
|
||||
end
|
||||
|
||||
puts "STATE=#{state_short}"
|
||||
|
||||
host = ARGV[1]
|
||||
|
||||
vmware_drv = VMwareDriver.new(host)
|
||||
|
||||
puts vmware_drv.poll(deploy_id)
|
||||
|
@ -19,71 +19,19 @@
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
|
||||
|
||||
if !ONE_LOCATION
|
||||
ETC_LOCATION="/etc/one" if !defined?(ETC_LOCATION)
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
else
|
||||
ETC_LOCATION=ONE_LOCATION+"/etc" if !defined?(ETC_LOCATION)
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
end
|
||||
|
||||
file = ARGV[0]
|
||||
@host = ARGV[1]
|
||||
|
||||
if !@host or !file
|
||||
exit -1
|
||||
end
|
||||
|
||||
load ETC_LOCATION + "/vmwarerc"
|
||||
|
||||
if USERNAME.class!=String || PASSWORD.class!=String
|
||||
warn "Bad ESX credentials, aborting"
|
||||
exit -1
|
||||
end
|
||||
|
||||
# Define the VM
|
||||
deployment_file = File.dirname(File.dirname(file)) + "/deployment.0"
|
||||
|
||||
data = perform_action("virsh -c #{LIBVIRT_URI} define #{deployment_file}")
|
||||
|
||||
if data.class == Fixnum
|
||||
exit data
|
||||
end
|
||||
|
||||
domainname = ""
|
||||
success = false
|
||||
|
||||
data.split('\n').each{ |line|
|
||||
domainname = line.match("Domain (.*) defined from (.*)")
|
||||
if domainname
|
||||
success = true
|
||||
break
|
||||
end
|
||||
}
|
||||
|
||||
if !success
|
||||
exit -1
|
||||
end
|
||||
|
||||
domainname = domainname[1]
|
||||
|
||||
# Revert snapshot VM
|
||||
# Note: This assumes the checkpoint name is "checkpoint", to change this
|
||||
# it is needed to change also
|
||||
# $ONE_LOCATION/lib/remotes/vmm/vmware/checkpoint
|
||||
|
||||
data = perform_action(
|
||||
"virsh -c #{LIBVIRT_URI} snapshot-revert #{domainname} checkpoint")
|
||||
|
||||
if data.class == Fixnum
|
||||
exit data
|
||||
end
|
||||
|
||||
# Delete checkpoint
|
||||
data = perform_action(
|
||||
"virsh -c #{LIBVIRT_URI} snapshot-delete #{domainname} checkpoint")
|
||||
|
||||
if data.class == Fixnum
|
||||
exit data
|
||||
end
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << File.dirname(__FILE__)
|
||||
|
||||
require 'vmwarelib'
|
||||
|
||||
checkpoint_file = ARGV[0]
|
||||
host = ARGV[1]
|
||||
|
||||
vmware_drv = VMwareDriver.new(host)
|
||||
|
||||
vmware_drv.restore(checkpoint_file)
|
||||
|
@ -19,50 +19,20 @@
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
|
||||
|
||||
if !ONE_LOCATION
|
||||
ETC_LOCATION = "/etc/one" if !defined?(ETC_LOCATION)
|
||||
VAR_LOCATION = "/var/lib/one" if !defined?(VAR_LOCATION)
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
else
|
||||
ETC_LOCATION = ONE_LOCATION + "/etc" if !defined?(ETC_LOCATION)
|
||||
VAR_LOCATION = ONE_LOCATION + "/var" if !defined?(VAR_LOCATION)
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << File.dirname(__FILE__)
|
||||
|
||||
require 'vmwarelib'
|
||||
|
||||
deploy_id = ARGV[0]
|
||||
file = ARGV[1]
|
||||
@host = ARGV[2]
|
||||
|
||||
if !@host or !deploy_id or !file
|
||||
exit -1
|
||||
end
|
||||
|
||||
load ETC_LOCATION + "/vmwarerc"
|
||||
|
||||
if USERNAME.class!=String || PASSWORD.class!=String
|
||||
warn "Bad ESX credentials, aborting"
|
||||
exit -1
|
||||
end
|
||||
|
||||
# Create snapshot
|
||||
checkpoint_xml_file = VAR_LOCATION + "/remotes/vmm/vmware/checkpoint"
|
||||
|
||||
data = perform_action(
|
||||
"virsh -c #{LIBVIRT_URI} snapshot-create #{deploy_id} #{checkpoint_xml_file}")
|
||||
|
||||
if data.class == Fixnum
|
||||
exit data
|
||||
end
|
||||
|
||||
# Suspend VM
|
||||
data = perform_action("virsh -c #{LIBVIRT_URI} suspend #{deploy_id}")
|
||||
|
||||
if data.class == Fixnum
|
||||
exit data
|
||||
end
|
||||
|
||||
# Undefine VM
|
||||
data = perform_action("virsh -c #{LIBVIRT_URI} undefine #{deploy_id}")
|
||||
|
||||
if data.class == Fixnum
|
||||
exit data
|
||||
end
|
||||
host = ARGV[2]
|
||||
|
||||
vmware_drv = VMwareDriver.new(host)
|
||||
|
||||
vmware_drv.save(deploy_id)
|
||||
|
@ -19,44 +19,19 @@
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
|
||||
|
||||
if !ONE_LOCATION
|
||||
ETC_LOCATION="/etc/one" if !defined?(ETC_LOCATION)
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
else
|
||||
ETC_LOCATION=ONE_LOCATION+"/etc" if !defined?(ETC_LOCATION)
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << File.dirname(__FILE__)
|
||||
|
||||
require 'vmwarelib'
|
||||
|
||||
deploy_id = ARGV[0]
|
||||
@host = ARGV[1]
|
||||
|
||||
if !@host or !deploy_id
|
||||
exit -1
|
||||
end
|
||||
|
||||
load ETC_LOCATION + "/vmwarerc"
|
||||
|
||||
if USERNAME.class!=String || PASSWORD.class!=String
|
||||
warn "Bad ESX credentials, aborting"
|
||||
exit -1
|
||||
end
|
||||
|
||||
data = perform_action("virsh -c #{LIBVIRT_URI} shutdown #{deploy_id}")
|
||||
|
||||
if data.class == Fixnum
|
||||
exit data
|
||||
end
|
||||
|
||||
begin
|
||||
data = perform_action("virsh -c #{LIBVIRT_URI} list")
|
||||
if data.class == Fixnum
|
||||
exit data
|
||||
end
|
||||
sleep 2
|
||||
end while data.match(deploy_id)
|
||||
|
||||
data = perform_action("virsh -c #{LIBVIRT_URI} undefine #{deploy_id}")
|
||||
|
||||
if data.class == Fixnum
|
||||
exit data
|
||||
end
|
||||
|
||||
host = ARGV[1]
|
||||
|
||||
vmware_drv = VMwareDriver.new(host)
|
||||
|
||||
vmware_drv.shutdown(deploy_id)
|
||||
|
Loading…
Reference in New Issue
Block a user