Backlog #4437
Automatically create first initial snapshot
Status: | Pending | Start date: | 04/29/2016 | |
---|---|---|---|---|
Priority: | High | Due date: | ||
Assignee: | - | % Done: | 0% | |
Category: | Core & System | |||
Target version: | - |
Description
Hello,
Making some tests on a VM in ONE 4.14.2, I took disk snapshots to be able to redo my testing, but then I realise I forgot to create manually a first snapshot for the “untouched” image disk.
Normally, I do a DELETE-RECREATE
to revert to initial disk state, but this loose my snapshots.
Is it possible to create a first snapshot before starting a VM, if none are present?
Regards.
Related issues
History
#1 Updated by Ruben S. Montero about 5 years ago
- Tracker changed from Request to Backlog
- Category changed from Drivers - VM to Core & System
- Priority changed from Normal to High
This make sense, we are working on the delete action for 5.0 to expose it under the admin interface. So this option will come in handy ...
Cheers
#2 Updated by Ruben S. Montero about 5 years ago
- Related to Feature #3801: Revisit delete operation added
#3 Updated by Anton Todorov about 5 years ago
Hi,
I would like to share my thoughts regarding this interesting feature request.
What do you think about a global configuration attribute/variable/ for this feature (enabled/disabled) then per Template and per Image attributes to override the global flag? In such way every admin will have the freedom to tune the OpenNebula behavior regarding the needs.
Kind Regards,
Anton Todorov
#4 Updated by EOLE Team almost 5 years ago
Anton Todorov wrote:
Hi,
I would like to share my thoughts regarding this interesting feature request.
What do you think about a global configuration attribute/variable/ for this feature (enabled/disabled) then per Template and per Image attributes to override the global flag? In such way every admin will have the freedom to tune the OpenNebula behavior regarding the needs.
I personally think such configurability at different levels with the possibility to bloc or not the option to sublevels should be the de facto standard behavior ;-)
Regards.
#5 Updated by EOLE Team almost 5 years ago
Hello,
I work around this issue by creating a VM_HOOK
to make the initial snapshot for each OS
disk if no snapshot exists:
- The hook configuration
VM_HOOK = [ name = "initial_snapshot", on = "RUNNING", command = "initial_snapshot", arguments = "$ID" ]
- The hook script
#!/usr/bin/env ruby # coding: utf-8 # -------------------------------------------------------------------------- # # Copyright 2016, Équipe EOLE <eole@ac-dijon.fr> # # Author: Daniel Dehennin <daniel.dehennin@ac-dijon.fr> # # # # 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. # #--------------------------------------------------------------------------- # ############################################################################## # Script to implement initial snapshot for DISKs ############################################################################## ############################################################################## ONE_LOCATION=ENV["ONE_LOCATION"] if !ONE_LOCATION RUBY_LIB_LOCATION="/usr/lib/one/ruby" VMDIR="/var/lib/one" CONFIG_FILE="/var/lib/one/config" else RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" VMDIR=ONE_LOCATION+"/var" CONFIG_FILE=ONE_LOCATION+"/var/config" end $: << RUBY_LIB_LOCATION require 'opennebula' include OpenNebula if !(vm_id = ARGV[0]) puts "Missing VM ID" exit(-1) end RUNNING_STATE = OpenNebula::VirtualMachine::LCM_STATE.index('RUNNING') # Check if an image is of type OS # Params: # +image+:: an OpenNebula::Image object def is_snapshotable?(image) image.info return !image.has_elements?("TYPE") \ || image.retrieve_elements("TYPE") == ["0"] end # Check if a disk of a VM already has a snapshot # Params: # +disk_id+:: ID of the disk # +vm+:: an OpenNebula::VirtualMachine def has_snapshots?(disk_id, vm) return vm.element_xml("/VM/SNAPSHOTS[child::DISK_ID='#{disk_id}']") != '' end begin client = Client.new() rescue Exception => error puts "Error: #{error}" exit(-1) end begin vm = OpenNebula::VirtualMachine.new_with_id(vm_id, client) vm.info rescue Exception => error puts "Error: #{error}" exit(-1) end vm.each '/VM/TEMPLATE/DISK' do |disk| disk_id = disk.retrieve_elements("DISK_ID")[0].to_i image_id = disk.retrieve_elements("IMAGE_ID")[0].to_i image = OpenNebula::Image.new_with_id(image_id, client) if !is_snapshotable?(image) || has_snapshots?(disk_id, vm) puts "Nothing to do for disk #{disk_id}" next end puts "Create initial snapshot for disk #{disk_id}" vm.disk_snapshot_create(disk_id, "initial snapshot") begin sleep(1) vm.info end until vm.lcm_state() == RUNNING_STATE end
#6 Updated by EOLE Team almost 5 years ago
- File initial_snapshot added
I upload new version of my hook (initial_snapshot) to skip persistent disk, include datablocks and provide more informations in logs.