Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Openstack CinderManager EventCatcher
Browse files Browse the repository at this point in the history
mansam committed Apr 26, 2018
1 parent 06a468c commit 835a4cb
Showing 8 changed files with 109 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -225,12 +225,12 @@ def scoped_get_volume(volume_id, tenant_id)

def scoped_get_snapshot(snapshot_id, tenant_id)
tenant = memoized_get_tenant(tenant_id)
safe_get { @os_handle.detect_volume_service(tenant.try(:name)).snapshots.get(snapshot_id) }
safe_get { @os_handle.detect_volume_service(tenant.try(:name)).get_snapshot_details(snapshot_id).body["snapshot"] }
end

def scoped_get_backup(backup_id, tenant_id)
tenant = memoized_get_tenant(tenant_id)
safe_get { @os_handle.detect_volume_service(tenant.try(:name)).backups.get(backup_id) }
safe_get { @os_handle.detect_volume_service(tenant.try(:name)).get_backup_details(backup_id).body["backup"] }
end

private
Original file line number Diff line number Diff line change
@@ -46,7 +46,8 @@ def initialize_inventory_collections
add_inventory_collections_with_references(
storage,
%i(cloud_volumes cloud_volume_backups cloud_volume_snapshots),
:parent => manager.cinder_manager
:parent => manager.cinder_manager,
:builder_params => {:ext_management_system => manager.cinder_manager}
)

######## Custom processing of Ancestry ##########
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
class ManageIQ::Providers::Openstack::StorageManager::CinderManager < ManageIQ::Providers::StorageManager::CinderManager
require_nested :EventCatcher
require_nested :Refresher
include ManageIQ::Providers::Openstack::ManagerMixin

def self.event_monitor_class
ManageIQ::Providers::Openstack::StorageManager::CinderManager::EventCatcher
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class ManageIQ::Providers::Openstack::StorageManager::CinderManager::EventCatcher < ::MiqEventCatcher
require_nested :Runner

def self.ems_class
ManageIQ::Providers::Openstack::StorageManager::CinderManager
end

def self.settings_name
:event_catcher_openstack_cinder
end

def self.all_valid_ems_in_zone
require 'manageiq/providers/openstack/legacy/openstack_event_monitor'
super.select do |ems|
ems.sync_event_monitor_available?.tap do |available|
_log.info("Event Monitor unavailable for #{ems.name}. Check log history for more details.") unless available
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class ManageIQ::Providers::Openstack::StorageManager::CinderManager::EventCatcher::Runner < ManageIQ::Providers::BaseManager::EventCatcher::Runner
include ManageIQ::Providers::Openstack::EventCatcherMixin

def add_openstack_queue(event)
event_hash = ManageIQ::Providers::Openstack::StorageManager::CinderManager::EventParser.event_to_hash(event, @cfg[:ems_id])
EmsEvent.add_queue('add', @cfg[:ems_id], event_hash)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module ManageIQ::Providers::Openstack::StorageManager::CinderManager::EventParser
def self.event_to_hash(event, ems_id)
content = message_content(event, ems_id)
event_type = content["event_type"]
payload = content["payload"] || {}

log_header = "ems_id: [#{ems_id}] " unless ems_id.nil?
_log.debug("#{log_header}event: [#{event_type}]") if $log && $log.debug?

# attributes that are common to all notifications
event_hash = {
:event_type => event_type,
:source => "OPENSTACK",
:message => payload,
:timestamp => content["timestamp"],
:username => content["_context_user_name"],
:full_data => event,
:ems_id => ems_id
}

event_hash[:vm_ems_ref] = payload["instance_id"] if payload.key? "instance_id"
event_hash[:host_ems_ref] = payload["host"] if payload.key? "host"
event_hash[:availability_zone_ems_ref] = payload["availability_zone"] if payload.key? "availability_zone"
event_hash[:chain_id] = payload["reservation_id"] if payload.key? "reservation_id"
event_hash
end

def self.message_content(event, ems_id)
unless ems_id.nil?
ems = ExtManagementSystem.find_by_id(ems_id)
if ems.connection_configuration_by_role("amqp")
if event[:content].key?("oslo.message")
return JSON.parse(event[:content]["oslo.message"])
end
end
end
event[:content]
end
end
Original file line number Diff line number Diff line change
@@ -21,40 +21,44 @@ def parse
def parse_ems_event_targets(ems_event)
target_collection = ManagerRefresh::TargetCollection.new(:manager => ems_event.ext_management_system.parent_manager, :event => ems_event)

# there's almost always a tenant id regardless of event type
collect_identity_tenant_references!(target_collection, ems_event)

if ems_event.event_type.start_with?("volume.")
collect_volume_references!(target_collection, ems_event)
elsif ems_event.event_type.start_with?("snapshot.")
collect_snapshot_references!(target_collection, ems_event)
elsif ems_event.event_type.start_with?("backup.")
collect_backup_references!(target_collection, ems_event)
end

target_collection.targets
end

def collect_volume_references!(target_collection, ems_event)
resource_id = ems_event.full_data.fetch_path(:content, 'payload', 'volume_id') || ems_event.full_data.fetch_path(:content, 'payload', 'resource_id')
add_target(target_collection, :cloud_volumes, resource_id) if resource_id
tenant_id = ems_event.full_data.fetch_path(:content, 'payload', 'project_id')
resource_id = ems_event.full_data.fetch_path(:content, 'payload', 'resource_id')
add_target(target_collection, :cloud_volumes, resource_id, :tenant_id => tenant_id) if resource_id
end

def collect_snapshot_references!(target_collection, ems_event)
resource_id = ems_event.full_data.fetch_path(:content, 'payload', 'snapshot_id') || ems_event.full_data.fetch_path(:content, 'payload', 'resource_id')
add_target(target_collection, :cloud_volume_snapshots, resource_id) if resource_id
tenant_id = ems_event.full_data.fetch_path(:content, 'payload', 'project_id')
resource_id = ems_event.full_data.fetch_path(:content, 'payload', 'resource_id')
add_target(target_collection, :cloud_volume_snapshots, resource_id, :tenant_id => tenant_id) if resource_id
volume_id = ems_event.full_data.fetch_path(:content, 'payload', 'volume_id')
add_target(target_collection, :cloud_volumes, volume_id) if volume_id
add_target(target_collection, :cloud_volumes, volume_id, :tenant_id => tenant_id) if volume_id
end

def collect_identity_tenant_references!(target_collection, ems_event)
tenant_id = ems_event.full_data.fetch_path(:content, 'payload', 'tenant_id') || ems_event.full_data.fetch_path(:content, 'payload', 'project_id') || ems_event.full_data.fetch_path(:content, 'payload', 'initiator', 'project_id')
add_target(target_collection, :cloud_tenants, tenant_id) if tenant_id
def collect_backup_references!(target_collection, ems_event)
tenant_id = ems_event.full_data.fetch_path(:content, 'payload', 'project_id')
resource_id = ems_event.full_data.fetch_path(:content, 'payload', 'resource_id')
add_target(target_collection, :cloud_volume_backups, resource_id, :tenant_id => tenant_id) if resource_id
volume_id = ems_event.full_data.fetch_path(:content, 'payload', 'volume_id')
add_target(target_collection, :cloud_volumes, volume_id, :tenant_id => tenant_id) if volume_id
end

def parsed_targets(target_collection = {})
target_collection.select { |_target_class, references| references[:manager_ref].present? }
end

def add_target(target_collection, association, ref)
target_collection.add_target(:association => association, :manager_ref => {:ems_ref => ref})
def add_target(target_collection, association, ref, options = {})
target_collection.add_target(:association => association, :manager_ref => {:ems_ref => ref}, :options => options)
end
end
17 changes: 16 additions & 1 deletion config/settings.yml
Original file line number Diff line number Diff line change
@@ -141,7 +141,22 @@
:amqp_recovery_attempts: 4
:amqp_vhost: '/'
:ceilometer:
:event_types_regex: '\A(?!firewall|floatingip|gateway|net|port|router|subnet|security_group|vpn)'
:event_types_regex: '\A(?!firewall|floatingip|gateway|net|port|router|subnet|security_group|vpn|volume|snapshot|backup)'
:event_catcher_openstack_cinder:
:poll: 15.seconds
:topics:
:nova: notifications.*
:cinder: notifications.*
:glance: notifications.*
:heat: notifications.*
:duration: 10.seconds
:capacity: 50
:amqp_port: 5672
:amqp_heartbeat: 30
:amqp_recovery_attempts: 4
:amqp_vhost: '/'
:ceilometer:
:event_types_regex: '\A(volume|snapshot|backup)'
:event_catcher_openstack_infra:
:poll: 15.seconds
:topics:

0 comments on commit 835a4cb

Please sign in to comment.