mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-11 04:58:16 +03:00
Feature #2898: Flow template instantiate + merge in CLI
This commit is contained in:
parent
879b57725c
commit
1172c4a812
@ -304,7 +304,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
Instantiate a Service Template
|
||||
EOT
|
||||
|
||||
command :instantiate, instantiate_desc, :template_id,
|
||||
command :instantiate, instantiate_desc, :template_id, [:file, nil],
|
||||
:options => [Service::JSON_FORMAT, Service::TOP] do
|
||||
client = Service::Client.new(
|
||||
:username => options[:username],
|
||||
@ -312,7 +312,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
:url => options[:server],
|
||||
:user_agent => USER_AGENT)
|
||||
|
||||
json_str = Service.build_json_action('instantiate')
|
||||
params = Hash.new
|
||||
|
||||
if(args[1])
|
||||
params['merge_template'] = File.read(args[1])
|
||||
end
|
||||
|
||||
json_str = Service.build_json_action('instantiate', params)
|
||||
|
||||
response = client.post("#{RESOURCE_PATH}/#{args[0]}/action", json_str)
|
||||
|
||||
|
@ -171,14 +171,7 @@ module OpenNebula
|
||||
def allocate(template_json)
|
||||
template = JSON.parse(template_json)
|
||||
|
||||
validator = Validator::Validator.new(
|
||||
:default_values => true,
|
||||
:delete_extra_properties => false
|
||||
)
|
||||
|
||||
validator.validate!(template, SCHEMA)
|
||||
|
||||
validate_values(template)
|
||||
validate(template)
|
||||
|
||||
super(template.to_json, template['name'])
|
||||
end
|
||||
@ -193,6 +186,12 @@ module OpenNebula
|
||||
def update(template_json)
|
||||
template = JSON.parse(template_json)
|
||||
|
||||
validator(template)
|
||||
|
||||
super(template.to_json)
|
||||
end
|
||||
|
||||
def self.validate(template)
|
||||
validator = Validator::Validator.new(
|
||||
:default_values => true,
|
||||
:delete_extra_properties => false
|
||||
@ -201,13 +200,11 @@ module OpenNebula
|
||||
validator.validate!(template, SCHEMA)
|
||||
|
||||
validate_values(template)
|
||||
|
||||
super(template.to_json)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def validate_values(template)
|
||||
def self.validate_values(template)
|
||||
parser = ElasticityGrammarParser.new
|
||||
|
||||
roles = template['roles']
|
||||
|
@ -416,8 +416,29 @@ post '/service_template/:id/action' do
|
||||
error CloudServer::HTTP_ERROR_CODE[rc.errno], rc.message
|
||||
end
|
||||
|
||||
merge_template = opts['merge_template']
|
||||
|
||||
if !merge_template.nil?
|
||||
begin
|
||||
template = JSON.parse(merge_template)
|
||||
orig_template = JSON.parse(service_template.template)
|
||||
|
||||
instantiate_template = orig_template.merge(template)
|
||||
|
||||
ServiceTemplate.validate(instantiate_template)
|
||||
|
||||
instantiate_template = instantiate_template.to_json
|
||||
|
||||
rescue Validator::ParseException, JSON::ParserError
|
||||
error 400, $!.message
|
||||
end
|
||||
else
|
||||
instantiate_template = service_template.template
|
||||
end
|
||||
|
||||
|
||||
service = OpenNebula::Service.new(OpenNebula::Service.build_xml, @client)
|
||||
rc = service.allocate(service_template.template)
|
||||
rc = service.allocate(instantiate_template)
|
||||
if OpenNebula.is_error?(rc)
|
||||
error CloudServer::HTTP_ERROR_CODE[rc.errno], rc.message
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user