redfish_client 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45295e03b5e8ec0dda4fd0d7401f95516c92d48eba415337d25d3d2ef210a869
4
- data.tar.gz: bfe94afbb669fdd6bb4b407b8ddacfaf17695b49f4bdd2d83645290f97f7b5b6
3
+ metadata.gz: 4b1f7a963b818e8c87405bd16dc08ad715d703a9bc4368a268180f3f75efd9b9
4
+ data.tar.gz: 12972d4bb0c529e2a78bb6142622ef161da444ee7d409fe0677f1fdd28846311
5
5
  SHA512:
6
- metadata.gz: c99e489c2328e9a1fb3ada71d3c62f0a3ce9d75e93bf78206e56490a4153d60a20601bc5d7fee351485ede848a6c640310f7df3b29c3c73c138ac4b466f62b3d
7
- data.tar.gz: 20b278901afbfaa467ec1bd72056f6fbf7420d6ab62f9352193023a46a9e44b7712a37ebb495db1016d6b77a8ca1a7eb729c06ab56c7e8061150e894b64a22f2
6
+ metadata.gz: dbe8c7587ea30dc6483b42e8b17416d2a432b6f1753774b5e2f55373dc195a7b2907ab44c22dcba8db672adb6266fe24dd97b40a9c6c821c7f1587ef83f9bacf
7
+ data.tar.gz: cd9cb0800c58554b877dc41c481a18e612b3d557f795ee4546fd9230e4299ac1c5c5e3eb66ca6ac279f12945679e72d86d2c699a0d7fbbfa6d5401042b69d9ec
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "uri"
5
+
6
+ module RedfishClient
7
+ # EventListener class can be used to stream events from Redfish service. It
8
+ # is a thin wrapper around SSE listener that does the dirty work of
9
+ # splitting each event into its EventRecords and reporting them as separate
10
+ # events.
11
+ class EventListener
12
+ # Create new EventListener instance.
13
+ #
14
+ # @param sse_client [ServerSentEvents::Client] SSE client
15
+ def initialize(sse_client)
16
+ @sse_client = sse_client
17
+ end
18
+
19
+ # Stream events from redfish service.
20
+ #
21
+ # Events that this method yields are actually EventRecords, extracted from
22
+ # the actual Redfish Event.
23
+ def listen
24
+ @sse_client.listen do |event|
25
+ split_event_into_records(event).each { |r| yield(r) }
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def split_event_into_records(event)
32
+ JSON.parse(event.data).fetch("Events", [])
33
+ end
34
+ end
35
+ end
@@ -2,6 +2,8 @@
2
2
 
3
3
  require "base64"
4
4
  require "json"
5
+ require "server_sent_events"
6
+
5
7
  require "redfish_client/resource"
6
8
 
7
9
  module RedfishClient
@@ -62,6 +64,18 @@ module RedfishClient
62
64
  Resource.new(@connector, oid: oid)
63
65
  end
64
66
 
67
+ # Return event listener.
68
+ #
69
+ # If the service does not support SSE, this function will return nil.
70
+ #
71
+ # @return [EventListener, nil] event listener
72
+ def event_listener
73
+ address = dig("EventService", "ServerSentEventUri")
74
+ return nil if address.nil?
75
+
76
+ EventListener.new(ServerSentEvents.create_client(address))
77
+ end
78
+
65
79
  private
66
80
 
67
81
  def session_login_available?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RedfishClient
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.required_ruby_version = "~> 2.1"
31
31
 
32
32
  spec.add_runtime_dependency "excon", "~> 0.60"
33
+ spec.add_runtime_dependency "server_sent_events", "~> 0.1"
33
34
 
34
35
  spec.add_development_dependency "bundler", "~> 1.16"
35
36
  spec.add_development_dependency "rake", ">= 11.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redfish_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tadej Borovšak
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-12 00:00:00.000000000 Z
11
+ date: 2018-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.60'
27
+ - !ruby/object:Gem::Dependency
28
+ name: server_sent_events
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -144,6 +158,7 @@ files:
144
158
  - lib/redfish_client.rb
145
159
  - lib/redfish_client/caching_connector.rb
146
160
  - lib/redfish_client/connector.rb
161
+ - lib/redfish_client/event_listener.rb
147
162
  - lib/redfish_client/resource.rb
148
163
  - lib/redfish_client/root.rb
149
164
  - lib/redfish_client/version.rb