-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Separate collector from inventory and targeted refresh #115
Merged
durandom
merged 5 commits into
ManageIQ:master
from
Ladas:separate_collector_from_inventory
Feb 2, 2017
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,19 @@ | ||
class ManageIQ::Providers::Amazon::Inventory | ||
require_nested :Factory | ||
require_nested :HashCollection | ||
require_nested :Collectors | ||
require_nested :Targets | ||
require_nested :TargetCollection | ||
|
||
attr_reader :ems, :target, :inventory_collections, :options | ||
attr_reader :ems, :target, :collector, :inventory_collections, :options | ||
|
||
def initialize(ems, target) | ||
@ems = ems | ||
@target = target | ||
@options = Settings.ems_refresh[ems.class.ems_type] | ||
@inventory_collections = {:_inventory_collection => true} | ||
|
||
@known_flavors = Set.new | ||
@collector = initialize_collector | ||
|
||
initialize_inventory_collections | ||
end | ||
|
||
def aws_ec2 | ||
@aws_ec2 ||= ems.connect | ||
end | ||
|
||
def aws_cloud_formation | ||
@aws_cloud_formation ||= ems.connect(:service => :CloudFormation) | ||
end | ||
|
||
def aws_elb | ||
@aws_elb ||= ems.connect(:service => :ElasticLoadBalancing) | ||
end | ||
|
||
def aws_s3 | ||
@aws_s3 ||= ems.connect(:service => :S3) | ||
end | ||
|
||
def instances | ||
[] | ||
end | ||
|
||
def flavors | ||
[] | ||
end | ||
|
||
def availability_zones | ||
[] | ||
end | ||
|
||
def key_pairs | ||
[] | ||
end | ||
|
||
def private_images | ||
[] | ||
end | ||
|
||
def shared_images | ||
[] | ||
end | ||
|
||
def public_images | ||
[] | ||
end | ||
|
||
def stacks | ||
[] | ||
end | ||
|
||
def stack_resources(_stack_name) | ||
[] | ||
end | ||
|
||
def stack_template(_stack_name) | ||
[] | ||
end | ||
|
||
def cloud_networks | ||
[] | ||
end | ||
|
||
def cloud_subnets | ||
[] | ||
end | ||
|
||
def security_groups | ||
[] | ||
end | ||
|
||
def network_ports | ||
[] | ||
end | ||
|
||
def load_balancers | ||
[] | ||
end | ||
|
||
def health_check_members(_load_balancer_name) | ||
[] | ||
end | ||
|
||
def floating_ips | ||
[] | ||
end | ||
end |
127 changes: 127 additions & 0 deletions
127
app/models/manageiq/providers/amazon/inventory/collectors.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,127 @@ | ||
class ManageIQ::Providers::Amazon::Inventory::Collectors | ||
attr_reader :ems, :target, :options | ||
|
||
attr_reader :instances, :instances_refs, :instances_deleted | ||
attr_reader :flavors, :flavors_refs, :flavors_deleted | ||
attr_reader :availability_zones, :availability_zones_refs, :availability_zones_deleted | ||
attr_reader :key_pairs, :key_pairs_refs, :key_pairs_deleted | ||
attr_reader :private_images, :private_images_refs, :private_images_deleted | ||
attr_reader :shared_images, :shared_images_refs, :shared_images_deleted | ||
attr_reader :public_images, :public_images_refs, :public_images_deleted | ||
attr_reader :cloud_networks, :cloud_networks_refs, :cloud_networks_deleted | ||
attr_reader :cloud_subnets, :cloud_subnets_refs, :cloud_subnets_deleted | ||
attr_reader :security_groups, :security_groups_refs, :security_groups_deleted | ||
attr_reader :floating_ips, :floating_ips_refs, :floating_ips_deleted | ||
attr_reader :network_ports, :network_ports_refs, :network_ports_deleted | ||
attr_reader :load_balancers, :load_balancers_refs, :load_balancers_deleted | ||
attr_reader :stacks, :stacks_refs, :stacks_deleted | ||
attr_reader :cloud_volumes, :cloud_volumes_refs | ||
attr_reader :cloud_volume_snapshots, :cloud_volume_snapshots_refs | ||
|
||
|
||
def initialize(ems, target) | ||
@ems = ems | ||
@target = target | ||
@options = Settings.ems_refresh[ems.class.ems_type] | ||
|
||
initialize_inventory_sources | ||
end | ||
|
||
def initialize_inventory_sources | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So every collector has all this? Shouldnt it be per Subclass different? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, we need is always defined, so by default all data are [] |
||
@instances = [] | ||
@instances_refs = Set.new | ||
@instances_deleted = [] | ||
@flavors = [] | ||
@flavors_refs = Set.new | ||
@flavors_deleted = [] | ||
@availability_zones = [] | ||
@availability_zones_refs = Set.new | ||
@availability_zones_deleted = [] | ||
@key_pairs = [] | ||
@key_pairs_refs = Set.new | ||
@key_pairs_deleted = [] | ||
@private_images = [] | ||
@private_images_refs = Set.new | ||
@private_images_deleted = [] | ||
@shared_images = [] | ||
@shared_images_refs = Set.new | ||
@shared_images_deleted = [] | ||
@public_images = [] | ||
@public_images_refs = Set.new | ||
@public_images_deleted = [] | ||
@cloud_networks = [] | ||
@cloud_networks_refs = Set.new | ||
@cloud_networks_deleted = [] | ||
@cloud_subnets = [] | ||
@cloud_subnets_refs = Set.new | ||
@cloud_subnets_deleted = [] | ||
@security_groups = [] | ||
@security_groups_refs = Set.new | ||
@security_groups_deleted = [] | ||
@floating_ips = [] | ||
@floating_ips_refs = Set.new | ||
@floating_ips_deleted = [] | ||
@network_ports = [] | ||
@network_ports_refs = Set.new | ||
@network_ports_deleted = [] | ||
@load_balancers = [] | ||
@load_balancers_refs = Set.new | ||
@stacks = [] | ||
@stacks_refs = Set.new | ||
@cloud_volumes = [] | ||
@cloud_volumes_refs = Set.new | ||
@cloud_volume_snapshots = [] | ||
@cloud_volume_snapshots_refs = Set.new | ||
# Nested resources | ||
@stack_resources = {} | ||
@stack_resources_refs = {} | ||
@stack_template = {} | ||
@stack_template_refs = {} | ||
@health_check_members = {} | ||
@health_check_members_refs = {} | ||
end | ||
|
||
def hash_collection | ||
::ManageIQ::Providers::Amazon::Inventory::HashCollection | ||
end | ||
|
||
def aws_ec2 | ||
@aws_ec2 ||= ems.connect | ||
end | ||
|
||
def aws_cloud_formation | ||
@aws_cloud_formation ||= ems.connect(:service => :CloudFormation) | ||
end | ||
|
||
def aws_elb | ||
@aws_elb ||= ems.connect(:service => :ElasticLoadBalancing) | ||
end | ||
|
||
def aws_s3 | ||
@aws_s3 ||= ems.connect(:service => :S3) | ||
end | ||
|
||
def stack_resources(stack_name) | ||
@stack_resources.try(:[], stack_name) || [] | ||
end | ||
|
||
def stack_resources_refs(stack_name) | ||
@stack_resources_refs.try(:[], stack_name) || [] | ||
end | ||
|
||
def stack_template(stack_name) | ||
@stack_template.try(:[], stack_name) || [] | ||
end | ||
|
||
def stack_template_refs(stack_name) | ||
@stack_template_refs.try(:[], stack_name) || [] | ||
end | ||
|
||
def health_check_members(load_balancer_name) | ||
@health_check_members.try(:[], load_balancer_name) || [] | ||
end | ||
|
||
def health_check_members_refs(load_balancer_name) | ||
@health_check_members_refs.try(:[], load_balancer_name) || [] | ||
end | ||
end |
49 changes: 49 additions & 0 deletions
49
app/models/manageiq/providers/amazon/inventory/collectors/cloud_manager.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,49 @@ | ||
class ManageIQ::Providers::Amazon::Inventory::Collectors::CloudManager < ManageIQ::Providers::Amazon::Inventory::Collectors | ||
def instances | ||
hash_collection.new(aws_ec2.instances) | ||
end | ||
|
||
def flavors | ||
ManageIQ::Providers::Amazon::InstanceTypes.all | ||
end | ||
|
||
def availability_zones | ||
hash_collection.new(aws_ec2.client.describe_availability_zones[:availability_zones]) | ||
end | ||
|
||
def key_pairs | ||
hash_collection.new(aws_ec2.client.describe_key_pairs[:key_pairs]) | ||
end | ||
|
||
def private_images | ||
hash_collection.new(aws_ec2.client.describe_images(:owners => [:self], | ||
:filters => [{:name => "image-type", | ||
:values => ["machine"]}])[:images]) | ||
end | ||
|
||
def shared_images | ||
hash_collection.new(aws_ec2.client.describe_images(:executable_users => [:self], | ||
:filters => [{:name => "image-type", | ||
:values => ["machine"]}])[:images]) | ||
end | ||
|
||
def public_images | ||
filters = options.public_images_filters | ||
hash_collection.new(aws_ec2.client.describe_images(:executable_users => [:all], | ||
:filters => filters)[:images]) | ||
end | ||
|
||
def stacks | ||
hash_collection.new(aws_cloud_formation.client.describe_stacks[:stacks]) | ||
end | ||
|
||
def stack_resources(stack_name) | ||
stack_resources = aws_cloud_formation.client.list_stack_resources(:stack_name => stack_name).try(:stack_resource_summaries) | ||
|
||
hash_collection.new(stack_resources || []) | ||
end | ||
|
||
def stack_template(stack_name) | ||
aws_cloud_formation.client.get_template(:stack_name => stack_name).template_body | ||
end | ||
end |
34 changes: 34 additions & 0 deletions
34
app/models/manageiq/providers/amazon/inventory/collectors/network_manager.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,34 @@ | ||
class ManageIQ::Providers::Amazon::Inventory::Collectors::NetworkManager < ManageIQ::Providers::Amazon::Inventory::Collectors | ||
def cloud_networks | ||
hash_collection.new(aws_ec2.client.describe_vpcs[:vpcs]) | ||
end | ||
|
||
def cloud_subnets | ||
hash_collection.new(aws_ec2.client.describe_subnets[:subnets]) | ||
end | ||
|
||
def security_groups | ||
hash_collection.new(aws_ec2.security_groups) | ||
end | ||
|
||
def network_ports | ||
hash_collection.new(aws_ec2.client.describe_network_interfaces.network_interfaces) | ||
end | ||
|
||
def load_balancers | ||
hash_collection.new(aws_elb.client.describe_load_balancers.load_balancer_descriptions) | ||
end | ||
|
||
def health_check_members(load_balancer_name) | ||
hash_collection.new(aws_elb.client.describe_instance_health( | ||
:load_balancer_name => load_balancer_name).instance_states) | ||
end | ||
|
||
def floating_ips | ||
hash_collection.new(aws_ec2.client.describe_addresses.addresses) | ||
end | ||
|
||
def instances | ||
hash_collection.new(aws_ec2.instances) | ||
end | ||
end |
9 changes: 9 additions & 0 deletions
9
app/models/manageiq/providers/amazon/inventory/collectors/storage_manager/ebs.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 @@ | ||
class ManageIQ::Providers::Amazon::Inventory::Collectors::StorageManager::Ebs < ManageIQ::Providers::Amazon::Inventory::Collectors | ||
def cloud_volumes | ||
hash_collection.new(aws_ec2.client.describe_volumes[:volumes]) | ||
end | ||
|
||
def cloud_volume_snapshots | ||
hash_collection.new(aws_ec2.client.describe_snapshots(:owner_ids => [:self])[:snapshots]) | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont like this class being a plural. It should be
Collector
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can do singular, I have there Targets and Collectors