diff --git a/src/cli/onevm b/src/cli/onevm index 3cee2b84e6..ff2fbeb1b3 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -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 diff --git a/src/flow/lib/models/service.rb b/src/flow/lib/models/service.rb index 2ade5b0829..6a2c6c7e20 100644 --- a/src/flow/lib/models/service.rb +++ b/src/flow/lib/models/service.rb @@ -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 diff --git a/src/flow/lib/strategy.rb b/src/flow/lib/strategy.rb index 266c84f574..7af826d4b4 100644 --- a/src/flow/lib/strategy.rb +++ b/src/flow/lib/strategy.rb @@ -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 diff --git a/src/flow/lib/strategy/straight.rb b/src/flow/lib/strategy/straight.rb index 5371c15fdd..3d52e935bb 100644 --- a/src/flow/lib/strategy/straight.rb +++ b/src/flow/lib/strategy/straight.rb @@ -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 diff --git a/src/ipamm_mad/remotes/packet/register_address_range b/src/ipamm_mad/remotes/packet/register_address_range index 18416eaa6b..0affde86da 100755 --- a/src/ipamm_mad/remotes/packet/register_address_range +++ b/src/ipamm_mad/remotes/packet/register_address_range @@ -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 diff --git a/src/oca/ruby/opennebula/wait_ext.rb b/src/oca/ruby/opennebula/wait_ext.rb index b9fa6b210c..34d0e6ad0b 100644 --- a/src/oca/ruby/opennebula/wait_ext.rb +++ b/src/oca/ruby/opennebula/wait_ext.rb @@ -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 diff --git a/src/vnm_mad/remotes/elastic/packet_vnm.rb b/src/vnm_mad/remotes/elastic/packet_vnm.rb index d20d083c23..e0032743ce 100644 --- a/src/vnm_mad/remotes/elastic/packet_vnm.rb +++ b/src/vnm_mad/remotes/elastic/packet_vnm.rb @@ -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 diff --git a/src/vnm_mad/remotes/elastic/post b/src/vnm_mad/remotes/elastic/post index 58bf13fdbc..d891410ba2 100755 --- a/src/vnm_mad/remotes/elastic/post +++ b/src/vnm_mad/remotes/elastic/post @@ -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 diff --git a/src/vnm_mad/remotes/elastic/remote_clean b/src/vnm_mad/remotes/elastic/remote_clean index a746ecf3f2..75ff203d32 100755 --- a/src/vnm_mad/remotes/elastic/remote_clean +++ b/src/vnm_mad/remotes/elastic/remote_clean @@ -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 diff --git a/src/vnm_mad/remotes/elastic/remote_post b/src/vnm_mad/remotes/elastic/remote_post index 0e230aa6e8..66917b5dba 100755 --- a/src/vnm_mad/remotes/elastic/remote_post +++ b/src/vnm_mad/remotes/elastic/remote_post @@ -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 diff --git a/src/vnm_mad/remotes/elastic/update_sg b/src/vnm_mad/remotes/elastic/update_sg index 96b77ccc57..3f81f0c93b 100755 --- a/src/vnm_mad/remotes/elastic/update_sg +++ b/src/vnm_mad/remotes/elastic/update_sg @@ -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 diff --git a/src/vnm_mad/remotes/nodeport/clean b/src/vnm_mad/remotes/nodeport/clean index d731b6bbcb..70af7d8988 100755 --- a/src/vnm_mad/remotes/nodeport/clean +++ b/src/vnm_mad/remotes/nodeport/clean @@ -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 diff --git a/src/vnm_mad/remotes/nodeport/post b/src/vnm_mad/remotes/nodeport/post index fb122ffbd8..9ec9060d1c 100755 --- a/src/vnm_mad/remotes/nodeport/post +++ b/src/vnm_mad/remotes/nodeport/post @@ -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 diff --git a/src/vnm_mad/remotes/nodeport/update_sg b/src/vnm_mad/remotes/nodeport/update_sg index bd411872ed..6083f78074 100755 --- a/src/vnm_mad/remotes/nodeport/update_sg +++ b/src/vnm_mad/remotes/nodeport/update_sg @@ -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