Skip to content

Commit

Permalink
Merge pull request #29 from agrare/add_cloud_database_support
Browse files Browse the repository at this point in the history
Collect Oracle and MySQL Cloud Databases

(cherry picked from commit b06d8c5)
  • Loading branch information
Fryguy committed Sep 10, 2021
1 parent fea9057 commit efe8c8c
Show file tree
Hide file tree
Showing 7 changed files with 634 additions and 1,153 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class ManageIQ::Providers::OracleCloud::CloudManager < ManageIQ::Providers::CloudManager
require_nested :AvailabilityZone
require_nested :CloudDatabase
require_nested :CloudVolume
require_nested :EventCatcher
require_nested :EventParser
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ManageIQ::Providers::OracleCloud::CloudManager::CloudDatabase < ::CloudDatabase
end
20 changes: 20 additions & 0 deletions app/models/manageiq/providers/oracle_cloud/inventory/collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ def instances
end
end

def mysql_databases
@mysql_databases ||= compartments.flat_map do |compartment|
mysql_client.list_db_systems(compartment.id).data
end
end

def oracle_databases
@oracle_databases ||= compartments.flat_map do |compartment|
database_client.list_autonomous_databases(compartment.id).data
end
end

def shapes
@shapes ||= compartments.flat_map do |compartment|
compute_client.list_shapes(compartment.id).data
Expand Down Expand Up @@ -116,10 +128,18 @@ def compute_client
@compute_client ||= manager.connect(:service => "Core::ComputeClient")
end

def database_client
@database_client ||= manager.connect(:service => "Database::DatabaseClient")
end

def identity_client
@identity_client ||= manager.connect(:service => "Identity::IdentityClient")
end

def mysql_client
@mysql_client ||= manager.connect(:service => "Mysql::DbSystemClient")
end

def virtual_network_client
@virtual_network_client ||= manager.connect(:service => "Core::VirtualNetworkClient")
end
Expand Down
22 changes: 22 additions & 0 deletions app/models/manageiq/providers/oracle_cloud/inventory/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def parse
availability_domains
boot_volumes
cloud_tenants
databases
flavors
images
instances
Expand Down Expand Up @@ -50,6 +51,27 @@ def cloud_tenants
end
end

def databases
collector.oracle_databases.each do |database|
persister.cloud_databases.build(
:ems_ref => database.id,
:name => database.db_name,
:cloud_tenant => persister.cloud_tenants.lazy_find(database.compartment_id),
:db_engine => "Oracle Database #{database.db_version}",
:used_storage => database.data_storage_size_in_gbs&.gigabytes
)
end

collector.mysql_databases.each do |database|
persister.cloud_databases.build(
:ems_ref => database.id,
:name => database.display_name,
:cloud_tenant => persister.cloud_tenants.lazy_find(database.compartment_id),
:db_engine => "MySQL #{database.mysql_version}"
)
end
end

def flavors
collector.shapes.each do |shape|
persister.flavors.build(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def initialize_inventory_collections
add_cloud_collection(:availability_zones, :secondary_refs => {:by_name => %i(name)})
add_cloud_collection(:cloud_tenants)
add_cloud_collection(:cloud_volumes)
add_cloud_collection(:cloud_databases)
add_cloud_collection(:disks)
add_cloud_collection(:flavors)
add_cloud_collection(:hardwares)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
assert_specific_flavor
assert_specific_instance
assert_specific_image
assert_specific_cloud_database
assert_specific_cloud_network
assert_specific_cloud_subnet
assert_specific_cloud_volume
Expand Down Expand Up @@ -61,12 +62,13 @@ def assert_ems
expect(ems.last_refresh_date).not_to be_nil

expect(ems.availability_zones.count).to eq(3)
expect(ems.cloud_tenants.count).to eq(3)
expect(ems.cloud_databases.count).to eq(1)
expect(ems.cloud_tenants.count).to eq(2)
expect(ems.cloud_subnets.count).to eq(1)
expect(ems.cloud_networks.count).to eq(1)
expect(ems.cloud_volumes.count).to eq(3)
expect(ems.flavors.count).to eq(13)
expect(ems.miq_templates.count).to eq(100)
expect(ems.cloud_volumes.count).to eq(2)
expect(ems.flavors.count).to eq(3)
expect(ems.miq_templates.count).to eq(99)
expect(ems.network_ports.count).to eq(1)
expect(ems.vms.count).to eq(1)
end
Expand Down Expand Up @@ -150,15 +152,15 @@ def assert_specific_instance(expected_raw_power_state: "RUNNING", expected_power
end

def assert_specific_image
template = ems.miq_templates.find_by(:ems_ref => "ocid1.image.oc1.iad.aaaaaaaaqdc7jslbtue7abhwvxaq3ihvazfvihhs2rwk2mvciv36v7ux5sda")
template = ems.miq_templates.find_by(:ems_ref => "ocid1.image.oc1.iad.aaaaaaaab3w3vzjenuyy3idksenczspj77wz74o7unpxid6xr7zmsyi7u47q")
expect(template).to have_attributes(
:vendor => "oracle",
:name => "Oracle-Linux-7.9-2021.01.12-0",
:name => "Oracle-Linux-7.9-2021.07.27-0",
:location => "unknown",
:uid_ems => "ocid1.image.oc1.iad.aaaaaaaaqdc7jslbtue7abhwvxaq3ihvazfvihhs2rwk2mvciv36v7ux5sda",
:uid_ems => "ocid1.image.oc1.iad.aaaaaaaab3w3vzjenuyy3idksenczspj77wz74o7unpxid6xr7zmsyi7u47q",
:power_state => "never",
:type => "ManageIQ::Providers::OracleCloud::CloudManager::Template",
:ems_ref => "ocid1.image.oc1.iad.aaaaaaaaqdc7jslbtue7abhwvxaq3ihvazfvihhs2rwk2mvciv36v7ux5sda",
:ems_ref => "ocid1.image.oc1.iad.aaaaaaaab3w3vzjenuyy3idksenczspj77wz74o7unpxid6xr7zmsyi7u47q",
:raw_power_state => "never"
)

Expand All @@ -173,6 +175,17 @@ def assert_specific_image
)
end

def assert_specific_cloud_database
cloud_database = ems.cloud_databases.find_by(:ems_ref => "ocid1.autonomousdatabase.oc1.iad.anuwcljsw3enqvya6pxc43uemcy2zx7purn64fimk5euwq4kmfwlqasvsmga")
expect(cloud_database).to have_attributes(
:name => "DB202108131402",
:db_engine => "Oracle Database 19c",
:used_storage => 20.gigabytes,
:type => "ManageIQ::Providers::OracleCloud::CloudManager::CloudDatabase",
:cloud_tenant => ems.cloud_tenants.find_by(:ems_ref => root_tenant_id)
)
end

def assert_specific_cloud_network
cloud_network = ems.cloud_networks.first
expect(cloud_network).to have_attributes(
Expand Down
Loading

0 comments on commit efe8c8c

Please sign in to comment.