-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14398 from borod108/rfe/new_provider_refresh
Use the new OvirtSDK for refresh
- Loading branch information
Showing
37 changed files
with
17,171 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
app/models/manageiq/providers/redhat/infra_manager/inventory.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module ManageIQ::Providers::Redhat::InfraManager::Inventory | ||
require_nested :Inventory | ||
end |
15 changes: 15 additions & 0 deletions
15
app/models/manageiq/providers/redhat/infra_manager/inventory/builder.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module ManageIQ::Providers::Redhat::InfraManager::Inventory | ||
class Builder | ||
attr_reader :ext_management_system | ||
|
||
def initialize(ems) | ||
@ext_management_system = ems | ||
end | ||
|
||
def build | ||
strategy_model = ManageIQ::Providers::Redhat::InfraManager::Inventory::Strategies | ||
api_version = ext_management_system.highest_allowed_api_version | ||
"#{strategy_model}::V#{api_version}".constantize | ||
end | ||
end | ||
end |
4 changes: 4 additions & 0 deletions
4
app/models/manageiq/providers/redhat/infra_manager/inventory/inventory.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module ManageIQ::Providers::Redhat::InfraManager::Inventory | ||
class Error < StandardError; end | ||
class VmNotReadyToBoot < Error; end | ||
end |
9 changes: 9 additions & 0 deletions
9
app/models/manageiq/providers/redhat/infra_manager/inventory/strategies/v3.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module ManageIQ::Providers::Redhat::InfraManager::Inventory::Strategies | ||
class V3 | ||
attr_reader :ext_management_system | ||
|
||
def initialize(args) | ||
@ext_management_system = args[:ems] | ||
end | ||
end | ||
end |
184 changes: 184 additions & 0 deletions
184
app/models/manageiq/providers/redhat/infra_manager/inventory/strategies/v4.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
module ManageIQ::Providers::Redhat::InfraManager::Inventory::Strategies | ||
class V4 | ||
attr_accessor :connection | ||
attr_reader :ems | ||
|
||
def initialize(args) | ||
@ems = args[:ems] | ||
end | ||
|
||
def host_targeted_refresh(target) | ||
ems.with_provider_connection(:version => 4) do |connection| | ||
@connection = connection | ||
res = {} | ||
res[:host] = collect_host(get_uuid_from_target(target)) | ||
res | ||
end | ||
end | ||
|
||
def vm_targeted_refresh(target) | ||
ems.with_provider_connection(:version => 4) do |connection| | ||
@connection = connection | ||
vm_id = get_uuid_from_target(target) | ||
res = {} | ||
res[:cluster] = collect_clusters | ||
res[:datacenter] = collect_datacenters | ||
res[:vm] = collect_vm_by_uuid(vm_id) | ||
res[:storage] = target.storages.empty? ? collect_storages : collect_storage(target.storages.map { |s| get_uuid_from_target(s) }) | ||
res[:template] = search_templates("vm.id=#{vm_id}") | ||
res | ||
end | ||
end | ||
|
||
def get_uuid_from_href(ems_ref) | ||
URI(ems_ref).path.split('/').last | ||
end | ||
|
||
def get_uuid_from_target(object) | ||
get_uuid_from_href(object.ems_ref) | ||
end | ||
|
||
def refresh | ||
ems.with_provider_connection(:version => 4) do |connection| | ||
@connection = connection | ||
res = {} | ||
res[:cluster] = collect_clusters | ||
res[:storage] = collect_storages | ||
res[:host] = collect_hosts | ||
res[:vm] = collect_vms | ||
res[:template] = collect_templates | ||
res[:network] = collect_networks | ||
res[:datacenter] = collect_datacenters | ||
res | ||
end | ||
end | ||
|
||
def collect_clusters | ||
connection.system_service.clusters_service.list | ||
end | ||
|
||
def collect_storages | ||
connection.system_service.storage_domains_service.list | ||
end | ||
|
||
def collect_storage(uuids) | ||
uuids.collect do |uuid| | ||
connection.system_service.storage_domains_service.storage_domain_service(uuid).get | ||
end | ||
end | ||
|
||
def collect_hosts | ||
connection.system_service.hosts_service.list.collect do |h| | ||
HostPreloadedAttributesDecorator.new(h, connection) | ||
end | ||
end | ||
|
||
def collect_host(uuid) | ||
host = connection.system_service.hosts_service.host_service(uuid).get | ||
[HostPreloadedAttributesDecorator.new(host, connection)] | ||
end | ||
|
||
def collect_vms | ||
connection.system_service.vms_service.list.collect do |vm| | ||
VmPreloadedAttributesDecorator.new(vm, connection) | ||
end | ||
end | ||
|
||
def collect_vm_by_uuid(uuid) | ||
vm = connection.system_service.vms_service.vm_service(uuid).get | ||
[VmPreloadedAttributesDecorator.new(vm, connection)] | ||
end | ||
|
||
def collect_templates | ||
connection.system_service.templates_service.list.collect do |template| | ||
TemplatePreloadedAttributesDecorator.new(template, connection) | ||
end | ||
end | ||
|
||
def search_templates(search) | ||
connection.system_service.templates_service.list(:search => search).collect do |template| | ||
TemplatePreloadedAttributesDecorator.new(template, connection) | ||
end | ||
end | ||
|
||
def collect_networks | ||
connection.system_service.networks_service.list | ||
end | ||
|
||
def collect_datacenters | ||
connection.system_service.data_centers_service.list.collect do |datacenter| | ||
DatacenterPreloadedAttributesDecorator.new(datacenter, connection) | ||
end | ||
end | ||
|
||
def api | ||
ems.with_provider_connection(:version => 4) do |connection| | ||
connection.system_service.get.product_info.version.full_version | ||
end | ||
end | ||
|
||
def service | ||
ems.with_provider_connection(:version => 4) do |connection| | ||
OpenStruct.new(:version_string => connection.system_service.get.product_info.version.full_version) | ||
end | ||
end | ||
|
||
class HostPreloadedAttributesDecorator < SimpleDelegator | ||
attr_reader :nics, :statistics | ||
def initialize(host, connection) | ||
@obj = host | ||
@nics = connection.follow_link(host.nics) | ||
@statistics = connection.follow_link(host.statistics) | ||
super(host) | ||
end | ||
end | ||
|
||
class DatacenterPreloadedAttributesDecorator < SimpleDelegator | ||
attr_reader :storage_domains | ||
def initialize(datacenter, connection) | ||
@obj = datacenter | ||
@storage_domains = connection.follow_link(datacenter.storage_domains) | ||
super(datacenter) | ||
end | ||
end | ||
|
||
class VmPreloadedAttributesDecorator < SimpleDelegator | ||
attr_reader :disks, :nics, :reported_devices, :snapshots | ||
def initialize(vm, connection) | ||
@obj = vm | ||
@disks = self.class.get_attached_disks(vm, connection) | ||
@nics = connection.follow_link(vm.nics) | ||
@reported_devices = connection.follow_link(vm.reported_devices) | ||
@snapshots = connection.follow_link(vm.snapshots) | ||
super(vm) | ||
end | ||
|
||
def self.get_attached_disks(vm, connection) | ||
AttachedDisksFetcher.get_attached_disks(vm, connection) | ||
end | ||
end | ||
|
||
class AttachedDisksFetcher | ||
def self.get_attached_disks(disks_owner, connection) | ||
attachments = connection.follow_link(disks_owner.disk_attachments) | ||
attachments.map do |attachment| | ||
res = connection.follow_link(attachment.disk) | ||
res.interface = attachment.interface | ||
res.bootable = attachment.bootable | ||
res.active = attachment.active | ||
res | ||
end | ||
end | ||
end | ||
|
||
class TemplatePreloadedAttributesDecorator < SimpleDelegator | ||
attr_reader :disks, :nics | ||
def initialize(template, connection) | ||
@obj = template | ||
@disks = AttachedDisksFetcher.get_attached_disks(template, connection) | ||
@nics = connection.follow_link(template.nics) | ||
super(template) | ||
end | ||
end | ||
end | ||
end |
7 changes: 4 additions & 3 deletions
7
app/models/manageiq/providers/redhat/infra_manager/refresh/parse/parser_builder.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.