mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
L #-: lint some files (#1220)
This commit is contained in:
parent
26c02b657e
commit
4293059b45
@ -1670,14 +1670,16 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
i_end_p = Integer(i_range[1].split('/')[0])
|
||||
|
||||
if args[1].nil?
|
||||
[*e_start_p..e_end_p].zip([*i_start_p..i_end_p]) do |p1, p2|
|
||||
start_r = Array(e_start_p..e_end_p)
|
||||
end_r = Array(i_start_p..i_end_p)
|
||||
|
||||
start_r.zip(end_r) do |p1, p2|
|
||||
puts "#{ip}@#{p1} -> #{p2}"
|
||||
end
|
||||
else
|
||||
puts "#{ip}@#{e_start_p + Integer(args[1]) - 1} -> #{args[1]}"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Deprecated commands
|
||||
|
@ -140,12 +140,14 @@ module OpenNebula
|
||||
# Return true if the service can be undeployed
|
||||
# @return true if the service can be undeployed, false otherwise
|
||||
def can_undeploy?
|
||||
# rubocop:disable Style/IfWithBooleanLiteralBranches
|
||||
if (transient_state? && state != Service::STATE['UNDEPLOYING']) ||
|
||||
state == Service::STATE['DONE'] || failed_state?
|
||||
false
|
||||
else
|
||||
true
|
||||
end
|
||||
# rubocop:enable Style/IfWithBooleanLiteralBranches
|
||||
end
|
||||
|
||||
# Return true if the service can be updated
|
||||
|
@ -34,7 +34,7 @@ module Strategy
|
||||
|
||||
# Ruby 1.8 compatibility
|
||||
if result.instance_of?(Array)
|
||||
result = Hash[result]
|
||||
result = result.to_h
|
||||
end
|
||||
|
||||
result
|
||||
@ -52,7 +52,7 @@ module Strategy
|
||||
|
||||
# Ruby 1.8 compatibility
|
||||
if result.instance_of?(Array)
|
||||
result = Hash[result]
|
||||
result = result.to_h
|
||||
end
|
||||
|
||||
result
|
||||
|
@ -77,7 +77,7 @@ module Straight
|
||||
|
||||
# Ruby 1.8 compatibility
|
||||
if running_roles.instance_of?(Array)
|
||||
running_roles = Hash[running_roles]
|
||||
running_roles = running_roles.to_h
|
||||
end
|
||||
|
||||
result = roles.select do |_name, role|
|
||||
@ -99,7 +99,7 @@ module Straight
|
||||
|
||||
# Ruby 1.8 compatibility
|
||||
if result.instance_of?(Array)
|
||||
result = Hash[result]
|
||||
result = result.to_h
|
||||
end
|
||||
|
||||
result
|
||||
@ -134,7 +134,7 @@ module Straight
|
||||
|
||||
# Ruby 1.8 compatibility
|
||||
if result.instance_of?(Array)
|
||||
result = Hash[result]
|
||||
result = result.to_h
|
||||
end
|
||||
|
||||
result
|
||||
|
@ -112,8 +112,9 @@ require 'digest'
|
||||
|
||||
IP_TYPE = %w[public_ipv4 global_ipv4]
|
||||
|
||||
DEFAULT_PRIVATE_CIDR = "172.16.0.0/12"
|
||||
DEFAULT_PRIVATE_CIDR = '172.16.0.0/12'
|
||||
|
||||
# IP Address class
|
||||
class IPAddr
|
||||
|
||||
# Add ^ operator to the IPAddr class
|
||||
@ -131,7 +132,7 @@ class IPAddr
|
||||
n = IN6MASK ^ @mask_addr
|
||||
i = 128
|
||||
else
|
||||
raise AddressFamilyError, "unsupported address family"
|
||||
raise AddressFamilyError, 'unsupported address family'
|
||||
end
|
||||
while n>0
|
||||
n >>= 1
|
||||
@ -139,6 +140,7 @@ class IPAddr
|
||||
end
|
||||
i
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
begin
|
||||
@ -206,7 +208,7 @@ begin
|
||||
|
||||
packet.create_ip(ip)
|
||||
|
||||
ipmd5 = Digest::MD5.hexdigest("#{ip.address}").to_i(16) & mask
|
||||
ipmd5 = Digest::MD5.hexdigest(ip.address.to_s).to_i(16) & mask
|
||||
eip = IPAddr.new(ipmd5, Socket::AF_INET)
|
||||
|
||||
ipvm = (eip & mask) | cidr
|
||||
|
@ -14,107 +14,118 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
|
||||
require 'opennebula/host'
|
||||
require 'opennebula/image'
|
||||
require 'opennebula/virtual_machine'
|
||||
|
||||
module OpenNebula::WaitExtEvent
|
||||
def wait_event(ctx, event, timeout)
|
||||
subscriber = ctx.socket(ZMQ::SUB)
|
||||
module OpenNebula
|
||||
|
||||
# Create subscriber
|
||||
key = ''
|
||||
content = ''
|
||||
# Module to wait OpenNebula objects events using ZMQ
|
||||
module WaitExtEvent
|
||||
|
||||
subscriber.setsockopt(ZMQ::RCVTIMEO, timeout * 1000)
|
||||
subscriber.setsockopt(ZMQ::SUBSCRIBE, event)
|
||||
subscriber.connect(@client.one_zmq)
|
||||
def wait_event(ctx, event, timeout)
|
||||
subscriber = ctx.socket(ZMQ::SUB)
|
||||
|
||||
rc = subscriber.recv_string(key)
|
||||
rc = subscriber.recv_string(content) if rc != -1
|
||||
# Create subscriber
|
||||
key = ''
|
||||
content = ''
|
||||
|
||||
return if ZMQ::Util.errno == ZMQ::EAGAIN || rc == -1
|
||||
subscriber.setsockopt(ZMQ::RCVTIMEO, timeout * 1000)
|
||||
subscriber.setsockopt(ZMQ::SUBSCRIBE, event)
|
||||
subscriber.connect(@client.one_zmq)
|
||||
|
||||
content
|
||||
ensure
|
||||
subscriber.setsockopt(ZMQ::UNSUBSCRIBE, event)
|
||||
subscriber.close
|
||||
end
|
||||
rc = subscriber.recv_string(key)
|
||||
rc = subscriber.recv_string(content) if rc != -1
|
||||
|
||||
def wait2(sstr1, sstr2, timeout = 60, cycles = -1)
|
||||
wfun = OpenNebula::WaitExt::WAIT[self.class]
|
||||
return if ZMQ::Util.errno == ZMQ::EAGAIN || rc == -1
|
||||
|
||||
# Start with a timeout of 2 seconds, to wait until the first
|
||||
# info.
|
||||
#
|
||||
# The timeout is increased later, to avoid multiple info calls.
|
||||
c_timeout = 2
|
||||
recvs = 0
|
||||
in_state = false
|
||||
|
||||
# Subscribe with timeout seconds
|
||||
#
|
||||
# Subscribe string:
|
||||
#
|
||||
# EVENT STATE element_name/state_str//self.ID
|
||||
#
|
||||
# - element_name: is the element name to find in the message
|
||||
# - self.ID: returns element ID to find in the message
|
||||
ctx = ZMQ::Context.new(1)
|
||||
|
||||
until in_state || (cycles != -1 && recvs >= cycles)
|
||||
content = wait_event(ctx,
|
||||
wfun[:event].call(self, sstr1, sstr2),
|
||||
c_timeout)
|
||||
|
||||
if content && !content.empty?
|
||||
in_state = wfun[:in_state_e].call(sstr1, sstr2, content)
|
||||
|
||||
break if in_state
|
||||
end
|
||||
|
||||
c_timeout *= 10
|
||||
c_timeout = timeout if c_timeout > timeout
|
||||
|
||||
rco = info
|
||||
|
||||
return false if OpenNebula.is_error?(rco)
|
||||
|
||||
in_state = wfun[:in_state].call(self, sstr1, sstr2)
|
||||
|
||||
recvs += 1
|
||||
content
|
||||
ensure
|
||||
subscriber.setsockopt(ZMQ::UNSUBSCRIBE, event)
|
||||
subscriber.close
|
||||
end
|
||||
|
||||
def wait2(sstr1, sstr2, timeout = 60, cycles = -1)
|
||||
wfun = OpenNebula::WaitExt::WAIT[self.class]
|
||||
|
||||
# Start with a timeout of 2 seconds, to wait until the first
|
||||
# info.
|
||||
#
|
||||
# The timeout is increased later, to avoid multiple info calls.
|
||||
c_timeout = 2
|
||||
recvs = 0
|
||||
in_state = false
|
||||
|
||||
# Subscribe with timeout seconds
|
||||
#
|
||||
# Subscribe string:
|
||||
#
|
||||
# EVENT STATE element_name/state_str//self.ID
|
||||
#
|
||||
# - element_name: is the element name to find in the message
|
||||
# - self.ID: returns element ID to find in the message
|
||||
ctx = ZMQ::Context.new(1)
|
||||
|
||||
until in_state || (cycles != -1 && recvs >= cycles)
|
||||
content = wait_event(ctx,
|
||||
wfun[:event].call(self, sstr1, sstr2),
|
||||
c_timeout)
|
||||
|
||||
if content && !content.empty?
|
||||
in_state = wfun[:in_state_e].call(sstr1, sstr2, content)
|
||||
|
||||
break if in_state
|
||||
end
|
||||
|
||||
c_timeout *= 10
|
||||
c_timeout = timeout if c_timeout > timeout
|
||||
|
||||
rco = info
|
||||
|
||||
return false if OpenNebula.is_error?(rco)
|
||||
|
||||
in_state = wfun[:in_state].call(self, sstr1, sstr2)
|
||||
|
||||
recvs += 1
|
||||
end
|
||||
|
||||
in_state
|
||||
end
|
||||
|
||||
in_state
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
module OpenNebula::WaitExtPolling
|
||||
def wait2(sstr1, sstr2, timeout = 60, cycles = -1)
|
||||
wfun = OpenNebula::WaitExt::WAIT[self.class]
|
||||
module OpenNebula
|
||||
|
||||
stime = 5
|
||||
recvs = 0
|
||||
cycles = timeout / stime
|
||||
in_state = false
|
||||
# Module to wait OpenNebula objects events using polling
|
||||
module WaitExtPolling
|
||||
|
||||
loop do
|
||||
rco = info
|
||||
def wait2(sstr1, sstr2, timeout = 60, cycles = -1)
|
||||
wfun = OpenNebula::WaitExt::WAIT[self.class]
|
||||
|
||||
return false if OpenNebula.is_error?(rco)
|
||||
stime = 5
|
||||
recvs = 0
|
||||
cycles = timeout / stime if cycles == -1
|
||||
in_state = false
|
||||
|
||||
in_state = wfun[:in_state].call(self, sstr1, sstr2)
|
||||
loop do
|
||||
rco = info
|
||||
|
||||
recvs += 1
|
||||
return false if OpenNebula.is_error?(rco)
|
||||
|
||||
break if in_state || recvs >= cycles
|
||||
in_state = wfun[:in_state].call(self, sstr1, sstr2)
|
||||
|
||||
sleep stime
|
||||
recvs += 1
|
||||
|
||||
break if in_state || recvs >= cycles
|
||||
|
||||
sleep stime
|
||||
end
|
||||
|
||||
in_state
|
||||
end
|
||||
|
||||
in_state
|
||||
end
|
||||
|
||||
end
|
||||
@ -124,6 +135,7 @@ end
|
||||
#
|
||||
# rubocop:disable Style/ClassAndModuleChildren
|
||||
module OpenNebula::WaitExt
|
||||
|
||||
# Wait classes and the name published in ZMQ/STATE
|
||||
WAIT = {
|
||||
OpenNebula::Host => {
|
||||
@ -176,7 +188,7 @@ module OpenNebula::WaitExt
|
||||
},
|
||||
|
||||
:in_state => lambda {|o, s1, s2|
|
||||
obj_s1 = Integer(o['STATE'])
|
||||
obj_s1 = Integer(o['STATE'])
|
||||
inx_s1 = OpenNebula::VirtualMachine::VM_STATE.index(s1)
|
||||
|
||||
obj_s2 = Integer(o['LCM_STATE'])
|
||||
@ -203,13 +215,15 @@ module OpenNebula::WaitExt
|
||||
wait?(obj)
|
||||
|
||||
class << obj
|
||||
begin
|
||||
require 'ffi-rzmq'
|
||||
|
||||
include OpenNebula::WaitExtEvent
|
||||
rescue LoadError
|
||||
include OpenNebula::WaitExtPolling
|
||||
end
|
||||
begin
|
||||
require 'ffi-rzmq'
|
||||
|
||||
include OpenNebula::WaitExtEvent
|
||||
rescue LoadError
|
||||
include OpenNebula::WaitExtPolling
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
super
|
||||
|
@ -68,7 +68,6 @@ class PacketProvider
|
||||
0
|
||||
rescue Packet::Error => e
|
||||
# potential VM poweroff(itself) + resume
|
||||
|
||||
if e.message == '{"errors"=>["Address has already been taken"]}'
|
||||
return 0
|
||||
end
|
||||
|
@ -70,7 +70,7 @@ begin
|
||||
begin
|
||||
rc = SSHCommand.run(remote_post, hostname, nil, template64)
|
||||
|
||||
raise StandardError.new rc.stderr unless rc.code == 0
|
||||
raise StandardError, rc.stderr unless rc.code == 0
|
||||
|
||||
drv.run_hooks(ARGV, template64) if drv.activate == 0
|
||||
rescue StandardError => e
|
||||
|
@ -16,8 +16,8 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
$: << File.dirname(__FILE__)
|
||||
$: << File.join(File.dirname(__FILE__), "..")
|
||||
$LOAD_PATH << File.dirname(__FILE__)
|
||||
$LOAD_PATH << File.join(File.dirname(__FILE__), '..')
|
||||
|
||||
require 'vnmmad'
|
||||
|
||||
@ -31,7 +31,7 @@ begin
|
||||
deploy_id,
|
||||
false)
|
||||
filter_driver.deactivate
|
||||
rescue Exception => e
|
||||
rescue StandardError => e
|
||||
OpenNebula.log_error(e.message)
|
||||
OpenNebula.log_error(e.backtrace)
|
||||
exit 1
|
||||
|
@ -16,8 +16,8 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
$: << File.dirname(__FILE__)
|
||||
$: << File.join(File.dirname(__FILE__), "..")
|
||||
$LOAD_PATH << File.dirname(__FILE__)
|
||||
$LOAD_PATH << File.join(File.dirname(__FILE__), '..')
|
||||
|
||||
require 'vnmmad'
|
||||
|
||||
@ -31,7 +31,7 @@ begin
|
||||
deploy_id,
|
||||
false)
|
||||
filter_driver.activate
|
||||
rescue Exception => e
|
||||
rescue StandardError => e
|
||||
OpenNebula.log_error(e.message)
|
||||
OpenNebula.log_error(e.backtrace)
|
||||
exit 1
|
||||
|
@ -16,8 +16,8 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
$: << File.dirname(__FILE__)
|
||||
$: << File.join(File.dirname(__FILE__), "..")
|
||||
$LOAD_PATH << File.dirname(__FILE__)
|
||||
$LOAD_PATH << File.join(File.dirname(__FILE__), '..')
|
||||
|
||||
require 'vnmmad'
|
||||
|
||||
@ -31,7 +31,7 @@ begin
|
||||
deploy_id,
|
||||
false)
|
||||
filter_driver.activate(true)
|
||||
rescue Exception => e
|
||||
rescue StandardError => e
|
||||
OpenNebula.log_error(e.message)
|
||||
OpenNebula.log_error(e.backtrace)
|
||||
exit 1
|
||||
|
@ -34,7 +34,7 @@ begin
|
||||
deploy_id,
|
||||
false)
|
||||
filter_driver.deactivate
|
||||
rescue Exception => e
|
||||
rescue StandardError => e
|
||||
OpenNebula.log_error(e.message)
|
||||
OpenNebula.log_error(e.backtrace)
|
||||
exit 1
|
||||
|
@ -35,7 +35,7 @@ begin
|
||||
drv.deactivate
|
||||
|
||||
filter_driver.activate(true) if drv.activate == 0
|
||||
rescue Exception => e
|
||||
rescue StandardError => e
|
||||
OpenNebula.log_error(e.message)
|
||||
OpenNebula.log_error(e.backtrace)
|
||||
exit 1
|
||||
|
@ -16,8 +16,8 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
$: << File.dirname(__FILE__)
|
||||
$: << File.join(File.dirname(__FILE__), "..")
|
||||
$LOAD_PATH << File.dirname(__FILE__)
|
||||
$LOAD_PATH << File.join(File.dirname(__FILE__), '..')
|
||||
|
||||
require 'vnmmad'
|
||||
|
||||
@ -31,7 +31,7 @@ begin
|
||||
deploy_id,
|
||||
false)
|
||||
filter_driver.activate(true)
|
||||
rescue Exception => e
|
||||
rescue StandardError => e
|
||||
OpenNebula.log_error(e.message)
|
||||
OpenNebula.log_error(e.backtrace)
|
||||
exit 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user