mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
development: Removes TODO comments, add start/stop log messages and includes API retries.
* LXD Remove some TODOs * Handle LXD ocassional shutdown error * Fix API response error handling * Explicitly log the moment the container starts/stops * Update client.rb (cherry picked from commit bfe6c41fd68d98860ef64e42c01fba95d762109b)
This commit is contained in:
parent
523612b923
commit
df4b534cf6
@ -30,6 +30,7 @@ class LXDClient
|
||||
|
||||
API = '/1.0'.freeze
|
||||
HEADER = { 'Host' => 'localhost' }.freeze
|
||||
API_RETRY = 5 # Attempts, in case a response is failed to read from LXD
|
||||
|
||||
attr_reader :lxd_path, :snap
|
||||
|
||||
@ -119,18 +120,26 @@ class LXDClient
|
||||
def get_response(request, data)
|
||||
request.body = JSON.dump(data) unless data.nil?
|
||||
|
||||
request.exec(@socket, '1.1', request.path)
|
||||
|
||||
response = nil
|
||||
|
||||
loop do
|
||||
response = Net::HTTPResponse.read_new(@socket)
|
||||
break unless response.is_a?(Net::HTTPContinue)
|
||||
API_RETRY.times do
|
||||
request.exec(@socket, '1.1', request.path)
|
||||
response = nil
|
||||
|
||||
loop do
|
||||
response = Net::HTTPResponse.read_new(@socket)
|
||||
break unless response.is_a?(Net::HTTPContinue)
|
||||
end
|
||||
|
||||
response.reading_body(@socket, request.response_body_permitted?) {}
|
||||
next unless response.body.length >= 2
|
||||
|
||||
response = JSON.parse(response.body)
|
||||
|
||||
break
|
||||
end
|
||||
|
||||
response.reading_body(@socket, request.response_body_permitted?) {}
|
||||
|
||||
response = JSON.parse(response.body)
|
||||
raise LXDError, 'error' => 'Failed to read response from LXD' if response.nil?
|
||||
|
||||
raise LXDError, response if response['type'] == 'error'
|
||||
|
||||
|
@ -139,7 +139,6 @@ class Container
|
||||
cmd = "#{Mapper::COMMANDS[:lsblk]} -J"
|
||||
_rc, o, _e = Command.execute(cmd, false)
|
||||
|
||||
# TODO: Add extra mounts to raise
|
||||
raise "Container rootfs still mounted \n#{o}" if o.include?(@rootfs_dir)
|
||||
|
||||
wait?(@client.delete("#{CONTAINERS}/#{name}"), wait, timeout)
|
||||
@ -186,10 +185,12 @@ class Container
|
||||
# Contianer Status Control
|
||||
#---------------------------------------------------------------------------
|
||||
def start(options = {})
|
||||
OpenNebula.log '--- Starting container ---'
|
||||
change_state(__method__, options)
|
||||
end
|
||||
|
||||
|
||||
def stop(options = { :timeout => 120 })
|
||||
OpenNebula.log '--- Stopping container ---'
|
||||
change_state(__method__, options)
|
||||
|
||||
# Remove nic from ovs-switch if needed
|
||||
|
@ -51,7 +51,6 @@ class Qcow2Mapper < Mapper
|
||||
# before unmapping seems to prevent this behavior on the nbd module
|
||||
# used with the kernel versions in ubuntu 16.04
|
||||
|
||||
# TODO: avoid using if kpartx was not used
|
||||
hide_parts(device)
|
||||
cmd = "#{COMMANDS[:nbd]} -d #{device}"
|
||||
|
||||
|
@ -19,7 +19,6 @@ require 'yaml'
|
||||
# This class reads and holds configuration attributes for the LXD driver
|
||||
class LXDConfiguration < Hash
|
||||
|
||||
# TODO: Create lxdrc file from this hash to avoid duplicated config
|
||||
DEFAULT_CONFIGURATION = {
|
||||
:vnc => {
|
||||
:command => '/bin/login',
|
||||
|
Loading…
x
Reference in New Issue
Block a user