diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 719fa71ade..af8e9360c3 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 # @@ -895,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/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/lib/vcenter_driver/virtual_machine.rb b/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb index 4e87ade0c1..d5ffca5a48 100644 --- a/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb +++ b/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb @@ -1007,12 +1007,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 @@ -1021,14 +1021,14 @@ class VirtualMachine raise "Cannot create snapshot for VM: #{e.message}\n#{e.backtrace}" 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 @@ -1041,10 +1041,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 @@ -1059,12 +1059,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/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) 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 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 "\