From 36c66e58888e30bec4bea0eb46ec3b97094199fb Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Mon, 20 Feb 2017 12:15:48 +0100 Subject: [PATCH 1/3] F #4913: Fix symlinks for dummy and not supported vmm actions --- src/vmm_mad/remotes/common/dummy.sh | 3 +- .../not_supported.sh} | 40 +++++++++++-------- src/vmm_mad/remotes/vcenter/migrate | 35 +--------------- src/vmm_mad/remotes/vcenter/preconfigure | 1 + 4 files changed, 26 insertions(+), 53 deletions(-) rename src/vmm_mad/remotes/{vcenter/prereconfigure => common/not_supported.sh} (67%) mode change 100755 => 120000 src/vmm_mad/remotes/vcenter/migrate create mode 120000 src/vmm_mad/remotes/vcenter/preconfigure diff --git a/src/vmm_mad/remotes/common/dummy.sh b/src/vmm_mad/remotes/common/dummy.sh index 2ed62a9d7b..3ee910cdd1 100755 --- a/src/vmm_mad/remotes/common/dummy.sh +++ b/src/vmm_mad/remotes/common/dummy.sh @@ -16,5 +16,4 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -SCRIPT_NAME=$(basename $0) -echo "Action $SCRIPT_NAME not supported" 1>&2 +exit 0 diff --git a/src/vmm_mad/remotes/vcenter/prereconfigure b/src/vmm_mad/remotes/common/not_supported.sh similarity index 67% rename from src/vmm_mad/remotes/vcenter/prereconfigure rename to src/vmm_mad/remotes/common/not_supported.sh index 564d84fc38..3f0a8a1be5 100755 --- a/src/vmm_mad/remotes/vcenter/prereconfigure +++ b/src/vmm_mad/remotes/common/not_supported.sh @@ -1,20 +1,26 @@ -#!/usr/bin/env ruby +#!/bin/bash -# ---------------------------------------------------------------------------- # -# 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. # -# ---------------------------------------------------------------------------- # +# -------------------------------------------------------------------------- # +# 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. # +#--------------------------------------------------------------------------- # -exit(0) +script_name=$(basename $0) + +source $(dirname $0)/../../scripts_common.sh + +error_message "$script_name: Operation not supported" + +exit 1 diff --git a/src/vmm_mad/remotes/vcenter/migrate b/src/vmm_mad/remotes/vcenter/migrate deleted file mode 100755 index 39058c4157..0000000000 --- a/src/vmm_mad/remotes/vcenter/migrate +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env ruby - -# ---------------------------------------------------------------------------- # -# Copyright 2002-2017, 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 'vcenter_driver2' - -# Not supported -STDERR.puts "Migrate action is not supportef for vCenter" -exit -1 \ No newline at end of file diff --git a/src/vmm_mad/remotes/vcenter/migrate b/src/vmm_mad/remotes/vcenter/migrate new file mode 120000 index 0000000000..9c454e8cd4 --- /dev/null +++ b/src/vmm_mad/remotes/vcenter/migrate @@ -0,0 +1 @@ +../common/not_supported.sh \ No newline at end of file diff --git a/src/vmm_mad/remotes/vcenter/preconfigure b/src/vmm_mad/remotes/vcenter/preconfigure new file mode 120000 index 0000000000..300563f2ad --- /dev/null +++ b/src/vmm_mad/remotes/vcenter/preconfigure @@ -0,0 +1 @@ +../common/dummy.sh \ No newline at end of file From 469ff036a748d64620f92767423cd25f324d63f6 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Tue, 21 Feb 2017 10:06:49 +0100 Subject: [PATCH 2/3] F #4913: Tweak the snapshot actions Snapshot name is stored in the description field of vCenter The information is passed via STDIN and not as positional argument --- src/vmm_mad/exec/one_vmm_exec.rb | 3 ++- .../lib/vcenter_driver/virtual_machine.rb | 26 +++++++++---------- src/vmm_mad/remotes/vcenter/snapshot_create | 9 +++++-- src/vmm_mad/remotes/vcenter/snapshot_delete | 4 +-- src/vmm_mad/remotes/vcenter/snapshot_revert | 4 +-- 5 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 719fa71ade..557437fefb 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -739,7 +739,8 @@ class ExecDriver < VirtualMachineDriver id, host, ACTION[:snapshot_create], - :script_name => "snapshot_create") + :script_name => "snapshot_create", + :stdin => xml_data) end # diff --git a/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb b/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb index 9d9e0c758d..26d1bd16c8 100644 --- a/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb +++ b/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb @@ -989,12 +989,12 @@ class VirtualMachine end # Create a snapshot for the VM - def create_snapshot(snapshot_name, vm_ref) + def create_snapshot(snap_id, snap_name) snapshot_hash = { - :name => snapshot_name, - :description => "OpenNebula Snapshot of VM #{vm_ref}", - :memory => true, - :quiesce => true + :name => snap_id, + :description => snap_name, + :memory => true, + :quiesce => true } begin @@ -1003,14 +1003,14 @@ class VirtualMachine raise "Cannot create snapshot for VM: #{e.message}" end - return snapshot_name + return snap_id end # Revert to a VM snapshot - def revert_snapshot(snapshot_name) + def revert_snapshot(snap_id) snapshot_list = self["snapshot.rootSnapshotList"] - snapshot = find_snapshot_in_list(snapshot_list, snapshot_name) + snapshot = find_snapshot_in_list(snapshot_list, snap_id) return nil if !snapshot @@ -1023,10 +1023,10 @@ class VirtualMachine end # Delete VM snapshot - def delete_snapshot(snapshot_name) + def delete_snapshot(snap_id) snapshot_list = self["snapshot.rootSnapshotList"] - snapshot = find_snapshot_in_list(snapshot_list, snapshot_name) + snapshot = find_snapshot_in_list(snapshot_list, snap_id) return nil if !snapshot @@ -1041,12 +1041,12 @@ class VirtualMachine end end - def find_snapshot_in_list(list, snapshot_name) + def find_snapshot_in_list(list, snap_id) list.each do |i| - if i.name == snapshot_name + if i.name == snap_id.to_s return i.snapshot elsif !i.childSnapshotList.empty? - snap = find_snapshot(i.childSnapshotList, snapshot_name) + snap = find_snapshot(i.childSnapshotList, snap_id) return snap if snap end end rescue nil diff --git a/src/vmm_mad/remotes/vcenter/snapshot_create b/src/vmm_mad/remotes/vcenter/snapshot_create index eaed76bfbb..8fc488b2e7 100755 --- a/src/vmm_mad/remotes/vcenter/snapshot_create +++ b/src/vmm_mad/remotes/vcenter/snapshot_create @@ -30,18 +30,23 @@ $: << File.dirname(__FILE__) require 'vcenter_driver2' vm_ref = ARGV[0] -snapshot_name = ARGV[1] +snap_id = ARGV[1] vc_cluster_name = ARGV[3] +drv_action = OpenNebula::XMLElement.new +drv_action.initialize_xml(Base64.decode64(STDIN.read), 'VMM_DRIVER_ACTION_DATA') + host = VCenterDriver::VIHelper.find_by_name(OpenNebula::HostPool, vc_cluster_name) host_id = host['ID'] +snap_name = drv_action["VM/TEMPLATE/SNAPSHOT[ACTIVE='YES']/NAME"] + begin vi_client = VCenterDriver::VIClient.new_from_host(host_id) vm = VCenterDriver::VirtualMachine.new_from_ref(vm_ref, vi_client) - vm.create_snapshot(snapshot_name, vm_ref) + vm.create_snapshot(snap_id, snap_name) rescue Exception => e STDERR.puts "Snapshot of VM #{vm_ref} on vCenter cluster "\ diff --git a/src/vmm_mad/remotes/vcenter/snapshot_delete b/src/vmm_mad/remotes/vcenter/snapshot_delete index ccade6b202..f27a1e5beb 100755 --- a/src/vmm_mad/remotes/vcenter/snapshot_delete +++ b/src/vmm_mad/remotes/vcenter/snapshot_delete @@ -30,7 +30,7 @@ $: << File.dirname(__FILE__) require 'vcenter_driver2' vm_ref = ARGV[0] -snapshot_name = ARGV[1] +snap_id = ARGV[1] vc_cluster_name = ARGV[3] host = VCenterDriver::VIHelper.find_by_name(OpenNebula::HostPool, vc_cluster_name) @@ -41,7 +41,7 @@ begin vm = VCenterDriver::VirtualMachine.new_from_ref(vm_ref, vi_client) - vm.delete_snapshot(snapshot_name) + vm.delete_snapshot(snap_id) rescue Exception => e STDERR.puts "Snapshot of VM #{vm_ref} on vCenter cluster "\ diff --git a/src/vmm_mad/remotes/vcenter/snapshot_revert b/src/vmm_mad/remotes/vcenter/snapshot_revert index 61c77e644b..ad1069aece 100755 --- a/src/vmm_mad/remotes/vcenter/snapshot_revert +++ b/src/vmm_mad/remotes/vcenter/snapshot_revert @@ -30,7 +30,7 @@ $: << File.dirname(__FILE__) require 'vcenter_driver2' vm_ref = ARGV[0] -snapshot_name = ARGV[1] +snap_id = ARGV[1] vc_cluster_name = ARGV[3] host = VCenterDriver::VIHelper.find_by_name(OpenNebula::HostPool, vc_cluster_name) @@ -41,7 +41,7 @@ begin vm = VCenterDriver::VirtualMachine.new_from_ref(vm_ref, vi_client) - vm.revert_snapshot(snapshot_name) + vm.revert_snapshot(snap_id) rescue Exception => e STDERR.puts "Snapshot of VM #{vm_ref} on vCenter cluster "\ From e70caf371515253547f146cddacef85e2b5a19c3 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Tue, 21 Feb 2017 10:07:35 +0100 Subject: [PATCH 3/3] F #4913: Attach-nic requires the XML data of the VM This information is passed via STDIN and not as a positional argument. --- src/vmm_mad/exec/one_vmm_exec.rb | 2 +- src/vmm_mad/remotes/vcenter/attach_nic | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 557437fefb..af8e9360c3 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -896,7 +896,7 @@ class ExecDriver < VirtualMachineDriver { :driver => :vmm, :action => :attach_nic, - :parameters => [:deploy_id, mac, source, model, vn_mad, target, xml_data] + :parameters => [:deploy_id, mac, source, model, vn_mad, target] }, # Execute post-boot networking setup { diff --git a/src/vmm_mad/remotes/vcenter/attach_nic b/src/vmm_mad/remotes/vcenter/attach_nic index 75c8c162d6..29cd03ba24 100755 --- a/src/vmm_mad/remotes/vcenter/attach_nic +++ b/src/vmm_mad/remotes/vcenter/attach_nic @@ -33,11 +33,12 @@ vm_ref = ARGV[0] mac = ARGV[1] bridge = ARGV[2] model = ARGV[3] -xml_data = ARGV[4] vc_cluster_name = ARGV[-1] drv_action = OpenNebula::XMLElement.new -drv_action.initialize_xml(xml_data, 'VM') +drv_action.initialize_xml(Base64.decode64(STDIN.read), 'VMM_DRIVER_ACTION_DATA') + +vm_xml = drv_action.retrieve_xmlelements("VM").first host = VCenterDriver::VIHelper.find_by_name(OpenNebula::HostPool, vc_cluster_name) host_id = host['ID'] @@ -47,13 +48,13 @@ begin vm = VCenterDriver::VirtualMachine.new_from_ref(vm_ref, vi_client) - # Setting one_item with info with xml_data including NIC to be added - vm.one_item = drv_action + # Setting one_item with info with the vm_xml including NIC to be added + vm.one_item = vm_xml nic = { - "MAC" => mac, + "MAC" => mac, "BRIDGE" => bridge, - "MODEL" => model + "MODEL" => model } vm.attach_nic(nic)