forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
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 ManageIQ#5533 from agrare/gce_inventory_refresher
Basic GCE inventory refresher
- Loading branch information
Showing
23 changed files
with
3,128 additions
and
14 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
6 changes: 6 additions & 0 deletions
6
app/models/manageiq/providers/google/cloud_manager/availability_zone.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,6 @@ | ||
class ManageIQ::Providers::Google::CloudManager::AvailabilityZone < ::AvailabilityZone | ||
def provider_object(connection = nil) | ||
connection ||= ext_management_system.connect | ||
connection.availability_zones[ems_ref] | ||
end | ||
end |
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,2 @@ | ||
class ManageIQ::Providers::Google::CloudManager::Flavor < ::Flavor | ||
end |
189 changes: 189 additions & 0 deletions
189
app/models/manageiq/providers/google/cloud_manager/refresh_parser.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,189 @@ | ||
require 'fog/google' | ||
|
||
module ManageIQ::Providers | ||
module Google | ||
class CloudManager::RefreshParser < ManageIQ::Providers::CloudManager::RefreshParser | ||
include Vmdb::Logging | ||
|
||
def self.ems_inv_to_hashes(ems, options = nil) | ||
new(ems, options).ems_inv_to_hashes | ||
end | ||
|
||
def initialize(ems, options = nil) | ||
@ems = ems | ||
@connection = ems.connect | ||
@options = options || {} | ||
@data = {} | ||
@data_index = {} | ||
end | ||
|
||
def ems_inv_to_hashes | ||
log_header = "Collecting data for EMS : [#{@ems.name}] id: [#{@ems.id}]" | ||
|
||
_log.info("#{log_header}...") | ||
get_zones | ||
get_flavors | ||
get_cloud_networks | ||
get_images | ||
get_instances | ||
_log.info("#{log_header}...Complete") | ||
|
||
@data | ||
end | ||
|
||
private | ||
|
||
def get_zones | ||
zones = @connection.zones.all | ||
process_collection(zones, :availability_zones) { |zone| parse_zone(zone) } | ||
end | ||
|
||
def get_flavors | ||
flavors = @connection.flavors.all | ||
process_collection(flavors, :flavors) { |flavor| parse_flavor(flavor) } | ||
end | ||
|
||
def get_cloud_networks | ||
networks = @connection.networks.all | ||
process_collection(networks, :cloud_networks) { |network| parse_cloud_network(network) } | ||
end | ||
|
||
def get_images | ||
images = @connection.images.all | ||
process_collection(images, :vms) { |image| parse_image(image) } | ||
end | ||
|
||
def get_instances | ||
instances = @connection.servers.all | ||
process_collection(instances, :vms) { |instance| parse_instance(instance) } | ||
end | ||
|
||
def process_collection(collection, key) | ||
@data[key] ||= [] | ||
|
||
collection.each do |item| | ||
uid, new_result = yield(item) | ||
next if uid.nil? | ||
|
||
@data[key] |= [new_result] | ||
@data_index.store_path(key, uid, new_result) | ||
end | ||
end | ||
|
||
def parse_zone(zone) | ||
name = uid = zone.name | ||
type = ManageIQ::Providers::Google::CloudManager::AvailabilityZone.name | ||
|
||
new_result = { | ||
:type => type, | ||
:ems_ref => uid, | ||
:name => name, | ||
} | ||
|
||
return uid, new_result | ||
end | ||
|
||
def parse_flavor(flavor) | ||
uid = flavor.name | ||
|
||
type = ManageIQ::Providers::Google::CloudManager::Flavor.name | ||
new_result = { | ||
:type => type, | ||
:ems_ref => flavor.name, | ||
:name => flavor.name, | ||
:description => flavor.description, | ||
:enabled => !flavor.deprecated, | ||
:cpus => flavor.guest_cpus, | ||
:cpu_cores => 1, | ||
:memory => flavor.memory_mb * 1.megabyte, | ||
} | ||
|
||
return uid, new_result | ||
end | ||
|
||
def parse_cloud_network(network) | ||
uid = network.id | ||
|
||
new_result = { | ||
:ems_ref => uid, | ||
:name => network.name, | ||
:cidr => network.ipv4_range, | ||
:status => "active", | ||
:enabled => true, | ||
} | ||
|
||
return uid, new_result | ||
end | ||
|
||
def parse_image(image) | ||
uid = image.id | ||
name = image.name | ||
name ||= uid | ||
type = ManageIQ::Providers::Google::CloudManager::Template.name | ||
|
||
new_result = { | ||
:type => type, | ||
:uid_ems => uid, | ||
:ems_ref => uid, | ||
:name => name, | ||
:vendor => "google", | ||
:raw_power_state => "never", | ||
:operating_system => process_os(image), | ||
:template => true, | ||
:publicly_available => true, | ||
} | ||
|
||
return uid, new_result | ||
end | ||
|
||
def process_os(image) | ||
{ | ||
:product_name => OperatingSystem.normalize_os_name(image.name) | ||
} | ||
end | ||
|
||
def parse_instance(instance) | ||
uid = instance.id | ||
name = instance.name | ||
name ||= uid | ||
|
||
flavor_uid = parse_uid_from_url(instance.machine_type) | ||
flavor = @data_index.fetch_path(:flavors, flavor_uid) | ||
|
||
zone_uid = parse_uid_from_url(instance.zone) | ||
zone = @data_index.fetch_path(:availability_zones, zone_uid) | ||
|
||
type = ManageIQ::Providers::Google::CloudManager::Vm.name | ||
new_result = { | ||
:type => type, | ||
:uid_ems => uid, | ||
:ems_ref => uid, | ||
:name => name, | ||
:description => instance.description, | ||
:vendor => "google", | ||
:raw_power_state => instance.state, | ||
:flavor => flavor, | ||
:availability_zone => zone, | ||
:hardware => { | ||
:cpu_sockets => flavor[:cpus], | ||
:cpu_total_cores => flavor[:cpu_cores], | ||
:cpu_cores_per_socket => 1, | ||
:memory_mb => flavor[:memory] / 1.megabyte, | ||
:disks => [], | ||
:networks => [], | ||
} | ||
} | ||
|
||
return uid, new_result | ||
end | ||
|
||
def parse_uid_from_url(url) | ||
# A lot of attributes in gce are full URLs with the | ||
# uid being the last component. This helper method | ||
# returns the last component of the url | ||
uid = url.split('/')[-1] | ||
uid | ||
end | ||
end | ||
end | ||
end |
3 changes: 3 additions & 0 deletions
3
app/models/manageiq/providers/google/cloud_manager/refresh_worker.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 @@ | ||
class ManageIQ::Providers::Google::CloudManager::RefreshWorker < ManageIQ::Providers::BaseManager::RefreshWorker | ||
require_nested :Runner | ||
end |
2 changes: 2 additions & 0 deletions
2
app/models/manageiq/providers/google/cloud_manager/refresh_worker/runner.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,2 @@ | ||
class ManageIQ::Providers::Google::CloudManager::RefreshWorker::Runner < ManageIQ::Providers::BaseManager::RefreshWorker::Runner | ||
end |
16 changes: 9 additions & 7 deletions
16
app/models/manageiq/providers/google/cloud_manager/refresher.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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
class ManageIQ::Providers::Google::CloudManager::Refresher < ManageIQ::Providers::BaseManager::Refresher | ||
include ::EmsRefresh::Refreshers::EmsRefresherMixin | ||
module ManageIQ::Providers::Google | ||
class CloudManager::Refresher < ManageIQ::Providers::BaseManager::Refresher | ||
include ::EmsRefresh::Refreshers::EmsRefresherMixin | ||
|
||
def parse_inventory(ems, _targets) | ||
::ManageIQ::Providers::Google::CloudManager::RefreshParser.ems_inv_to_hashes(ems, refresher_options) | ||
end | ||
def parse_inventory(ems, _targets) | ||
ManageIQ::Providers::Google::CloudManager::RefreshParser.ems_inv_to_hashes(ems, refresher_options) | ||
end | ||
|
||
def post_process_refresh_classes | ||
[::Vm] | ||
def post_process_refresh_classes | ||
[::Vm] | ||
end | ||
end | ||
end |
6 changes: 6 additions & 0 deletions
6
app/models/manageiq/providers/google/cloud_manager/template.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,6 @@ | ||
class ManageIQ::Providers::Google::CloudManager::Template < ManageIQ::Providers::CloudManager::Template | ||
def provider_object(connection = nil) | ||
connection ||= ext_management_system.connect | ||
connection.images[ems_ref] | ||
end | ||
end |
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,37 @@ | ||
class ManageIQ::Providers::Google::CloudManager::Vm < ManageIQ::Providers::CloudManager::Vm | ||
def provider_object(connection = nil) | ||
connection ||= ext_management_system.connect | ||
connection.instances[ems_ref] | ||
end | ||
|
||
# | ||
# Relationship methods | ||
# | ||
|
||
def disconnect_inv | ||
super | ||
|
||
# Mark all instances no longer found as terminated | ||
power_state == "off" | ||
save | ||
end | ||
|
||
def disconnected | ||
false | ||
end | ||
|
||
def disconnected? | ||
false | ||
end | ||
|
||
def self.calculate_power_state(raw_power_state) | ||
case raw_power_state.downcase | ||
when "running" | ||
"on" | ||
when "terminated" | ||
"off" | ||
else | ||
"unknown" | ||
end | ||
end | ||
end |
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
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
4 changes: 4 additions & 0 deletions
4
...ervice_models/miq_ae_service_manageiq-providers-google-cloud_manager-availability_zone.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 MiqAeMethodService | ||
class MiqAeServiceManageIQ_Providers_Google_CloudManager_AvailabilityZone < MiqAeServiceAvailabilityZone | ||
end | ||
end |
4 changes: 4 additions & 0 deletions
4
...on_engine/service_models/miq_ae_service_manageiq-providers-google-cloud_manager-flavor.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 MiqAeMethodService | ||
class MiqAeServiceManageIQ_Providers_Google_CloudManager_Flavor < MiqAeServiceFlavor | ||
end | ||
end |
4 changes: 4 additions & 0 deletions
4
..._engine/service_models/miq_ae_service_manageiq-providers-google-cloud_manager-template.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 MiqAeMethodService | ||
class MiqAeServiceManageIQ_Providers_Google_CloudManager_Template < MiqAeServiceManageIQ_Providers_CloudManager_Template | ||
end | ||
end |
4 changes: 4 additions & 0 deletions
4
...mation_engine/service_models/miq_ae_service_manageiq-providers-google-cloud_manager-vm.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 MiqAeMethodService | ||
class MiqAeServiceManageIQ_Providers_Google_CloudManager_Vm < MiqAeServiceManageIQ_Providers_CloudManager_Vm | ||
end | ||
end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,5 @@ | ||
FactoryGirl.define do | ||
factory :vm_google, :class => "ManageIQ::Providers::Google::CloudManager::Vm", :parent => :vm_cloud do | ||
vendor "google" | ||
end | ||
end |
Oops, something went wrong.