From 754c663cb5ed0165a563dbdb86616f23762f04e4 Mon Sep 17 00:00:00 2001 From: Evgeny Yurchenko Date: Wed, 11 Mar 2015 17:04:05 +0000 Subject: [PATCH] Introduce disk-snapshot and VM shutdown functionality. --- lib/fog/opennebula/compute.rb | 2 ++ lib/fog/opennebula/models/compute/servers.rb | 4 +++ .../requests/compute/vm_disk_snapshot.rb | 25 +++++++++++++++++++ .../requests/compute/vm_shutdown.rb | 23 +++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 lib/fog/opennebula/requests/compute/vm_disk_snapshot.rb create mode 100644 lib/fog/opennebula/requests/compute/vm_shutdown.rb diff --git a/lib/fog/opennebula/compute.rb b/lib/fog/opennebula/compute.rb index 59dc86d25..f515c29b3 100644 --- a/lib/fog/opennebula/compute.rb +++ b/lib/fog/opennebula/compute.rb @@ -28,6 +28,8 @@ module Fog request :vm_resume request :vm_stop request :template_pool + request :vm_disk_snapshot + request :vm_shutdown class Mock include Collections diff --git a/lib/fog/opennebula/models/compute/servers.rb b/lib/fog/opennebula/models/compute/servers.rb index 4c8127bda..1a13cb852 100644 --- a/lib/fog/opennebula/models/compute/servers.rb +++ b/lib/fog/opennebula/models/compute/servers.rb @@ -19,6 +19,10 @@ module Fog new data.first unless data.empty? end + def shutdown(id) + service.vm_shutdown(id) + end + end end end diff --git a/lib/fog/opennebula/requests/compute/vm_disk_snapshot.rb b/lib/fog/opennebula/requests/compute/vm_disk_snapshot.rb new file mode 100644 index 000000000..5f8853adb --- /dev/null +++ b/lib/fog/opennebula/requests/compute/vm_disk_snapshot.rb @@ -0,0 +1,25 @@ +module Fog + module Compute + class OpenNebula + class Real + + def vm_disk_snapshot(id, disk_id, image_name) + vmpool = ::OpenNebula::VirtualMachinePool.new(client) + vmpool.info!(-2,id,id,-1) + + rc = 0 + vmpool.each do |vm| + rc = vm.disk_snapshot(disk_id, image_name) + if(rc.is_a? ::OpenNebula::Error) + raise(rc) + end + end + rc + end #def vm_disk_snapshot + + class Mock + end + end + end + end +end diff --git a/lib/fog/opennebula/requests/compute/vm_shutdown.rb b/lib/fog/opennebula/requests/compute/vm_shutdown.rb new file mode 100644 index 000000000..91149fa0d --- /dev/null +++ b/lib/fog/opennebula/requests/compute/vm_shutdown.rb @@ -0,0 +1,23 @@ +module Fog + module Compute + class OpenNebula + class Real + + def vm_shutdown(id) + vmpool = ::OpenNebula::VirtualMachinePool.new(client) + vmpool.info!(-2,id,id,-1) + + vmpool.each do |vm| + vm.shutdown() + end + end #def vm_disk_snapshot + + end + class Mock + def vm_shutdown(id) + true + end + end + end + end +end