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

[WIP] Discover ip address of the physical infra provider #15553

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions app/models/ems_refresh/save_inventory_physical_infra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def save_ems_physical_infra_inventory(ems, hashes, target = nil)

# Save and link other subsections
save_child_inventory(ems, hashes, child_keys, target)
discover_ip_physical_infra(ems)

ems.save!
hashes[:id] = ems.id
Expand Down Expand Up @@ -58,4 +59,35 @@ def save_asset_details_inventory(parent, hash)
return if hash.nil?
save_inventory_single(:asset_details, parent, hash)
end

def ipaddress?(hostname)
IPAddr.new(hostname)
return true
rescue
return false
end

def resolve_hostname(ipaddress, ems)
ems.hostname = "https://#{Resolv.getname(ipaddress)}/"
_log.info("EMS ID: #{ems.id}" + " Resolved hostname successfully.")
Copy link
Member

Choose a reason for hiding this comment

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

Can you put another print showing this method in action?

Copy link
Member Author

@CharlleDaniel CharlleDaniel Jul 25, 2017

Choose a reason for hiding this comment

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

Yes, I can.

hostname

After the refresh:
hostname2

rescue => err
_log.warn("EMS ID: #{ems.id}" + " It's not possible resolve hostname of the physical infra, #{err}.")
end

def resolve_ip_address(hostname, ems)
ems.ipaddress = Resolv.getaddress(hostname)
Copy link
Member

Choose a reason for hiding this comment

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

@agrare you had a PR recently that changed the refresh process to treat the EMS as a first class item in inventory parsing, right?

I think that would work better here than doing more parsing in the save_inventory logic.

Copy link
Member

Choose a reason for hiding this comment

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

@blomquisg yes #15252 added the ability to update the ems in save_ems_inventory
And ManageIQ/manageiq-providers-vmware#62 is an (unmerged 😉 😉) example of its use.

Copy link
Member

Choose a reason for hiding this comment

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

ZING! (merged now)

Copy link
Member

Choose a reason for hiding this comment

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

🤣 thanks!

_log.info("EMS ID: #{ems.id}" + " Resolved ip address successfully.")
rescue => err
_log.warn("EMS ID: #{ems.id}" + " It's not possible resolve ip address of the physical infra, #{err}.")
end

def discover_ip_physical_infra(ems)
hostname = URI.parse(ems.hostname).host || URI.parse(ems.hostname).path
if ems.ipaddress.blank?
resolve_ip_address(hostname, ems)
end
if ipaddress?(hostname)
resolve_hostname(hostname, ems)
end
end
end