F #7460: Updates to oneform server

- Lint
- Add bash completion for oneform commands
- Driver state is now stored in /var/lib/one/oneform
- Improve rendering of descriptions in CLI (HTML/MD support)
- Move cloud providers to oneform registry
- Disable dummy driver by default
- Qeury paths for driver/provider list

co-authored-by: vickmp <vpalma@opennebula.io>
This commit is contained in:
Ruben S. Monteroandvickmp committed 2026-02-02 19:50:01 +01:00
1 parent eb890be80c
commit baae300fb8
163 files changed
+719 -4759

No files matched your search

+152
View File
@@ -265,6 +265,158 @@ module CLIHelper
exit(-1)
end
# Render a small HTML subset for terminal output
# Supports: p, br, ul/ol/li, strong/b, em/i, code, a[href]
def self.render_html(text)
return '' if text.nil? || text.empty?
use_ansi = $stdout.tty?
bold_on = use_ansi ? "\33[1m" : ''
faint_on = use_ansi ? "\33[2m" : ''
reset = use_ansi ? "\33[0m" : ''
mono_on = use_ansi ? "\33[36m" : ''
bullet = use_ansi ? '•' : '*'
# OSC 8 hyperlink escape (clickable links)
osc8_link = lambda do |label, url|
return "#{label} (#{url})" unless use_ansi
"\e]8;;#{url}\a#{label}\e]8;;\a"
end
s = text.to_s.gsub("\r\n", "\n")
# Block tags -> newlines
s = s.gsub(%r{<\s*br\s*/?\s*>}i, "\n")
s = s.gsub(%r{<\s*/\s*p\s*>}i, "\n")
s = s.gsub(/<\s*p\b[^>]*>/i, '')
s = s.gsub(%r{<\s*/\s*(div|section|article)\s*>}i, "\n\n")
s = s.gsub(/<\s*(div|section|article)\b[^>]*>/i, '')
# Links: <a href="url">label</a>
s = s.gsub(%r{<\s*a\b[^>]*href\s*=\s*["']([^"']+)["'][^>]*>(.*?)<\s*/\s*a\s*>}im) do
url = Regexp.last_match(1).strip
label = Regexp.last_match(2).to_s
osc8_link.call(label, url)
end
# Lists
s = s.gsub(/<\s*li\b[^>]*>/i, "#{bullet} ")
# Inline formatting
if use_ansi
s = s.gsub(%r{<\s*/\s*(strong|b)\s*>}i, reset)
s = s.gsub(/<\s*(strong|b)\b[^>]*>/i, bold_on)
s = s.gsub(%r{<\s*/\s*(em|i)\s*>}i, reset)
s = s.gsub(/<\s*(em|i)\b[^>]*>/i, faint_on)
# <code>
s = s.gsub(%r{<\s*code\b[^>]*>(.*?)<\s*/\s*code\s*>}im) do
"#{faint_on}#{mono_on}#{Regexp.last_match(1)}#{reset}"
end
else
s = s.gsub(%r{<\s*/?\s*(strong|b|em|i|code)\b[^>]*>}i, '')
end
# Remove any remaining tags
s = s.gsub(/<[^>]+>/, '')
# Decode minimal HTML entities
s = s.gsub('&amp;', '&')
.gsub('&lt;', '<')
.gsub('&gt;', '>')
.gsub('&quot;', '"')
.gsub('&#39;', "'")
.gsub('&nbsp;', ' ')
# Normalize whitespace
s = s.lines.map(&:rstrip).join("\n")
s.gsub(/\n{3,}/, "\n\n").strip
end
# Render a small Markdown subset for terminal output. Supports headings,
# bold, italic, inline code, and unordered lists.
def self.render_md(text)
return '' if text.nil? || text.empty?
use_ansi = $stdout.tty?
bold_on = use_ansi ? "\33[1m" : ''
reset = use_ansi ? "\33[0m" : ''
faint_on = use_ansi ? "\33[2m" : ''
mono_on = use_ansi ? "\33[36m" : ''
bullet = use_ansi ? '•' : '*'
# OSC 8 hyperlink sequences
osc8_link = lambda do |label, url|
return "#{label} (#{url})" unless use_ansi
"\e]8;;#{url}\a#{label}\e]8;;\a"
end
lines = text.to_s.gsub("\r\n", "\n").split("\n", -1)
out = lines.map do |line|
# Preserve empty lines
if line.strip.empty?
''
# Headings (#, ##, ###)
elsif (m = line.match(/\A\s{0,3}(\#{1,3})\s+(.*)\z/))
title = m[2].strip
"#{bold_on}#{title}#{reset}"
# Unordered list items (*, -, +)
elsif (m = line.match(/\A(\s*)[*+-]\s+(.*)\z/))
indent = m[1]
item = m[2]
"#{indent}#{bullet} #{item}"
else
line
end
end.join("\n")
# Links [label](url)
out = out.gsub(/\[([^\]]+)\]\(([^)]+)\)/) do
label = Regexp.last_match(1)
url = Regexp.last_match(2).strip
osc8_link.call(label, url)
end
# Autolinks <https://example.com>
out = out.gsub(/<((?:https?|mailto):[^>\s]+)>/) do
url = Regexp.last_match(1)
osc8_link.call(url, url)
end
# Inline formatting (simple, non-nested)
if use_ansi
# Inline code: `code`
out = out.gsub(/`([^`]+)`/) do
m = Regexp.last_match(1)
"#{faint_on}#{mono_on}#{m}#{reset}"
end
# Bold: **text**
out = out.gsub(/\*\*([^\*]+)\*\*/) do
m = Regexp.last_match(1)
"#{bold_on}#{m}#{reset}"
end
# Italic: *text*
out = out.gsub(/(^|[^*])\*([^*\n]+)\*(?!\*)/) do
m1 = Regexp.last_match(1)
m2 = Regexp.last_match(2)
"#{m1}#{faint_on}#{m2}#{reset}"
end
else
# Non-tty, keep markdown mostly as-is, but normalize list bullets
out = out.gsub(/\A(\s*)[*+-]\s+/m, "\\1#{bullet} ")
end
out
end
# Check if value is in base64
#
# @param value [String] Value to check
+17 -18
View File
@@ -42,7 +42,7 @@ class OneFormHelper < OpenNebulaHelper::OneHelper
CLIHelper::ShowTable.new(config_file, self) do
column :NAME, 'NAME', :left, :size => 15 do |d|
File.basename(d[:source])
File.basename(d[:system_path])
end
column :DEPLOYMENTS, 'DEPLOYMENTS', :left, :expand => true do |d|
@@ -65,8 +65,8 @@ class OneFormHelper < OpenNebulaHelper::OneHelper
#
# @param client [OneForm::Client] Petition client
# @param options [Hash] CLI options
def list_driver_pool(client, options)
response = client.list_drivers
def list_driver_pool(client, options, params = {})
response = client.list_drivers(params)
if CloudClient.is_error?(response)
[response[:err_code], response[:message]]
@@ -90,7 +90,7 @@ class OneFormHelper < OpenNebulaHelper::OneHelper
#
# @param client [OneForm::Client] Petition client
# @param options [Hash] CLI options
def top_driver_pool(client, options)
def top_driver_pool(client, options, params = {})
options[:delay] ? delay = options[:delay] : delay = 4
begin
@@ -98,7 +98,7 @@ class OneFormHelper < OpenNebulaHelper::OneHelper
CLIHelper.scr_cls
CLIHelper.scr_move(0, 0)
list_driver_pool(client, options)
list_driver_pool(client, options, params)
sleep delay
end
@@ -129,15 +129,14 @@ class OneFormHelper < OpenNebulaHelper::OneHelper
str = '%-20s: %-20s'
str_h1 = '%-80s'
CLIHelper.print_header(
str_h1 % "#{File.basename(response[:source]).upcase} ONEFORM DRIVER INFORMATION"
)
driver_name = File.basename(response[:system_path])
CLIHelper.print_header(str_h1 % "#{driver_name.upcase} ONEFORM DRIVER INFORMATION")
puts Kernel.format str, 'NAME', response[:name]
puts Kernel.format str, 'DESCRIPTION', response[:description]
puts Kernel.format str, 'SYSTEM PATH', response[:source]
puts Kernel.format str, 'VERSION', response[:version]
puts Kernel.format str, 'STATE', response[:state]
puts Kernel.format str, 'SOURCE', response[:registry]
puts Kernel.format str, 'VERSION', response[:version]
puts
@@ -191,21 +190,20 @@ class OneFormHelper < OpenNebulaHelper::OneHelper
puts
CLIHelper.print_header(str_h1 % 'DEPLOYMENT CONFIGURATIONS', false)
CLIHelper.print_header(str_h1 % 'DEPLOYMENT CONFIGURATIONS', true)
puts
configs = response[:deployment_confs] || []
configs.each do |conf|
CLIHelper.print_header(str_h1 % conf[:name], false)
puts Kernel.format str, 'DESCRIPTION', conf[:description] || '--'
puts Kernel.format str, 'INVENTORY_FILE', conf[:inventory] || '--'
CLIHelper.print_header(str_h1 % conf[:name].upcase, false)
puts conf[:description].nil? ? '--' : CLIHelper.render_html(conf[:description])
puts
next unless conf[:user_inputs] && !conf[:user_inputs].empty?
CLIHelper.print_header("#{conf[:inventory].upcase} INPUTS", false)
CLIHelper.print_header("#{conf[:inventory].upcase} CONFIGURATION INPUTS", false)
CLIHelper::ShowTable.new(nil, self) do
column :NAME, '', :left, :size => 25, :adjust => true do |input|
input[:name] || '--'
@@ -233,13 +231,14 @@ class OneFormHelper < OpenNebulaHelper::OneHelper
[
:name,
:description,
:source,
:version,
:registry,
:state,
:fireedge,
:connection,
:user_inputs,
:deployment_confs,
:version
:system_path
].include?(k)
end
+7 -6
View File
@@ -79,8 +79,8 @@ class OneProviderHelper < OpenNebulaHelper::OneHelper
#
# @param client [Service::Client] Petition client
# @param options [Hash] CLI options
def list_provider_pool(client, options)
response = client.list_providers
def list_provider_pool(client, options, params = {})
response = client.list_providers(params)
if CloudClient.is_error?(response)
[response[:err_code], response[:message]]
@@ -104,7 +104,7 @@ class OneProviderHelper < OpenNebulaHelper::OneHelper
#
# @param client [Service::Client] Petition client
# @param options [Hash] CLI options
def top_provider_pool(client, options)
def top_provider_pool(client, options, params = {})
options[:delay] ? delay = options[:delay] : delay = 4
begin
@@ -112,7 +112,7 @@ class OneProviderHelper < OpenNebulaHelper::OneHelper
CLIHelper.scr_cls
CLIHelper.scr_move(0, 0)
list_provider_pool(client, options)
list_provider_pool(client, options, params)
sleep delay
end
@@ -129,8 +129,8 @@ class OneProviderHelper < OpenNebulaHelper::OneHelper
# @param client [Service::Client] Petition client
# @param service_template [Integer] Provider ID
# @param options [Hash] CLI options
def format_resource(client, provider_id, options)
response = client.get_provider(provider_id)
def format_resource(client, provider_id, options, params = {})
response = client.get_provider(provider_id, params)
if CloudClient.is_error?(response)
[response[:err_code], response[:message]]
@@ -195,6 +195,7 @@ class OneProviderHelper < OpenNebulaHelper::OneHelper
:name,
:description,
:fireedge,
:user_inputs,
:connection,
:registration_time,
:provision_ids,
+6 -6
View File
@@ -93,8 +93,8 @@ class OneProvisionHelper < OpenNebulaHelper::OneHelper
#
# @param client [Service::Client] Petition client
# @param options [Hash] CLI options
def list_provision_pool(client, options)
response = client.list_provisions(options)
def list_provision_pool(client, options, params = {})
response = client.list_provisions(params)
if CloudClient.is_error?(response)
[response[:err_code], response[:message]]
@@ -118,7 +118,7 @@ class OneProvisionHelper < OpenNebulaHelper::OneHelper
#
# @param client [Service::Client] Petition client
# @param options [Hash] CLI options
def top_provision_pool(client, options)
def top_provision_pool(client, options, params = {})
options[:delay] ? delay = options[:delay] : delay = 4
begin
@@ -126,7 +126,7 @@ class OneProvisionHelper < OpenNebulaHelper::OneHelper
CLIHelper.scr_cls
CLIHelper.scr_move(0, 0)
list_provision_pool(client, options)
list_provision_pool(client, options, params)
sleep delay
end
@@ -143,8 +143,8 @@ class OneProvisionHelper < OpenNebulaHelper::OneHelper
# @param client [Service::Client] Petition client
# @param service_template [Integer] Provider ID
# @param options [Hash] CLI options
def format_resource(client, provision_id, options)
response = client.get_provision(provision_id)
def format_resource(client, provision_id, options, params = {})
response = client.get_provision(provision_id, params)
if CloudClient.is_error?(response)
[response[:err_code], response[:message]]
+14 -4
View File
@@ -52,6 +52,14 @@ CommandParser::CmdParser.new(ARGV) do
set :option, CommandParser::VERSION
set :option, CommandParser::HELP
ENABLED = {
:name => 'enabled',
:short => '-e',
:large => '--enabled',
:description => 'Show only enabled providers',
:default => false
}
helper = OneFormHelper.new
########################################################################
@@ -64,8 +72,9 @@ CommandParser::CmdParser.new(ARGV) do
command :list,
list_desc,
:options => FORMAT + CLIHelper::OPTIONS + [OpenNebulaHelper::DESCRIBE] do
helper.list_driver_pool(helper.client(options), options)
:options => FORMAT + CLIHelper::OPTIONS + [OpenNebulaHelper::DESCRIBE, ENABLED] do
enabled = options[:enabled] || false
helper.list_driver_pool(helper.client(options), options, :enabled => enabled)
end
top_desc = <<-EOT.unindent
@@ -74,9 +83,10 @@ CommandParser::CmdParser.new(ARGV) do
command :top,
top_desc,
:options => FORMAT + [CLIHelper::DELAY] do
:options => FORMAT + [CLIHelper::DELAY, ENABLED] do
Signal.trap('INT') { exit(-1) }
helper.top_driver_pool(helper.client(options), options)
enabled = options[:enabled] || false
helper.top_driver_pool(helper.client(options), options, :enabled => enabled)
0
end
+47 -6
View File
@@ -52,6 +52,22 @@ CommandParser::CmdParser.new(ARGV) do
set :option, CommandParser::VERSION
set :option, CommandParser::HELP
SENSITIVE = {
:name => 'sensitive',
:short => '-s',
:large => '--sensitive',
:description => 'Include sensitive values information in the output',
:default => false
}
ENABLED = {
:name => 'enabled',
:short => '-e',
:large => '--enabled',
:description => 'Show only enabled providers',
:default => false
}
helper = OneProviderHelper.new
############################################################################
@@ -83,8 +99,19 @@ CommandParser::CmdParser.new(ARGV) do
command :list,
list_desc,
:options => FORMAT + CLIHelper::OPTIONS + [OpenNebulaHelper::DESCRIBE] do
helper.list_provider_pool(helper.client(options), options)
:options => (
FORMAT + CLIHelper::OPTIONS +
[OpenNebulaHelper::DESCRIBE, SENSITIVE, ENABLED]
) do
sensitive = options[:sensitive] || false
enabled = options[:enabled] || false
helper.list_provider_pool(
helper.client(options),
options,
:include_sensitive => sensitive,
:enabled => enabled
)
end
top_desc = <<-EOT.unindent
@@ -93,9 +120,17 @@ CommandParser::CmdParser.new(ARGV) do
command :top,
top_desc,
:options => FORMAT + [CLIHelper::DELAY] do
:options => FORMAT + [CLIHelper::DELAY, SENSITIVE, ENABLED] do
Signal.trap('INT') { exit(-1) }
helper.top_provider_pool(helper.client(options), options)
sensitive = options[:sensitive] || false
enabled = options[:enabled] || false
helper.top_provider_pool(
helper.client(options),
options,
:include_sensitive => sensitive,
:enabled => enabled
)
0
end
@@ -104,15 +139,21 @@ CommandParser::CmdParser.new(ARGV) do
Show details of a specific provider template.
EOT
command :show, show_desc, :provider_id, :options => FORMAT do
command :show, show_desc, :provider_id, :options => FORMAT + [SENSITIVE] do
provider_id = args[0].to_i
sensitive = options[:sensitive] || false
if args[0].to_s !~ /^\d+$/
STDERR.puts 'Invalid provider ID'
exit(-1)
end
helper.format_resource(helper.client(options), provider_id, options)
helper.format_resource(
helper.client(options),
provider_id,
options,
:include_sensitive => sensitive
)
end
create_desc = <<-EOT.unindent
+35 -6
View File
@@ -126,6 +126,14 @@ CommandParser::CmdParser.new(ARGV) do
:format => String
}
SENSITIVE = {
:name => 'sensitive',
:short => '-s',
:large => '--sensitive',
:description => 'Include sensitive values information in the output',
:default => false
}
helper = OneProvisionHelper.new
############################################################################
@@ -157,8 +165,17 @@ CommandParser::CmdParser.new(ARGV) do
command :list,
list_desc,
:options => FORMAT + CLIHelper::OPTIONS + [ALL, OpenNebulaHelper::DESCRIBE] do
helper.list_provision_pool(helper.client(options), options)
:options => (
FORMAT + CLIHelper::OPTIONS +
[ALL, OpenNebulaHelper::DESCRIBE, SENSITIVE]
)do
sensitive = options[:sensitive] || false
helper.list_provision_pool(
helper.client(options),
options,
:include_sensitive => sensitive
)
end
top_desc = <<-EOT.unindent
@@ -167,9 +184,15 @@ CommandParser::CmdParser.new(ARGV) do
command :top,
top_desc,
:options => FORMAT + [CLIHelper::DELAY] do
:options => FORMAT + [CLIHelper::DELAY, SENSITIVE] do
Signal.trap('INT') { exit(-1) }
helper.top_provision_pool(helper.client(options), options)
sensitive = options[:sensitive] || false
helper.top_provision_pool(
helper.client(options),
options,
:include_sensitive => sensitive
)
0
end
@@ -178,10 +201,16 @@ CommandParser::CmdParser.new(ARGV) do
Show details of a specific provision.
EOT
command :show, show_desc, :provision_id, :options => FORMAT do
command :show, show_desc, :provision_id, :options => FORMAT + [SENSITIVE] do
provision_id = args[0].to_i
sensitive = options[:sensitive] || false
helper.format_resource(helper.client(options), provision_id, options)
helper.format_resource(
helper.client(options),
provision_id,
options,
:include_sensitive => sensitive
)
end
create_desc = <<-EOT.unindent