stoarray 0.2.0 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a53326d24d57ffb7ff0dfb2d411eba1a8ef69e4a
4
- data.tar.gz: 403071201cf86e546061ca8803cd2c7be16fc357
3
+ metadata.gz: 54621ac991e320be941167c659727b3b74612451
4
+ data.tar.gz: 3fb264dd34728b63ab4bf0878cd49ac7c8df4686
5
5
  SHA512:
6
- metadata.gz: a0b004540bc61a3bd412b1b480c056bcfadf70b84ead88fffe33c6d0e7b7eb3628ae9d0c8332c33a6045c8cbfc7b426685eb997ae22c9d583b846dc81893a0ca
7
- data.tar.gz: f073c3e361096a7a1752ccf4b3c32b2428d8553339a6d3dfd8b03c892242a9fe84d860f3e1d3755d487d9f5d3fa0d01cf777ecccd24355c1fc64924a5cc35d72
6
+ metadata.gz: da928a8f35f7b7a0bb2b98429cf197ccc23f4f4fea05c7a3190b9feda5be45e3549551b12e0f2ea6de50db64a39872c92b32d20f2d7459ae14e6650d57edd04f
7
+ data.tar.gz: 74ad7745fb5cc5d4da4af6bec87a94f8e2227376fbbf689f25fe9f85e3ee03924da807d246c6dab026a59b3a0c29b33b17e7446537daea32384fe35eca7ab31d
data/CHANGELOG.md ADDED
@@ -0,0 +1,40 @@
1
+ # CHANGELOG for stoarray
2
+
3
+ This file is used to list changes made to the stoarray gem.
4
+
5
+ ## 03172016
6
+
7
+ * All code should have test coverage now!
8
+ * Conversion to rest-client complete. Removed getty, del33t, verbal_gerbil.
9
+ * make_call - (previously cally) Added rescue so I can return error messages.
10
+ * cookie - Removed "testy" stuff & added break on failure (raise).
11
+ * Consistent success messages for both Pure and Xtremio clone refreshes.
12
+
13
+ ## 03152016
14
+
15
+ * Add Mark Gibbon's line to generate an error if a valid cookie is not received.
16
+ * All code should be covered now except the cookie block!
17
+
18
+ ## 03142016
19
+
20
+ * Additional tests using mockable.io: Refresh and flippy covered now.
21
+ * New delete method using rest-client. Needs work! (handling params).
22
+
23
+ ## 03112016
24
+
25
+ * Using mockable.io for API call testing, updating rspec tests.
26
+
27
+ ## 03102016
28
+
29
+ * Added new array method for gathering stats from the arrays.
30
+
31
+ ## 03092016
32
+
33
+ * Break call setup out of initialize and into new methods.
34
+ * Update dependent methods to use new call methods.
35
+ * Add rest-client gem to resolve issue with GETs on Xtremio.
36
+
37
+ - - -
38
+ Check the [Markdown Syntax Guide](http://daringfireball.net/projects/markdown/syntax) for help with Markdown.
39
+
40
+ The [Github Flavored Markdown page](http://github.github.com/github-flavored-markdown/) describes the differences between markdown on github and standard markdown.
data/README.md CHANGED
@@ -35,8 +35,8 @@ It is very easy to then build from there.
35
35
  ###First the json configuration file:
36
36
 
37
37
  {
38
- "authorization":"123li123o90yourapitoken2h1hi3",
39
- "base_url":"https:///purearray01.something.net/api/1.4/",
38
+ "authorization": "123li123o90yourapitoken2h1hi3",
39
+ "base_url": "https://purearray01.something.net/api/1.4/",
40
40
  "headers": { "Content-Type": "application/json" },
41
41
  "params_snap_u23": {
42
42
  "snap_pairs": {
data/lib/arraycalls.rb CHANGED
@@ -1,37 +1,48 @@
1
1
  class Stoarray
2
2
 
3
3
  VERBS = {
4
- 'get' => Net::HTTP::Get,
5
- 'post' => Net::HTTP::Post,
6
- 'put' => Net::HTTP::Put,
7
- 'delete' => Net::HTTP::Delete
4
+ 'delete' => :Delete,
5
+ 'get' => :Get,
6
+ 'post' => :Post,
7
+ 'put' => :Put
8
8
  }
9
9
 
10
10
  def initialize(headers: {}, meth: 'Get', params: {}, url: 'https://array/')
11
- @url = URI.parse(url) # URL of the call
12
11
  @headers = headers
13
- @call = VERBS[meth.downcase].new(@url.path, initheader = @headers)
14
- @call.body = params.to_json # Pure and Xtremio expect json parameters
15
- @request = Net::HTTP.new(@url.host, @url.port)
16
- @request.read_timeout = 30
17
- @request.use_ssl = true if @url.to_s =~ /https/
18
- @request.verify_mode = OpenSSL::SSL::VERIFY_NONE # parameterize?
12
+ @meth = meth
13
+ @params = params
14
+ @url = url
19
15
  end
20
16
 
21
- def cookie(testy: false)
22
- if @url.to_s =~ /auth\/session/
23
- case testy
24
- when false
25
- @response = @request.start { |http| http.request(@call) }
26
- all_cookies = @response.get_fields('set-cookie')
27
- when true
28
- all_cookies = ['cookie time']
29
- end
30
- cookies_array = Array.new
31
- all_cookies.each { | cookie |
32
- cookies_array.push(cookie.split('; ')[0])
33
- }
34
- cookies = cookies_array.join('; ')
17
+ def array
18
+ if @url.to_s =~ /array/
19
+ responder(make_call)
20
+ else
21
+ error_text("array", @url.to_s, "array")
22
+ end
23
+ end
24
+
25
+ def make_call
26
+ @params = @params.to_json unless @meth.downcase == 'get' || @meth.downcase == 'delete'
27
+ begin
28
+ response = RestClient::Request.execute(headers: @headers,
29
+ method: VERBS[@meth.downcase],
30
+ payload: @params,
31
+ timeout: 30,
32
+ url: @url,
33
+ verify_ssl: false)
34
+ rescue => e
35
+ e.response
36
+ else
37
+ response
38
+ end
39
+ end
40
+
41
+ def cookie
42
+ if @url =~ /auth\/session/
43
+ response = make_call
44
+ raise 'There was an issue getting a cookie!' unless response.code == 200
45
+ cookie = (response.cookies.map{|key,val| key + '=' + val})[0]
35
46
  else
36
47
  error_text("cookie", @url.to_s, 'auth/session')
37
48
  end
@@ -47,19 +58,12 @@ class Stoarray
47
58
  }
48
59
  end
49
60
 
50
- def flippy(temp_hash, testy: false)
61
+ def flippy(temp_hash)
62
+ # This method is to get around a "feature" of Xtremio where it renames the
63
+ # target snapshot set. We flip between name and name_347. Comprende?
51
64
  flippy = temp_hash['to-snapshot-set-id'] + '_347'
52
- url = 'https://' + @url.host + '/api/json/v2/types/snapshot-sets'
53
- case testy
54
- when false
55
- x = Stoarray.new(headers: @headers, meth: 'Get', params: {}, url: url).snap
56
- when true
57
- x = {
58
- "response" => {
59
- "snapshot-sets" => [ { "name" => flippy } ]
60
- }
61
- }
62
- end
65
+ url = 'https://' + URI.parse(@url).host + '/api/json/v2/types/snapshot-sets'
66
+ x = Stoarray.new(headers: @headers, meth: 'Get', params: {}, url: url).snap
63
67
  if x['response']['snapshot-sets'].any? { |y| y['name'].include?(flippy) }
64
68
  temp_hash['snapshot-set-name'] = temp_hash['to-snapshot-set-id']
65
69
  temp_hash['to-snapshot-set-id'] = flippy
@@ -72,8 +76,7 @@ class Stoarray
72
76
 
73
77
  def host
74
78
  if @url.to_s =~ /host/
75
- response = @request.start { |http| http.request(@call) }
76
- responder(response)
79
+ responder(make_call)
77
80
  else
78
81
  error_text("host", @url.to_s, "host")
79
82
  end
@@ -81,8 +84,7 @@ class Stoarray
81
84
 
82
85
  def pgroup
83
86
  if @url.to_s =~ /pgroup/
84
- response = @request.start { |http| http.request(@call) }
85
- responder(response)
87
+ responder(make_call)
86
88
  else
87
89
  error_text("pgroup", @url.to_s, "pgroup")
88
90
  end
@@ -91,14 +93,22 @@ class Stoarray
91
93
  def refresh
92
94
  case @url.to_s
93
95
  when /snapshot/ # Xtremio
94
- @call.body = flippy(JSON.parse(@call.body)).to_json
95
- refreshy = @request.start { |http| http.request(@call) }
96
- responder(refreshy)
96
+ tgt = @params['to-snapshot-set-id']
97
+ @params = flippy(@params)
98
+ src = @params['from-consistency-group-id']
99
+ cln = responder(make_call)
100
+ if cln['status'] == 201
101
+ cln['response'] = 'SUCCESS: Xtremio refresh completed from consistency group ' \
102
+ + src + ' to snapshot set ' + tgt + '.'
103
+ cln
104
+ else
105
+ cln
106
+ end
97
107
  when /1.4/ # Pure, handle the interim snap automagically
98
108
  error_state = false
99
- url = 'https://' + @url.host + '/api/1.4/pgroup'
100
- source = (JSON.parse(@call.body))['source']
101
- suffix = Time.new.strftime("%A") # Day of the week.
109
+ url = 'https://' + URI.parse(@url).host + '/api/1.4/pgroup'
110
+ source = @params['source']
111
+ suffix = 'interim'
102
112
  pam = { :snap => true, :source => source, :suffix => suffix }
103
113
  snap = Stoarray.new(headers: @headers, meth: 'Post', params: pam, url: url).pgroup
104
114
  respond = {
@@ -114,12 +124,11 @@ class Stoarray
114
124
  }
115
125
  }
116
126
  if snap['status'] >= 200 && snap['status'] <= 299
117
- pairs = (JSON.parse(@call.body))['snap_pairs']
118
- pairs.each do |key, val|
119
- tgt = 'clone_' + val
127
+ @params['snap_pairs'].each do |key, val|
128
+ tgt = 'clone_' + val # used only for logging!
120
129
  src = source[0] + '.' + suffix + '.' + key
121
130
  pam = { :overwrite => true, :source => src }
122
- url = 'https://' + @url.host + '/api/1.4/volume/' + val
131
+ url = 'https://' + URI.parse(@url).host + '/api/1.4/volume/' + val
123
132
  clone = Stoarray.new(headers: @headers, meth: 'Post', params: pam, url: url).volume
124
133
  respond['response'][tgt] = {
125
134
  "response" => clone['response']
@@ -128,7 +137,7 @@ class Stoarray
128
137
  "status" => clone['status']
129
138
  }
130
139
  end
131
- url = 'https://' + @url.host + '/api/1.4/pgroup/' + source[0] + '.' + suffix
140
+ url = 'https://' + URI.parse(@url).host + '/api/1.4/pgroup/' + source[0] + '.' + suffix
132
141
  zappy = Stoarray.new(headers: @headers, meth: 'Delete', params: {}, url: url).pgroup
133
142
  respond['response']['destroy'] = {
134
143
  "response" => zappy['response']
@@ -136,16 +145,14 @@ class Stoarray
136
145
  respond['status']['destroy'] = {
137
146
  "status" => zappy['status']
138
147
  }
139
- pam = { :eradicate => true }
140
- disintegrate = Stoarray.new(headers: @headers, meth: 'Delete', params: pam, url: url).pgroup
148
+ url = url + '?eradicate=true'
149
+ disintegrate = Stoarray.new(headers: @headers, meth: 'Delete', params: {}, url: url).pgroup
141
150
  respond['response']['eradicate'] = {
142
151
  "response" => disintegrate['response']
143
152
  }
144
153
  respond['status']['eradicate'] = {
145
154
  "status" => disintegrate['status']
146
155
  }
147
- else
148
- respond
149
156
  end
150
157
  respond['status'].each do |key, val|
151
158
  error_state = true if val.any? { |status, code| code.to_i < 200 || code.to_i > 299 }
@@ -155,7 +162,7 @@ class Stoarray
155
162
  else
156
163
  response = {
157
164
  "response" =>
158
- "SUCCESS: Refresh completed for #{source[0]} protection group.\n",
165
+ "SUCCESS: Pure refresh completed from #{source[0]} protection group.\n",
159
166
  "status" => 201
160
167
  }
161
168
  end
@@ -164,7 +171,7 @@ class Stoarray
164
171
  end
165
172
  end
166
173
 
167
- def responder(response) # combine into one method? with error_text
174
+ def responder(response)
168
175
  response = {
169
176
  "response" => JSON.parse(response.body),
170
177
  "status" => response.code.to_i
@@ -173,8 +180,7 @@ class Stoarray
173
180
 
174
181
  def snap
175
182
  if @url.to_s =~ /snapshot/
176
- response = @request.start { |http| http.request(@call) }
177
- responder(response)
183
+ responder(make_call)
178
184
  else
179
185
  error_text("snap", @url.to_s, "snapshot")
180
186
  end
@@ -182,8 +188,7 @@ class Stoarray
182
188
 
183
189
  def volume
184
190
  if @url.to_s =~ /volume/
185
- response = @request.start { |http| http.request(@call) }
186
- responder(response)
191
+ responder(make_call)
187
192
  else
188
193
  error_text("volume", @url.to_s, "volume")
189
194
  end
data/lib/stoarray.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  require 'base64'
2
2
  require 'cgi'
3
3
  require 'json'
4
- require 'net/http'
5
- require 'net/https'
6
- require 'uri'
4
+ require 'rest-client'
7
5
  require 'arraycalls'
@@ -1,3 +1,3 @@
1
1
  class Stoarray
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/stoarray.gemspec CHANGED
@@ -27,4 +27,6 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency deppy
28
28
  end
29
29
 
30
+ spec.add_runtime_dependency 'rest-client'
31
+
30
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stoarray
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kody Wilson
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rest-client
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
139
153
  description: Interact with storage array api using Ruby
140
154
  email:
141
155
  - kodywilson@gmail.com
@@ -147,6 +161,7 @@ files:
147
161
  - ".gitignore"
148
162
  - ".rspec"
149
163
  - ".travis.yml"
164
+ - CHANGELOG.md
150
165
  - CODE_OF_CONDUCT.md
151
166
  - Gemfile
152
167
  - Guardfile