mirror of
https://github.com/OpenNebula/one.git
synced 2025-02-28 17:57:22 +03:00
parent
1c30a04726
commit
224fb62712
33
install.sh
33
install.sh
@ -255,12 +255,14 @@ VAR_DIRS="$VAR_LOCATION/remotes \
|
||||
$VAR_LOCATION/remotes/im/vcenter.d \
|
||||
$VAR_LOCATION/remotes/im/ec2.d \
|
||||
$VAR_LOCATION/remotes/im/az.d \
|
||||
$VAR_LOCATION/remotes/im/one.d \
|
||||
$VAR_LOCATION/remotes/vmm \
|
||||
$VAR_LOCATION/remotes/vmm/lib \
|
||||
$VAR_LOCATION/remotes/vmm/kvm \
|
||||
$VAR_LOCATION/remotes/vmm/vcenter \
|
||||
$VAR_LOCATION/remotes/vmm/ec2 \
|
||||
$VAR_LOCATION/remotes/vmm/az \
|
||||
$VAR_LOCATION/remotes/vmm/one \
|
||||
$VAR_LOCATION/remotes/vnm \
|
||||
$VAR_LOCATION/remotes/vnm/802.1Q \
|
||||
$VAR_LOCATION/remotes/vnm/vxlan \
|
||||
@ -386,6 +388,7 @@ INSTALL_FILES=(
|
||||
IM_PROBES_VCENTER_FILES:$VAR_LOCATION/remotes/im/vcenter.d
|
||||
IM_PROBES_EC2_FILES:$VAR_LOCATION/remotes/im/ec2.d
|
||||
IM_PROBES_AZ_FILES:$VAR_LOCATION/remotes/im/az.d
|
||||
IM_PROBES_ONE_FILES:$VAR_LOCATION/remotes/im/one.d
|
||||
IM_PROBES_VERSION:$VAR_LOCATION/remotes
|
||||
AUTH_SSH_FILES:$VAR_LOCATION/remotes/auth/ssh
|
||||
AUTH_X509_FILES:$VAR_LOCATION/remotes/auth/x509
|
||||
@ -401,6 +404,7 @@ INSTALL_FILES=(
|
||||
VMM_EXEC_VCENTER_SCRIPTS:$VAR_LOCATION/remotes/vmm/vcenter
|
||||
VMM_EXEC_EC2_SCRIPTS:$VAR_LOCATION/remotes/vmm/ec2
|
||||
VMM_EXEC_AZ_SCRIPTS:$VAR_LOCATION/remotes/vmm/az
|
||||
VMM_EXEC_ONE_SCRIPTS:$VAR_LOCATION/remotes/vmm/one
|
||||
TM_FILES:$VAR_LOCATION/remotes/tm
|
||||
TM_SHARED_FILES:$VAR_LOCATION/remotes/tm/shared
|
||||
TM_FS_LVM_FILES:$VAR_LOCATION/remotes/tm/fs_lvm
|
||||
@ -612,7 +616,8 @@ RUBY_LIB_FILES="src/mad/ruby/ActionManager.rb \
|
||||
src/sunstone/OpenNebulaVNC.rb \
|
||||
src/vmm_mad/remotes/vcenter/vcenter_driver.rb \
|
||||
src/vmm_mad/remotes/az/az_driver.rb \
|
||||
src/vmm_mad/remotes/ec2/ec2_driver.rb"
|
||||
src/vmm_mad/remotes/ec2/ec2_driver.rb \
|
||||
src/vmm_mad/remotes/one/opennebula_driver.rb"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Ruby auth library files, to be installed under $LIB_LOCATION/ruby/opennebula
|
||||
@ -791,6 +796,30 @@ VMM_EXEC_AZ_SCRIPTS="src/vmm_mad/remotes/az/cancel \
|
||||
src/vmm_mad/remotes/az/prereconfigure \
|
||||
src/vmm_mad/remotes/az/resize_disk"
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# VMM Driver opennebula scripts, to be installed under $REMOTES_LOCATION/vmm/one
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
VMM_EXEC_ONE_SCRIPTS="src/vmm_mad/remotes/one/cancel \
|
||||
src/vmm_mad/remotes/one/attach_disk \
|
||||
src/vmm_mad/remotes/one/detach_disk \
|
||||
src/vmm_mad/remotes/one/attach_nic \
|
||||
src/vmm_mad/remotes/one/detach_nic \
|
||||
src/vmm_mad/remotes/one/snapshot_create \
|
||||
src/vmm_mad/remotes/one/snapshot_revert \
|
||||
src/vmm_mad/remotes/one/snapshot_delete \
|
||||
src/vmm_mad/remotes/one/deploy \
|
||||
src/vmm_mad/remotes/one/migrate \
|
||||
src/vmm_mad/remotes/one/migrate_local \
|
||||
src/vmm_mad/remotes/one/restore \
|
||||
src/vmm_mad/remotes/one/reboot \
|
||||
src/vmm_mad/remotes/one/reset \
|
||||
src/vmm_mad/remotes/one/save \
|
||||
src/vmm_mad/remotes/one/poll \
|
||||
src/vmm_mad/remotes/one/shutdown \
|
||||
src/vmm_mad/remotes/one/reconfigure \
|
||||
src/vmm_mad/remotes/one/prereconfigure"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Information Manager Probes, to be installed under $REMOTES_LOCATION/im
|
||||
#-------------------------------------------------------------------------------
|
||||
@ -820,6 +849,8 @@ IM_PROBES_EC2_FILES="src/im_mad/remotes/ec2.d/poll"
|
||||
|
||||
IM_PROBES_AZ_FILES="src/im_mad/remotes/az.d/poll"
|
||||
|
||||
IM_PROBES_ONE_FILES="src/im_mad/remotes/one.d/poll"
|
||||
|
||||
IM_PROBES_VERSION="src/im_mad/remotes/VERSION"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
@ -423,6 +423,18 @@ IM_MAD = [
|
||||
# ARGUMENTS = "-c -t 1 -r 0 az" ]
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Hybrid OpenNebula Information Driver Manager Configuration
|
||||
# -r number of retries when monitoring a host
|
||||
# -t number of threads, i.e. number of hosts monitored at the same time
|
||||
#-------------------------------------------------------------------------------
|
||||
# IM_MAD = [
|
||||
# NAME = "one",
|
||||
# SUNSTONE_NAME = "OpenNebula",
|
||||
# EXECUTABLE = "one_im_sh",
|
||||
# ARGUMENTS = "-c -t 1 -r 0 one" ]
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Dummy Information Driver Manager Configuration
|
||||
#-------------------------------------------------------------------------------
|
||||
@ -577,6 +589,25 @@ VM_MAD = [
|
||||
#]
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Hybrid OpenNebula Virtualization Driver Manager Configuration
|
||||
# -r number of retries when monitoring a host
|
||||
# -t number of threads, i.e. number of actions performed at the same time
|
||||
#-------------------------------------------------------------------------------
|
||||
# VM_MAD = [
|
||||
# NAME = "one",
|
||||
# SUNSTONE_NAME = "OpenNebula",
|
||||
# EXECUTABLE = "one_vmm_sh",
|
||||
# ARGUMENTS = "-t 15 -r 0 one",
|
||||
# TYPE = "xml",
|
||||
# KEEP_SNAPSHOTS = "no",
|
||||
# IMPORTED_VMS_ACTIONS = "terminate, terminate-hard, hold, release, suspend,
|
||||
# resume, delete, reboot, reboot-hard, resched, unresched, poweroff,
|
||||
# poweroff-hard"
|
||||
# ]
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Dummy Virtualization Driver Configuration
|
||||
#-------------------------------------------------------------------------------
|
||||
|
@ -722,7 +722,8 @@ static const map<std::string, unsigned int> MAX_HOST_VAR_SIZES = {
|
||||
{"EC2_SECRET", 41},
|
||||
{"AZ_ID", 41},
|
||||
{"AZ_CERT", 3130},
|
||||
{"VCENTER_PASSWORD", 22}
|
||||
{"VCENTER_PASSWORD", 22},
|
||||
{"ONE_PASSWORD", 22}
|
||||
};
|
||||
|
||||
int Host::post_update_template(string& error)
|
||||
|
36
src/im_mad/remotes/one.d/poll
Executable file
36
src/im_mad/remotes/one.d/poll
Executable file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2016, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# 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. #
|
||||
# -------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
|
||||
require 'opennebula_driver'
|
||||
host = ARGV[-1]
|
||||
host_id = ARGV[-2]
|
||||
|
||||
one2one_drv = OpenNebulaDriver.new(host, host_id)
|
||||
|
||||
one2one_drv.monitor_all_vms
|
||||
|
@ -32,7 +32,7 @@ module OpenNebulaJSON
|
||||
host_hash['cluster_id'].to_i)
|
||||
delete_values = ['name', 'im_mad', 'vm_mad', 'cluster_id']
|
||||
|
||||
template_str = hash_to_str(host_hash, delete_values)
|
||||
template_str = template_to_str(host_hash, delete_values)
|
||||
if !template_str.nil?
|
||||
params=Hash.new
|
||||
params['template_raw'] = template_str
|
||||
|
@ -121,6 +121,7 @@ define(function(require) {
|
||||
$("#im_mad", context).val(this.value).change();
|
||||
$(".vcenter_credentials", context).hide();
|
||||
$(".ec2_extra", context).hide();
|
||||
$(".one_extra", context).hide();
|
||||
$(".drivers", context).hide();
|
||||
$("#name_container", context).show();
|
||||
|
||||
@ -134,6 +135,9 @@ define(function(require) {
|
||||
} else if (this.value == "ec2") {
|
||||
$(".ec2_extra", context).show();
|
||||
Sunstone.showFormPanelSubmit(TAB_ID);
|
||||
} else if (this.value == "one") {
|
||||
$(".one_extra", context).show();
|
||||
Sunstone.showFormPanelSubmit(TAB_ID);
|
||||
} else {
|
||||
Sunstone.showFormPanelSubmit(TAB_ID);
|
||||
}
|
||||
@ -160,6 +164,27 @@ define(function(require) {
|
||||
tr.remove();
|
||||
});
|
||||
|
||||
context.off("click", ".add_custom_tag", context);
|
||||
context.on("click", ".add_custom_tag", context, function(){
|
||||
$("tbody.capacity_one", context).append(
|
||||
"<tr class='row_capacity_one'>\
|
||||
<td style='display: flex; justify-content: flex-start'>\
|
||||
<input class='capacity_key' type='text' name='key'>\
|
||||
</td>\
|
||||
<td>\
|
||||
<input class='capacity_value' type='number' min='0' name='value'>\
|
||||
</td>\
|
||||
<td style='width: 150%; display: flex; justify-content: flex-end'>\
|
||||
<a href='#'><i class='fa fa-times-circle remove-capacity'></i></a>\
|
||||
</td>\
|
||||
</tr>");
|
||||
});
|
||||
|
||||
context.on("click", "tbody.capacity_one i.remove-capacity", function(){
|
||||
var tr = $(this).closest('tr');
|
||||
tr.remove();
|
||||
});
|
||||
|
||||
$("#host_type_mad", context).change();
|
||||
|
||||
$("form.vcenter_credentials", context)
|
||||
@ -266,6 +291,21 @@ define(function(require) {
|
||||
host_json["host"]["capacity"] = capacity;
|
||||
}
|
||||
}
|
||||
|
||||
if(vmm_mad == "one"){
|
||||
var user = $('input[name="ONE_USER"]').val();
|
||||
var pass = $('input[name="ONE_PASSWORD"]').val();
|
||||
var endpoint = $('input[name="ONE_ENDPOINT"]').val();
|
||||
var cpu = $('input[name="ONE_CAPACITY_CPU"]').val();
|
||||
var memory = $('input[name="ONE_CAPACITY_MEMORY"]').val();
|
||||
|
||||
host_json["host"]["ONE_USER"] = user;
|
||||
host_json["host"]["ONE_PASSWORD"] = pass;
|
||||
host_json["host"]["ONE_ENDPOINT"] = endpoint;
|
||||
host_json["host"]["ONE_CAPACITY"] = {};
|
||||
host_json["host"]["ONE_CAPACITY"]["CPU"] = cpu;
|
||||
host_json["host"]["ONE_CAPACITY"]["MEMORY"] = memory;
|
||||
}
|
||||
//Create the OpenNebula.Host.
|
||||
//If it is successfull we refresh the list.
|
||||
Sunstone.runAction("Host.create", host_json);
|
||||
|
@ -135,6 +135,46 @@
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="one_extra">
|
||||
<fieldset>
|
||||
<legend>{{tr "OpenNebula"}}</legend>
|
||||
<div class="row">
|
||||
<div class="large-6 columns">
|
||||
<label for="ONE_USER">{{tr "Remote username"}}</label>
|
||||
<input type="text" name="ONE_USER" />
|
||||
</div>
|
||||
<div class="large-6 columns">
|
||||
<label for="ONE_PASSWORD">{{tr "Remote password"}}</label>
|
||||
<input type="text" name="ONE_PASSWORD" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="large-12 columns">
|
||||
<label for="ONE_ENDPOINT">{{tr "Remote endpoint"}}</label>
|
||||
<input type="text" name="ONE_ENDPOINT" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="medium-12 columns">
|
||||
<label>{{tr "Remote capacity"}}</label>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="large-1 columns"></div>
|
||||
<div class="large-11 columns">
|
||||
<label for="ONE_CAPACITY_CPU">{{tr "CPU"}}</label>
|
||||
<input type="number" name="ONE_CAPACITY_CPU" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="large-1 columns"></div>
|
||||
<div class="large-11 columns">
|
||||
<label for="ONE_CAPACITY_MEMORY">{{tr "Memory"}}</label>
|
||||
<input type="number" name="ONE_CAPACITY_MEMORY" />
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
</form>
|
||||
<form data-abide novalidate class="vcenter_credentials" action="">
|
||||
<fieldset>
|
||||
|
20
src/vmm_mad/remotes/one/attach_disk
Executable file
20
src/vmm_mad/remotes/one/attach_disk
Executable file
@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-201, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
SCRIPT_NAME=$(basename $0)
|
||||
echo "Action $SCRIPT_NAME not supported" 1>&2
|
20
src/vmm_mad/remotes/one/attach_nic
Executable file
20
src/vmm_mad/remotes/one/attach_nic
Executable file
@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2018, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
SCRIPT_NAME=$(basename $0)
|
||||
echo "Action $SCRIPT_NAME not supported" 1>&2
|
42
src/vmm_mad/remotes/one/cancel
Executable file
42
src/vmm_mad/remotes/one/cancel
Executable file
@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2018, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# 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. #
|
||||
# -------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << File.dirname(__FILE__)
|
||||
|
||||
require 'opennebula_driver'
|
||||
|
||||
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
|
||||
|
||||
one2one_drv = OpenNebulaDriver.new(host)
|
||||
one2one_drv.cancel(deploy_id, lcm_state)
|
53
src/vmm_mad/remotes/one/deploy
Executable file
53
src/vmm_mad/remotes/one/deploy
Executable file
@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2018, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# 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. #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << File.dirname(__FILE__)
|
||||
|
||||
require 'opennebula_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
|
||||
|
||||
one2one_drv = OpenNebulaDriver.new(host)
|
||||
|
||||
text=File.read(dfile)
|
||||
|
||||
begin
|
||||
puts one2one_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
|
20
src/vmm_mad/remotes/one/detach_disk
Executable file
20
src/vmm_mad/remotes/one/detach_disk
Executable file
@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2018, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
SCRIPT_NAME=$(basename $0)
|
||||
echo "Action $SCRIPT_NAME not supported" 1>&2
|
20
src/vmm_mad/remotes/one/detach_nic
Executable file
20
src/vmm_mad/remotes/one/detach_nic
Executable file
@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2018, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
SCRIPT_NAME=$(basename $0)
|
||||
echo "Action $SCRIPT_NAME not supported" 1>&2
|
20
src/vmm_mad/remotes/one/migrate
Executable file
20
src/vmm_mad/remotes/one/migrate
Executable file
@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2018, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
SCRIPT_NAME=$(basename $0)
|
||||
echo "Action $SCRIPT_NAME not supported" 1>&2
|
20
src/vmm_mad/remotes/one/migrate_local
Executable file
20
src/vmm_mad/remotes/one/migrate_local
Executable file
@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2018, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
SCRIPT_NAME=$(basename $0)
|
||||
echo "Action $SCRIPT_NAME not supported" 1>&2
|
618
src/vmm_mad/remotes/one/opennebula_driver.rb
Executable file
618
src/vmm_mad/remotes/one/opennebula_driver.rb
Executable file
@ -0,0 +1,618 @@
|
||||
#!/usr/bin/env ruby
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2018, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# 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. #
|
||||
# -------------------------------------------------------------------------- #
|
||||
ONE_LOCATION = ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION = "/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
ETC_LOCATION = "/etc/one/" if !defined?(ETC_LOCATION)
|
||||
else
|
||||
RUBY_LIB_LOCATION = ONE_LOCATION + "/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
ETC_LOCATION = ONE_LOCATION + "/etc/" if !defined?(ETC_LOCATION)
|
||||
end
|
||||
|
||||
# Load credentials and environment
|
||||
require 'yaml'
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
|
||||
require 'CommandManager'
|
||||
require 'scripts_common'
|
||||
require 'rexml/document'
|
||||
require 'VirtualMachineDriver'
|
||||
require 'opennebula'
|
||||
|
||||
# The main class for the driver
|
||||
class OpenNebulaDriver
|
||||
ACTION = VirtualMachineDriver::ACTION
|
||||
POLL_ATTRIBUTE = VirtualMachineDriver::POLL_ATTRIBUTE
|
||||
VM_STATE = VirtualMachineDriver::VM_STATE
|
||||
|
||||
LIMIT_DEFAULT = "-1"
|
||||
LIMIT_UNLIMITED = "-2"
|
||||
|
||||
UNLIMITED_CPU_VALUE = "100000"
|
||||
UNLIMITED_MEMORY_VALUE = "1073741824"
|
||||
|
||||
# Local deploy ids will be formed with this prefix and the remote VM ID
|
||||
#DEPLOY_ID_PREFIX = "one-"
|
||||
DEPLOY_ID_PREFIX = "opennebula-hybrid-"
|
||||
|
||||
# Remote VM names will be formed with this prefix, plus the local VM ID
|
||||
REMOTE_NAME_PREFIX = "remote-opennebula-"
|
||||
|
||||
# constructor, loads credentials and endpoint
|
||||
def initialize(host_name, host_id=nil)
|
||||
@host_name = host_name
|
||||
@host_id = host_id
|
||||
|
||||
client = OpenNebula::Client.new
|
||||
if host_id.nil?
|
||||
host_pool = OpenNebula::HostPool.new(client)
|
||||
host_pool.info
|
||||
objects=host_pool.select {|object| object.name==host_name }
|
||||
xmlhost = objects.first
|
||||
host_id = xmlhost["ID"].to_i
|
||||
end
|
||||
|
||||
host = OpenNebula::Host.new_with_id(host_id, client)
|
||||
host.info
|
||||
|
||||
region = {}
|
||||
|
||||
["user", "password", "endpoint", "capacity"].each do |key|
|
||||
if key == "capacity"
|
||||
region[key] = {}
|
||||
["cpu", "memory"].each do |key_c|
|
||||
value = host.retrieve_elements("/HOST/TEMPLATE/ONE_#{key.upcase}/#{key_c.upcase}")[0]
|
||||
if host.retrieve_elements("/HOST/TEMPLATE/ONE_#{key.upcase}/#{key_c.upcase}")[0].nil? || value == ""
|
||||
raise "Region for host #{host} does not have '#{key_c.upcase}' defined in host template"
|
||||
end
|
||||
region[key][key_c] = value.to_i
|
||||
end
|
||||
else
|
||||
value = host.retrieve_elements("/HOST/TEMPLATE/ONE_#{key.upcase}")[0]
|
||||
if host.retrieve_elements("/HOST/TEMPLATE/ONE_#{key.upcase}")[0].nil? || value == ""
|
||||
raise "Region for host #{host} does not have '#{key.upcase}' defined in host template"
|
||||
end
|
||||
region[key] = value
|
||||
end
|
||||
end
|
||||
|
||||
system = OpenNebula::System.new(client)
|
||||
config = system.get_configuration
|
||||
raise "Error getting oned configuration : #{config.message}" if OpenNebula.is_error?(config)
|
||||
|
||||
token = config["ONE_KEY"]
|
||||
conn_opts = {
|
||||
:password => host["/HOST/TEMPLATE/ONE_PASSWORD"],
|
||||
}
|
||||
|
||||
begin
|
||||
conn_opts = OpenNebula.decrypt(conn_opts, token)
|
||||
region["password"] = conn_opts[:password]
|
||||
rescue
|
||||
raise "HOST: #{host} must have remote host password to work properly"
|
||||
end
|
||||
|
||||
secret = "#{region['user']}:#{region['password']}"
|
||||
|
||||
@client = OpenNebula::Client.new(secret, region['endpoint'], :sync => true)
|
||||
|
||||
@cpu = region['capacity']['cpu']
|
||||
@memory = region['capacity']['memory']
|
||||
|
||||
@cpu = 0 if @cpu.nil?
|
||||
@memory = 0 if @memory.nil?
|
||||
end
|
||||
|
||||
# DEPLOY action, also sets ports and ip if needed
|
||||
def deploy(id, host, xml_text, lcm_state, deploy_id)
|
||||
if lcm_state == "BOOT" || lcm_state == "BOOT_FAILURE"
|
||||
one_info = get_deployment_info(host, xml_text)
|
||||
|
||||
#load_default_template_values
|
||||
|
||||
tid = one_value(one_info, 'TEMPLATE_ID')
|
||||
|
||||
if (tid.nil? || tid == "")
|
||||
STDERR.puts("Cannot find TEMPLATE_ID in deployment file")
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
extra_template = "REMOTE_OPENNEBULA = YES\n"<<
|
||||
"REMOTE_OPENNEBULA_VM_ID = #{id}\n"
|
||||
|
||||
# The OpenNebula context will be included
|
||||
xml = OpenNebula::XMLElement.new
|
||||
xml.initialize_xml(xml_text, 'VM')
|
||||
|
||||
if xml.has_elements?('TEMPLATE/CONTEXT')
|
||||
# Since there is only 1 level ',' will not be added
|
||||
context_str = xml.template_like_str('TEMPLATE/CONTEXT')
|
||||
|
||||
if xml['TEMPLATE/CONTEXT/TOKEN'] == 'YES'
|
||||
# TODO use OneGate library. See ec2_driver.rb
|
||||
token_str = generate_onegate_token(xml)
|
||||
if token_str
|
||||
context_str << "\nONEGATE_TOKEN=\"#{token_str}\""
|
||||
end
|
||||
end
|
||||
|
||||
extra_template << context_str
|
||||
end
|
||||
|
||||
t = OpenNebula::Template.new_with_id(tid, @client)
|
||||
rc = t.instantiate(REMOTE_NAME_PREFIX+id, true, extra_template, false)
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
STDERR.puts(rc.to_str())
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
deploy_id = "#{DEPLOY_ID_PREFIX}#{rc}"
|
||||
vm = get_remote_vm(deploy_id)
|
||||
|
||||
new_context_update = "CONTEXT = [" << context_str <<"]"
|
||||
new_context_update = new_context_update.gsub("\n", ",\n")
|
||||
rc = vm.updateconf(new_context_update)
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
STDERR.puts(rc.to_str())
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
vm.release
|
||||
|
||||
rc = vm.update("REMOTE_OPENNEBULA_DEPLOY_ID = \"#{deploy_id}\"", true)
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
STDERR.puts("Error adding REMOTE_OPENNEBULA_DEPLOY_ID attribute to VM #{rc}: #{rc.to_str()}")
|
||||
end
|
||||
|
||||
puts(deploy_id)
|
||||
else
|
||||
restore(deploy_id)
|
||||
deploy_id
|
||||
end
|
||||
end
|
||||
|
||||
# Shutdown an instance
|
||||
def shutdown(deploy_id, lcm_state)
|
||||
vm = get_remote_vm(deploy_id)
|
||||
|
||||
case lcm_state
|
||||
when "SHUTDOWN"
|
||||
rc = vm.terminate
|
||||
when "SHUTDOWN_POWEROFF"
|
||||
rc = vm.poweroff
|
||||
when "SHUTDOWN_UNDEPLOY"
|
||||
rc = vm.undeploy
|
||||
end
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
STDERR.puts(rc.to_str())
|
||||
exit(-1)
|
||||
end
|
||||
end
|
||||
|
||||
# Reboot an instance
|
||||
def reboot(deploy_id)
|
||||
vm = get_remote_vm(deploy_id)
|
||||
rc = vm.reboot()
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
STDERR.puts(rc.to_str())
|
||||
exit(-1)
|
||||
end
|
||||
end
|
||||
|
||||
# Reboot (hard) an instance
|
||||
def reset(deploy_id)
|
||||
vm = get_remote_vm(deploy_id)
|
||||
rc = vm.reboot(true)
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
STDERR.puts(rc.to_str())
|
||||
exit(-1)
|
||||
end
|
||||
end
|
||||
|
||||
# Cancel an instance
|
||||
def cancel(deploy_id, lcm_state)
|
||||
vm = get_remote_vm(deploy_id)
|
||||
|
||||
case lcm_state
|
||||
when "SHUTDOWN"
|
||||
rc = vm.terminate(true)
|
||||
when "SHUTDOWN_POWEROFF"
|
||||
rc = vm.poweroff(true)
|
||||
when "SHUTDOWN_UNDEPLOY"
|
||||
rc = vm.undeploy(true)
|
||||
end
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
STDERR.puts(rc.to_str())
|
||||
exit(-1)
|
||||
end
|
||||
end
|
||||
|
||||
# Save an instance
|
||||
def save(deploy_id)
|
||||
vm = get_remote_vm(deploy_id)
|
||||
|
||||
rc = vm.suspend()
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
STDERR.puts(rc.to_str())
|
||||
exit(-1)
|
||||
end
|
||||
end
|
||||
|
||||
# Resumes an instance
|
||||
def restore(deploy_id)
|
||||
vm = get_remote_vm(deploy_id)
|
||||
rc = vm.resume()
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
STDERR.puts(rc.to_str())
|
||||
exit(-1)
|
||||
end
|
||||
end
|
||||
|
||||
# Get info (IP, and state) for an instance
|
||||
def poll(id, deploy_id)
|
||||
vm = get_remote_vm(deploy_id)
|
||||
rc = vm.info
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
STDERR.puts(rc.to_str())
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
puts parse_poll(vm)
|
||||
end
|
||||
|
||||
# Get the info of all the remote instances
|
||||
def monitor_all_vms
|
||||
user = OpenNebula::User.new_with_id("-1", @client)
|
||||
rc = user.info
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
STDERR.puts("Error getting remote user information: #{rc.to_str()}")
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
group = OpenNebula::Group.new_with_id("-1", @client)
|
||||
rc = group.info
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
STDERR.puts("Error getting remote group information: #{rc.to_str()}")
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
if @cpu != 0
|
||||
totalcpu = @cpu
|
||||
else
|
||||
u_cpu = user['VM_QUOTA/VM/CPU']
|
||||
g_cpu = group['VM_QUOTA/VM/CPU']
|
||||
|
||||
if u_cpu == LIMIT_DEFAULT || u_cpu.nil?
|
||||
u_cpu = user['DEFAULT_USER_QUOTAS/VM_QUOTA/VM/CPU']
|
||||
end
|
||||
|
||||
if g_cpu == LIMIT_DEFAULT || g_cpu.nil?
|
||||
g_cpu = group['DEFAULT_GROUP_QUOTAS/VM_QUOTA/VM/CPU']
|
||||
end
|
||||
|
||||
u_cpu = LIMIT_UNLIMITED if u_cpu.nil?
|
||||
g_cpu = LIMIT_UNLIMITED if g_cpu.nil?
|
||||
|
||||
u_cpu = UNLIMITED_CPU_VALUE if u_cpu == LIMIT_UNLIMITED
|
||||
g_cpu = UNLIMITED_CPU_VALUE if g_cpu == LIMIT_UNLIMITED
|
||||
|
||||
totalcpu = ([u_cpu.to_f, g_cpu.to_f].min * 100).round
|
||||
end
|
||||
|
||||
if @memory != 0
|
||||
totalmemory = @memory
|
||||
else
|
||||
u_memory = user['VM_QUOTA/VM/MEMORY']
|
||||
g_memory = group['VM_QUOTA/VM/MEMORY']
|
||||
|
||||
if u_memory == LIMIT_DEFAULT || u_memory.nil?
|
||||
u_memory = user['DEFAULT_USER_QUOTAS/VM_QUOTA/VM/MEMORY']
|
||||
end
|
||||
|
||||
if g_memory == LIMIT_DEFAULT || g_memory.nil?
|
||||
g_memory = group['DEFAULT_GROUP_QUOTAS/VM_QUOTA/VM/MEMORY']
|
||||
end
|
||||
|
||||
u_memory = LIMIT_UNLIMITED if u_memory.nil?
|
||||
g_memory = LIMIT_UNLIMITED if g_memory.nil?
|
||||
|
||||
u_memory = UNLIMITED_MEMORY_VALUE if u_memory == LIMIT_UNLIMITED
|
||||
g_memory = UNLIMITED_MEMORY_VALUE if g_memory == LIMIT_UNLIMITED
|
||||
|
||||
totalmemory = [u_memory.to_i, g_memory.to_i].min
|
||||
end
|
||||
|
||||
host_info = "HYPERVISOR=opennebula\n"
|
||||
host_info << "PUBLIC_CLOUD=YES\n"
|
||||
host_info << "PRIORITY=-1\n"
|
||||
host_info << "TOTALMEMORY=#{totalmemory * 1024}\n"
|
||||
host_info << "TOTALCPU=#{totalcpu}\n"
|
||||
host_info << "HOSTNAME=\"#{@host_name}\"\n"
|
||||
|
||||
vms_info = "VM_POLL=YES\n"
|
||||
|
||||
if user['VM_QUOTA/VM/CPU_USED'].nil?
|
||||
usedcpu = 0
|
||||
else
|
||||
usedcpu = (user['VM_QUOTA/VM/CPU_USED'].to_f * 100).round
|
||||
end
|
||||
|
||||
if user['VM_QUOTA/VM/MEMORY_USED'].nil?
|
||||
usedmemory = 0
|
||||
else
|
||||
usedmemory = user['VM_QUOTA/VM/MEMORY_USED'].to_i * 1024
|
||||
end
|
||||
|
||||
vmpool = OpenNebula::VirtualMachinePool.new(@client,
|
||||
OpenNebula::VirtualMachinePool::INFO_ALL_VM)
|
||||
rc = vmpool.info
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
STDERR.puts(rc.to_str())
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
vmpool.each do |vm|
|
||||
poll_data = parse_poll(vm)
|
||||
|
||||
deploy_id = vm["USER_TEMPLATE/REMOTE_OPENNEBULA_DEPLOY_ID"] || "#{DEPLOY_ID_PREFIX}#{vm.id()}"
|
||||
vmid = vm["USER_TEMPLATE/REMOTE_OPENNEBULA_VM_ID"] || "-1"
|
||||
|
||||
vm_template_to_one = vm_to_import(vm)
|
||||
vm_template_to_one = Base64.encode64(vm_template_to_one).gsub("\n","")
|
||||
|
||||
vms_info << "VM=[\n"
|
||||
vms_info << " ID=\"#{vmid}\",\n"
|
||||
vms_info << " DEPLOY_ID=\"#{deploy_id}\",\n"
|
||||
vms_info << " VM_NAME=#{vm.name},\n"
|
||||
vms_info << " IMPORT_TEMPLATE=\"#{vm_template_to_one}\",\n"
|
||||
vms_info << " POLL=\"#{poll_data}\" ]\n"
|
||||
end
|
||||
|
||||
host_info << "USEDMEMORY=#{usedmemory}\n"
|
||||
host_info << "USEDCPU=#{usedcpu}\n"
|
||||
host_info << "FREEMEMORY=#{(totalmemory - usedmemory)}\n"
|
||||
host_info << "FREECPU=#{(totalcpu - usedcpu)}\n"
|
||||
|
||||
puts host_info
|
||||
puts vms_info
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Get the OpenNebula hybrid section of the template. With more than one section
|
||||
# the HOST element is used and matched with the host
|
||||
def get_deployment_info(host, xml_text)
|
||||
xml = REXML::Document.new xml_text
|
||||
|
||||
one = nil
|
||||
|
||||
all_one_elements = xml.root.get_elements("//USER_TEMPLATE/PUBLIC_CLOUD")
|
||||
|
||||
# First, let's see if we have an one site that matches
|
||||
# our desired host name
|
||||
all_one_elements.each { |element|
|
||||
cloud = element.elements["HOST"]
|
||||
if cloud && cloud.text.upcase == host.upcase
|
||||
one = element
|
||||
end
|
||||
}
|
||||
|
||||
if !one
|
||||
# If we don't find the one site, and ONE just
|
||||
# knows about one one site, let's use that
|
||||
if all_one_elements.size == 1
|
||||
one = all_one_elements[0]
|
||||
else
|
||||
STDERR.puts("Cannot find PUBLIC_CLOUD element in deployment "\
|
||||
" file or no HOST site matching the requested in the "\
|
||||
"template.")
|
||||
exit(-1)
|
||||
end
|
||||
end
|
||||
|
||||
one
|
||||
end
|
||||
|
||||
# Retrieve the vm information from the instance
|
||||
def parse_poll(vm)
|
||||
begin
|
||||
vm_hash = vm.to_hash()
|
||||
|
||||
state = ""
|
||||
|
||||
state = case vm.state_str
|
||||
when "INIT" || "PENDING" || "HOLD" || "CLONING"
|
||||
VM_STATE[:active]
|
||||
when "ACTIVE"
|
||||
case vm.lcm_state_str
|
||||
when /_FAILURE$/ || "UNKNOWN"
|
||||
VM_STATE[:error]
|
||||
else
|
||||
VM_STATE[:active]
|
||||
end
|
||||
when "STOPPED" || "SUSPENDED"
|
||||
VM_STATE[:paused]
|
||||
when "DONE" || "POWEROFF" || "UNDEPLOYED"
|
||||
VM_STATE[:deleted]
|
||||
when "FAILED" || "CLONING_FAILURE"
|
||||
VM_STATE[:error]
|
||||
else
|
||||
VM_STATE[:unknown]
|
||||
end
|
||||
|
||||
info = "#{POLL_ATTRIBUTE[:state]}=#{state} "
|
||||
|
||||
if state != VM_STATE[:active]
|
||||
return info
|
||||
end
|
||||
|
||||
monitoring = vm_hash['VM']['MONITORING']
|
||||
|
||||
if (!monitoring.nil?)
|
||||
info << vm.template_like_str('MONITORING', true).gsub("\n", " ").gsub('"', '').gsub(/\[ */, "[").gsub(/, */,",").gsub(/ *\]/, "]").gsub(/STATE=./,"")
|
||||
end
|
||||
|
||||
return info
|
||||
rescue
|
||||
# Unkown state if exception occurs retrieving information from
|
||||
# an instance
|
||||
"#{POLL_ATTRIBUTE[:state]}=#{VM_STATE[:unknown]} "
|
||||
end
|
||||
end
|
||||
|
||||
# Returns the value of the xml specified by the name or the default
|
||||
# one if it does not exist
|
||||
# +xml+: REXML Document, containing one hybrid information
|
||||
# +name+: String, xpath expression to retrieve the value
|
||||
# +block+: Block, block to be applied to the value before returning it
|
||||
def one_value(xml, name, &block)
|
||||
value = value_from_xml(xml, name) || @defaults[name]
|
||||
if block_given? && value
|
||||
block.call(value)
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
def value_from_xml(xml, name)
|
||||
if xml
|
||||
element = xml.elements[name]
|
||||
element.text.strip if element && element.text
|
||||
end
|
||||
end
|
||||
|
||||
# Load the default values that will be used to create a new instance, if
|
||||
# not provided in the template. These values are defined in the
|
||||
# ONE_DRIVER_DEFAULT file
|
||||
def load_default_template_values
|
||||
@defaults = Hash.new
|
||||
|
||||
if File.exists?(ONE_DRIVER_DEFAULT)
|
||||
fd = File.new(ONE_DRIVER_DEFAULT)
|
||||
xml = REXML::Document.new fd
|
||||
fd.close()
|
||||
|
||||
return if !xml || !xml.root
|
||||
|
||||
xml.elements.each("/TEMPLATE/PUBLIC_CLOUD/*") do |e|
|
||||
@defaults[e.name] = e.text
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Retrive the vm object for the remote opennebula
|
||||
def get_remote_vm(deploy_id)
|
||||
begin
|
||||
match = deploy_id.match( /#{DEPLOY_ID_PREFIX}(.*)/ )
|
||||
|
||||
if (match.nil?)
|
||||
raise "Deploy ID #{deploy_id} was not created with this driver"
|
||||
end
|
||||
|
||||
id = match[1]
|
||||
|
||||
return OpenNebula::VirtualMachine.new_with_id(id, @client)
|
||||
rescue => e
|
||||
STDERR.puts e.message
|
||||
exit(-1)
|
||||
end
|
||||
end
|
||||
|
||||
# Build template for importation
|
||||
def vm_to_import(vm)
|
||||
cpu = vm['TEMPLATE/CPU']
|
||||
vcpu = vm['TEMPLATE/VCPU']
|
||||
mem = vm['TEMPLATE/MEMORY']
|
||||
|
||||
template_id = vm['TEMPLATE/TEMPLATE_ID']
|
||||
|
||||
deploy_id = "#{DEPLOY_ID_PREFIX}#{vm.id()}"
|
||||
|
||||
str = "NAME = \"Instance from #{vm.name()}\"\n"\
|
||||
"CPU = \"#{cpu}\"\n"\
|
||||
"VCPU = \"#{1}\"\n"\
|
||||
"MEMORY = \"#{mem}\"\n"\
|
||||
"HYPERVISOR = \"opennebula\"\n"\
|
||||
"PUBLIC_CLOUD = [\n"\
|
||||
" TYPE =\"opennebula\",\n"\
|
||||
" TEMPLATE_ID =\"#{template_id}\"\n"\
|
||||
"]\n"\
|
||||
"IMPORT_VM_ID = \"#{deploy_id}\"\n"\
|
||||
"SCHED_REQUIREMENTS=\"NAME=\\\"#{@host_name}\\\"\"\n"\
|
||||
"DESCRIPTION = \"Instance imported from a remote OpenNebula, from VM instance"\
|
||||
" #{vm.id()}\"\n"
|
||||
|
||||
str
|
||||
end
|
||||
|
||||
# TODO move this method to a OneGate library. See ec2_driver.rb
|
||||
def generate_onegate_token(xml)
|
||||
# Create the OneGate token string
|
||||
vmid_str = xml["ID"]
|
||||
stime_str = xml["STIME"]
|
||||
str_to_encrypt = "#{vmid_str}:#{stime_str}"
|
||||
|
||||
user_id = xml['TEMPLATE/CREATED_BY']
|
||||
|
||||
if user_id.nil?
|
||||
STDERR.puts {"VMID:#{vmid} CREATED_BY not present" \
|
||||
" in the VM TEMPLATE"}
|
||||
return nil
|
||||
end
|
||||
|
||||
user = OpenNebula::User.new_with_id(user_id,
|
||||
OpenNebula::Client.new)
|
||||
rc = user.info
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
STDERR.puts {"VMID:#{vmid} user.info" \
|
||||
" error: #{rc.message}"}
|
||||
return nil
|
||||
end
|
||||
|
||||
token_password = user['TEMPLATE/TOKEN_PASSWORD']
|
||||
|
||||
if token_password.nil?
|
||||
STDERR.puts {"VMID:#{vmid} TOKEN_PASSWORD not present"\
|
||||
" in the USER:#{user_id} TEMPLATE"}
|
||||
return nil
|
||||
end
|
||||
|
||||
cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
|
||||
cipher.encrypt
|
||||
cipher.key = token_password
|
||||
onegate_token = cipher.update(str_to_encrypt)
|
||||
onegate_token << cipher.final
|
||||
|
||||
onegate_token_64 = Base64.encode64(onegate_token).chop
|
||||
end
|
||||
end
|
37
src/vmm_mad/remotes/one/poll
Executable file
37
src/vmm_mad/remotes/one/poll
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2018, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# 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. #
|
||||
# -------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << File.dirname(__FILE__)
|
||||
|
||||
require 'opennebula_driver'
|
||||
|
||||
deploy_id = ARGV[0]
|
||||
host = ARGV[2]
|
||||
id = ARGV[1]
|
||||
|
||||
one2one_drv = OpenNebulaDriver.new(host)
|
||||
one2one_drv.poll(id, deploy_id)
|
20
src/vmm_mad/remotes/one/prereconfigure
Executable file
20
src/vmm_mad/remotes/one/prereconfigure
Executable file
@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2018, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
SCRIPT_NAME=$(basename $0)
|
||||
echo "Action $SCRIPT_NAME not supported" 1>&2
|
36
src/vmm_mad/remotes/one/reboot
Executable file
36
src/vmm_mad/remotes/one/reboot
Executable file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2018, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# 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. #
|
||||
# -------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << File.dirname(__FILE__)
|
||||
|
||||
require 'opennebula_driver'
|
||||
|
||||
deploy_id = ARGV[0]
|
||||
host = ARGV[1]
|
||||
|
||||
one2one_drv = OpenNebulaDriver.new(host)
|
||||
one2one_drv.reboot(deploy_id)
|
20
src/vmm_mad/remotes/one/reconfigure
Executable file
20
src/vmm_mad/remotes/one/reconfigure
Executable file
@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2018, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
SCRIPT_NAME=$(basename $0)
|
||||
echo "Action $SCRIPT_NAME not supported" 1>&2
|
36
src/vmm_mad/remotes/one/reset
Executable file
36
src/vmm_mad/remotes/one/reset
Executable file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2018, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# 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. #
|
||||
# -------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << File.dirname(__FILE__)
|
||||
|
||||
require 'opennebula_driver'
|
||||
|
||||
deploy_id = ARGV[1]
|
||||
host = ARGV[0]
|
||||
|
||||
one2one_drv = OpenNebulaDriver.new(host)
|
||||
one2one_drv.reset(deploy_id)
|
37
src/vmm_mad/remotes/one/restore
Executable file
37
src/vmm_mad/remotes/one/restore
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2018, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# 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. #
|
||||
# -------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << File.dirname(__FILE__)
|
||||
|
||||
require 'opennebula_driver'
|
||||
|
||||
checkpoint_file = ARGV[0]
|
||||
host = ARGV[1]
|
||||
deploy_id = ARGV[2]
|
||||
|
||||
one2one_drv = OpenNebulaDriver.new(host)
|
||||
one2one_drv.restore(deploy_id)
|
37
src/vmm_mad/remotes/one/save
Executable file
37
src/vmm_mad/remotes/one/save
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2018, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# 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. #
|
||||
# -------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << File.dirname(__FILE__)
|
||||
|
||||
require 'opennebula_driver'
|
||||
|
||||
deploy_id = ARGV[0]
|
||||
file = ARGV[1]
|
||||
host = ARGV[2]
|
||||
|
||||
one2one_drv = OpenNebulaDriver.new(host)
|
||||
one2one_drv.save(deploy_id)
|
43
src/vmm_mad/remotes/one/shutdown
Executable file
43
src/vmm_mad/remotes/one/shutdown
Executable file
@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2018, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# 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. #
|
||||
# -------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << File.dirname(__FILE__)
|
||||
|
||||
require 'opennebula_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
|
||||
|
||||
one2one_drv = OpenNebulaDriver.new(host)
|
||||
one2one_drv.shutdown(deploy_id, lcm_state)
|
20
src/vmm_mad/remotes/one/snapshot_create
Executable file
20
src/vmm_mad/remotes/one/snapshot_create
Executable file
@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2018, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
SCRIPT_NAME=$(basename $0)
|
||||
echo "Action $SCRIPT_NAME not supported" 1>&2
|
20
src/vmm_mad/remotes/one/snapshot_delete
Executable file
20
src/vmm_mad/remotes/one/snapshot_delete
Executable file
@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2018, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
SCRIPT_NAME=$(basename $0)
|
||||
echo "Action $SCRIPT_NAME not supported" 1>&2
|
20
src/vmm_mad/remotes/one/snapshot_revert
Executable file
20
src/vmm_mad/remotes/one/snapshot_revert
Executable file
@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2018, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
SCRIPT_NAME=$(basename $0)
|
||||
echo "Action $SCRIPT_NAME not supported" 1>&2
|
Loading…
x
Reference in New Issue
Block a user