purest 0.1.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Purest
4
+ class Messages < Purest::APIMethods
5
+ @access_methods = %i[get update]
6
+
7
+ GET_PARAMS = %i[audit flagged login open recent user].freeze
8
+
9
+ def get(options = nil)
10
+ super(options, 'message', GET_PARAMS)
11
+ end
12
+
13
+ def update(options = nil)
14
+ # In this case, 'id' is the identifier of a message,
15
+ # not its name
16
+ appended_path = options.delete(:id) if options[:id]
17
+ super(options, 'message', appended_path)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Purest
4
+ class Network < Purest::APIMethods
5
+ @access_methods = %i[get create update delete]
6
+
7
+ GET_PARAMS = [].freeze
8
+
9
+ def get(options = nil)
10
+ super(options, 'network', GET_PARAMS)
11
+ end
12
+
13
+ def create(options = nil)
14
+ super(options, 'network/vif')
15
+ end
16
+
17
+ def update(options = nil)
18
+ super(options, 'network')
19
+ end
20
+
21
+ def delete(options = nil)
22
+ super(options, 'network')
23
+ end
24
+ end
25
+ end
@@ -1,52 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Purest
4
- class PhysicalArray < Purest::Rest
4
+ class PhysicalArray < Purest::APIMethods
5
5
  @access_methods = %i[get create update delete]
6
6
 
7
- GET_PARAMS = [:action, :banner, :connection_key, :controllers, :historical,
8
- :idle_timeout, :ntpserver, :phonehome, :proxy, :relayhost, :scsi_timeout,
9
- :senderdomain, :space, :syslogserver, :throttle]
7
+ GET_PARAMS = %i[action banner connection_key controllers historical
8
+ idle_timeout ntpserver phonehome proxy relayhost scsi_timeout
9
+ senderdomain space syslogserver throttle].freeze
10
10
 
11
11
  # Get a list of hosts, GET
12
12
  # @param options [Hash] options to pass
13
13
  def get(options = nil)
14
- @options = options
15
- create_session unless authenticated?
16
-
17
- raw_resp = @conn.get do |req|
18
- url = ["/api/#{Purest.configuration.api_version}/array"]
19
-
20
- # Map /connection, /console_lock, /phonehome, /remoteassist
21
- # depending on what was passed in
22
- [:connection, :console_lock, :phonehome, :remoteassist].each do |path|
23
- url.map!{|u| u + "/#{path.to_s}"} if !@options.nil? && @options[path]
24
- end
25
-
26
- # Generate array, consisting of url parts, to be built
27
- # by concat_url method below
28
- GET_PARAMS.each do |param|
29
- url += self.send(:"use_#{param}",@options)
30
- end
31
-
32
- # Build url from array of parts, send request
33
- req.url concat_url url
34
- end
35
-
36
- JSON.parse(raw_resp.body, :symbolize_names => true)
14
+ super(options, 'array', GET_PARAMS, %i[show_connection show_console_lock show_phonehome show_remoteassist])
37
15
  end
38
16
 
39
- # Create a connection between two arrays
40
- # @param options [Hash] options to pass
41
17
  def create(options = nil)
42
- @options = options
43
-
44
- raw_resp = @conn.post do |req|
45
- req.url "/api/#{Purest.configuration.api_version}/array/connection"
46
- req.body = @options.to_json
47
- end
48
-
49
- JSON.parse(raw_resp.body, :symbolize_names => true)
18
+ super(options, 'array/connection')
50
19
  end
51
20
 
52
21
  # Update attributes on an array, PUT
@@ -58,19 +27,19 @@ module Purest
58
27
  url = ["/api/#{Purest.configuration.api_version}/array"]
59
28
 
60
29
  if !@options.nil? && @options[:connected_array]
61
- url.map!{|u| u + "/connection/#{@options[:connected_array]}"}
30
+ url.map! { |u| u + "/connection/#{@options[:connected_array]}" }
62
31
  end
63
32
 
64
33
  # Small conditional to ease remote assistance connecting/disconnecting
65
34
  if !@options.nil? && @options[:remote_assist]
66
- url.map!{|u| u + "/remoteassist"}
35
+ url.map! { |u| u + '/remoteassist' }
67
36
  @options[:action] = @options.delete(:remote_assist)
68
37
  end
69
38
 
70
39
  # Small loop to ease console locking and home phoning
71
- [:console_lock, :phonehome].each do |path|
40
+ %i[console_lock phonehome].each do |path|
72
41
  if !@options.nil? && @options[path]
73
- url.map!{|u| u + "/#{path.to_s}"}
42
+ url.map! { |u| u + "/#{path}" }
74
43
  @options[:enabled] = @options.delete(path)
75
44
  end
76
45
  end
@@ -86,7 +55,7 @@ module Purest
86
55
  req.url concat_url url
87
56
  end
88
57
 
89
- JSON.parse(raw_resp.body, :symbolize_names => true)
58
+ JSON.parse(raw_resp.body, symbolize_names: true)
90
59
  end
91
60
 
92
61
  # Disconnect one array from another
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Purest
4
+ class Port < Purest::APIMethods
5
+ @access_methods = %i[get]
6
+
7
+ GET_PARAMS = [:initiators].freeze
8
+
9
+ def get(options = nil)
10
+ super(options, 'port', GET_PARAMS)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Purest
4
+ class ProtectionGroup < Purest::APIMethods
5
+ @access_methods = %i[get create update delete]
6
+
7
+ GET_PARAMS = %i[names pending pending_only retention schedule
8
+ snap source space target total transfer].freeze
9
+
10
+ def get(options = nil)
11
+ super(options, 'pgroup', GET_PARAMS)
12
+ end
13
+
14
+ def create(options = nil)
15
+ super(options, 'pgroup')
16
+ end
17
+
18
+ def update(options = nil)
19
+ super(options, 'pgroup')
20
+ end
21
+
22
+ def delete(options = nil)
23
+ super(options, 'pgroup')
24
+ end
25
+ end
26
+ end
@@ -2,9 +2,8 @@
2
2
 
3
3
  module Purest
4
4
  # Base class for interacting with PURE storage REST API
5
- class Rest < Purest::CustomExceptions
5
+ class Rest
6
6
  @access_methods = []
7
- @get_params = []
8
7
 
9
8
  # Initialize the fadaray connection, create session unless one exists
10
9
  def initialize
@@ -15,11 +14,7 @@ module Purest
15
14
  # Check if session exists, and whether or not it's expired
16
15
  def authenticated?
17
16
  if defined? @session_expire
18
- if Time.now.utc < @session_expire
19
- true
20
- else
21
- false
22
- end
17
+ Time.now.utc < @session_expire
23
18
  else
24
19
  false
25
20
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Purest
4
+ class SNMP < Purest::APIMethods
5
+ @access_methods = %i[get create update delete]
6
+
7
+ GET_PARAMS = [:engine_id].freeze
8
+
9
+ def get(options = nil)
10
+ super(options, 'snmp', GET_PARAMS)
11
+ end
12
+
13
+ def create(options = nil)
14
+ super(options, 'snmp')
15
+ end
16
+
17
+ def update(options = nil)
18
+ super(options, 'snmp')
19
+ end
20
+
21
+ def delete(options = nil)
22
+ super(options, 'snmp')
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Purest
4
+ class Subnet < Purest::APIMethods
5
+ @access_methods = %i[get create update delete]
6
+
7
+ GET_PARAMS = [].freeze
8
+
9
+ def get(options = nil)
10
+ super(options, 'subnet', GET_PARAMS)
11
+ end
12
+
13
+ def create(options = nil)
14
+ super(options, 'subnet')
15
+ end
16
+
17
+ def update(options = nil)
18
+ super(options, 'subnet')
19
+ end
20
+
21
+ def delete(options = nil)
22
+ super(options, 'subnet')
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Purest
4
+ class Users < Purest::APIMethods
5
+ @access_methods = %i[get create update delete]
6
+
7
+ GET_PARAMS = %i[api_token expose publickey].freeze
8
+
9
+ def get(options = nil)
10
+ if !options.nil? && options[:name] && options[:api_token]
11
+ path = "admin/#{options[:name]}/apitoken"
12
+ options.delete_if { |k| k == :name || k == :api_token }
13
+ else
14
+ path = 'admin'
15
+ end
16
+
17
+ super(options, path, GET_PARAMS)
18
+ end
19
+
20
+ def create(options = nil)
21
+ path = "admin/#{options.delete(:name)}/apitoken"
22
+ super(options, path)
23
+ end
24
+
25
+ def update(options = nil)
26
+ super(options, 'admin')
27
+ end
28
+
29
+ def delete(options = nil)
30
+ path = "admin/#{options.delete(:name)}/apitoken"
31
+ super(options, path)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Purest
4
+ VERSION = '1.0.1'
5
+ end
@@ -1,108 +1,39 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Purest
4
- class Volume < Purest::Rest
4
+ class Volume < Purest::APIMethods
5
5
  @access_methods = %i[get create update delete]
6
6
 
7
- GET_PARAMS = [:action, :block_size, :connect, :historical, :length, :names,
8
- :pending, :pending_only, :pgrouplist, :private, :protect,
9
- :shared, :snap, :space]
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 volumes, GET
12
12
  # @param options [Hash] options to pass
13
13
  def get(options = nil)
14
- @options = options
15
- create_session unless authenticated?
16
-
17
- # Build up a url from parts, allowing for dynamic http calls
18
- # by simply passing in params accepted by Pure's API
19
- raw_resp = @conn.get do |req|
20
- url = ["/api/#{Purest.configuration.api_version}/volume"]
21
-
22
- url.map!{|u| u + "/#{@options[:name]}"} if !@options.nil? && @options[:name]
23
-
24
- # Map /diff, /hgroup, or /host depending on option passed
25
- [:show_diff, :show_hgroup, :show_host].each do |path|
26
- new_path = path.to_s.gsub('show_', '')
27
- url.map!{|u| u + "/#{new_path}"} if !@options.nil? && @options[path]
28
- end
29
-
30
- # Generate array, consisting of url parts, to be built
31
- # by concat_url method below
32
- GET_PARAMS.each do |param|
33
- url += self.send(:"use_#{param}",@options)
34
- end
35
-
36
- # Build url from array of parts, send request
37
- req.url concat_url url
38
- end
39
-
40
- JSON.parse(raw_resp.body, :symbolize_names => true)
14
+ super(options, 'volume', GET_PARAMS, %i[show_diff show_hgroup show_host])
41
15
  end
42
16
 
43
- # Create a volume, POST
44
- # @param options [Hash] options to pass
45
17
  def create(options = nil)
46
- @options = options
47
-
48
- raw_resp = @conn.post do |req|
49
- url = "/api/#{Purest.configuration.api_version}/volume"
50
- url += "/#{@options[:name]}" if @options[:name]
51
- url += "/pgroup/#{@options[:pgroup]}" if @options[:pgroup]
52
- req.body = @options.to_json
53
-
54
- req.url url
18
+ if options[:name] && options[:protection_group]
19
+ appended_path = "#{options.delete(:name)}/pgroup/#{options.delete(:protection_group)}"
55
20
  end
56
21
 
57
- JSON.parse(raw_resp.body, :symbolize_names => true)
22
+ super(options, 'volume', appended_path)
58
23
  end
59
24
 
60
- # Update a volume, PUT
61
- # @param options [Hash] options to pass
62
25
  def update(options = nil)
63
- @options = options
64
-
65
- raw_resp = @conn.put do |req|
66
- # Here we construct the url first, because the options hash
67
- # may have to be manipulated below
68
- req.url "/api/#{Purest.configuration.api_version}/volume/#{@options[:name]}"
69
-
70
- # Repurpose @options[:name] so that it is now set to the new_name
71
- # allowing us to rename a volume.
72
- @options[:name] = @options.delete(:new_name) if @options[:new_name]
73
-
74
- # Remove name from @options which is sent in the body,
75
- # if size is passed in, because those two cannot be sent together.
76
- @options.delete(:name) if @options[:size]
77
-
78
- req.body = @options.to_json
79
- end
80
-
81
- JSON.parse(raw_resp.body, :symbolize_names => true)
26
+ super(options, 'volume')
82
27
  end
83
28
 
84
29
  # Delete a volume, DELETE
85
30
  # @param options [Hash] options to pass
86
31
  def delete(options = nil)
87
- @options = options
88
-
89
- raw_resp = @conn.delete do |req|
90
- url = "/api/#{Purest.configuration.api_version}/volume/#{@options[:name]}"
91
- url += "/pgroup/#{@options[:pgroup]}" if @options[:pgroup]
92
-
93
- req.url url
94
- end
95
-
96
- if @options[:eradicate]
97
- raw_resp = @conn.delete do |req|
98
- url = ["/api/#{Purest.configuration.api_version}/volume/#{@options[:name]}"]
99
- req.body = @options.to_json
100
-
101
- req.url concat_url url
102
- end
32
+ if options[:name] && options[:protection_group]
33
+ appended_path = "#{options.delete(:name)}/pgroup/#{options.delete(:protection_group)}"
103
34
  end
104
35
 
105
- JSON.parse(raw_resp.body, :symbolize_names => true)
36
+ super(options, 'volume', appended_path)
106
37
  end
107
38
 
108
39
  private
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: purest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean McKinley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-29 00:00:00.000000000 Z
11
+ date: 2018-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cucumber
@@ -25,47 +25,75 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: pry
28
+ name: fakes-rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.11.3
33
+ version: '2.1'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.11.3
40
+ version: '2.1'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: fivemat
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 3.7.0
47
+ version: '1.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 3.7.0
54
+ version: '1.3'
55
55
  - !ruby/object:Gem::Dependency
56
- name: fakes-rspec
56
+ name: gem-release
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '2.1'
61
+ version: 2.0.1
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '2.1'
68
+ version: 2.0.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.11.3
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.11.3
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.7.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 3.7.0
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: rubocop
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -109,33 +137,33 @@ dependencies:
109
137
  - !ruby/object:Gem::Version
110
138
  version: 0.15.2
111
139
  - !ruby/object:Gem::Dependency
112
- name: faraday_middleware
140
+ name: faraday-cookie_jar
113
141
  requirement: !ruby/object:Gem::Requirement
114
142
  requirements:
115
143
  - - "~>"
116
144
  - !ruby/object:Gem::Version
117
- version: 0.12.2
145
+ version: 0.0.6
118
146
  type: :runtime
119
147
  prerelease: false
120
148
  version_requirements: !ruby/object:Gem::Requirement
121
149
  requirements:
122
150
  - - "~>"
123
151
  - !ruby/object:Gem::Version
124
- version: 0.12.2
152
+ version: 0.0.6
125
153
  - !ruby/object:Gem::Dependency
126
- name: faraday-cookie_jar
154
+ name: faraday_middleware
127
155
  requirement: !ruby/object:Gem::Requirement
128
156
  requirements:
129
157
  - - "~>"
130
158
  - !ruby/object:Gem::Version
131
- version: 0.0.6
159
+ version: 0.12.2
132
160
  type: :runtime
133
161
  prerelease: false
134
162
  version_requirements: !ruby/object:Gem::Requirement
135
163
  requirements:
136
164
  - - "~>"
137
165
  - !ruby/object:Gem::Version
138
- version: 0.0.6
166
+ version: 0.12.2
139
167
  description:
140
168
  email: sean.mckinley@outlook.com
141
169
  executables: []
@@ -144,12 +172,27 @@ extra_rdoc_files: []
144
172
  files:
145
173
  - README.md
146
174
  - lib/purest.rb
175
+ - lib/purest/alerts.rb
176
+ - lib/purest/api_methods.rb
177
+ - lib/purest/app.rb
178
+ - lib/purest/cert.rb
147
179
  - lib/purest/configuration.rb
148
- - lib/purest/custom_exceptions.rb
180
+ - lib/purest/directory_service.rb
181
+ - lib/purest/dns.rb
182
+ - lib/purest/drive.rb
183
+ - lib/purest/hardware.rb
149
184
  - lib/purest/host.rb
150
185
  - lib/purest/host_group.rb
186
+ - lib/purest/messages.rb
187
+ - lib/purest/network.rb
151
188
  - lib/purest/physical_array.rb
189
+ - lib/purest/port.rb
190
+ - lib/purest/protection_group.rb
152
191
  - lib/purest/rest.rb
192
+ - lib/purest/snmp.rb
193
+ - lib/purest/subnet.rb
194
+ - lib/purest/users.rb
195
+ - lib/purest/version.rb
153
196
  - lib/purest/volume.rb
154
197
  homepage:
155
198
  licenses: