mirror of
https://github.com/OpenNebula/one.git
synced 2025-02-05 21:57:24 +03:00
M #-: fix provision states (#681)
This commit is contained in:
parent
3202a252d1
commit
82596d982b
@ -81,11 +81,12 @@ module OneProvision
|
||||
#
|
||||
# @param hosts [OpenNebula::Host Array] Hosts to configure
|
||||
# @param hosts [OpenNebula::Datastore array] Datastores for vars
|
||||
# @param provision [OpenNebula::Provision] Provision info
|
||||
# @param ping [Boolean] True to check ping to hosts
|
||||
def configure(hosts, datastores, ping = true)
|
||||
def configure(hosts, datastores, provision = nil, ping = true)
|
||||
return if hosts.nil? || hosts.empty?
|
||||
|
||||
Driver.retry_loop 'Failed to configure hosts' do
|
||||
Driver.retry_loop('Failed to configure hosts', provision) do
|
||||
check_ansible_version
|
||||
|
||||
ansible_dir = generate_ansible_configs(hosts, datastores)
|
||||
|
@ -13,7 +13,6 @@
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
module OneProvision
|
||||
|
||||
# Driver
|
||||
@ -75,17 +74,17 @@ module OneProvision
|
||||
end
|
||||
end
|
||||
|
||||
if provision
|
||||
provision.state = Provision::STATE['ERROR']
|
||||
provision.update
|
||||
end
|
||||
|
||||
case choice
|
||||
when :retry
|
||||
sleep(seconds) if seconds
|
||||
|
||||
retry
|
||||
when :quit
|
||||
if provision
|
||||
provision.state = Provision::STATE['ERROR']
|
||||
provision.update
|
||||
end
|
||||
|
||||
exit(-1)
|
||||
when :skip
|
||||
return :skip
|
||||
@ -95,11 +94,6 @@ module OneProvision
|
||||
Utils.fail('Cleanup unsupported for this operation')
|
||||
end
|
||||
|
||||
if provision
|
||||
provision.state = Provision::STATE['ERROR']
|
||||
provision.update
|
||||
end
|
||||
|
||||
exit(-1)
|
||||
end
|
||||
end
|
||||
@ -209,7 +203,7 @@ module OneProvision
|
||||
terraform = Terraform.singleton(provider, tf)
|
||||
|
||||
terraform.generate_deployment_file(provision)
|
||||
terraform.send(action)
|
||||
terraform.send(action, provision)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -30,7 +30,7 @@ module OneProvision
|
||||
'CONFIGURING' => 2,
|
||||
'RUNNING' => 3,
|
||||
'ERROR' => 4,
|
||||
'DONE' => 5
|
||||
'DELETING' => 5
|
||||
}
|
||||
|
||||
STATE_STR = %w[
|
||||
@ -39,7 +39,7 @@ module OneProvision
|
||||
CONFIGURING
|
||||
RUNNING
|
||||
ERROR
|
||||
DONE
|
||||
DELETING
|
||||
]
|
||||
|
||||
# Available resources that can be created with the provision
|
||||
@ -301,15 +301,7 @@ module OneProvision
|
||||
|
||||
OneProvisionLogger.info('Deploying')
|
||||
|
||||
ips = nil
|
||||
ids = nil
|
||||
state = nil
|
||||
conf = nil
|
||||
|
||||
Driver.retry_loop('Failed to deploy hosts', self) do
|
||||
ips, ids, state, conf = Driver.tf_action(self,
|
||||
'deploy')
|
||||
end
|
||||
ips, ids, state, conf = Driver.tf_action(self, 'deploy')
|
||||
|
||||
OneProvisionLogger.info('Monitoring hosts')
|
||||
|
||||
@ -340,10 +332,6 @@ module OneProvision
|
||||
rescue OneProvisionCleanupException
|
||||
delete(cleanup, timeout)
|
||||
|
||||
self.state = STATE['DONE']
|
||||
|
||||
update
|
||||
|
||||
-1
|
||||
end
|
||||
end
|
||||
@ -353,9 +341,9 @@ module OneProvision
|
||||
# @param force [Boolean] Force the configuration although provision
|
||||
# is already configured
|
||||
def configure(force = false)
|
||||
if state == STATE['DONE']
|
||||
unless [STATE['RUNNING'], STATE['ERROR']].include?(state)
|
||||
return OpenNebula::Error.new(
|
||||
'Provision is DONE, can\'t configure it'
|
||||
"Can't configure provision in #{STATE_STR[state]}"
|
||||
)
|
||||
end
|
||||
|
||||
@ -367,7 +355,7 @@ module OneProvision
|
||||
|
||||
update
|
||||
|
||||
rc = Ansible.configure(hosts, datastores)
|
||||
rc = Ansible.configure(hosts, datastores, self)
|
||||
|
||||
if rc == 0
|
||||
self.state = STATE['RUNNING']
|
||||
@ -383,12 +371,6 @@ module OneProvision
|
||||
# @param cleanup [Boolean] True to delete running VMs and images
|
||||
# @param timeout [Integer] Timeout for deleting running VMs
|
||||
def delete(cleanup, timeout)
|
||||
if state == STATE['DONE']
|
||||
return OpenNebula::Error.new(
|
||||
'Provision is DONE, can\'t delete it'
|
||||
)
|
||||
end
|
||||
|
||||
if running_vms? && !cleanup
|
||||
Utils.fail('Provision with running VMs can\'t be deleted')
|
||||
end
|
||||
@ -397,6 +379,10 @@ module OneProvision
|
||||
Utils.fail('Provision with images can\'t be deleted')
|
||||
end
|
||||
|
||||
self.state = STATE['DELETING']
|
||||
|
||||
update
|
||||
|
||||
delete_vms(timeout) if cleanup
|
||||
|
||||
delete_images(timeout) if cleanup
|
||||
@ -780,7 +766,7 @@ module OneProvision
|
||||
#
|
||||
# @param timeout [Integer] Timeout for deleting running VMs
|
||||
def delete_vms(timeout)
|
||||
Driver.retry_loop 'Failed to delete running_vms' do
|
||||
Driver.retry_loop('Failed to delete running_vms', self) do
|
||||
next if hosts.nil?
|
||||
|
||||
d_hosts = []
|
||||
@ -813,7 +799,7 @@ module OneProvision
|
||||
#
|
||||
# @param timeout [Integer] Timeout for deleting running VMs
|
||||
def delete_images(timeout)
|
||||
Driver.retry_loop 'Failed to delete images' do
|
||||
Driver.retry_loop('Failed to delete images', self) do
|
||||
d_datastores = []
|
||||
|
||||
next if datastores.nil?
|
||||
@ -902,7 +888,7 @@ module OneProvision
|
||||
objects[resource].delete_if do |obj|
|
||||
msg = "#{resource.chomp('s')} #{obj['id']}"
|
||||
|
||||
Driver.retry_loop "Failed to delete #{msg}" do
|
||||
Driver.retry_loop("Failed to delete #{msg}", self) do
|
||||
OneProvisionLogger.debug("Deleting OpenNebula #{msg}")
|
||||
|
||||
o = Resource.object(resource)
|
||||
|
@ -134,16 +134,18 @@ module OneProvision
|
||||
|
||||
# Deploy infra via Terraform
|
||||
#
|
||||
# @param provision [OpenNebula::Provision] Provision information
|
||||
#
|
||||
# @return [String, String]
|
||||
# - IPs for each deployed host
|
||||
# - Deploy ID for each host
|
||||
# - Terraform state in base64
|
||||
# - Terraform config in base64
|
||||
def deploy
|
||||
tempdir = init(false, false)
|
||||
def deploy(provision)
|
||||
tempdir = init(provision, false, false)
|
||||
|
||||
# Apply
|
||||
Driver.retry_loop "Driver action 'tf deploy' failed" do
|
||||
Driver.retry_loop("Driver action 'tf deploy' failed", provision) do
|
||||
_, e, s = Driver.run(
|
||||
"cd #{tempdir}; terraform apply -auto-approve"
|
||||
)
|
||||
@ -176,7 +178,7 @@ module OneProvision
|
||||
|
||||
[ips, ids, state, conf]
|
||||
ensure
|
||||
FileUtils.rm_r(tempdir) if File.exist?(tempdir)
|
||||
FileUtils.rm_r(tempdir) if tempdir && File.exist?(tempdir)
|
||||
end
|
||||
|
||||
# Get polling information from a host
|
||||
@ -189,21 +191,22 @@ module OneProvision
|
||||
|
||||
output(tempdir, "ip_#{id}")
|
||||
ensure
|
||||
FileUtils.rm_r(tempdir) if File.exist?(tempdir)
|
||||
FileUtils.rm_r(tempdir) if tempdir && File.exist?(tempdir)
|
||||
end
|
||||
|
||||
# Destroy infra via Terraform
|
||||
#
|
||||
# @param target [String] Target to destroy
|
||||
# @param provision [OpenNebula::Provision] Provision information
|
||||
# @param target [String] Target to destroy
|
||||
#
|
||||
# @return [Array]
|
||||
# - Terraform state in base64
|
||||
# - Terraform config in base64
|
||||
def destroy(target = nil)
|
||||
tempdir = init
|
||||
def destroy(provision, target = nil)
|
||||
tempdir = init(provision)
|
||||
|
||||
# Destroy
|
||||
Driver.retry_loop "Driver action 'tf destroy' failed" do
|
||||
Driver.retry_loop("Driver action 'tf destroy' failed", provision) do
|
||||
_, e, s = Driver.run(
|
||||
"cd #{tempdir}; terraform destroy #{target} -auto-approve"
|
||||
)
|
||||
@ -221,7 +224,7 @@ module OneProvision
|
||||
|
||||
[state, conf]
|
||||
ensure
|
||||
FileUtils.rm_r(tempdir) if File.exist?(tempdir)
|
||||
FileUtils.rm_r(tempdir) if tempdir && File.exist?(tempdir)
|
||||
end
|
||||
|
||||
# Destroys a cluster
|
||||
@ -346,9 +349,10 @@ module OneProvision
|
||||
|
||||
# Initialize Terraform directory content
|
||||
#
|
||||
# @param state [Boolean] True to copy state, false otherwise
|
||||
# @param decode [Boolean] True to decode @conf and @state
|
||||
def init(state = true, decode = true)
|
||||
# @param provisino [OpenNebula::Provision] Provision information
|
||||
# @param state [Boolean] True to copy state, false otherwise
|
||||
# @param decode [Boolean] True to decode @conf and @state
|
||||
def init(provision = nil, state = true, decode = true)
|
||||
tempdir = Dir.mktmpdir('tf')
|
||||
|
||||
if decode
|
||||
@ -375,7 +379,7 @@ module OneProvision
|
||||
upgrade(tempdir)
|
||||
|
||||
# Init
|
||||
Driver.retry_loop "Driver action 'tf init' failed" do
|
||||
Driver.retry_loop("Driver action 'tf init' failed", provision) do
|
||||
_, e, s = Driver.run("cd #{tempdir}; terraform init")
|
||||
|
||||
unless s && s.success?
|
||||
|
Loading…
x
Reference in New Issue
Block a user