Skip to content

Commit

Permalink
Merge pull request ManageIQ#15901 from bmclaughlin/enable-cockpit-for…
Browse files Browse the repository at this point in the history
…-cloud-providers

Fix web console for AWS, GCE and enable for RHOS
  • Loading branch information
jrafanie authored Sep 1, 2017
2 parents f09d174 + 47bcea1 commit 24add7e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 23 deletions.
9 changes: 2 additions & 7 deletions app/models/container_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class ContainerNode < ApplicationRecord
include TenantIdentityMixin
include SupportsFeatureMixin
include ArchivedMixin
include CockpitMixin
include_concern 'Purging'

EXTERNAL_LOGGING_PATH = "/#/discover?_g=()&_a=(columns:!(hostname,level,kubernetes.pod_name,message),filters:!((meta:(disabled:!f,index:'%{index}',key:hostname,negate:!f),%{query})),index:'%{index}',interval:auto,query:(query_string:(analyze_wildcard:!t,query:'*')),sort:!(time,desc))".freeze
Expand Down Expand Up @@ -81,13 +82,7 @@ def kubernetes_hostname
def cockpit_url
URI::HTTP.build(:host => kubernetes_hostname, :port => 9090)
address = kubernetes_hostname || name
miq_server = ext_management_system.nil? ? nil : ext_management_system.zone.remote_cockpit_ws_miq_server
if miq_server

end
MiqCockpit::WS.url(miq_server,
MiqCockpitWsWorker.fetch_worker_settings_from_server(miq_server),
address)
MiqCockpit::WS.url(cockpit_server, cockpit_worker, address)
end

def evaluate_alert(_alert_id, _event)
Expand Down
10 changes: 10 additions & 0 deletions app/models/mixins/cockpit_mixin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module CockpitMixin
extend ActiveSupport::Concern
def cockpit_server
ext_management_system.try(:zone).try(:remote_cockpit_ws_miq_server)
end

def cockpit_worker
cockpit_server.nil? ? nil : MiqCockpitWsWorker.fetch_worker_settings_from_server(cockpit_server)
end
end
14 changes: 9 additions & 5 deletions app/models/vm/operations.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module Vm::Operations
extend ActiveSupport::Concern

include CockpitMixin

include_concern 'Guest'
include_concern 'Power'
include_concern 'Lifecycle'
Expand All @@ -15,14 +17,16 @@ module Vm::Operations

def cockpit_url
return if ipaddresses.blank?
miq_server = ext_management_system.nil? ? nil : ext_management_system.zone.remote_cockpit_ws_miq_server
MiqCockpit::WS.url(miq_server,
MiqCockpitWsWorker.fetch_worker_settings_from_server(miq_server),
ipv4_address || ipaddresses.first)
MiqCockpit::WS.url(cockpit_server, cockpit_worker, ipv4_address || ipaddresses.first)
end

def ipv4_address
ipaddresses.find { |ip| IPAddr.new(ip).ipv4? }
return public_address unless public_address.nil?
ipaddresses.find { |ip| IPAddr.new(ip).ipv4? && !ip.starts_with?('192') }
end

def public_address
ipaddresses.find { |ip| !Addrinfo.tcp(ip, 80).ipv4_private? && IPAddr.new(ip).ipv4? }
end

def validate_collect_running_processes
Expand Down
59 changes: 48 additions & 11 deletions spec/models/vm/operations_spec.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,62 @@
describe 'VM::Operations' do
before(:each) do
miq_server = EvmSpecHelper.local_miq_server
@ems = FactoryGirl.create(:ems_vmware, :zone => miq_server.zone)
@vm = FactoryGirl.create(:vm_vmware, :ems_id => @ems.id)
allow(@vm).to receive(:ipaddresses).and_return(@ipaddresses)
@miq_server = EvmSpecHelper.local_miq_server
@ems = FactoryGirl.create(:ems_vmware, :zone => @miq_server.zone)
@vm = FactoryGirl.create(:vm_vmware, :ems_id => @ems.id)
ipaddresses = %w(fe80::21a:4aff:fe22:dde5 127.0.0.1)
allow(@vm).to receive(:ipaddresses).and_return(ipaddresses)

@hardware = FactoryGirl.create(:hardware)
@hardware.ipaddresses << '10.142.0.2'
@hardware.ipaddresses << '35.190.140.48'
end

context '#cockpit_url' do
it '#returns a valid Cockpit url' do
@ipaddresses = %w(fe80::21a:4aff:fe22:dde5 127.0.0.1)
expect(@vm).to receive(:cockpit_url).and_return('http://127.0.0.1:9090')
@vm.send(:cockpit_url)
url = @vm.send(:cockpit_url)
expect(url).to eq(URI::HTTP.build(:host => "127.0.0.1", :port => 9090))
end
end

context '#ipv4_address' do
after(:each) { @vm.send(:return_ipv4_address) }

it 'returns the existing ipv4 address' do
@ipaddresses = %w(fe80::21a:4aff:fe22:dde5 127.0.0.1)
expect(@vm).to receive(:return_ipv4_address).and_return('127.0.0.1')
url = @vm.send(:ipv4_address)
expect(url).to eq('127.0.0.1')
end

context 'cloud providers' do
before(:each) { @ipaddresses = %w(10.10.1.121 35.190.140.48) }
it 'returns the public ipv4 address for AWS' do
ems = FactoryGirl.create(:ems_google, :project => 'manageiq-dev')
az = FactoryGirl.create(:availability_zone_google)
vm = FactoryGirl.create(:vm_google,
:ext_management_system => ems,
:ems_ref => 123,
:availability_zone => az,
:hardware => @hardware)
allow(vm).to receive(:ipaddresses).and_return(@ipaddresses)
url = vm.send(:ipv4_address)
expect(url).to eq('35.190.140.48')
end

it 'returns the public ipv4 address for GCE' do
ems = FactoryGirl.create(:ems_amazon)
vm = FactoryGirl.create(:vm_amazon, :ext_management_system => ems, :hardware => @hardware)
allow(vm).to receive(:ipaddresses).and_return(@ipaddresses)
url = vm.send(:ipv4_address)
expect(url).to eq('35.190.140.48')
end
end
end

context '#public_address' do
it 'returns a public ipv4 address' do
ipaddresses = %w(10.10.1.121 35.190.140.48)
ems = FactoryGirl.create(:ems_amazon)
vm = FactoryGirl.create(:vm_amazon, :ext_management_system => ems, :hardware => @hardware)
allow(vm).to receive(:ipaddresses).and_return(ipaddresses)
url = vm.send(:public_address)
expect(url).to eq('35.190.140.48')
end
end
end

0 comments on commit 24add7e

Please sign in to comment.