1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-22 13:33:52 +03:00

F OpenNebula/one#6059: Added QoL features for backup management (#2837)

using the CLI
This commit is contained in:
Daniel Clavijo Coca 2023-11-28 09:19:44 -06:00 committed by GitHub
parent 7fa9bac391
commit 611fe5f363
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 75 additions and 8 deletions

View File

@ -445,7 +445,7 @@ _oneimage() {
fi
opts="create clone delete persistent nonpersistent update enable chtype
disable chgrp chown chmod rename snapshot-delete snapshot-revert
snapshot-flatten list show top lock unlock orphans dockerfile"
snapshot-flatten list show top lock unlock orphans dockerfile restore"
cmd=oneimage
if [ "$COMP_CWORD" == 1 ]; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
@ -462,6 +462,9 @@ _oneimage() {
disable)
_complete $cmd $COL_NAME "stat=rdy"
;;
restore)
_complete $cmd $COL_NAME "type=BK"
;;
create)
COMPREPLY=( $(compgen -A file -- "${cur}") )
return 0
@ -740,7 +743,7 @@ _onevm() {
rename snapshot-create snapshot-revert snapshot-delete disk-snapshot-create
disk-snapshot-revert disk-snapshot-delete disk-snapshot-rename disk-resize
list show top resize save updateconf lock unlock create-chart
delete-chart update-chart backup restore ssh port-forward"
delete-chart update-chart backup restore ssh port-forward backupmode"
cmd=onevm
if [ "$COMP_CWORD" == 1 ]; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
@ -752,7 +755,7 @@ _onevm() {
unresched|rename|snapshot-create|snapshot-revert|snapshot-delete| \
disk-snapshot-create|disk-snapshot-delete|disk-snapshot-revert| \
disk-snapshot-rename|disk-resize|save|updateconf|lock|unlock|create-chart| \
delete-chart|update-chart|backup|restore|ssh|port-forward)
delete-chart|update-chart|backup|restore|ssh|port-forward|backupmode)
_complete $cmd
;;
undeploy|poweroff|reboot|shutdown|suspend|stop|migrate)

View File

@ -593,6 +593,8 @@ Bash symbols must be escaped on STDIN passing'
OPTIONS = FORMAT, EXTENDED, NUMERIC, KILOBYTES
BACKUP_MODES = %w[FULL INCREMENT]
class OneHelper
attr_accessor :client
@ -717,6 +719,14 @@ Bash symbols must be escaped on STDIN passing'
end
end
def backup_mode_valid?(sus_backup_mode)
BACKUP_MODES.each do |backup_mode|
return true if backup_mode.casecmp?(sus_backup_mode)
end
false
end
#-----------------------------------------------------------------------
# List pool functions
#-----------------------------------------------------------------------

View File

@ -173,6 +173,15 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
:format => String
}
FILTERS = [
{
:name => 'backup',
:large => '--backup',
:description => 'Show only backup type images',
:format => String
}
]
def self.rname
'IMAGE'
end
@ -263,13 +272,13 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
tmpl_pool.info
pool.each do |img|
next if img['TYPE'].to_i == 6 # skip backup images
attrs = { :id => img['ID'],
:name => img['NAME'],
:uname => img['UNAME'] }
orphans << img['ID'] if check_orphan(tmpl_pool,
xpath,
'IMAGE', attrs)
orphans << img['ID'] if check_orphan(tmpl_pool, xpath, 'IMAGE', attrs)
end
orphans

View File

@ -639,6 +639,21 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
# rubocop:enable Style/SpecialGlobalVars
end
def get_backup_mode(vm_id)
vm = retrieve_resource(vm_id)
if vm.has_elements?('/VM/BACKUPS/BACKUP_CONFIG')
vm.template_like_str('BACKUPS/BACKUP_CONFIG/MODE')
else
nil
end
end
def set_backup_mode(vm_ref, backup_mode)
vm = retrieve_resource(vm_ref)
vm.updateconf("BACKUP_CONFIG = [\"MODE\"=\"#{backup_mode}\"]")
end
private
def factory(id = nil)

View File

@ -130,6 +130,7 @@ CommandParser::CmdParser.new(ARGV) do
list_options += OpenNebulaHelper::FORMAT
list_options << OpenNebulaHelper::NUMERIC
list_options << OpenNebulaHelper::DESCRIBE
list_options << OneImageHelper::FILTERS
CREATE_OPTIONS = [OneDatastoreHelper::DATASTORE,
OneImageHelper::IMAGE,
@ -487,6 +488,16 @@ CommandParser::CmdParser.new(ARGV) do
EOT
command :list, list_desc, [:filterflag, nil], :options => list_options do
if options.key?(:backup)
filter = 'TYPE=BK'
if options[:filter]
options[:filter] << filter
else
options[:filter] = [filter]
end
options.delete(:backup)
end
helper.list_pool(options, false, args[0])
end

View File

@ -1325,6 +1325,26 @@ CommandParser::CmdParser.new(ARGV) do
end
end
backupmode_set_desc = <<-EOT.unindent
Updates the backup mode of a VM. Can be #{OpenNebulaHelper::BACKUP_MODES.join('|')}
EOT
command :backupmode, backupmode_set_desc, :vmid, :mode do
vm_ref = args[0]
backup_mode = args[1]
if !helper.backup_mode_valid?(backup_mode)
err_msg = "Invalid backup mode: #{backup_mode}\n"
err_msg << "Valid backup modes are: #{OpenNebulaHelper::BACKUP_MODES.join(',')}"
STDERR.puts err_msg
exit(-1)
end
# TODO: Ensure other BACKUP_CONFIG is not overwritten
helper.set_backup_mode(vm_ref, backup_mode)
end
updateconf_desc = <<-EOT.unindent
Updates the configuration of a VM. Valid states are: running, pending,
failure, poweroff, undeploy, hold or cloning.
@ -1362,8 +1382,7 @@ CommandParser::CmdParser.new(ARGV) do
exit(-1)
end
helper.perform_action(args[0], options,
'Updating VM configuration') do |vm|
helper.perform_action(args[0], options, 'Updating VM configuration') do |vm|
if template.empty?
rc = vm.info