redfish_client 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/lib/redfish_client/connector.rb +22 -18
- data/lib/redfish_client/resource.rb +24 -10
- data/lib/redfish_client/root.rb +13 -2
- data/lib/redfish_client/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0d5afda19f44e42b56223398478a6542c3001449eaa268a554adf53be44f169
|
4
|
+
data.tar.gz: 3a37535bab3af7cc4457c9aed9b9718da7b27922b2a70da58938d376576df10d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23cf48798d7952009e20c450f9fcc22aa6116902ef01c6d2446c1c4f35ea2ed2ec4a9db6f817583dec42fb09221ff3764b72577e05fe9327bc92ffc1d4890f37
|
7
|
+
data.tar.gz: 83517b7ef8012c483e4b73afbe456e618e0ebf614d5d741ba42f2bf5fbf7ca0cdde35badb3e56512fc0a786503c84df424d97e2d617160105e58eafbeb534d46
|
data/.rubocop.yml
CHANGED
@@ -25,9 +25,12 @@ module RedfishClient
|
|
25
25
|
# @param verify [Boolean] verify SSL certificate of the service
|
26
26
|
def initialize(url, verify = true)
|
27
27
|
@url = url
|
28
|
-
@verify = verify
|
29
28
|
@headers = DEFAULT_HEADERS.dup
|
30
|
-
|
29
|
+
middlewares = Excon.defaults[:middlewares] +
|
30
|
+
[Excon::Middleware::RedirectFollower]
|
31
|
+
@connection = Excon.new(@url,
|
32
|
+
ssl_verify_peer: verify,
|
33
|
+
middlewares: middlewares)
|
31
34
|
end
|
32
35
|
|
33
36
|
# Add HTTP headers to the requests made by the connector.
|
@@ -35,7 +38,6 @@ module RedfishClient
|
|
35
38
|
# @param headers [Hash<String, String>] headers to be added
|
36
39
|
def add_headers(headers)
|
37
40
|
@headers.merge!(headers)
|
38
|
-
@connection = create_connection
|
39
41
|
end
|
40
42
|
|
41
43
|
# Remove HTTP headers from requests made by the connector.
|
@@ -46,7 +48,6 @@ module RedfishClient
|
|
46
48
|
# @param headers [List<String>] headers to remove
|
47
49
|
def remove_headers(headers)
|
48
50
|
headers.each { |h| @headers.delete(h) }
|
49
|
-
@connection = create_connection
|
50
51
|
end
|
51
52
|
|
52
53
|
# Issue GET request to service.
|
@@ -54,29 +55,25 @@ module RedfishClient
|
|
54
55
|
# @param path [String] path to the resource, relative to the base url
|
55
56
|
# @return [Excon::Response] response object
|
56
57
|
def get(path)
|
57
|
-
@connection.get(path: path)
|
58
|
+
@connection.get(path: path, headers: @headers)
|
58
59
|
end
|
59
60
|
|
60
61
|
# Issue POST requests to the service.
|
61
62
|
#
|
62
63
|
# @param path [String] path to the resource, relative to the base
|
63
|
-
# @param
|
64
|
+
# @param data [Hash] data to be sent over the socket, JSON encoded
|
64
65
|
# @return [Excon::Response] response object
|
65
|
-
def post(path,
|
66
|
-
|
67
|
-
params[:body] = body if body
|
68
|
-
@connection.post(params)
|
66
|
+
def post(path, data = nil)
|
67
|
+
@connection.post(prepare_request_params(path, data))
|
69
68
|
end
|
70
69
|
|
71
70
|
# Issue PATCH requests to the service.
|
72
71
|
#
|
73
72
|
# @param path [String] path to the resource, relative to the base
|
74
|
-
# @param
|
73
|
+
# @param data [Hash] data to be sent over the socket
|
75
74
|
# @return [Excon::Response] response object
|
76
|
-
def patch(path,
|
77
|
-
|
78
|
-
params[:body] = body if body
|
79
|
-
@connection.patch(params)
|
75
|
+
def patch(path, data = nil)
|
76
|
+
@connection.patch(prepare_request_params(path, data))
|
80
77
|
end
|
81
78
|
|
82
79
|
# Issue DELETE requests to the service.
|
@@ -84,13 +81,20 @@ module RedfishClient
|
|
84
81
|
# @param path [String] path to the resource, relative to the base
|
85
82
|
# @return [Excon::Response] response object
|
86
83
|
def delete(path)
|
87
|
-
@connection.delete(path: path)
|
84
|
+
@connection.delete(path: path, headers: @headers)
|
88
85
|
end
|
89
86
|
|
90
87
|
private
|
91
88
|
|
92
|
-
def
|
93
|
-
|
89
|
+
def prepare_request_params(path, data)
|
90
|
+
params = { path: path }
|
91
|
+
if data
|
92
|
+
params[:body] = data.to_json
|
93
|
+
params[:headers] = @headers.merge("Content-Type" => "application/json")
|
94
|
+
else
|
95
|
+
params[:headers] = @headers
|
96
|
+
end
|
97
|
+
params
|
94
98
|
end
|
95
99
|
end
|
96
100
|
end
|
@@ -24,6 +24,13 @@ module RedfishClient
|
|
24
24
|
# resource to accomplish the task a hand.
|
25
25
|
class NoODataId < StandardError; end
|
26
26
|
|
27
|
+
# NoResource error is raised if the service cannot find requested
|
28
|
+
# resource.
|
29
|
+
class NoResource < StandardError; end
|
30
|
+
|
31
|
+
# Headers, returned from the service when resource has been constructed.
|
32
|
+
attr_reader :headers
|
33
|
+
|
27
34
|
# Create new resource.
|
28
35
|
#
|
29
36
|
# Resource can be created either by passing in OpenData identifier or
|
@@ -34,19 +41,17 @@ module RedfishClient
|
|
34
41
|
# @param connector [RedfishClient::Connector] connector that will be used
|
35
42
|
# to fetch the resources
|
36
43
|
# @param oid [String] OpenData id of the resource
|
37
|
-
# @param content [Hash]
|
44
|
+
# @param content [Hash] content to populate resource with
|
45
|
+
# @raise [NoResource] resource cannot be retrieved from the service
|
38
46
|
def initialize(connector, oid: nil, content: nil)
|
47
|
+
@cache = {}
|
48
|
+
@connector = connector
|
49
|
+
|
39
50
|
if oid
|
40
|
-
|
41
|
-
@content = JSON.parse(resp.data[:body])
|
42
|
-
@content["@odata.id"] = oid
|
43
|
-
@headers = resp.data[:headers]
|
51
|
+
initialize_from_service(oid)
|
44
52
|
else
|
45
53
|
@content = content
|
46
54
|
end
|
47
|
-
|
48
|
-
@cache = {}
|
49
|
-
@connector = connector
|
50
55
|
end
|
51
56
|
|
52
57
|
# Access resource content.
|
@@ -136,7 +141,7 @@ module RedfishClient
|
|
136
141
|
# @return [Excon::Response] response
|
137
142
|
# @raise [NoODataId] resource has no OpenData id
|
138
143
|
def post(field: "@odata.id", path: nil, payload: nil)
|
139
|
-
@connector.post(get_path(field, path), payload
|
144
|
+
@connector.post(get_path(field, path), payload)
|
140
145
|
end
|
141
146
|
|
142
147
|
# Issue a PATCH requests to the selected endpoint.
|
@@ -150,7 +155,7 @@ module RedfishClient
|
|
150
155
|
# @return [Excon::Response] response
|
151
156
|
# @raise [NoODataId] resource has no OpenData id
|
152
157
|
def patch(field: "@odata.id", path: nil, payload: nil)
|
153
|
-
@connector.patch(get_path(field, path), payload
|
158
|
+
@connector.patch(get_path(field, path), payload)
|
154
159
|
end
|
155
160
|
|
156
161
|
# Issue a DELETE requests to the endpoint of the resource.
|
@@ -167,6 +172,15 @@ module RedfishClient
|
|
167
172
|
|
168
173
|
private
|
169
174
|
|
175
|
+
def initialize_from_service(oid)
|
176
|
+
resp = @connector.get(oid)
|
177
|
+
raise NoResource unless resp.status == 200
|
178
|
+
|
179
|
+
@content = JSON.parse(resp.data[:body])
|
180
|
+
@content["@odata.id"] = oid
|
181
|
+
@headers = resp.data[:headers]
|
182
|
+
end
|
183
|
+
|
170
184
|
def get_path(field, path)
|
171
185
|
raise NoODataId if path.nil? && !key?(field)
|
172
186
|
path || @content[field]
|
data/lib/redfish_client/root.rb
CHANGED
@@ -46,8 +46,19 @@ module RedfishClient
|
|
46
46
|
# Find Redfish service object by OData ID field.
|
47
47
|
#
|
48
48
|
# @param oid [String] Odata id of the resource
|
49
|
-
# @return [Resource] new resource
|
49
|
+
# @return [Resource, nil] new resource or nil if resource cannot be found
|
50
50
|
def find(oid)
|
51
|
+
find!(oid)
|
52
|
+
rescue NoResource
|
53
|
+
nil
|
54
|
+
end
|
55
|
+
|
56
|
+
# Find Redfish service object by OData ID field.
|
57
|
+
#
|
58
|
+
# @param oid [String] Odata id of the resource
|
59
|
+
# @return [Resource] new resource
|
60
|
+
# @raise [NoResource] resource cannot be fetched
|
61
|
+
def find!(oid)
|
51
62
|
Resource.new(@connector, oid: oid)
|
52
63
|
end
|
53
64
|
|
@@ -60,7 +71,7 @@ module RedfishClient
|
|
60
71
|
def session_login(username, password)
|
61
72
|
r = @connector.post(
|
62
73
|
@content["Links"]["Sessions"]["@odata.id"],
|
63
|
-
|
74
|
+
"UserName" => username, "Password" => password
|
64
75
|
)
|
65
76
|
raise AuthError, "Invalid credentials" unless r.status == 201
|
66
77
|
|
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.2.
|
4
|
+
version: 0.2.2
|
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-05-
|
11
|
+
date: 2018-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|
@@ -168,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
168
|
version: '0'
|
169
169
|
requirements: []
|
170
170
|
rubyforge_project:
|
171
|
-
rubygems_version: 2.7.
|
171
|
+
rubygems_version: 2.7.7
|
172
172
|
signing_key:
|
173
173
|
specification_version: 4
|
174
174
|
summary: Simple Redfish client library
|