1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

L #-: Lint ipam/elasitc files (#661)

This commit is contained in:
Jan Orel 2021-01-18 17:32:18 +01:00 committed by GitHub
parent 3ce190b989
commit d346a65b37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 25 additions and 11 deletions

View File

@ -91,16 +91,19 @@ require 'opennebula'
require 'oneprovision'
require 'ipaddr'
# Add ^ and < operators to the IPAddr class
class IPAddr
attr_reader :addr
def ^(other)
return self.clone.set(@addr ^ other.to_i)
clone.set(@addr ^ other.to_i)
end
def <(other)
return @addr < other.addr
@addr < other.addr
end
end
begin
@ -126,7 +129,7 @@ begin
cidr = IPAddr.new(cidr_s)
if ! ['255.255.0.0', '16'].include? mask
if !['255.255.0.0', '16'].include? mask
STDERR.puts 'Elastic CIDR block has to be /16'
exit(-1)
end

View File

@ -97,10 +97,13 @@ require 'ipaddr'
IP_TYPE = %w[public_ipv4 global_ipv4]
# Add ^ operator to the IPAddr class
class IPAddr
def ^(other)
return self.clone.set(@addr ^ other.to_i)
clone.set(@addr ^ other.to_i)
end
end
begin

View File

@ -82,9 +82,11 @@ class ElasticDriver < VNMMAD::VNMDriver
next if attach_nic_id && attach_nic_id != nic[:nic_id]
ip("route del #{nic[:ip]}/32 dev #{nic[:bridge]} | true")
ip("neighbour del proxy #{nic[:gateway]} dev #{nic[:bridge]} | true")
ip("neighbour del proxy #{nic[:gateway]} dev #{nic[:bridge]} " <<
'| true')
next if nic[:conf][:keep_empty_bridge]
ip("link delete #{nic[:bridge]} | true")
end
@ -102,6 +104,7 @@ class ElasticDriver < VNMMAD::VNMDriver
attach_nic_id = @vm['TEMPLATE/NIC[ATTACH="YES"]/NIC_ID']
rc = @vm.each_nic do |nic|
next if attach_nic_id && attach_nic_id != nic[:nic_id]
# pass aws_allocation_id if present
opts = { :alloc_id => nic[:aws_allocation_id] }
@ -111,7 +114,10 @@ class ElasticDriver < VNMMAD::VNMDriver
assigned << [nic[:ip], nic[:external]]
end
assigned.each {|ip, ext| provider.unassign(ip, ext) } unless rc # rollback
# rollback
assigned.each do |ip, ext|
provider.unassign(ip, ext)
end unless rc
!rc
end
@ -125,6 +131,7 @@ class ElasticDriver < VNMMAD::VNMDriver
attach_nic_id = @vm['TEMPLATE/NIC[ATTACH="YES"]/NIC_ID']
@vm.each_nic do |nic|
next if attach_nic_id && attach_nic_id != nic[:nic_id]
provider.unassign(nic[:ip], nic[:external])
end
end
@ -160,5 +167,6 @@ class ElasticDriver < VNMMAD::VNMDriver
commands.add :ip, params
commands.run_remote(@ssh)
end
end
# rubocop:enable Naming/FileName
# rubocop:enable Naming/FileName

View File

@ -91,7 +91,9 @@ class AWSProvider
filter = [{ :name => 'public-ip', :values => [external] }]
aws_ip = @ec2.describe_addresses({ :filters => filter }).addresses[0]
if aws_ip.nil? || aws_ip.network_interface_id.nil? || aws_ip.private_ip_address.nil?
if aws_ip.nil? \
|| aws_ip.network_interface_id.nil? \
|| aws_ip.private_ip_address.nil?
return
end

View File

@ -49,7 +49,7 @@ class PacketProvider
@deploy_id = host['TEMPLATE/PROVISION/DEPLOY_ID']
end
def assign(ip, _external, opts = {})
def assign(ip, _external, _opts = {})
@client.assign_cidr_device("#{ip}/32", @deploy_id)
0
rescue StandardError => e

View File

@ -50,7 +50,6 @@ begin
deploy_id)
drv.create_bridges
rescue StandardError => e
OpenNebula.log_error(e.message)
OpenNebula.log_error(e.backtrace)

View File

@ -141,7 +141,6 @@ module VNMMAD
@nic[:vlan_dev] = "#{@nic[:phydev]}.#{@nic[:vlan_id]}"
end
def list_interface_vlan(_name)
nil
end