mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
(cherry picked from commit fb562bdf8adf05ac41806fd60d2a9118b0863b94)
This commit is contained in:
parent
ee58967e96
commit
4d19829486
@ -229,6 +229,13 @@ class OneProvisionHelper < OpenNebulaHelper::OneHelper
|
||||
:format => Integer
|
||||
}
|
||||
|
||||
HOSTNAMES = {
|
||||
:name => 'hostnames',
|
||||
:large => '--hostnames h1,h2',
|
||||
:description => 'Hostnames when adding new host to onpremise provision',
|
||||
:format => Array
|
||||
}
|
||||
|
||||
########################################################################
|
||||
|
||||
MODES = CommandParser::OPTIONS - [CommandParser::VERBOSE] +
|
||||
@ -474,7 +481,7 @@ class OneProvisionHelper < OpenNebulaHelper::OneHelper
|
||||
|
||||
return [-1, rc.message] if OpenNebula.is_error?(rc)
|
||||
|
||||
rc = provision.add_hosts(amount)
|
||||
rc = provision.add_hosts(amount, options[:hostnames])
|
||||
|
||||
return [-1, rc.message] if OpenNebula.is_error?(rc)
|
||||
|
||||
|
@ -255,7 +255,8 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
host_add_desc,
|
||||
:provisionid,
|
||||
:options => [OneProvisionHelper::MODES,
|
||||
OneProvisionHelper::AMOUNT] do
|
||||
OneProvisionHelper::AMOUNT,
|
||||
OneProvisionHelper::HOSTNAMES] do
|
||||
helper.add_hosts(args[0], options)
|
||||
end
|
||||
|
||||
|
@ -407,8 +407,10 @@ module OneProvision
|
||||
|
||||
# Provisions and configures new hosts
|
||||
#
|
||||
# @param amount [Intenger] Amount of hosts to add to the provision
|
||||
def add_hosts(amount)
|
||||
# @param amount [Intenger] Amount of hosts to add to the provision
|
||||
# @param hostnames [Array] Array of hostnames to add. Works only in
|
||||
# on premise provisions
|
||||
def add_hosts(amount, hostnames)
|
||||
if !state || state != STATE['RUNNING']
|
||||
return OpenNebula::Error.new(
|
||||
"Can't add hosts to provision in #{STATE_STR[state]}"
|
||||
@ -457,11 +459,22 @@ module OneProvision
|
||||
# idx used to generate hostname
|
||||
idx = hosts.size
|
||||
|
||||
# If the user set hostnames, iterate over them to create the
|
||||
# hosts. This is thought for on premise provision, where the hosts
|
||||
# are already created in on premise infrastructure
|
||||
if hostnames
|
||||
iterate = hostnames
|
||||
else
|
||||
iterate = amount.times.map.with_index(idx) do |_, i|
|
||||
"edge-host#{i}"
|
||||
end
|
||||
end
|
||||
|
||||
# Allocate hosts in OpenNebula and add them to the provision
|
||||
amount.times do
|
||||
host['provision']['index'] = idx
|
||||
iterate.each.with_index(idx) do |item, i|
|
||||
host['provision']['index'] = i
|
||||
host['provision']['hostname'] = ''
|
||||
host['provision']['hostname'] = "edge-host#{idx}"
|
||||
host['provision']['hostname'] = item
|
||||
|
||||
h = Resource.object('hosts', @provider, host)
|
||||
dfile = h.create_deployment_file
|
||||
@ -477,8 +490,6 @@ module OneProvision
|
||||
one_host.offline
|
||||
|
||||
update
|
||||
|
||||
idx += 1
|
||||
end
|
||||
|
||||
OneProvisionLogger.info('Deploying')
|
||||
|
@ -47,7 +47,7 @@ module OneProvision
|
||||
) if @p_template['connection']
|
||||
config = Base64.strict_encode64(
|
||||
@p_template['configuration'].to_yaml
|
||||
)
|
||||
) if @p_template['configuration']
|
||||
|
||||
reject = %w[im_mad vm_mad provision connection configuration count]
|
||||
|
||||
|
@ -31,6 +31,7 @@ module OneProvision
|
||||
@hosts = provision.info_objects('hosts')
|
||||
end
|
||||
|
||||
# Deploys a new host
|
||||
def deploy(_)
|
||||
OneProvisionLogger.info('(Deploy skipped)')
|
||||
|
||||
@ -48,6 +49,13 @@ module OneProvision
|
||||
# @param [String] Host public IP
|
||||
def poll(_) end
|
||||
|
||||
# Provisions and configures new hosts
|
||||
#
|
||||
# @param provision [OpenNebula::Provision] Provision information
|
||||
def add_hosts(_)
|
||||
deploy(nil)
|
||||
end
|
||||
|
||||
# Destroy infra via Terraform
|
||||
#
|
||||
# @param target [String] Target to destroy
|
||||
|
@ -116,7 +116,11 @@ module OneProvision
|
||||
raise OneProvisionLoopException, "Unknown provider: #{p_name}"
|
||||
end
|
||||
|
||||
@@providers[p_name].new(provider, tf[:state], tf[:conf])
|
||||
if tf
|
||||
@@providers[p_name].new(provider, tf[:state], tf[:conf])
|
||||
else
|
||||
@@providers[p_name].new(provider)
|
||||
end
|
||||
end
|
||||
|
||||
# Check connection attributes of a provider template
|
||||
|
Loading…
x
Reference in New Issue
Block a user