mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-23 17:33:56 +03:00
Feature #1224: Add snapshot_create vmm/kvm driver action
This commit is contained in:
parent
9cfa59d06e
commit
3425256254
@ -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"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
#
|
||||
|
26
src/vmm_mad/remotes/kvm/snapshot_create
Executable file
26
src/vmm_mad/remotes/kvm/snapshot_create
Executable file
@ -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."
|
Loading…
Reference in New Issue
Block a user