Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F #4: add loading config file #6

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion oneswap
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ require 'socket'
require 'ipaddr'
require 'open3'
require 'rexml'
require 'yaml'
require 'cgi'

CommandParser::CmdParser.new(ARGV) do
Expand Down Expand Up @@ -306,11 +307,18 @@ CommandParser::CmdParser.new(ARGV) do
:format => String
}

CONF_FILE = {
:name => 'config_file',
:large => '--config-file /path/to/custom/config.yaml',
:description => 'Path to custom Configuration File, default is /var/lib/one/oneswap.yaml',
:format => String
}

ESXI_OPTS = [ESXI, ESXI_USER, ESXI_PASS]
V2V_OPTS = [WORK_DIR, FORMAT, VIRTIO, WIN_GA, LNX_GA, DELETE, VDDK, RHSRVANY]

LIST_OPTS = [NAME, DATACENTER, CLUSTER, STATE] + AUTH_OPTS
CONVERT_OPTS = [NETWORK, NO_IP, NO_MAC, DATASTORE, CONTEXT, FALLBACK, CUSTOM, HYBRID, V2V_PATH,
CONVERT_OPTS = [NETWORK, NO_IP, NO_MAC, DATASTORE, CONTEXT, FALLBACK, CUSTOM, HYBRID, V2V_PATH, CONF_FILE,
ONE_DS, ONE_DS_CLUSTER, ONE_CLUSTER, ONE_HOST] + AUTH_OPTS + ESXI_OPTS + V2V_OPTS

set :option, CommandParser::OPTIONS + OpenNebulaHelper::CLIENT_OPTIONS
Expand Down Expand Up @@ -376,6 +384,9 @@ CommandParser::CmdParser.new(ARGV) do

command :convert, conv_desc, :vm_name, :options => CONVERT_OPTS do
begin
if options[:config_file] && !File.exist?(options[:config_file])
raise "Unable to find the config file at #{options[:config_file]}"
end
raise 'ESXi Transfer requires at least IP and Password' if options[:esxi_ip] && options[:esxi_pass].nil?
raise 'ESXI and VDDK cannot be used at same time, recommend VDDK.' if options[:esxi_ip] && options[:vddk]
if options[:hybrid] && ( options[:custom] || options[:esxi_ip] || options[:vddk] )
Expand Down Expand Up @@ -405,6 +416,10 @@ CommandParser::CmdParser.new(ARGV) do
options[:datastore] ||= 1
options[:virt_tools] ||= '/usr/share/virt-tools'
options[:v2v_path] ||= 'virt-v2v'
options[:config_file] ||= '/var/lib/one/oneswap.yaml'

cfg_file = YAML.load_file(options[:config_file]) if File.exist?(options[:config_file])
options.merge!(cfg_file) if cfg_file

helper.convert(args[0], options)
rescue StandardError => e
Expand Down
28 changes: 28 additions & 0 deletions oneswap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#:vcenter:
#:vuser:
#:vpass:
#:port:
#:network:
#:skip_ip:
#:skip_mac:
#:datastore:
#:work_dir:
#:format:
#:delete:
#:context:
#:esxi_ip:
#:esxi_user:
#:esxi_pass:
#:vddk_path:
#:custom_convert:
#:fallback:
#:hybrid:
#:qemu_ga_win:
#:qemu_ga_linux:
#:virtio_path:
#:virt_tools:
#:one_cluster:
#:one_host:
#:one_datastore:
#:one_datastore_cluster:
#:v2v_path: