purest 0.1.0 → 1.0.1
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/README.md +414 -104
- data/lib/purest.rb +4 -1
- data/lib/purest/alerts.rb +25 -0
- data/lib/purest/api_methods.rb +125 -0
- data/lib/purest/app.rb +13 -0
- data/lib/purest/cert.rb +23 -0
- data/lib/purest/directory_service.rb +17 -0
- data/lib/purest/dns.rb +17 -0
- data/lib/purest/drive.rb +13 -0
- data/lib/purest/hardware.rb +17 -0
- data/lib/purest/host.rb +18 -65
- data/lib/purest/host_group.rb +21 -62
- data/lib/purest/messages.rb +20 -0
- data/lib/purest/network.rb +25 -0
- data/lib/purest/physical_array.rb +11 -42
- data/lib/purest/port.rb +13 -0
- data/lib/purest/protection_group.rb +26 -0
- data/lib/purest/rest.rb +2 -7
- data/lib/purest/snmp.rb +25 -0
- data/lib/purest/subnet.rb +25 -0
- data/lib/purest/users.rb +34 -0
- data/lib/purest/version.rb +5 -0
- data/lib/purest/volume.rb +12 -81
- metadata +61 -18
- data/lib/purest/custom_exceptions.rb +0 -14
data/lib/purest.rb
CHANGED
@@ -31,7 +31,10 @@ module Purest
|
|
31
31
|
self.root_path = File.expand_path __dir__
|
32
32
|
self.lib_path = File.expand_path 'purest', __dir__
|
33
33
|
|
34
|
-
require_libs
|
34
|
+
require_libs 'rest', 'api_methods', 'configuration', 'alerts', 'app', 'cert',
|
35
|
+
'directory_service', 'dns', 'drive', 'hardware', 'host',
|
36
|
+
'host_group', 'messages', 'network', 'physical_array', 'port',
|
37
|
+
'protection_group', 'snmp', 'subnet', 'users', 'volume'
|
35
38
|
|
36
39
|
self.configuration ||= Purest::Configuration.new
|
37
40
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Purest
|
4
|
+
class Alerts < Purest::APIMethods
|
5
|
+
@access_methods = %i[get create update delete]
|
6
|
+
|
7
|
+
GET_PARAMS = [].freeze
|
8
|
+
|
9
|
+
def get(options = nil)
|
10
|
+
super(options, 'alert', GET_PARAMS)
|
11
|
+
end
|
12
|
+
|
13
|
+
def create(options = nil)
|
14
|
+
super(options, 'alert')
|
15
|
+
end
|
16
|
+
|
17
|
+
def update(options = nil)
|
18
|
+
super(options, 'alert')
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete(options = nil)
|
22
|
+
super(options, 'alert')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Purest
|
4
|
+
class APIMethods < Purest::Rest
|
5
|
+
def append_path(url, options)
|
6
|
+
options.each do |path|
|
7
|
+
new_path = path.to_s.gsub('show_', '')
|
8
|
+
url.map! { |u| u + "/#{new_path}" } if !@options.nil? && @options[path]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def get(options = nil, path = nil, params = nil, appended_paths = nil)
|
13
|
+
@options = options
|
14
|
+
create_session unless authenticated?
|
15
|
+
|
16
|
+
raw_resp = @conn.get do |req|
|
17
|
+
url = ["/api/#{Purest.configuration.api_version}/#{path}"]
|
18
|
+
|
19
|
+
# Name is pretty universal, since most endpoints allow you to query
|
20
|
+
# specific items, e.g. /hosts/host1 or /volume/volume1
|
21
|
+
# where host1 and volume1 are names
|
22
|
+
url.map! { |u| u + "/#{@options[:name]}" } if !@options.nil? && @options[:name]
|
23
|
+
|
24
|
+
# Here we append the various paths, based on available GET endpoints
|
25
|
+
append_path(url, appended_paths) unless appended_paths.nil?
|
26
|
+
|
27
|
+
# Generate methods for url building based on
|
28
|
+
# params passed in, e.g. [:pending, :action] becomes
|
29
|
+
# use_pending and use_action
|
30
|
+
params.each do |param|
|
31
|
+
self.class.send(:define_method, :"use_#{param}") do |options|
|
32
|
+
options ? use_named_parameter(param, options[param]) : []
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Generate array, consisting of url parts, to be built
|
37
|
+
# by concat_url method below
|
38
|
+
params.each do |param|
|
39
|
+
url += send(:"use_#{param}", @options)
|
40
|
+
end
|
41
|
+
|
42
|
+
req.url concat_url url
|
43
|
+
end
|
44
|
+
|
45
|
+
JSON.parse(raw_resp.body, symbolize_names: true)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Create a resource, POST
|
49
|
+
# @param options [Hash] options to pass in
|
50
|
+
# @param path [String] the endpoint to send to
|
51
|
+
# @param appended_path [String] additional paths for some endpoints
|
52
|
+
def create(options = nil, path = nil, appended_path = nil)
|
53
|
+
@options = options
|
54
|
+
create_session unless authenticated?
|
55
|
+
|
56
|
+
raw_resp = @conn.post do |req|
|
57
|
+
# Base URL + path
|
58
|
+
url = ["/api/#{Purest.configuration.api_version}/#{path}"]
|
59
|
+
|
60
|
+
# Base URL + path + name, if supplied
|
61
|
+
url.map! { |u| u + "/#{@options[:name]}" } if @options[:name]
|
62
|
+
|
63
|
+
# Base URL + path + appended_path, if supplied
|
64
|
+
url.map! { |u| u + "/#{appended_path}" } if appended_path
|
65
|
+
|
66
|
+
# Turn whatever options we have into JSON
|
67
|
+
req.body = @options.to_json
|
68
|
+
|
69
|
+
# Set the request URL, and finally make the request
|
70
|
+
req.url concat_url url
|
71
|
+
end
|
72
|
+
|
73
|
+
JSON.parse(raw_resp.body, symbolize_names: true)
|
74
|
+
end
|
75
|
+
|
76
|
+
def update(options = nil, path = nil, appended_path = nil)
|
77
|
+
@options = options
|
78
|
+
create_session unless authenticated?
|
79
|
+
|
80
|
+
raw_resp = @conn.put do |req|
|
81
|
+
# Base URL + path
|
82
|
+
url = "/api/#{Purest.configuration.api_version}/#{path}"
|
83
|
+
|
84
|
+
# Base URL + path + name, if supplied
|
85
|
+
url += "/#{@options[:name]}" if @options[:name]
|
86
|
+
|
87
|
+
# Base URL + appended path
|
88
|
+
url += "/#{appended_path}" if appended_path
|
89
|
+
|
90
|
+
# Since :name and :new_name are used the same throughout almost every class
|
91
|
+
# it seems reasonable to do this here
|
92
|
+
@options[:name] = @options.delete(:new_name) if !@options.nil? && @options[:new_name]
|
93
|
+
|
94
|
+
req.body = @options.to_json
|
95
|
+
|
96
|
+
req.url url
|
97
|
+
end
|
98
|
+
|
99
|
+
JSON.parse(raw_resp.body, symbolize_names: true)
|
100
|
+
end
|
101
|
+
|
102
|
+
def delete(options = nil, path = nil, appended_path = nil)
|
103
|
+
@options = options
|
104
|
+
|
105
|
+
raw_resp = @conn.delete do |req|
|
106
|
+
url = "/api/#{Purest.configuration.api_version}/#{path}"
|
107
|
+
url += "/#{@options[:name]}" if @options[:name]
|
108
|
+
url += "/#{appended_path}" if appended_path
|
109
|
+
|
110
|
+
req.url url
|
111
|
+
end
|
112
|
+
|
113
|
+
# Unfortuantely this can't all be done in a single request, so if you
|
114
|
+
# want to eradicate a subsequent request has to be made :(
|
115
|
+
if @options[:eradicate]
|
116
|
+
raw_resp = @conn.delete do |req|
|
117
|
+
req.url "/api/#{Purest.configuration.api_version}/#{path}/#{@options[:name]}"
|
118
|
+
req.body = @options.to_json
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
JSON.parse(raw_resp.body, symbolize_names: true)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
data/lib/purest/app.rb
ADDED
data/lib/purest/cert.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Purest
|
4
|
+
class Cert < Purest::APIMethods
|
5
|
+
@access_methods = %i[get update]
|
6
|
+
|
7
|
+
GET_PARAMS = %i[certificate common_name country email
|
8
|
+
intermediate_certificate locality organization
|
9
|
+
organizational_unit state].freeze
|
10
|
+
|
11
|
+
def get(options = nil)
|
12
|
+
if !options.nil? && options[:csr]
|
13
|
+
super(options, 'cert/certificate_signing_request', GET_PARAMS)
|
14
|
+
else
|
15
|
+
super(options, 'cert', GET_PARAMS)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def update(options = nil)
|
20
|
+
super(options, 'cert')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Purest
|
4
|
+
class DirectoryService < Purest::APIMethods
|
5
|
+
@access_methods = %i[get update]
|
6
|
+
|
7
|
+
GET_PARAMS = %i[certificate groups].freeze
|
8
|
+
|
9
|
+
def get(options = nil)
|
10
|
+
super(options, 'directoryservice', GET_PARAMS)
|
11
|
+
end
|
12
|
+
|
13
|
+
def update(options = nil)
|
14
|
+
super(options, 'directoryservice')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/purest/dns.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Purest
|
4
|
+
class DNS < Purest::APIMethods
|
5
|
+
@access_methods = %i[get update]
|
6
|
+
|
7
|
+
GET_PARAMS = [].freeze
|
8
|
+
|
9
|
+
def get(options = nil)
|
10
|
+
super(options, 'dns', GET_PARAMS)
|
11
|
+
end
|
12
|
+
|
13
|
+
def update(options = nil)
|
14
|
+
super(options, 'dns')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/purest/drive.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Purest
|
4
|
+
class Hardware < Purest::APIMethods
|
5
|
+
@access_methods = %i[get update]
|
6
|
+
|
7
|
+
GET_PARAMS = [].freeze
|
8
|
+
|
9
|
+
def get(options = nil)
|
10
|
+
super(options, 'hardware', GET_PARAMS)
|
11
|
+
end
|
12
|
+
|
13
|
+
def update(options = nil)
|
14
|
+
super(options, 'hardware')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/purest/host.rb
CHANGED
@@ -1,89 +1,42 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Purest
|
4
|
-
class Host < Purest::
|
4
|
+
class Host < Purest::APIMethods
|
5
5
|
@access_methods = %i[get create update delete]
|
6
6
|
|
7
|
-
GET_PARAMS = [
|
8
|
-
|
7
|
+
GET_PARAMS = %i[action all chap connect names personality
|
8
|
+
private protect shared space].freeze
|
9
9
|
|
10
10
|
# Get a list of hosts, GET
|
11
11
|
# @param options [Hash] options to pass
|
12
12
|
def get(options = nil)
|
13
|
-
|
14
|
-
create_session unless authenticated?
|
15
|
-
|
16
|
-
raw_resp = @conn.get do |req|
|
17
|
-
url = ["/api/#{Purest.configuration.api_version}/host"]
|
18
|
-
url.map!{|u| u + "/#{@options[:name]}"} if !@options.nil? && @options[:name]
|
19
|
-
url.map!{|u| u + "/volume"} if !@options.nil? && @options[:show_volumes]
|
20
|
-
|
21
|
-
# Generate array, consisting of url parts, to be built
|
22
|
-
# by concat_url method below
|
23
|
-
GET_PARAMS.each do |param|
|
24
|
-
url += self.send(:"use_#{param}",@options)
|
25
|
-
end
|
26
|
-
|
27
|
-
# Build url from array of parts, send request
|
28
|
-
req.url concat_url url
|
29
|
-
end
|
30
|
-
|
31
|
-
JSON.parse(raw_resp.body, :symbolize_names => true)
|
13
|
+
super(options, 'host', GET_PARAMS, [:show_volume])
|
32
14
|
end
|
33
15
|
|
34
|
-
# Create a host, POST
|
35
|
-
# @param options [Hash] options to pass
|
36
16
|
def create(options = nil)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
url.map!{|u| u + "/pgroup/#{@options[:protection_group]}"} if @options[:protection_group]
|
45
|
-
url.map!{|u| u + "/volume/#{@options[:volume]}"} if @options[:volume]
|
46
|
-
req.body = @options.to_json
|
47
|
-
|
48
|
-
req.url concat_url url
|
17
|
+
# The API doesn't accept some of these options in the HTTP body
|
18
|
+
# during a POST, so we remove them from the options hash after
|
19
|
+
# creating a path to append to the base URL in APIMethods.create
|
20
|
+
if options[:name] && options[:volume]
|
21
|
+
appended_path = "#{options.delete(:name)}/volume/#{options.delete(:volume)}"
|
22
|
+
elsif options[:name] && options[:protection_group]
|
23
|
+
appended_path = "#{options.delete(:name)}/pgroup/#{options.delete(:protection_group)}"
|
49
24
|
end
|
50
|
-
|
51
|
-
JSON.parse(raw_resp.body, :symbolize_names => true)
|
25
|
+
super(options, 'host', appended_path)
|
52
26
|
end
|
53
27
|
|
54
|
-
# Update a host, PUT
|
55
|
-
# @param options [Hash] options to pass
|
56
28
|
def update(options = nil)
|
57
|
-
|
58
|
-
|
59
|
-
create_session unless authenticated?
|
60
|
-
|
61
|
-
raw_resp = @conn.put do |req|
|
62
|
-
req.url "/api/#{Purest.configuration.api_version}/host/#{@options[:name]}"
|
63
|
-
|
64
|
-
# Repurpose @options[:name] so that it is now set to the new_name
|
65
|
-
# allowing us to rename a volume.
|
66
|
-
@options[:name] = @options.delete(:new_name) if @options[:new_name]
|
67
|
-
req.body = @options.to_json
|
68
|
-
end
|
69
|
-
|
70
|
-
JSON.parse(raw_resp.body, :symbolize_names => true)
|
29
|
+
super(options, 'host')
|
71
30
|
end
|
72
31
|
|
73
32
|
def delete(options = nil)
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
raw_resp = @conn.delete do |req|
|
79
|
-
url = ["/api/#{Purest.configuration.api_version}/host/#{@options[:name]}"]
|
80
|
-
url.map!{|u| u + "/pgroup/#{@options[:protection_group]}"} if @options[:protection_group]
|
81
|
-
url.map!{|u| u + "/volume/#{@options[:volume]}"} if @options[:volume]
|
82
|
-
|
83
|
-
req.url concat_url url
|
33
|
+
if options[:name] && options[:volume]
|
34
|
+
appended_path = "#{options.delete(:name)}/volume/#{options.delete(:volume)}"
|
35
|
+
elsif options[:name] && options[:protection_group]
|
36
|
+
appended_path = "#{options.delete(:name)}/pgroup/#{options.delete(:protection_group)}"
|
84
37
|
end
|
85
38
|
|
86
|
-
|
39
|
+
super(options, 'host', appended_path)
|
87
40
|
end
|
88
41
|
|
89
42
|
private
|
data/lib/purest/host_group.rb
CHANGED
@@ -1,90 +1,49 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
3
|
module Purest
|
4
|
-
class HostGroup < Purest::
|
4
|
+
class HostGroup < Purest::APIMethods
|
5
5
|
@access_methods = %i[get create update delete]
|
6
6
|
|
7
|
-
GET_PARAMS = [
|
8
|
-
|
9
|
-
|
7
|
+
GET_PARAMS = %i[action block_size connect historical length names
|
8
|
+
pending pending_only pgrouplist private protect
|
9
|
+
shared snap space].freeze
|
10
10
|
|
11
11
|
# Get a list of hostgroups, GET
|
12
12
|
# @param options [Hash] options to pass in
|
13
13
|
def get(options = nil)
|
14
|
-
|
15
|
-
create_session unless authenticated?
|
16
|
-
|
17
|
-
raw_resp = @conn.get do |req|
|
18
|
-
url = ["/api/#{Purest.configuration.api_version}/hgroup"]
|
19
|
-
url.map!{|u| u + "/#{@options[:name]}"} if !@options.nil? && @options[:name]
|
20
|
-
url.map!{|u| u + "/volume"} if !@options.nil? && @options[:name] && @options[:show_volumes]
|
21
|
-
|
22
|
-
# Generate array, consisting of url parts, to be built
|
23
|
-
# by concat_url method below
|
24
|
-
GET_PARAMS.each do |param|
|
25
|
-
url += self.send(:"use_#{param}",@options)
|
26
|
-
end
|
27
|
-
|
28
|
-
req.url concat_url url
|
29
|
-
end
|
30
|
-
|
31
|
-
JSON.parse(raw_resp.body, :symbolize_names => true)
|
14
|
+
super(options, 'hgroup', GET_PARAMS, [:show_volume])
|
32
15
|
end
|
33
16
|
|
34
17
|
def create(options = nil)
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
req.body = @options.to_json
|
44
|
-
req.url concat_url url
|
18
|
+
# The API doesn't accept some of these options in the HTTP body
|
19
|
+
# during a POST, so we remove them from the options hash after
|
20
|
+
# creating a path to append to the base URL in APIMethods.create
|
21
|
+
if options[:name] && options[:volume]
|
22
|
+
appended_path = "#{options.delete(:name)}/volume/#{options.delete(:volume)}"
|
23
|
+
elsif options[:name] && options[:protection_group]
|
24
|
+
appended_path = "#{options.delete(:name)}/pgroup/#{options.delete(:protection_group)}"
|
45
25
|
end
|
46
|
-
|
47
|
-
JSON.parse(raw_resp.body, :symbolize_names => true)
|
26
|
+
super(options, 'hgroup', appended_path)
|
48
27
|
end
|
49
28
|
|
50
|
-
# Update a host group, PUT
|
51
|
-
# @param options [Hash] options to pass
|
52
29
|
def update(options = nil)
|
53
|
-
|
54
|
-
|
55
|
-
create_session unless authenticated?
|
56
|
-
|
57
|
-
raw_resp = @conn.put do |req|
|
58
|
-
req.url "/api/#{Purest.configuration.api_version}/hgroup/#{@options[:name]}"
|
59
|
-
|
60
|
-
# Repurpose @options[:name] so that it is now set to the new_name
|
61
|
-
# allowing us to rename a volume.
|
62
|
-
@options[:name] = @options.delete(:new_name) if @options[:new_name]
|
63
|
-
req.body = @options.to_json
|
64
|
-
end
|
65
|
-
|
66
|
-
JSON.parse(raw_resp.body, :symbolize_names => true)
|
30
|
+
super(options, 'hgroup')
|
67
31
|
end
|
68
32
|
|
69
33
|
# Delete a host group, DELETE
|
70
34
|
# @param options[Hash] options to pass
|
71
35
|
def delete(options = nil)
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
raw_resp = @conn.delete do |req|
|
77
|
-
url = ["/api/#{Purest.configuration.api_version}/hgroup/#{@options[:name]}"]
|
78
|
-
url.map!{|u| u + "/pgroup/#{@options[:protection_group]}"} if @options[:protection_group]
|
79
|
-
url.map!{|u| u + "/volume/#{@options[:volume]}"} if @options[:volume]
|
80
|
-
|
81
|
-
req.url concat_url url
|
36
|
+
if options[:name] && options[:volume]
|
37
|
+
appended_path = "#{options.delete(:name)}/volume/#{options.delete(:volume)}"
|
38
|
+
elsif options[:name] && options[:protection_group]
|
39
|
+
appended_path = "#{options.delete(:name)}/pgroup/#{options.delete(:protection_group)}"
|
82
40
|
end
|
83
41
|
|
84
|
-
|
42
|
+
super(options, 'hgroup', appended_path)
|
85
43
|
end
|
86
44
|
|
87
45
|
private
|
46
|
+
|
88
47
|
# Dynamic method generation, e.g. use_all, use_action, etc
|
89
48
|
GET_PARAMS.each do |param|
|
90
49
|
define_method :"use_#{param}" do |options|
|