Add option for archive and restore VMs

This commit is contained in:
Artur Gurgul 2025-08-13 10:21:46 +02:00
parent 8bbf7d31a5
commit 2840b6e221
3 changed files with 146 additions and 17 deletions

39
bin/vm
View file

@ -4,6 +4,10 @@ require 'optparse'
require 'ostruct'
require 'virtual-machine'
# Paramteters
# -env: DAT_VM_DATA=~/.cache/vm
# vm setup debian --arch "<host:arch64>" --name "<image_name: debian>"
options = OpenStruct.new
@ -18,6 +22,8 @@ OptionParser.new do |opt|
opt.on('--name NAME', 'Virtaul Machine name') do |name|
options.name = name
end
# --port (ssh port)
# --attached (do not leave the shell process)
# new from copy
# fetch from the server
end.parse!
@ -25,11 +31,40 @@ end.parse!
case subcommand
when :create
puts "Creating image...."
puts "vm create debian-copy --name debian"
puts "Creating image base on existing one...."
when :run
# same as setup but fetches image not
puts "Run the image or fetch and run...."
options[:distro] = parameter
VirtualMachine.run(options)
when :setup
options[:distro] = parameter
VirtualMachine.setup(options)
when :archive
# whole image or files that are not present in the archived
# --type files (zst all files by files)
# by default
#before start if should create index of files that are present on
# the vm, so later we can copy new files or changed
options[:distro] = parameter
VirtualMachine.archive(options)
when :appy
puts "appy chnages from VM to the host os"
when :restore
options[:distro] = parameter
VirtualMachine.restore(options)
#puts "download image from remote or if local copy exists then the local copy"
when :daemon
puts "setup a pprocess so i can attach to it"
# paramaters exatly as run/setup
when :status
puts "Print all images and status stopped/daemon(port)/running(port/)"
when :attach
puts "if not paramteres attaches to last used"
else
puts "Error not found #{options.type}"
end