1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-11 05:17:41 +03:00

F #5591: Add CLI support for custom role attrs (#2579)

This commit is contained in:
Victor Palma 2023-05-12 13:50:08 +02:00 committed by GitHub
parent 7a9a6f87b6
commit 6b11d98f3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 4 deletions

View File

@ -193,6 +193,35 @@ class OneFlowTemplateHelper < OpenNebulaHelper::OneHelper
ret
end
# Get custom role attributes values from user
#
# @param role [Hash] Service role with custom attributes
#
# @return [Hash] Role with custom attributes values
def custom_role_attrs(roles)
return if roles.nil? || roles.empty?
ret = {}
role_with_custom_attrs = false
roles.each do |role|
next unless role.key?('custom_attrs')
####################################################################
# Display Role Information
####################################################################
header = "> Please insert the user inputs for the role \"#{role['name']}\""
puts header
role.merge!(custom_attrs(role['custom_attrs']))
role_with_custom_attrs = true
end
ret['roles'] = roles if role_with_custom_attrs
ret
end
def networks(vnets)
return unless vnets

View File

@ -61,6 +61,7 @@ require 'command_parser'
require 'opennebula/oneflow_client'
require 'cli_helper'
require 'one_helper/oneflowtemplate_helper'
require 'one_helper/onetemplate_helper'
USER_AGENT = 'CLI'
@ -253,14 +254,18 @@ CommandParser::CmdParser.new(ARGV) do
break
end
params['merge_template'] = {}
body = JSON.parse(response.body)['DOCUMENT']['TEMPLATE']['BODY']
params['merge_template'] = helper.custom_attrs(
body['custom_attrs']
)
# Check global custom attributes
custom_attrs = helper.custom_attrs(body['custom_attrs'])
params['merge_template'].merge!(custom_attrs) unless custom_attrs.nil?
params['merge_template'] = {} unless params['merge_template']
# 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