1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

B #6726: Fix CLI paramters converted wrongly to 0 id (#3287)

These parameters were fixed:
* schedid in onebackupjob
* execid in onehook
* snapshot_id in oneimage
* nicid, pciid, sched_id and sgid in onevm
* nicid in onevrouter
* serverid in onezone

For all those parameters the string used as ID:
* if possible the name is converted is converted to int ID
* fails if the resource doesn't have name
This commit is contained in:
Pavel Czerný 2024-11-05 16:26:33 +01:00 committed by GitHub
parent e815d973a8
commit f5b2a17360
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 93 additions and 8 deletions

View File

@ -828,7 +828,7 @@ module CommandParser
end
def format_int(arg)
arg.match(/^\d+$/) ? [0,arg] : [-1]
arg.match(/^\d+$/) ? [0,arg] : [-1, "Argument '#{arg}' is not a valid ID"]
end
def format_file(arg)

View File

@ -201,6 +201,22 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
Image::SHORT_IMAGE_TYPES[type_str]
end
def retrieve_snapshot_id(image_id, id)
return [0, id.to_i] if id =~ /\A\d+\z/
image = retrieve_resource(image_id)
image.info
ids = image.retrieve_elements(
"/IMAGE/SNAPSHOTS/SNAPSHOT[NAME='#{id}']/ID"
)
return [-1, "#{id} not found or duplicated"] \
if ids.nil? || ids.size > 1
[0, ids[0].to_i]
end
def format_pool(options)
config_file = self.class.table_conf

View File

@ -252,6 +252,19 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
[0, ids[0].to_i]
end
def retrieve_nic_id(vm_id, id)
return [0, id.to_i] if id =~ /\A\d+\z/
vm = retrieve_resource(vm_id)
vm.info
ids = vm.retrieve_elements("/VM/TEMPLATE/NIC[NAME='#{id}']/NIC_ID")
return [-1, "NIC #{id} not found or duplicated"] \
if ids.nil? || ids.size > 1
[0, ids[0].to_i]
end
def format_pool(options)
config_file = self.class.table_conf

View File

@ -506,6 +506,22 @@ class OneZoneHelper < OpenNebulaHelper::OneHelper
Zone::SHORT_ZONE_STATES[state_str]
end
def retrieve_server_id(zone_id, id)
return [0, id.to_i] if id =~ /\A\d+\z/
zone = retrieve_resource(zone_id)
zone.info
ids = zone.retrieve_elements(
"/ZONE/SERVER_POOL/SERVER[NAME='#{id}']/ID"
)
return [-1, "#{id} not found or duplicated"] \
if ids.nil? || ids.size > 1
[0, ids[0].to_i]
end
def format_pool(options)
config_file = self.class.table_conf

View File

@ -120,6 +120,10 @@ CommandParser::CmdParser.new(ARGV) do
helper.filterflag_to_i(arg)
end
set :format, :schedid, 'Scheduled Action id' do |arg|
format_int(arg)
end
########################################################################
# Commands
########################################################################

View File

@ -103,6 +103,10 @@ CommandParser::CmdParser.new(ARGV) do
helper.list_to_id(arg)
end
set :format, :execid, 'Hook execution id' do |arg|
format_int(arg)
end
########################################################################
# Hook log Options
########################################################################

View File

@ -149,7 +149,9 @@ CommandParser::CmdParser.new(ARGV) do
end
set :format, :imageid, OneImageHelper.to_id_desc do |arg|
helper.to_id(arg)
tmp = helper.to_id(arg)
@current_image = tmp[1]
tmp
end
set :format, :imageid_list, OneImageHelper.list_to_id_desc do |arg|
@ -170,6 +172,10 @@ CommandParser::CmdParser.new(ARGV) do
end
end
set :format, :snapshot_id, 'Snapshot name or id' do |arg|
helper.retrieve_snapshot_id(@current_image, arg)
end
########################################################################
# Commands
########################################################################

View File

@ -320,7 +320,7 @@ CommandParser::CmdParser.new(ARGV) do
helper.filterflag_to_i(arg)
end
set :format, :diskid, 'Integer' do |arg|
set :format, :diskid, 'Disk id' do |arg|
format_int(arg)
end
@ -328,14 +328,30 @@ CommandParser::CmdParser.new(ARGV) do
OpenNebulaHelper.size_in_mb(arg)
end
format :snapshot_id, 'Snapshot identifier' do |arg|
set :format, :snapshot_id, 'Snapshot name or id' do |arg|
helper.retrieve_snapshot_id(@current_vm, arg)
end
format :disk_snapshot_id, 'Disk_snapshot identifier' do |arg|
set :format, :disk_snapshot_id, 'Disk_snapshot name or id' do |arg|
helper.retrieve_disk_snapshot_id(@current_vm, arg)
end
set :format, :nicid, 'NIC name or id' do |arg|
helper.retrieve_nic_id(@current_vm, arg)
end
set :format, :pciid, 'PCI id' do |arg|
format_int(arg)
end
set :format, :sched_id, 'Scheduled Action id' do |arg|
format_int(arg)
end
set :format, :sgid, 'Security Group id' do |arg|
format_int(arg)
end
########################################################################
# Commands
########################################################################

View File

@ -121,7 +121,7 @@ CommandParser::CmdParser.new(ARGV) do
helper.filterflag_to_i(arg)
end
format :roleid, 'Role identifier' do |arg|
set :format, :roleid, 'Role identifier' do |arg|
helper.retrieve_role_id(@current_vmg, arg)
end

View File

@ -152,7 +152,7 @@ CommandParser::CmdParser.new(ARGV) do
helper.filterflag_to_i(arg)
end
set :format, :ar_id, 'Integer' do |arg|
set :format, :ar_id, 'Address Range id' do |arg|
format_int(arg)
end

View File

@ -128,6 +128,10 @@ CommandParser::CmdParser.new(ARGV) do
OpenNebulaHelper.rname_to_id(arg, 'VMTEMPLATE')
end
set :format, :nicid, 'NIC id' do |arg|
format_int(arg)
end
########################################################################
# Commands
########################################################################

View File

@ -91,13 +91,19 @@ CommandParser::CmdParser.new(ARGV) do
# Formatters for arguments
########################################################################
set :format, :zoneid, OneZoneHelper.to_id_desc do |arg|
helper.to_id(arg)
tmp = helper.to_id(arg)
@current_zone = tmp[1]
tmp
end
set :format, :zoneid_list, OneZoneHelper.list_to_id_desc do |arg|
helper.list_to_id(arg)
end
set :format, :serverid, 'Server name or id' do |arg|
helper.retrieve_server_id(@current_zone, arg)
end
########################################################################
# Commands
########################################################################