mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-05 09:17:41 +03:00
F OpenNebula/one#6242: prioritize file read (#2779)
This commit is contained in:
parent
5ca01807f5
commit
7c91082e33
@ -155,6 +155,8 @@ class OneBackupJobHelper < OpenNebulaHelper::OneHelper
|
||||
# Get user information
|
||||
if file
|
||||
str = File.read(file)
|
||||
elsif STDIN.wait_readable(0)
|
||||
str = STDIN.read
|
||||
else
|
||||
str = OpenNebulaHelper.update_template(id, bj, nil, xpath)
|
||||
end
|
||||
|
@ -397,6 +397,8 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
|
||||
# Get user information
|
||||
if file
|
||||
str = File.read(file)
|
||||
elsif STDIN.wait_readable(0)
|
||||
str = STDIN.read
|
||||
else
|
||||
str = OpenNebulaHelper.update_template(vm_id, vm, nil, xpath)
|
||||
end
|
||||
|
@ -130,6 +130,10 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
- using a template description file:
|
||||
|
||||
onebackupjob create weekly_backup.tmpl
|
||||
|
||||
- using a template description via stdin:
|
||||
|
||||
cat $bj_template | onebackupjob create
|
||||
EOT
|
||||
|
||||
command :create,
|
||||
@ -143,6 +147,8 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
begin
|
||||
if args[0]
|
||||
template = File.read(args[0])
|
||||
elsif STDIN.wait_readable?(0)
|
||||
template = STDIN.read
|
||||
else
|
||||
template = OneBackupJobHelper.create_backupjob_template(options)
|
||||
end
|
||||
|
@ -113,8 +113,11 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
helper.create_resource(options) do |datastore|
|
||||
begin
|
||||
template = File.read(args[0]) if args[0]
|
||||
template = STDIN.read if STDIN.wait_readable(0)
|
||||
if args[0]
|
||||
template = File.read(args[0])
|
||||
elsif STDIN.wait_readable(0)
|
||||
template = STDIN.read
|
||||
end
|
||||
datastore.allocate(template, cid)
|
||||
rescue StandardError => e
|
||||
STDERR.puts e.message
|
||||
|
@ -186,11 +186,13 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
command :create, create_desc, [:file, nil], :options => Service::JSON_FORMAT do
|
||||
client = helper.client(options)
|
||||
|
||||
template = nil
|
||||
template = File.read(args[0]) if args[0]
|
||||
template = STDIN.read if STDIN.wait_readable(0)
|
||||
if args[0]
|
||||
template = File.read(args[0])
|
||||
elsif STDIN.wait_readable(0)
|
||||
template = STDIN.read
|
||||
end
|
||||
|
||||
if template.nil?
|
||||
if !template
|
||||
STDERR.puts 'A template must be provided'
|
||||
exit(-1)
|
||||
end
|
||||
@ -257,38 +259,40 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
rc = 0
|
||||
client = helper.client(options)
|
||||
|
||||
number.times do
|
||||
template = nil
|
||||
template = File.read(args[1]) if args[1]
|
||||
template = STDIN.read if STDIN.wait_readable(0)
|
||||
if args[1]
|
||||
template = File.read(args[1])
|
||||
elsif STDIN.wait_readable(0)
|
||||
template = STDIN.read
|
||||
end
|
||||
params['merge_template'] = JSON.parse(template) if template
|
||||
|
||||
params['merge_template'] = JSON.parse(template) if template
|
||||
unless params['merge_template']
|
||||
response = client.get("#{RESOURCE_PATH}/#{args[0]}")
|
||||
|
||||
unless params['merge_template']
|
||||
response = client.get("#{RESOURCE_PATH}/#{args[0]}")
|
||||
|
||||
if CloudClient.is_error?(response)
|
||||
rc = [response.code.to_i, response.to_s]
|
||||
break
|
||||
end
|
||||
|
||||
params['merge_template'] = {}
|
||||
body = JSON.parse(response.body)['DOCUMENT']['TEMPLATE']['BODY']
|
||||
|
||||
# Check global custom attributes
|
||||
custom_attrs = helper.custom_attrs(body['custom_attrs'])
|
||||
params['merge_template'].merge!(custom_attrs) unless custom_attrs.nil?
|
||||
|
||||
# Check role level custom attributes
|
||||
custom_role_attrs = helper.custom_role_attrs(body['roles'])
|
||||
params['merge_template'].merge!(custom_role_attrs) unless custom_role_attrs.nil?
|
||||
|
||||
# Check vnets attributes
|
||||
vnets = helper.networks(body['networks'])
|
||||
params['merge_template'].merge!(vnets) unless vnets.nil?
|
||||
if CloudClient.is_error?(response)
|
||||
rc = [response.code.to_i, response.to_s]
|
||||
break
|
||||
end
|
||||
|
||||
json = Service.build_json_action('instantiate', params)
|
||||
params['merge_template'] = {}
|
||||
body = JSON.parse(response.body)['DOCUMENT']['TEMPLATE']['BODY']
|
||||
|
||||
# Check global custom attributes
|
||||
custom_attrs = helper.custom_attrs(body['custom_attrs'])
|
||||
params['merge_template'].merge!(custom_attrs) unless custom_attrs.nil?
|
||||
|
||||
# Check role level custom attributes
|
||||
custom_role_attrs = helper.custom_role_attrs(body['roles'])
|
||||
params['merge_template'].merge!(custom_role_attrs) unless custom_role_attrs.nil?
|
||||
|
||||
# Check vnets attributes
|
||||
vnets = helper.networks(body['networks'])
|
||||
params['merge_template'].merge!(vnets) unless vnets.nil?
|
||||
end
|
||||
|
||||
json = Service.build_json_action('instantiate', params)
|
||||
|
||||
number.times do
|
||||
response = client.post("#{RESOURCE_PATH}/#{args[0]}/action", json)
|
||||
|
||||
if CloudClient.is_error?(response)
|
||||
|
@ -164,6 +164,10 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
onehook create hook.tmpl
|
||||
|
||||
- using a Hook description file via stdin:
|
||||
|
||||
cat $hook_template | onehook create
|
||||
|
||||
EOT
|
||||
|
||||
command :create, create_desc, :file, :options =>
|
||||
@ -172,6 +176,11 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
begin
|
||||
if args[0]
|
||||
template = File.read(args[0])
|
||||
elsif STDIN.wait_readable(0)
|
||||
template = STDIN.read
|
||||
else
|
||||
STDERR.puts 'No hook template provided'
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
if options[:dry]
|
||||
|
@ -105,8 +105,11 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
command :create, create_desc, [:file, nil] do
|
||||
helper.create_resource(options) do |marketplace|
|
||||
begin
|
||||
template = File.read(args[0]) if args[0]
|
||||
template = STDIN.read if STDIN.wait_readable(0)
|
||||
if args[0]
|
||||
template = File.read(args[0])
|
||||
elsif STDIN.wait_readable(0)
|
||||
template = STDIN.read
|
||||
end
|
||||
marketplace.allocate(template)
|
||||
rescue StandardError => e
|
||||
STDERR.puts e.message
|
||||
|
@ -110,7 +110,14 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
command :create, create_desc, :file do
|
||||
helper.create_resource(options) do |obj|
|
||||
begin
|
||||
template = File.read(args[0])
|
||||
if args[0]
|
||||
template = File.read(args[0])
|
||||
elsif STDIN.wait_readable(0)
|
||||
template = STDIN.read
|
||||
else
|
||||
STDERR.puts 'No Security Group description provided'
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
obj.allocate(template)
|
||||
rescue StandardError => e
|
||||
|
@ -1352,8 +1352,11 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
template = ''
|
||||
|
||||
begin
|
||||
template = File.read(args[1]) if args[1]
|
||||
template = STDIN.read if STDIN.wait_readable(0)
|
||||
if args[1]
|
||||
template = File.read(args[1])
|
||||
elsif STDIN.wait_readable(0)
|
||||
template = STDIN.read
|
||||
end
|
||||
rescue StandardError => e
|
||||
STDERR.puts "Error reading template: #{e.message}."
|
||||
exit(-1)
|
||||
|
@ -136,7 +136,14 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
command :create, create_desc, :file do
|
||||
helper.create_resource(options) do |obj|
|
||||
begin
|
||||
template = File.read(args[0])
|
||||
if args[0]
|
||||
template = File.read(args[0])
|
||||
elsif STDIN.wait_readable(0)
|
||||
template = STDIN.read
|
||||
else
|
||||
STDERR.puts 'No VM Group description provided'
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
obj.allocate(template)
|
||||
rescue StandardError => e
|
||||
@ -283,8 +290,11 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
command :"role-add", role_add_desc, :vmgroupid, [:file, nil] do
|
||||
begin
|
||||
template = File.read(args[1]) if args[1]
|
||||
template = STDIN.read if STDIN.wait_readable(0)
|
||||
if args[1]
|
||||
template = File.read(args[1])
|
||||
elsif STDIN.wait_readable(0)
|
||||
template = STDIN.read
|
||||
end
|
||||
rescue StandardError => e
|
||||
STDERR.puts "Error reading template: #{e.message}."
|
||||
exit(-1)
|
||||
|
@ -171,8 +171,11 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
helper.create_resource(options) do |vn|
|
||||
begin
|
||||
template = File.read(args[0]) if args[0]
|
||||
template = STDIN.read if STDIN.wait_readable(0)
|
||||
if args[0]
|
||||
template = File.read(args[0])
|
||||
elsif STDIN.wait_readable(0)
|
||||
template = STDIN.read
|
||||
end
|
||||
vn.allocate(template, cid)
|
||||
rescue StandardError => e
|
||||
STDERR.puts "Error creating network: #{e.message}"
|
||||
@ -200,6 +203,8 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
helper.perform_action(args[0], options, 'address range added') do |vn|
|
||||
if args[1]
|
||||
ar = File.read(args[1])
|
||||
elsif STDIN.wait_readable(0)
|
||||
ar = STDIN.read
|
||||
else
|
||||
ar = OpenNebulaHelper.create_ar(options)
|
||||
end
|
||||
|
@ -149,6 +149,10 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
onevntemplate create vn_description.tmpl
|
||||
|
||||
- using a Virtual Network Template description file via stdin:
|
||||
|
||||
cat $vn_template | onevntemplate create
|
||||
|
||||
EOT
|
||||
|
||||
command :create, create_desc, [:file, nil], :options =>
|
||||
@ -157,6 +161,8 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
begin
|
||||
if args[0]
|
||||
template = File.read(args[0])
|
||||
elsif STDIN.wait_readable(0)
|
||||
template = STDIN.read
|
||||
end
|
||||
|
||||
if options[:dry]
|
||||
@ -250,6 +256,8 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
if args[1]
|
||||
extra_template = File.read(args[1])
|
||||
elsif STDIN.wait_readable(0)
|
||||
extra_template = STDIN.read
|
||||
else
|
||||
res = OpenNebulaHelper.create_template(options, t)
|
||||
|
||||
|
@ -140,8 +140,11 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
command :create, create_desc, [:file, nil] do
|
||||
helper.create_resource(options) do |obj|
|
||||
begin
|
||||
template = File.read(args[0]) if args[0]
|
||||
template = STDIN.read if STDIN.wait_readable(0)
|
||||
if args[0]
|
||||
template = File.read(args[0])
|
||||
elsif STDIN.wait_readable(0)
|
||||
template = STDIN.read
|
||||
end
|
||||
obj.allocate(template)
|
||||
rescue StandardError => e
|
||||
STDERR.puts e.message
|
||||
|
@ -109,7 +109,14 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
command :create, create_desc, :file do
|
||||
helper.create_resource(options) do |zone|
|
||||
begin
|
||||
template = File.read(args[0])
|
||||
if args[0]
|
||||
template = File.read(args[0])
|
||||
elsif STDIN.wait_readable(0)
|
||||
template = STDIN.read
|
||||
else
|
||||
STDERR.puts 'No zone template provided'
|
||||
exit(-1)
|
||||
end
|
||||
zone.allocate(template)
|
||||
rescue StandardError => e
|
||||
STDERR.puts e.message
|
||||
|
Loading…
Reference in New Issue
Block a user