mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-21 04:12:37 +09:00
Merge branch 'master' into feature-3782
This commit is contained in:
commit
bdb1e591da
46 files changed
+921
-182
No files matched your search
@@ -167,6 +167,11 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
|
||||
|
||||
NUM_THREADS = 15
|
||||
def sync(host_ids, options)
|
||||
if `id -u`.to_i == 0 || `id -G`.split.collect{|e| e.to_i}.include?(0)
|
||||
STDERR.puts("Cannot run 'onehost sync' as root")
|
||||
exit -1
|
||||
end
|
||||
|
||||
begin
|
||||
current_version = File.read(REMOTES_LOCATION+'/VERSION').strip
|
||||
rescue
|
||||
|
||||
@@ -303,11 +303,11 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
|
||||
d['AR_ID']
|
||||
end
|
||||
|
||||
column :OWNER, "", :left, :size=>10 do |d|
|
||||
column :OWNER, "", :left, :size=>15 do |d|
|
||||
if d['VM']
|
||||
"VM : #{d['VM']}"
|
||||
"V:#{d['VM']}"
|
||||
elsif d['VNET']
|
||||
"NET: #{d['VNET']}"
|
||||
"N:#{d['VNET']}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -319,7 +319,7 @@ class OneVNetHelper < OpenNebulaHelper::OneHelper
|
||||
d["IP"]||"-"
|
||||
end
|
||||
|
||||
column :IP6_GLOBAL, "", :donottruncate, :size=>31 do |d|
|
||||
column :IP6_GLOBAL, "", :donottruncate, :size=>26 do |d|
|
||||
d["IP6_GLOBAL"]||"-"
|
||||
end
|
||||
end.show(leases, {})
|
||||
|
||||
+4
-74
@@ -216,84 +216,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
end
|
||||
|
||||
vms_desc = <<-EOT.unindent
|
||||
Import vCenter running Virtual Machines into OpenNebula
|
||||
Deprecated action in onevcenter, please use onehost importvm instead
|
||||
EOT
|
||||
|
||||
command :vms, vms_desc, :options=>[ VCENTER, USER, PASS ] do
|
||||
if options[:vuser].nil? ||
|
||||
options[:vpass].nil? ||
|
||||
options[:vcenter].nil?
|
||||
STDERR.puts "vCenter connection parameters are mandatory to import"\
|
||||
" VM templates:\n"\
|
||||
"\t --vcenter vCenter hostname\n"\
|
||||
"\t --vuser username to login in vcenter\n"\
|
||||
"\t --vpass password for the user"
|
||||
exit -1
|
||||
end
|
||||
STDERR.puts "Deprecated action in onevcenter, please use onehost "\
|
||||
"importvm instead"
|
||||
|
||||
begin
|
||||
STDOUT.print "\nConnecting to vCenter: #{options[:vcenter]}..."
|
||||
|
||||
vc = VCenterDriver::VIClient.new_connection(
|
||||
:user => options[:vuser],
|
||||
:password => options[:vpass],
|
||||
:host => options[:vcenter])
|
||||
|
||||
STDOUT.print "done!\n\n"
|
||||
|
||||
STDOUT.print "Looking for running Virtual Machines..."
|
||||
|
||||
rs = vc.running_vms
|
||||
|
||||
STDOUT.print "done!\n"
|
||||
|
||||
rs.each {|dc, tmps|
|
||||
STDOUT.print "\nDo you want to process datacenter #{dc} [y/n]? "
|
||||
|
||||
next if STDIN.gets.strip.downcase != 'y'
|
||||
|
||||
if tmps.empty?
|
||||
STDOUT.print " No new running Virtual Machines found in"\
|
||||
" #{dc}...\n\n"
|
||||
next
|
||||
end
|
||||
|
||||
tmps.each{ |v|
|
||||
STDOUT.print "\n * Running Virtual Machine found:\n"\
|
||||
" - Name : #{v[:name]}\n"\
|
||||
" - UUID : #{v[:uuid]}\n"\
|
||||
" - Cluster: #{v[:host]}\n"\
|
||||
" Import this Virtual Machine [y/n]? "
|
||||
|
||||
next if STDIN.gets.strip.downcase != 'y'
|
||||
|
||||
one_v = ::OpenNebula::VirtualMachine.new(
|
||||
::OpenNebula::VirtualMachine.build_xml, vc.one)
|
||||
|
||||
rc = one_v.allocate(v[:one])
|
||||
|
||||
if ::OpenNebula.is_error?(rc)
|
||||
STDOUT.puts " Error creating Virtual Machine: "\
|
||||
"#{rc.message}\n"
|
||||
end
|
||||
|
||||
rc = one_v.deploy v[:host_id]
|
||||
|
||||
if ::OpenNebula.is_error?(rc)
|
||||
STDOUT.puts " Error creating Virtual Machine: "\
|
||||
"#{rc.message}\n"
|
||||
else
|
||||
STDOUT.puts " OpenNebula VM #{one_v.id} "\
|
||||
"created!\n"
|
||||
end
|
||||
}
|
||||
}
|
||||
rescue Exception => e
|
||||
STDOUT.puts "error: #{e.message}"
|
||||
exit -1
|
||||
end
|
||||
|
||||
exit 0
|
||||
exit -1
|
||||
end
|
||||
|
||||
network_desc = <<-EOT.unindent
|
||||
|
||||
@@ -52,6 +52,7 @@ done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/BASE_PATH \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/SAFE_DIRS \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/STAGING_DIR \
|
||||
/DS_DRIVER_ACTION_DATA/DATASTORE/TYPE \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/PATH \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/MD5 \
|
||||
/DS_DRIVER_ACTION_DATA/IMAGE/TEMPLATE/SHA1 \
|
||||
@@ -65,6 +66,7 @@ RESTRICTED_DIRS="${XPATH_ELEMENTS[i++]}"
|
||||
SAFE_DIRS="${XPATH_ELEMENTS[i++]}"
|
||||
BRIDGE_LIST="${XPATH_ELEMENTS[i++]}"
|
||||
STAGING_DIR="${XPATH_ELEMENTS[i++]:-/var/tmp}"
|
||||
TYPE="${XPATH_ELEMENTS[i++]}"
|
||||
SRC="${XPATH_ELEMENTS[i++]}"
|
||||
MD5="${XPATH_ELEMENTS[i++]}"
|
||||
SHA1="${XPATH_ELEMENTS[i++]}"
|
||||
@@ -76,6 +78,11 @@ IMAGE_HASH=`basename $DST`
|
||||
|
||||
set_up_datastore "$BASE_PATH" "$RESTRICTED_DIRS" "$SAFE_DIRS"
|
||||
|
||||
# Disable auto-decompress for the 'files' datastores (type 2)
|
||||
if [ "$TYPE" = "2" ]; then
|
||||
NO_DECOMPRESS="${NO_DECOMPRESS:-yes}"
|
||||
fi
|
||||
|
||||
if [ -n "$BRIDGE_LIST" ]; then
|
||||
DOWNLOADER_ARGS=`set_downloader_args "$MD5" "$SHA1" "$NO_DECOMPRESS" "$LIMIT_TRANSFER_BW" "$SRC" -`
|
||||
else
|
||||
|
||||
@@ -26,6 +26,8 @@ end
|
||||
# TODO : use virsh freecell when available
|
||||
######
|
||||
|
||||
ENV['LANG'] = 'C'
|
||||
|
||||
nodeinfo_text = `virsh -c qemu:///system nodeinfo`
|
||||
exit(-1) if $?.exitstatus != 0
|
||||
|
||||
@@ -40,36 +42,31 @@ nodeinfo_text.split(/\n/).each{|line|
|
||||
}
|
||||
|
||||
######
|
||||
# for everything else, top & proc
|
||||
#####
|
||||
# CPU
|
||||
######
|
||||
vmstat = `vmstat 1 2`
|
||||
$free_cpu = $total_cpu * ((vmstat.split("\n").to_a.last.split)[14].to_i)/100
|
||||
$used_cpu = $total_cpu - $free_cpu
|
||||
|
||||
NETINTERFACE = "eth|bond|em|p[0-9]+p[0-9]+"
|
||||
######
|
||||
# MEMORY
|
||||
######
|
||||
memory = `cat /proc/meminfo`
|
||||
meminfo = Hash.new()
|
||||
memory.each_line do |line|
|
||||
key, value = line.split(':')
|
||||
meminfo[key] = /\d+/.match(value)[0].to_i
|
||||
end
|
||||
|
||||
top_text=`top -bin2`
|
||||
exit(-1) if $?.exitstatus != 0
|
||||
$total_memory = meminfo['MemTotal']
|
||||
|
||||
top_text.gsub!(/^top.*^top.*?$/m, "") # Strip first top output
|
||||
$used_memory = meminfo['MemTotal'] - meminfo['MemFree'] - meminfo['Buffers'] - meminfo['Cached']
|
||||
$free_memory = $total_memory - $used_memory
|
||||
|
||||
top_text.split(/\n/).each{|line|
|
||||
if line.match('^%?Cpu')
|
||||
line[7..-1].split(",").each{|elemento|
|
||||
temp = elemento.strip.split(/[% ]/)
|
||||
if temp[1]=="id"
|
||||
idle = temp[0]
|
||||
$free_cpu = idle.to_f * $total_cpu.to_f / 100
|
||||
$used_cpu = $total_cpu.to_f - $free_cpu
|
||||
break
|
||||
end
|
||||
|
||||
}
|
||||
end
|
||||
}
|
||||
|
||||
$total_memory = `free -k|grep "Mem:" | awk '{print $2}'`
|
||||
tmp=`free -k|grep "buffers\/cache"|awk '{print $3 " " $4}'`.split
|
||||
|
||||
$used_memory=tmp[0]
|
||||
$free_memory=tmp[1]
|
||||
######
|
||||
# INTERFACE
|
||||
######
|
||||
NETINTERFACE = "eth|bond|em|enp|p[0-9]+p[0-9]+"
|
||||
|
||||
net_text=`cat /proc/net/dev`
|
||||
exit(-1) if $?.exitstatus != 0
|
||||
|
||||
@@ -320,7 +320,7 @@ function mkfs_command {
|
||||
OPTS="-F"
|
||||
;;
|
||||
|
||||
"reiserfs")
|
||||
"reiserfs"|"xfs")
|
||||
OPTS="-f -q"
|
||||
;;
|
||||
|
||||
@@ -355,7 +355,9 @@ function mkfs_command {
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
OPTS=""
|
||||
echo ""
|
||||
echo "Filesystem '$FSTYPE' not valid." 1>&2
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
@@ -356,11 +356,18 @@ void OpenNebulaTemplate::set_conf_default()
|
||||
#*******************************************************************************
|
||||
# Auth Manager Configuration
|
||||
#*******************************************************************************
|
||||
# DEFAULT_AUTH
|
||||
# SESSION_EXPIRATION_TIME
|
||||
# ENABLE_OTHER_PERMISSIONS
|
||||
# DEFAULT_UMASK
|
||||
#*******************************************************************************
|
||||
*/
|
||||
// DEFAULT_AUTH
|
||||
value = "default";
|
||||
|
||||
attribute = new SingleAttribute("DEFAULT_AUTH",value);
|
||||
conf_default.insert(make_pair(attribute->name(),attribute));
|
||||
|
||||
// SESSION_EXPIRATION_TIME
|
||||
value = "0";
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ module OpenNebula
|
||||
raise "ONE_AUTH file not present"
|
||||
end
|
||||
|
||||
@one_auth.rstrip!
|
||||
@one_auth = @one_auth.rstrip
|
||||
|
||||
if endpoint
|
||||
@one_endpoint = endpoint
|
||||
@@ -144,6 +144,8 @@ module OpenNebula
|
||||
@one_endpoint = "http://localhost:2633/RPC2"
|
||||
end
|
||||
|
||||
@one_endpoint= @one_endpoint.rstrip
|
||||
|
||||
@async = !options[:sync]
|
||||
|
||||
timeout=nil
|
||||
|
||||
@@ -503,7 +503,7 @@ if (Config.isTemplateCreationTabEnabled('input_output')){
|
||||
'</label>'+
|
||||
'<input type="text" id="PORT" name="port" />'+
|
||||
'</div>'+
|
||||
'<div class="large-6 columns hypervisor only_kvm only_vmware only_xen">'+
|
||||
'<div class="large-6 columns">'+
|
||||
'<label for="KEYMAP">'+tr("Keymap")+
|
||||
'<span class="tip">'+tr("Keyboard configuration locale to use in the VNC/SPICE display")+'</span>'+
|
||||
'</label>'+
|
||||
|
||||
@@ -87,26 +87,6 @@ get '/vcenter/templates' do
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
get '/vcenter/vms' do
|
||||
begin
|
||||
vms = vcenter_client.running_vms(
|
||||
$cloud_auth.client(session[:user], session[:active_zone_endpoint]))
|
||||
if vms.nil?
|
||||
msg = "No datacenter found"
|
||||
logger.error("[vCenter] " + msg)
|
||||
error = Error.new(msg)
|
||||
error 404, error.to_json
|
||||
end
|
||||
|
||||
[200, vms.to_json]
|
||||
rescue Exception => e
|
||||
logger.error("[vCenter] " + e.message)
|
||||
error = Error.new(e.message)
|
||||
error 403, error.to_json
|
||||
end
|
||||
end
|
||||
|
||||
get '/vcenter/networks' do
|
||||
begin
|
||||
networks = vcenter_client.vcenter_networks(
|
||||
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../common/failmigrate
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2015, OpenNebula Project (OpenNebula.org), C12G Labs #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
# FAILMIGRATE SOURCE DST remote_system_dir vmid dsid template
|
||||
# - SOURCE is the host where the VM is running
|
||||
# - DST is the host where the VM failed to be migrated
|
||||
# - remote_system_dir is the path for the VM home in the system datastore
|
||||
# - vmid is the id of the VM
|
||||
# - dsid is the target datastore
|
||||
# - template is the template of the VM in XML and base64 encoded
|
||||
|
||||
# To access the vm_template you can use the xpath.rb utility. Check the
|
||||
# datastore drivers for an example.
|
||||
|
||||
exit 0
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../common/failmigrate
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../common/failmigrate
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../common/failmigrate
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../common/failmigrate
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../common/failmigrate
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../common/failmigrate
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../common/failmigrate
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../common/failmigrate
|
||||
+5
-3
@@ -36,7 +36,6 @@
|
||||
const char * UserPool::CORE_AUTH = "core";
|
||||
const char * UserPool::SERVER_AUTH = "server*";
|
||||
const char * UserPool::PUBLIC_AUTH = "public";
|
||||
const char * UserPool::DEFAULT_AUTH = "default";
|
||||
|
||||
const char * UserPool::SERVER_NAME = "serveradmin";
|
||||
|
||||
@@ -248,7 +247,7 @@ error_no_open:
|
||||
|
||||
erro_exists:
|
||||
oss << "Password file " << filenames[i] << " already exists "
|
||||
<< "but OpenNebula is boostraping the database. Check your "
|
||||
<< "but OpenNebula is boostraping the database. Check your "
|
||||
<< "database configuration in oned.conf.";
|
||||
goto error_common;
|
||||
|
||||
@@ -713,6 +712,7 @@ bool UserPool::authenticate_external(const string& username,
|
||||
string mad_pass;
|
||||
string error_str;
|
||||
string tmp_str;
|
||||
string default_auth;
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
AuthManager * authm = nd.get_authm();
|
||||
@@ -734,7 +734,9 @@ bool UserPool::authenticate_external(const string& username,
|
||||
}
|
||||
|
||||
//Initialize authentication request and call the driver
|
||||
ar.add_authenticate(UserPool::DEFAULT_AUTH, username,"-",token);
|
||||
nd.get_configuration_attribute("DEFAULT_AUTH",default_auth);
|
||||
|
||||
ar.add_authenticate(default_auth, username,"-",token);
|
||||
|
||||
authm->trigger(AuthManager::AUTHENTICATE, &ar);
|
||||
ar.wait();
|
||||
|
||||
@@ -478,9 +478,11 @@ class ExecDriver < VirtualMachineDriver
|
||||
action = VmmAction.new(self, id, :migrate, drv_message)
|
||||
pre = "PRE"
|
||||
post = "POST"
|
||||
failed = "FAIL"
|
||||
|
||||
pre << action.data[:tm_command] << " " << action.data[:vm]
|
||||
post << action.data[:tm_command] << " " << action.data[:vm]
|
||||
failed << action.data[:tm_command] << " " << action.data[:vm]
|
||||
|
||||
steps=[
|
||||
# Execute a pre-migrate TM setup
|
||||
@@ -499,7 +501,15 @@ class ExecDriver < VirtualMachineDriver
|
||||
{
|
||||
:driver => :vmm,
|
||||
:action => :migrate,
|
||||
:parameters => [:deploy_id, :dest_host, :host]
|
||||
:parameters => [:deploy_id, :dest_host, :host],
|
||||
:fail_actions => [
|
||||
{
|
||||
:driver => :tm,
|
||||
:action => :tm_failmigrate,
|
||||
:parameters => failed.split,
|
||||
:no_fail => true
|
||||
}
|
||||
]
|
||||
},
|
||||
# Execute networking clean up operations
|
||||
# NOTE: VM is now in the new host. If we fail from now on, oned will
|
||||
|
||||
@@ -146,7 +146,50 @@ class VIClient
|
||||
# The associated resource pool for this connection
|
||||
########################################################################
|
||||
def resource_pool
|
||||
return @cluster.resourcePool
|
||||
rp_name = @one_host["TEMPLATE/VCENTER_RESOURCE_POOL"]
|
||||
|
||||
if rp_name.nil?
|
||||
@cluster.resourcePool
|
||||
else
|
||||
find_resource_pool(rp_name)
|
||||
end
|
||||
end
|
||||
|
||||
########################################################################
|
||||
# Searches the desired ResourcePool of the DataCenter for the current
|
||||
# connection. Returns a RbVmomi::VIM::ResourcePool or the default pool
|
||||
# if not found
|
||||
# @param rpool [String] the ResourcePool name
|
||||
########################################################################
|
||||
def find_resource_pool(poolName)
|
||||
baseEntity = @cluster
|
||||
entityArray = poolName.split('/')
|
||||
entityArray.each do |entityArrItem|
|
||||
if entityArrItem != ''
|
||||
if baseEntity.is_a? RbVmomi::VIM::Folder
|
||||
baseEntity = baseEntity.childEntity.find { |f|
|
||||
f.name == entityArrItem
|
||||
} or return @cluster.resourcePool
|
||||
elsif baseEntity.is_a? RbVmomi::VIM::ClusterComputeResource
|
||||
baseEntity = baseEntity.resourcePool.resourcePool.find { |f|
|
||||
f.name == entityArrItem
|
||||
} or return @cluster.resourcePool
|
||||
elsif baseEntity.is_a? RbVmomi::VIM::ResourcePool
|
||||
baseEntity = baseEntity.resourcePool.find { |f|
|
||||
f.name == entityArrItem
|
||||
} or return @cluster.resourcePool
|
||||
else
|
||||
return @cluster.resourcePool
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if !baseEntity.is_a?(RbVmomi::VIM::ResourcePool) and
|
||||
baseEntity.respond_to?(:resourcePool)
|
||||
baseEntity = baseEntity.resourcePool
|
||||
end
|
||||
|
||||
baseEntity
|
||||
end
|
||||
|
||||
########################################################################
|
||||
@@ -538,7 +581,8 @@ class VCenterHost < ::OpenNebula::Host
|
||||
|
||||
############################################################################
|
||||
# Generate an OpenNebula monitor string for this host. Reference:
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk25pubs/ReferenceGuide/vim.ComputeResource.Summary.html
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk25pubs/Reference
|
||||
# Guide/vim.ComputeResource.Summary.html
|
||||
# - effectiveCpu: Effective CPU resources (in MHz) available to run
|
||||
# VMs. This is the aggregated from all running hosts excluding hosts in
|
||||
# maintenance mode or unresponsive are not counted.
|
||||
@@ -690,6 +734,22 @@ class VCenterVm
|
||||
hid = VIClient::translate_hostname(hostname)
|
||||
connection = VIClient.new(hid)
|
||||
vm = connection.find_vm_template(deploy_id)
|
||||
|
||||
# Find out if we need to reconfigure capacity
|
||||
xml = REXML::Document.new xml_text
|
||||
|
||||
expected_cpu = xml.root.elements["//TEMPLATE/CPU"].text
|
||||
expected_memory = xml.root.elements["//TEMPLATE/MEMORY"].text
|
||||
current_cpu = vm.config.hardware.numCPU
|
||||
current_memory = vm.config.hardware.memoryMB
|
||||
|
||||
if current_cpu != expected_cpu or current_memory != expected_memory
|
||||
capacity_hash = {:numCPUs => expected_cpu.to_i,
|
||||
:memoryMB => expected_memory }
|
||||
spec = RbVmomi::VIM.VirtualMachineConfigSpec(capacity_hash)
|
||||
vm.ReconfigVM_Task(:spec => spec).wait_for_completion
|
||||
end
|
||||
|
||||
vm.PowerOnVM_Task.wait_for_completion
|
||||
return vm.config.uuid
|
||||
end
|
||||
@@ -1058,6 +1118,8 @@ class VCenterVm
|
||||
#
|
||||
########################################################################
|
||||
def vm_to_one
|
||||
host_name = @vm.runtime.host.parent.name
|
||||
|
||||
str = "NAME = \"#{@vm.name}\"\n"\
|
||||
"CPU = \"#{@vm.config.hardware.numCPU}\"\n"\
|
||||
"vCPU = \"#{@vm.config.hardware.numCPU}\"\n"\
|
||||
@@ -1068,21 +1130,25 @@ class VCenterVm
|
||||
" VM_TEMPLATE =\"#{@vm.config.uuid}\"\n"\
|
||||
"]\n"\
|
||||
"IMPORT_VM_ID = \"#{@vm.config.uuid}\"\n"\
|
||||
"SCHED_REQUIREMENTS=\"NAME=\\\"#{@vm.runtime.host.parent.name}\\\"\"\n"
|
||||
"SCHED_REQUIREMENTS=\"NAME=\\\"#{host_name}\\\"\"\n"
|
||||
|
||||
vp=@vm.config.extraConfig.select{|v| v[:key]=="remotedisplay.vnc.port"}
|
||||
vp = @vm.config.extraConfig.select{|v|
|
||||
v[:key]=="remotedisplay.vnc.port"}
|
||||
keymap = @vm.config.extraConfig.select{|v|
|
||||
v[:key]=="remotedisplay.vnc.keymap"}
|
||||
|
||||
if vp.size > 0
|
||||
str << "GRAPHICS = [\n"\
|
||||
" TYPE =\"vnc\",\n"\
|
||||
" LISTEN =\"0.0.0.0\",\n"\
|
||||
" PORT =\"#{vp[0][:value]}\"\n"\
|
||||
"]\n"
|
||||
" PORT =\"#{vp[0][:value]}\"\n"
|
||||
str << " ,KEYMAP =\"#{keymap[0][:value]}\"\n" if keymap
|
||||
str << "]\n"
|
||||
end
|
||||
|
||||
if @vm.config.annotation.nil? || @vm.config.annotation.empty?
|
||||
str << "DESCRIPTION = \"vCenter Virtual Machine imported by OpenNebula"\
|
||||
" from Cluster #{@vm.runtime.host.parent.name}\"\n"
|
||||
str << "DESCRIPTION = \"vCenter Virtual Machine imported by"\
|
||||
" OpenNebula from Cluster #{@vm.runtime.host.parent.name}\"\n"
|
||||
else
|
||||
notes = @vm.config.annotation.gsub("\\", "\\\\").gsub("\"", "\\\"")
|
||||
str << "DESCRIPTION = \"#{notes}\"\n"
|
||||
@@ -1193,7 +1259,6 @@ private
|
||||
def self.clone_vm(xml_text)
|
||||
|
||||
xml = REXML::Document.new xml_text
|
||||
|
||||
pcs = xml.root.get_elements("//USER_TEMPLATE/PUBLIC_CLOUD")
|
||||
|
||||
raise "Cannot find VCenter element in VM template." if pcs.nil?
|
||||
@@ -1210,33 +1275,29 @@ private
|
||||
raise "Cannot find VM_TEMPLATE in VCenter element." if uuid.nil?
|
||||
|
||||
uuid = uuid.text
|
||||
|
||||
vmid = xml.root.elements["/VM/ID"].text
|
||||
|
||||
hid = xml.root.elements["//HISTORY_RECORDS/HISTORY/HID"]
|
||||
|
||||
raise "Cannot find host id in deployment file history." if hid.nil?
|
||||
|
||||
context = xml.root.elements["//TEMPLATE/CONTEXT"]
|
||||
|
||||
connection = VIClient.new(hid)
|
||||
|
||||
vc_template = connection.find_vm_template(uuid)
|
||||
|
||||
relocate_spec = RbVmomi::VIM.VirtualMachineRelocateSpec(
|
||||
:diskMoveType => :moveChildMostDiskBacking,
|
||||
:pool => connection.resource_pool)
|
||||
:diskMoveType => :moveChildMostDiskBacking,
|
||||
:pool => connection.resource_pool)
|
||||
|
||||
clone_spec = RbVmomi::VIM.VirtualMachineCloneSpec(
|
||||
:location => relocate_spec,
|
||||
:powerOn => false,
|
||||
:template => false)
|
||||
:location => relocate_spec,
|
||||
:powerOn => false,
|
||||
:template => false)
|
||||
|
||||
begin
|
||||
vm = vc_template.CloneVM_Task(
|
||||
:folder => vc_template.parent,
|
||||
:name => "one-#{vmid}",
|
||||
:spec => clone_spec).wait_for_completion
|
||||
:folder => vc_template.parent,
|
||||
:name => "one-#{vmid}",
|
||||
:spec => clone_spec).wait_for_completion
|
||||
rescue Exception => e
|
||||
|
||||
if !e.message.start_with?('DuplicateName')
|
||||
@@ -1247,8 +1308,7 @@ private
|
||||
|
||||
raise "Cannot clone VM Template" if vm.nil?
|
||||
|
||||
vm.Destroy_Task.wait_for_completion
|
||||
|
||||
vm.Destroy_Task.wait_for_completion
|
||||
vm = vc_template.CloneVM_Task(
|
||||
:folder => vc_template.parent,
|
||||
:name => "one-#{vmid}",
|
||||
@@ -1257,8 +1317,11 @@ private
|
||||
|
||||
vm_uuid = vm.config.uuid
|
||||
|
||||
# VNC Section
|
||||
|
||||
vnc_port = xml.root.elements["/VM/TEMPLATE/GRAPHICS/PORT"]
|
||||
vnc_listen = xml.root.elements["/VM/TEMPLATE/GRAPHICS/LISTEN"]
|
||||
vnc_keymap = xml.root.elements["/VM/TEMPLATE/GRAPHICS/KEYMAP"]
|
||||
|
||||
if !vnc_listen
|
||||
vnc_listen = "0.0.0.0"
|
||||
@@ -1271,11 +1334,16 @@ private
|
||||
|
||||
if vnc_port
|
||||
config_array +=
|
||||
[{:key=>"remotedisplay.vnc.enabled", :value=>"TRUE"},
|
||||
{:key=>"remotedisplay.vnc.port", :value=>vnc_port.text},
|
||||
{:key=>"remotedisplay.vnc.ip", :value=>vnc_listen}]
|
||||
[{:key=>"remotedisplay.vnc.enabled",:value=>"TRUE"},
|
||||
{:key=>"remotedisplay.vnc.port", :value=>vnc_port.text},
|
||||
{:key=>"remotedisplay.vnc.ip", :value=>vnc_listen}]
|
||||
end
|
||||
|
||||
config_array += [{:key=>"remotedisplay.vnc.keymap",
|
||||
:value=>vnc_keymap.text}] if vnc_keymap
|
||||
|
||||
# Context section
|
||||
|
||||
if context
|
||||
# Remove <CONTEXT> (9) and </CONTEXT>\n (11)
|
||||
context_text = "# Context variables generated by OpenNebula\n"
|
||||
@@ -1293,7 +1361,8 @@ private
|
||||
context_vnc_spec = {:extraConfig =>config_array}
|
||||
end
|
||||
|
||||
# Take care of the NIC section, build the reconfig hash
|
||||
# NIC section, build the reconfig hash
|
||||
|
||||
nics = xml.root.get_elements("//TEMPLATE/NIC")
|
||||
nic_spec = {}
|
||||
|
||||
@@ -1309,12 +1378,19 @@ private
|
||||
nic_spec = {:deviceChange => nic_array}
|
||||
end
|
||||
|
||||
if !context_vnc_spec.empty? or !nic_spec.empty?
|
||||
spec_hash = context_vnc_spec.merge(nic_spec)
|
||||
spec = RbVmomi::VIM.VirtualMachineConfigSpec(spec_hash)
|
||||
vm.ReconfigVM_Task(:spec => spec).wait_for_completion
|
||||
end
|
||||
# Capacity section
|
||||
|
||||
cpu = xml.root.elements["//TEMPLATE/CPU"].text
|
||||
memory = xml.root.elements["//TEMPLATE/MEMORY"].text
|
||||
capacity_spec = {:numCPUs => cpu.to_i,
|
||||
:memoryMB => memory }
|
||||
|
||||
# Perform the VM reconfiguration
|
||||
spec_hash = context_vnc_spec.merge(nic_spec).merge(capacity_spec)
|
||||
spec = RbVmomi::VIM.VirtualMachineConfigSpec(spec_hash)
|
||||
vm.ReconfigVM_Task(:spec => spec).wait_for_completion
|
||||
|
||||
# Power on the VM
|
||||
vm.PowerOnVM_Task.wait_for_completion
|
||||
|
||||
return vm_uuid
|
||||
|
||||
@@ -28,6 +28,7 @@ $: << RUBY_LIB_LOCATION
|
||||
$: << File.dirname(__FILE__)
|
||||
|
||||
require 'vmware_driver'
|
||||
require 'vi_driver'
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Wait the VM to shutdown TIMEOUT (xPOLL_INTERVAL) seconds.
|
||||
@@ -39,12 +40,14 @@ TIMEOUT=300
|
||||
deploy_id = ARGV[0]
|
||||
host = ARGV[1]
|
||||
|
||||
VIDriver::initialize(host)
|
||||
|
||||
vmware_drv = VMwareDriver.new(host)
|
||||
|
||||
vmware_drv.shutdown(deploy_id)
|
||||
|
||||
count=0
|
||||
while (vmware_drv.poll(deploy_id).match(/STATE=(.*)/)[1] != "d") do
|
||||
while (VIDriver::poll_vm(deploy_id).match(/STATE=(.*)/)[1] != "d") do
|
||||
sleep POLL_INTERVAL
|
||||
if count > TIMEOUT then
|
||||
OpenNebula.log_debug("Timeout reached and VM #{deploy_id} is still alive.")
|
||||
|
||||
@@ -62,8 +62,15 @@ class EbtablesVLAN < VNMMAD::VNMDriver
|
||||
def deactivate
|
||||
lock
|
||||
|
||||
attach_nic_id = @vm['TEMPLATE/NIC[ATTACH="YES"]/NIC_ID']
|
||||
|
||||
process do |nic|
|
||||
if attach_nic_id && attach_nic_id != nic[:nic_id]
|
||||
next
|
||||
end
|
||||
|
||||
mac = nic[:mac]
|
||||
|
||||
# remove 0-padding
|
||||
mac = mac.split(":").collect{|e| e.hex.to_s(16)}.join(":")
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ module VNMMAD
|
||||
lock
|
||||
|
||||
vm_id = @vm['ID']
|
||||
|
||||
|
||||
process do |nic|
|
||||
#:white_ports_tcp => iptables_range
|
||||
#:white_ports_udp => iptables_range
|
||||
@@ -93,8 +93,15 @@ module VNMMAD
|
||||
def deactivate
|
||||
lock
|
||||
|
||||
vm_id = @vm['ID']
|
||||
vm_id = @vm['ID']
|
||||
|
||||
attach_nic_id = @vm['TEMPLATE/NIC[ATTACH="YES"]/NIC_ID']
|
||||
|
||||
process do |nic|
|
||||
if attach_nic_id && attach_nic_id != nic[:nic_id]
|
||||
next
|
||||
end
|
||||
|
||||
chain = "one-#{vm_id}-#{nic[:network_id]}"
|
||||
iptables_out = `#{command(:iptables)} -n -v --line-numbers -L FORWARD`
|
||||
if m = iptables_out.match(/.*#{chain}.*/)
|
||||
@@ -196,4 +203,4 @@ module VNMMAD
|
||||
"#{command(:iptables)} #{rule}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -23,7 +23,7 @@ module VNMMAD
|
||||
|
||||
DRIVER = "sg"
|
||||
XPATH_FILTER = "TEMPLATE/NIC"
|
||||
|
||||
|
||||
# Creates a new SG driver and scans SG Rules
|
||||
def initialize(vm, deploy_id = nil, hypervisor = nil)
|
||||
super(vm, XPATH_FILTER, deploy_id, hypervisor)
|
||||
@@ -48,7 +48,7 @@ module VNMMAD
|
||||
@security_group_rules = rules
|
||||
end
|
||||
|
||||
# Activate the rules, bootstrap iptables chains and set filter rules for
|
||||
# Activate the rules, bootstrap iptables chains and set filter rules for
|
||||
# each VM NIC
|
||||
def activate
|
||||
deactivate
|
||||
@@ -68,7 +68,7 @@ module VNMMAD
|
||||
sg_ids.each do |sg_id|
|
||||
rules = @security_group_rules[sg_id]
|
||||
|
||||
sg = SGIPTables::SecurityGroupIPTables.new(@vm, nic, sg_id,
|
||||
sg = SGIPTables::SecurityGroupIPTables.new(@vm, nic, sg_id,
|
||||
rules)
|
||||
|
||||
begin
|
||||
@@ -92,7 +92,13 @@ module VNMMAD
|
||||
lock
|
||||
|
||||
begin
|
||||
attach_nic_id = @vm['TEMPLATE/NIC[ATTACH="YES"]/NIC_ID']
|
||||
|
||||
@vm.nics.each do |nic|
|
||||
if attach_nic_id && attach_nic_id != nic[:nic_id]
|
||||
next
|
||||
end
|
||||
|
||||
SGIPTables.nic_deactivate(@vm, nic)
|
||||
end
|
||||
rescue Exception => e
|
||||
|
||||
@@ -72,7 +72,13 @@ class OpenvSwitchVLAN < VNMMAD::VNMDriver
|
||||
def deactivate
|
||||
lock
|
||||
|
||||
attach_nic_id = @vm['TEMPLATE/NIC[ATTACH="YES"]/NIC_ID']
|
||||
|
||||
process do |nic|
|
||||
if attach_nic_id && attach_nic_id != nic[:nic_id]
|
||||
next
|
||||
end
|
||||
|
||||
@nic = nic
|
||||
|
||||
# Remove flows
|
||||
|
||||
Reference in new issue
Block a user