Skip to content
This repository has been archived by the owner on Jul 25, 2023. It is now read-only.

Commit

Permalink
Parse host/vm/image guest devices
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Aug 9, 2018
1 parent 06e0e74 commit c79ab6a
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,23 @@ def fileshares
end

def hosts
inventory["hosts"] || []
@hosts ||= begin
inventory["hosts"] ||= []

switches_by_host_name = vnets.group_by { |switch| switch["VMHostName"] }
vm_networks_by_logical_network_id = vmnetworks.group_by { |net| net["LogicalNetwork"]["ID"] }

inventory["hosts"].each do |host|
host["VirtualSwitch"] = switches_by_host_name[host["Name"]] || []
host["VirtualSwitch"].each do |switch|
switch["LogicalNetworks"].to_a.each do |net|
net["VMNetworks"] = vm_networks_by_logical_network_id[net["ID"]] || []
end
end
end

inventory["hosts"]
end
end

def clusters
Expand All @@ -47,6 +63,14 @@ def images
inventory["images"] || []
end

def vnets
inventory["vnets"] || []
end

def vmnetworks
inventory["vmnetworks"] || []
end

private

def connection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,39 @@ def parse_host_hardware(host, data)
:cpu_cores_per_socket => data['CoresPerCPU'],
:serial_number => serial_number,
)

parse_host_guest_devices(hardware, data)
end

def parse_host_guest_devices(hardware, data)
switches = data["VirtualSwitch"]
adapters = switches.collect { |s| s["VMHostNetworkAdapters"] }.flatten

adapters.each do |adapter|
persister.host_guest_devices.build(
:hardware => hardware,
:uid_ems => adapter["ID"],
:device_name => adapter["ConnectionName"],
:device_type => "ethernet",
:model => adapter["Name"],
:location => adapter["BDFLocationInformation"],
:present => true,
:start_connected => true,
:controller_type => "ethernet",
:address => adapter["MacAddress"],
)
end

data["DVDDriveList"].each do |dvd|
persister.host_guest_devices.build(
:hardware => hardware,
:device_type => "cdrom",
:present => true,
:controller_type => "IDE",
:mode => "persistent",
:filename => dvd,
)
end
end

def parse_clusters
Expand Down Expand Up @@ -188,6 +221,7 @@ def parse_vm_hardware(vm, data)
)

parse_vm_disks(hardware, data["VirtualHardDisks"])
parse_vm_guest_devices(hardware, data)
end

def parse_vm_disks(hardware, virtual_hard_disks)
Expand All @@ -208,6 +242,52 @@ def parse_vm_disks(hardware, virtual_hard_disks)
end
end

def parse_vm_guest_devices(hardware, data)
data["VirtualNetworkAdapters"].to_a.each do |vnic|
persister.guest_devices.build(
:hardware => hardware,
:uid_ems => vnic["ID"],
:present => vnic["Enabled"],
:start_connected => vnic["Enabled"],
:address => vnic["MACAddress"],
:device_name => vnic["Name"],
:device_type => "ethernet",
:controller_type => "ethernet",
)
end

data["VirtualDVDDrives"].to_a.each do |dvd|
next if dvd["HostDrive"].blank?

persister.guest_devices.build(
:hardware => hardware,
:uid_ems => dvd["ID"],
:present => true,
:mode => "persistent",
:controller_type => "IDE",
:device_type => "cdrom",
:device_name => dvd["Name"],
:filename => dvd["HostDrive"],
)
end

if data["DVDISO"].present?
data["DVDISO"].each do |iso|
persister.guest_devices.build(
:hardware => hardware,
:uid_ems => iso["ID"],
:size => iso["Size"] / 1.megabyte,
:present => true,
:mode => "persistent",
:device_type => "cdrom",
:device_name => iso["Name"],
:filename => iso["SharePath"],
:controller_type => "IDE",
)
end
end
end

def parse_images
collector.images.each do |data|
template = persister.miq_templates.build(
Expand Down Expand Up @@ -243,5 +323,6 @@ def parse_image_hardware(template, data)
)

parse_vm_disks(hardware, data["VirtualHardDisks"])
parse_vm_guest_devices(hardware, data)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def initialize_inventory_collections
add_infra_collection(:guest_devices)
add_infra_collection(:hardwares)
add_infra_collection(:hosts)
add_infra_collection(:host_guest_devices)
add_infra_collection(:host_hardwares)
add_infra_collection(:miq_templates)
add_infra_collection(:operating_systems)
Expand Down

0 comments on commit c79ab6a

Please sign in to comment.