redfish_tools 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/redfish_tools/cli.rb +27 -2
- data/lib/redfish_tools/cli/record.rb +23 -0
- data/lib/redfish_tools/recorder.rb +98 -0
- data/lib/redfish_tools/servlet.rb +1 -1
- data/lib/redfish_tools/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4f91c3c5220c2e6d5dcc1629bd45530ab56bbcab6b82dec3434c29392c195dd
|
4
|
+
data.tar.gz: 7a2dc097bb6e566ea3b3a26926dc1a3bb12ab1ffade24013d5bc5b4a08970198
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee117d00c3b943b3acfc777563e16651af4e8e03d55fb4e2e647a9e3c22e4d0e254961943dbf9050ac70bf32de7410dce6dc6d0ec837c3159d0560ffcaca2dab
|
7
|
+
data.tar.gz: ab953ed1e9cf94325daeeabeacf4efdbae40992d4b42b7fa1e4ba1515dbe0fd5051e76733a3db1aed95726c476b3dc2c24d1c11d81dafd651fd3629b0b9f3961
|
data/lib/redfish_tools/cli.rb
CHANGED
@@ -34,13 +34,38 @@ module RedfishTools
|
|
34
34
|
def serve(path)
|
35
35
|
user = options[:user]
|
36
36
|
pass = options[:pass]
|
37
|
-
raise
|
38
|
-
raise
|
37
|
+
raise "Missing password" if user && pass.nil?
|
38
|
+
raise "Missing username" if user.nil? && pass
|
39
39
|
|
40
40
|
require "redfish_tools/cli/serve"
|
41
41
|
Serve.new(path, options).run
|
42
42
|
rescue StandardError => e
|
43
43
|
raise Thor::Error, e.to_s
|
44
44
|
end
|
45
|
+
|
46
|
+
desc "record SERVICE PATH", "create recording of SERVICE in PATH"
|
47
|
+
long_desc <<-LONGDESC
|
48
|
+
Record a Redfish service content into set of static files and store them
|
49
|
+
on disk. Sample record call:
|
50
|
+
|
51
|
+
$ . password_file
|
52
|
+
$ redfish record https://my.redfish.api:8443 output folder
|
53
|
+
|
54
|
+
Before running this command, make sure REDFISH_USERNAME and
|
55
|
+
REDFISH_PASSWORD environment variables are set. The recommended way of
|
56
|
+
setting them is by writing the assignments down into shell script that
|
57
|
+
can be then sourced as shown in example.
|
58
|
+
LONGDESC
|
59
|
+
def record(service, path)
|
60
|
+
username = ENV["REDFISH_USERNAME"]
|
61
|
+
password = ENV["REDFISH_PASSWORD"]
|
62
|
+
raise "Missing username" if username.nil?
|
63
|
+
raise "Missing password" if password.nil?
|
64
|
+
|
65
|
+
require "redfish_tools/cli/record"
|
66
|
+
Record.new(service, path, username, password).run
|
67
|
+
rescue StandardError => e
|
68
|
+
raise Thor::Error, e.to_s
|
69
|
+
end
|
45
70
|
end
|
46
71
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "redfish_client"
|
4
|
+
require "redfish_tools/recorder"
|
5
|
+
|
6
|
+
module RedfishTools
|
7
|
+
class Cli
|
8
|
+
class Record
|
9
|
+
def initialize(service, path, username, password)
|
10
|
+
@service = service
|
11
|
+
@path = path
|
12
|
+
@username = username
|
13
|
+
@password = password
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
client = RedfishClient.new(@service, verify: false)
|
18
|
+
client.login(@username, @password)
|
19
|
+
Recorder.new(client, @path).record
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "fileutils"
|
4
|
+
require "json"
|
5
|
+
require "set"
|
6
|
+
|
7
|
+
module RedfishTools
|
8
|
+
# Recorder represents entry point into mock creation process.
|
9
|
+
class Recorder
|
10
|
+
def initialize(client, disk_path)
|
11
|
+
raise "Directory '#{disk_path}' exists" if File.directory?(disk_path)
|
12
|
+
|
13
|
+
@path = disk_path
|
14
|
+
@client = client
|
15
|
+
end
|
16
|
+
|
17
|
+
def record
|
18
|
+
visited = Set.new
|
19
|
+
batch = Set.new([@client["@odata.id"]])
|
20
|
+
|
21
|
+
until batch.empty?
|
22
|
+
visited.merge(batch)
|
23
|
+
batch = process_oid_batch(batch, visited)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def process_oid_batch(batch, visited)
|
30
|
+
next_batch = Set.new
|
31
|
+
batch.each do |oid|
|
32
|
+
puts(" Recording #{oid}")
|
33
|
+
next_batch.merge(process_oid(oid).subtract(visited))
|
34
|
+
end
|
35
|
+
next_batch
|
36
|
+
end
|
37
|
+
|
38
|
+
def process_oid(oid)
|
39
|
+
start = Time.now
|
40
|
+
resource = @client.find(oid)
|
41
|
+
duration = Time.now - start
|
42
|
+
return Set.new unless resource
|
43
|
+
|
44
|
+
persist_to_disk(oid, resource.raw, resource.headers, duration)
|
45
|
+
extract_oids(resource.raw)
|
46
|
+
end
|
47
|
+
|
48
|
+
def persist_to_disk(oid, body, headers, duration)
|
49
|
+
resource_path = File.join(@path, oid)
|
50
|
+
index_path = File.join(resource_path, "index.json")
|
51
|
+
headers_path = File.join(resource_path, "headers.json")
|
52
|
+
time_path = File.join(resource_path, "time.json")
|
53
|
+
|
54
|
+
FileUtils.mkdir_p(resource_path)
|
55
|
+
write_json(index_path, sanitize(body))
|
56
|
+
write_json(headers_path, "GET" => headers)
|
57
|
+
write_json(time_path, "GET_Time" => duration.to_s)
|
58
|
+
end
|
59
|
+
|
60
|
+
def sanitize(data)
|
61
|
+
case data
|
62
|
+
when Hash then sanitize_hash(data)
|
63
|
+
when Array then data.map { |v| sanitize(v) }
|
64
|
+
else data
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def sanitize_hash(data)
|
69
|
+
keys = %w[serialnumber uuid durablename]
|
70
|
+
data.reduce({}) do |acc, (k, v)|
|
71
|
+
v = keys.include?(k.downcase) ? "REMOVED_FROM_MOCK" : sanitize(v)
|
72
|
+
acc.merge!(k => v)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def write_json(path, data)
|
77
|
+
write(path, data.to_json)
|
78
|
+
end
|
79
|
+
|
80
|
+
def write(path, data)
|
81
|
+
File.open(path, "w") { |f| f.write(data) }
|
82
|
+
end
|
83
|
+
|
84
|
+
def extract_oids_from_hash(data)
|
85
|
+
ids = Set.new
|
86
|
+
ids.add(data["@odata.id"]) if data["@odata.id"]
|
87
|
+
data.values.reduce(ids) { |a, v| a.merge(extract_oids(v)) }
|
88
|
+
end
|
89
|
+
|
90
|
+
def extract_oids(data)
|
91
|
+
case data
|
92
|
+
when Hash then extract_oids_from_hash(data)
|
93
|
+
when Array then data.reduce(Set.new) { |a, v| a.merge(extract_oids(v)) }
|
94
|
+
else Set.new
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -39,7 +39,7 @@ module RedfishTools
|
|
39
39
|
|
40
40
|
data = JSON.parse(request.body)
|
41
41
|
item_n = login_path?(request) ? login(item, data) : new_item(item, data)
|
42
|
-
return response.status = 400 unless item_n
|
42
|
+
return response.status = 400 unless item_n&.body
|
43
43
|
|
44
44
|
response.status = 201
|
45
45
|
set_headers(response, item_n.headers)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redfish_tools
|
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-
|
11
|
+
date: 2018-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redfish_client
|
@@ -129,8 +129,10 @@ files:
|
|
129
129
|
- exe/redfish
|
130
130
|
- lib/redfish_tools.rb
|
131
131
|
- lib/redfish_tools/cli.rb
|
132
|
+
- lib/redfish_tools/cli/record.rb
|
132
133
|
- lib/redfish_tools/cli/serve.rb
|
133
134
|
- lib/redfish_tools/datastore.rb
|
135
|
+
- lib/redfish_tools/recorder.rb
|
134
136
|
- lib/redfish_tools/server.rb
|
135
137
|
- lib/redfish_tools/servlet.rb
|
136
138
|
- lib/redfish_tools/version.rb
|