From 3425256254e9f6e8e10ce89c25da9e40655cbfe0 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Wed, 20 Feb 2013 15:05:58 +0100 Subject: [PATCH] Feature #1224: Add snapshot_create vmm/kvm driver action --- install.sh | 1 + src/mad/ruby/VirtualMachineDriver.rb | 58 ++++++++++++++----------- src/vmm_mad/exec/one_vmm_exec.rb | 22 ++++++++++ src/vmm_mad/remotes/kvm/snapshot_create | 26 +++++++++++ 4 files changed, 82 insertions(+), 25 deletions(-) create mode 100755 src/vmm_mad/remotes/kvm/snapshot_create diff --git a/install.sh b/install.sh index dee2497563..3dcfd6a1c6 100755 --- a/install.sh +++ b/install.sh @@ -752,6 +752,7 @@ VMM_EXEC_KVM_SCRIPTS="src/vmm_mad/remotes/kvm/cancel \ src/vmm_mad/remotes/kvm/poll_ganglia \ src/vmm_mad/remotes/kvm/attach_disk \ src/vmm_mad/remotes/kvm/detach_disk \ + src/vmm_mad/remotes/kvm/snapshot_create \ src/vmm_mad/remotes/kvm/shutdown" #------------------------------------------------------------------------------- diff --git a/src/mad/ruby/VirtualMachineDriver.rb b/src/mad/ruby/VirtualMachineDriver.rb index e53762c3d8..5c32634884 100644 --- a/src/mad/ruby/VirtualMachineDriver.rb +++ b/src/mad/ruby/VirtualMachineDriver.rb @@ -30,19 +30,20 @@ class VirtualMachineDriver < OpenNebulaDriver # Virtual Machine Driver Protocol constants ACTION = { - :deploy => "DEPLOY", - :shutdown => "SHUTDOWN", - :reboot => "REBOOT", - :reset => "RESET", - :cancel => "CANCEL", - :save => "SAVE", - :restore => "RESTORE", - :migrate => "MIGRATE", - :poll => "POLL", - :log => "LOG", - :attach_disk => "ATTACHDISK", - :detach_disk => "DETACHDISK", - :cleanup => "CLEANUP" + :deploy => "DEPLOY", + :shutdown => "SHUTDOWN", + :reboot => "REBOOT", + :reset => "RESET", + :cancel => "CANCEL", + :save => "SAVE", + :restore => "RESTORE", + :migrate => "MIGRATE", + :poll => "POLL", + :log => "LOG", + :attach_disk => "ATTACHDISK", + :detach_disk => "DETACHDISK", + :snapshot_create => "SNAPSHOTCREATE", + :cleanup => "CLEANUP" } POLL_ATTRIBUTE = { @@ -79,18 +80,20 @@ class VirtualMachineDriver < OpenNebulaDriver @hosts = Array.new - register_action(ACTION[:deploy].to_sym, method("deploy")) - register_action(ACTION[:shutdown].to_sym, method("shutdown")) - register_action(ACTION[:reboot].to_sym, method("reboot")) - register_action(ACTION[:reset].to_sym, method("reset")) - register_action(ACTION[:cancel].to_sym, method("cancel")) - register_action(ACTION[:save].to_sym, method("save")) - register_action(ACTION[:restore].to_sym, method("restore")) - register_action(ACTION[:migrate].to_sym, method("migrate")) - register_action(ACTION[:poll].to_sym, method("poll")) - register_action(ACTION[:attach_disk].to_sym, method("attach_disk")) - register_action(ACTION[:detach_disk].to_sym, method("detach_disk")) - register_action(ACTION[:cleanup].to_sym, method("cleanup")) + register_action(ACTION[:deploy].to_sym, method("deploy")) + register_action(ACTION[:shutdown].to_sym, method("shutdown")) + register_action(ACTION[:reboot].to_sym, method("reboot")) + register_action(ACTION[:reset].to_sym, method("reset")) + register_action(ACTION[:cancel].to_sym, method("cancel")) + register_action(ACTION[:save].to_sym, method("save")) + register_action(ACTION[:restore].to_sym, method("restore")) + register_action(ACTION[:migrate].to_sym, method("migrate")) + register_action(ACTION[:poll].to_sym, method("poll")) + register_action(ACTION[:attach_disk].to_sym, method("attach_disk")) + register_action(ACTION[:detach_disk].to_sym, method("detach_disk")) + register_action(ACTION[:snapshot_create].to_sym, + method("snapshot_create")) + register_action(ACTION[:cleanup].to_sym, method("cleanup")) end # Decodes the encoded XML driver message received from the core @@ -170,6 +173,11 @@ class VirtualMachineDriver < OpenNebulaDriver send_message(ACTION[:detach_disk],RESULT[:failure],id,error) end + def snapshot_create(id, drv_message) + error = "Action not implemented by driver #{self.class}" + send_message(ACTION[:snapshot_create],RESULT[:failure],id,error) + end + def cleanup(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:cleanup],RESULT[:failure],id,error) diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index ddb506b3c1..65e779e30f 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -608,6 +608,28 @@ class ExecDriver < VirtualMachineDriver action.run(steps) end + # + # SNAPSHOTCREATE action, creates a new system snapshot + # + def snapshot_create(id, drv_message) + action = ACTION[:snapshot_create] + xml_data = decode(drv_message) + + puts xml_data + host = xml_data.elements['HOST'].text + deploy_id = xml_data.elements['DEPLOY_ID'].text + + snap_id_xpath = "VM/TEMPLATE/SNAPSHOT[ACTIVE='YES']/SNAPSHOT_ID" + snap_id = xml_data.elements[snap_id_xpath].text.to_i + + snapshot_name = "onesnap-#{snap_id}" + do_action("#{deploy_id} #{snapshot_name}", + id, + host, + ACTION[:snapshot_create], + :script_name => "snapshot_create") + end + # # CLEANUP action, frees resources allocated in a host: VM and disk images # diff --git a/src/vmm_mad/remotes/kvm/snapshot_create b/src/vmm_mad/remotes/kvm/snapshot_create new file mode 100755 index 0000000000..2aba9bf784 --- /dev/null +++ b/src/vmm_mad/remotes/kvm/snapshot_create @@ -0,0 +1,26 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# Copyright 2002-2013, 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. # +#--------------------------------------------------------------------------- # + +source $(dirname $0)/kvmrc +source $(dirname $0)/../../scripts_common.sh + +DOMAIN="$1" +NAME="$2" + +exec_and_log "virsh --connect $LIBVIRT_URI snapshot-create-as $DOMAIN $NAME" \ + "Could not create snapshot $NAME for domain $DOMAIN."