-
Notifications
You must be signed in to change notification settings - Fork 107
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 #106 from aiperon/introduce_s3_manager
Introduce Amazon S3 StorageManager
- Loading branch information
Showing
19 changed files
with
427 additions
and
5 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
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
14 changes: 14 additions & 0 deletions
14
app/models/manageiq/providers/amazon/inventory/targets/storage_manager/s3.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,14 @@ | ||
class ManageIQ::Providers::Amazon::Inventory::Targets::StorageManager::S3 < | ||
ManageIQ::Providers::Amazon::Inventory::Targets | ||
def initialize_inventory_collections | ||
add_inventory_collections(%i(cloud_object_store_containers cloud_object_store_objects)) | ||
end | ||
|
||
def cloud_object_store_containers | ||
HashCollection.new(aws_s3.client.list_buckets.buckets) | ||
end | ||
|
||
def cloud_object_store_objects | ||
HashCollection.new([]) | ||
end | ||
end |
36 changes: 36 additions & 0 deletions
36
app/models/manageiq/providers/amazon/storage_manager/s3.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,36 @@ | ||
class ManageIQ::Providers::Amazon::StorageManager::S3 < ManageIQ::Providers::StorageManager | ||
require_nested :RefreshParser | ||
require_nested :RefreshWorker | ||
require_nested :Refresher | ||
|
||
include ManageIQ::Providers::Amazon::ManagerMixin | ||
include ManageIQ::Providers::StorageManager::ObjectMixin | ||
|
||
delegate :authentication_check, | ||
:authentication_status, | ||
:authentications, | ||
:authentication_for_summary, | ||
:zone, | ||
:connect, | ||
:verify_credentials, | ||
:with_provider_connection, | ||
:address, | ||
:ip_address, | ||
:hostname, | ||
:default_endpoint, | ||
:endpoints, | ||
:to => :parent_manager, | ||
:allow_nil => true | ||
|
||
def self.ems_type | ||
@ems_type ||= "s3".freeze | ||
end | ||
|
||
def self.description | ||
@description ||= "Amazon S3".freeze | ||
end | ||
|
||
def self.hostname_required? | ||
false | ||
end | ||
end |
52 changes: 52 additions & 0 deletions
52
app/models/manageiq/providers/amazon/storage_manager/s3/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,52 @@ | ||
class ManageIQ::Providers::Amazon::StorageManager::S3::RefreshParser | ||
include ManageIQ::Providers::Amazon::RefreshHelperMethods | ||
|
||
def initialize(ems, options = nil) | ||
@ems = ems | ||
@aws_s3 = ems.connect(:service => :S3) | ||
@data = {} | ||
@data_index = {} | ||
@options = options || {} | ||
end | ||
|
||
def ems_inv_to_hashes | ||
log_header = "MIQ(#{self.class.name}.#{__method__}) Collecting data for EMS name: [#{@ems.name}] id: [#{@ems.id}]" | ||
|
||
$aws_log.info("#{log_header}...") | ||
object_store | ||
|
||
$aws_log.info("#{log_header}...Complete") | ||
|
||
@data | ||
end | ||
|
||
def object_store | ||
buckets = @aws_s3.client.list_buckets.buckets | ||
process_collection(buckets, :cloud_object_store_containers) { |c| parse_container(c) } | ||
end | ||
|
||
def parse_container(bucket) | ||
uid = bucket.name | ||
|
||
new_result = { | ||
:ems_ref => uid, | ||
:key => bucket.name | ||
} | ||
return uid, new_result | ||
end | ||
|
||
def parse_object(obj, bucket) | ||
uid = obj.key | ||
|
||
new_result = { | ||
:ems_ref => uid, | ||
:etag => obj.etag, | ||
:last_modified => obj.last_modified, | ||
:content_length => obj.size, | ||
:key => obj.key, | ||
#:content_type => obj.content_type, | ||
:container => bucket | ||
} | ||
return uid, new_result | ||
end | ||
end |
30 changes: 30 additions & 0 deletions
30
app/models/manageiq/providers/amazon/storage_manager/s3/refresh_parser_inventory_object.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,30 @@ | ||
class ManageIQ::Providers::Amazon::StorageManager::S3::RefreshParserInventoryObject < ::ManagerRefresh::RefreshParserInventoryObject | ||
include ManageIQ::Providers::Amazon::RefreshHelperMethods | ||
|
||
def populate_inventory_collections | ||
log_header = "MIQ(#{self.class.name}.#{__method__}) Collecting data for EMS name: [#{inventory.ems.name}] id: [#{inventory.ems.id}]" | ||
|
||
$aws_log.info("#{log_header}...}") | ||
object_store | ||
$aws_log.info("#{log_header}...Complete") | ||
|
||
inventory_collections | ||
end | ||
|
||
private | ||
|
||
def object_store | ||
process_inventory_collection( | ||
inventory.cloud_object_store_containers, | ||
:cloud_object_store_containers | ||
) { |c| parse_container(c) } | ||
end | ||
|
||
def parse_container(bucket) | ||
uid = bucket['name'] | ||
{ | ||
:ems_ref => uid, | ||
:key => bucket['name'] | ||
} | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
app/models/manageiq/providers/amazon/storage_manager/s3/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,11 @@ | ||
class ManageIQ::Providers::Amazon::StorageManager::S3::RefreshWorker < ::MiqEmsRefreshWorker | ||
require_nested :Runner | ||
|
||
def self.ems_class | ||
ManageIQ::Providers::Amazon::StorageManager::S3 | ||
end | ||
|
||
def self.settings_name | ||
:ems_refresh_worker_amazon_s3 | ||
end | ||
end |
3 changes: 3 additions & 0 deletions
3
app/models/manageiq/providers/amazon/storage_manager/s3/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,3 @@ | ||
class ManageIQ::Providers::Amazon::StorageManager::S3::RefreshWorker::Runner < | ||
ManageIQ::Providers::BaseManager::RefreshWorker::Runner | ||
end |
39 changes: 39 additions & 0 deletions
39
app/models/manageiq/providers/amazon/storage_manager/s3/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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
class ManageIQ::Providers::Amazon::StorageManager::S3::Refresher < ManageIQ::Providers::BaseManager::Refresher | ||
include ::EmsRefresh::Refreshers::EmsRefresherMixin | ||
|
||
def collect_inventory_for_targets(ems, targets) | ||
targets_with_data = targets.collect do |target| | ||
target_name = target.try(:name) || target.try(:event_type) | ||
|
||
_log.info "Filtering inventory for #{target.class} [#{target_name}] id: [#{target.id}]..." | ||
|
||
if refresher_options.try(:[], :inventory_object_refresh) | ||
inventory = ManageIQ::Providers::Amazon::Inventory::Factory.inventory(ems, target) | ||
end | ||
|
||
_log.info "Filtering inventory...Complete" | ||
[target, inventory] | ||
end | ||
|
||
targets_with_data | ||
end | ||
|
||
def parse_targeted_inventory(ems, _target, inventory) | ||
log_header = format_ems_for_logging(ems) | ||
_log.debug "#{log_header} Parsing inventory..." | ||
hashes, = Benchmark.realtime_block(:parse_inventory) do | ||
if refresher_options.try(:[], :inventory_object_refresh) | ||
ManageIQ::Providers::Amazon::StorageManager::S3::RefreshParserInventoryObject.new(inventory).populate_inventory_collections | ||
else | ||
ManageIQ::Providers::Amazon::StorageManager::S3::RefreshParser.ems_inv_to_hashes(ems, refresher_options) | ||
end | ||
end | ||
_log.debug "#{log_header} Parsing inventory...Complete" | ||
|
||
hashes | ||
end | ||
|
||
def post_process_refresh_classes | ||
[] | ||
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
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
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.