1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-19 06:50:07 +03:00

F #4217: provision objects count (#406)

This commit is contained in:
Alejandro Huertas Herrero 2020-11-10 14:25:17 +01:00 committed by GitHub
parent 8b9cf9d611
commit 147ef6c481
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 53 additions and 21 deletions

View File

@ -263,7 +263,7 @@ module OpenNebula
recursive = false
end
if type != 'none'
if type && type != 'none'
rc = vm_template_ids
return rc if OpenNebula.is_error?(rc)

View File

@ -114,6 +114,10 @@ module OneProvision
# Returns provision provider
def provider
if @body['provider'] == 'dummy'
return { 'NAME' => 'dummy' }
end
Provider.by_name(@client, @body['provider'])
end
@ -282,12 +286,7 @@ module OneProvision
if skip == :none
configure
else
hosts.each do |h|
host = Host.new
host.info(h['id'])
host.one.enable
end
info_objects('hosts') {|h| h.enable }
end
create_virtual_resources(cfg)
@ -399,6 +398,8 @@ module OneProvision
return rc if OpenNebula.is_error?(rc)
0
ensure
unlock
end
# Updates provision objects
@ -618,22 +619,43 @@ module OneProvision
def create_hosts(cfg, cid)
return unless cfg['hosts']
hosts = []
cfg['hosts'].each do |h|
Driver.retry_loop 'Failed to create some host' do
erb = Utils.evaluate_erb(self, h)
dfile = Utils.create_deployment_file(erb)
h['count'].nil? ? count = 1 : count = Integer(h['count'])
playbooks = cfg['playbook']
playbooks = playbooks.join(',') if playbooks.is_a? Array
count.times.each do |idx|
Driver.retry_loop 'Failed to create some host' do
# Update hostname to avoid multiple same names
hostname = h['provision']['hostname'] if h['provision']
host = Host.new
host = host.create(dfile.to_xml, cid, playbooks)
h['id'] = Integer(host['ID'])
h['name'] = host['NAME']
if hostname && count > 1
h['provision']['hostname'] = "#{hostname}_#{idx}"
end
host.offline
erb = Utils.evaluate_erb(self, h)
dfile = Utils.create_deployment_file(erb)
playbooks = cfg['playbook']
playbooks = playbooks.join(',') if playbooks.is_a? Array
host = Host.new
host = host.create(dfile.to_xml, cid, playbooks)
if count > 1 && idx > 0
hosts << { 'id' => Integer(host['ID']),
'name' => host['NAME'] }
else
h['id'] = Integer(host['ID'])
h['name'] = host['NAME']
end
host.offline
end
end
end
cfg['hosts'] += hosts
end
# Updates provision hosts with new name

View File

@ -47,11 +47,11 @@ module OneProvision
when :cluster
Cluster.new(provider)
when :datastore
Datastore.new
Datastore.new(provider)
when :host
Host.new(provider)
when :image
Image.new(provider)
Image.new
when :network
Network.new(provider)
when :template

View File

@ -68,7 +68,7 @@ module OneProvision
# @param id [String] Object ID
def info(id)
@one = OpenNebula::Image.new_with_id(id, @client)
@one.info(true)
@one.info
end
private

View File

@ -34,7 +34,7 @@ module OneProvision
# @param id [String] Object ID
def info(id)
@one = OpenNebula::Template.new_with_id(id, @client)
@one.info(true)
@one.info(true, true)
end
private

View File

@ -83,6 +83,16 @@ module OneProvision
'file: no name given')
end
if !config['cluster']
Utils.fail('There is an error in your configuration ' \
'file: no cluster given')
end
if !config['cluster']['name']
Utils.fail('There is an error in your configuration ' \
'file: no cluster name given')
end
if config['hosts']
config['hosts'].each_with_index do |h, i|
im = h['im_mad']