Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds host to physical server relationship #14026

Merged
merged 9 commits into from
Mar 24, 2017
22 changes: 22 additions & 0 deletions app/controllers/api/physical_servers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Api
class PhysicalServersController < BaseController
def show
if params[:c_id]
physical_server = PhysicalServer.find(params[:c_id])
response_payload = physical_server.as_json
response_payload['host_id'] = case physical_server.host
when nil then nil
else physical_server.host.id
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, @chessbyte had a comment a while ago about this case statement.

The case statement could be:

response_payload['host_id'] = physical_server.host.try(:id)


render :json=> response_payload
else
super
end
end

def server_ident(server)
"Server instance: #{server.id} name:'#{server.name}'"
end
end
end
3 changes: 3 additions & 0 deletions app/models/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class Host < ApplicationRecord
has_many :host_aggregate_hosts, :dependent => :destroy
has_many :host_aggregates, :through => :host_aggregate_hosts

# Physical server reference
belongs_to :physical_server, :inverse_of => :host

serialize :settings, Hash

deprecate_attribute :address, :hostname
Expand Down
2 changes: 2 additions & 0 deletions app/models/physical_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class PhysicalServer < ApplicationRecord

belongs_to :ext_management_system, :foreign_key => :ems_id, :class_name => "ManageIQ::Providers::PhysicalInfraManager"

has_one :host, inverse_of => :physical_server

def name_with_details
details % {
:name => name,
Expand Down