stoarray 0.1.0 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7d21238eeab121c6b16db40cef11da6eeabba05
4
- data.tar.gz: 33ea290c4163b4675cba2c1ea6e522b8a8812893
3
+ metadata.gz: 729cbc99da583048d9d8278e9a1f915d68c09eb5
4
+ data.tar.gz: 4a5742000105b2510ad7c2722f4eb43881361a0b
5
5
  SHA512:
6
- metadata.gz: 385a3ccc6f2f69be5e63a489d61a5037a1d0d0176207b2df19479b5399de3d1c00d5e8b8e053339ef64a872910a89db1e235d2a43a14a5649df3e8728aeabcfc
7
- data.tar.gz: b37bf21898851ed4b22c7bba53a83b1439a6c7ba3e68e0f2170ed65e20e02ee2e15d0c2c93ddabab81e35cecca798a6ca3938c2dd6218d72067bc3c21b3689a5
6
+ metadata.gz: 5d8d86df8cb31d2cf3a7e3f5aa8dc322a607123aedd29d7d49a11fcadb009860f09ae24750bcedec2b4b7a4a461cc5afb36fb638f63e621624e2943522d55cd7
7
+ data.tar.gz: e9bbb34fd798a295a2c7f3c070ce42b1037a5fc4feca0f820680a3bfc9f4b1d7f8c4cd76cf005cd84d8ce3874aaedb2fd38b249e67ca825d8694d02eb30335b4
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  stoarray
2
2
  ========
3
3
 
4
- Library for making api calls to storage arrays with Ruby
4
+ Library for making api calls to storage arrays with Ruby.
5
5
 
6
6
  ## Installation
7
7
 
@@ -13,10 +13,6 @@ gem 'stoarray'
13
13
 
14
14
  And then execute:
15
15
 
16
- $ bundle
17
-
18
- Or install it yourself as:
19
-
20
16
  $ gem install stoarray
21
17
 
22
18
  ## Usage
@@ -27,7 +23,7 @@ In your script:
27
23
 
28
24
  EMC's Xtremio and Pure's storage arrays are currently supported.
29
25
 
30
- Both api's use json for parameters and my examples below follow suit.
26
+ Both api's use json for parameters and the examples below follow suit.
31
27
  I prefer to set variables that will not change in a json configuration file.
32
28
  It is very easy to then build from there.
33
29
 
@@ -56,47 +52,55 @@ Examples using Pure:
56
52
  }
57
53
 
58
54
  The top three likely will not change between api calls.
59
- authorization - This is your api token.
60
- base_url - URL for your array and api
61
- headers - Pass the content type (JSON in this case)
62
55
 
63
- ###Back to your script, after the require 'stoarray'
56
+ + authorization - This is your api token.
57
+ + base_url - URL for your array and api
58
+ + headers - Pass the content type (JSON in this case)
64
59
 
65
- # Location of json configuration file and api token
66
- conf = JSON.parse(File.read('/Users/yourid/pure.json'))
67
- token = conf['authorization']
60
+ ###Back to your script, after the require 'stoarray'
68
61
 
69
- Pure uses cookies. You get one with your api token and then it uses the cookie
70
- while your session persists (30 mins max unless you destroy it early).
62
+ ```ruby
63
+ # Location of json configuration file and api token
64
+ conf = JSON.parse(File.read('/Users/yourid/pure.json'))
65
+ token = conf['authorization']
66
+ ```
71
67
 
72
- # Get a cookie for our session
73
- url = conf['base_url'] + 'auth/session'
74
- headers = conf['headers']
75
- params = { api_token: token }
76
- cookies = Stoarray.new(headers: headers, meth: 'Post', params: params, url: url).cookie
68
+ Pure uses cookies. You trade one for your api token and then you can use the cookie
69
+ while your session persists (30 minute inactivity timeout, unless you destroy it early).
77
70
 
78
- # After we get a cookie, update headers to include it
79
- headers['Cookie'] = cookies
71
+ ```ruby
72
+ # Get a cookie for our session
73
+ url = conf['base_url'] + 'auth/session'
74
+ headers = conf['headers']
75
+ params = { api_token: token }
76
+ cookies = Stoarray.new(headers: headers, meth: 'Post', params: params, url: url).cookie
77
+
78
+ # After we get a cookie, update headers to include it
79
+ headers['Cookie'] = cookies
80
+ ```
80
81
 
81
82
  Now we will send application type json and the cookie with each call.
82
83
 
83
- # Create host and set list of WWN's
84
- params = conf['params_host_testsrv01']
85
- url_host = conf['base_url'] + 'host/' + conf['newhost']
86
- host = Stoarray.new(headers: headers, meth: 'Post', params: params, url: url_host).host
87
- puts host['response']
84
+ ```ruby
85
+ # Create host and set list of WWN's
86
+ params = conf['params_host_testsrv01']
87
+ url_host = conf['base_url'] + 'host/' + conf['newhost']
88
+ host = Stoarray.new(headers: headers, meth: 'Post', params: params, url: url_host).host
89
+ puts host['response']
90
+
91
+ # Create volumes and map them to new host
92
+ conf['new_luns_testsrv01'].each do |vol|
93
+ url_vol = conf['base_url'] + 'volume/' + vol
94
+ voly = Stoarray.new(headers: headers, meth: 'Post', params: { :size => "10G" }, url: url_vol).volume
95
+ puts JSON.parse(voly.body) if verbose == true
96
+ url_map = url_host + '/volume/' + vol
97
+ mappy = Stoarray.new(headers: headers, meth: 'Post', params: {}, url: url_map).host
98
+ puts mappy['response'] if verbose == true
99
+ end
88
100
 
89
- # Create volumes and map them to new host
90
- conf['new_luns_testsrv01'].each do |vol|
91
- url_vol = conf['base_url'] + 'volume/' + vol
92
- voly = Stoarray.new(headers: headers, meth: 'Post', params: { :size => "10G" }, url: url_vol).volume
93
- puts JSON.parse(voly.body) if verbose == true
94
- url_map = url_host + '/volume/' + vol
95
- mappy = Stoarray.new(headers: headers, meth: 'Post', params: {}, url: url_map).host
96
- puts mappy['response'] if verbose == true
97
- end
101
+ ```
98
102
 
99
- In this example, you end up with a new host on the array, named testsrv01, including WWN's, and 5 10GB volumes mapped to the host.
103
+ In the above example, you end up with a new host on the array, named testsrv01, including WWN's, and five, new 10GB volumes mapped to the host.
100
104
 
101
105
  ###Now for Xtremio, json first:
102
106
  {
@@ -112,27 +116,29 @@ In this example, you end up with a new host on the array, named testsrv01, inclu
112
116
  }
113
117
  }
114
118
 
115
- base_url - URL for your array and api
116
- headers - Content type and authorization
117
- authorization - "Basic 'Base64 hash of your username and password'"
119
+ + base_url - URL for your array and api
120
+ + headers - Content type and authorization
121
+ + authorization - "Basic 'Base64 hash of your username and password'"
118
122
 
119
123
  ###Now for your script - this one does a clone refresh
120
124
 
121
- #!/usr/bin/env ruby
125
+ ```ruby
126
+ #!/usr/bin/env ruby
122
127
 
123
- require 'stoarray'
128
+ require 'stoarray'
124
129
 
125
- # Location of json configuration file
126
- conf = JSON.parse(File.read('/path/to/config/file/xtremioclone.json'))
130
+ # Location of json configuration file
131
+ conf = JSON.parse(File.read('/path/to/config/file/xtremioclone.json'))
127
132
 
128
- headers = conf['headers']
133
+ headers = conf['headers']
129
134
 
130
- # Refresh the snap set
131
- url = conf['base_url'] + 'snapshots'
132
- params = conf['params_refresh_u04']
133
- refresh = Stoarray.new(headers: headers, meth: 'Post', params: params, url: url).refresh
134
- puts "Status: " + refresh['status'].to_s
135
- puts "Response: " + refresh['response'].to_s
135
+ # Refresh the snap set
136
+ url = conf['base_url'] + 'snapshots'
137
+ params = conf['params_refresh_u04']
138
+ refresh = Stoarray.new(headers: headers, meth: 'Post', params: params, url: url).refresh
139
+ puts "Status: " + refresh['status'].to_s
140
+ puts "Response: " + refresh['response'].to_s
141
+ ```
136
142
 
137
143
  ## Development
138
144
 
@@ -147,3 +153,9 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/kodywi
147
153
  ## License
148
154
 
149
155
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
156
+
157
+ [![Build Status](https://travis-ci.org/kodywilson/stoarray.svg?branch=master)](https://travis-ci.org/kodywilson/stoarray)
158
+
159
+ [![Gem Version](https://badge.fury.io/rb/stoarray.svg)](https://badge.fury.io/rb/stoarray)
160
+
161
+ [![Coverage Status](https://coveralls.io/repos/kodywilson/stoarray/badge.svg?branch=master&service=github)](https://coveralls.io/github/kodywilson/stoarray?branch=master)
data/lib/arraycalls.rb CHANGED
@@ -18,14 +18,23 @@ class Stoarray
18
18
  @request.verify_mode = OpenSSL::SSL::VERIFY_NONE # parameterize?
19
19
  end
20
20
 
21
- def cookie
22
- @response = @request.start { |http| http.request(@call) }
23
- all_cookies = @response.get_fields('set-cookie')
24
- cookies_array = Array.new
25
- all_cookies.each { | cookie |
26
- cookies_array.push(cookie.split('; ')[0])
27
- }
28
- cookies = cookies_array.join('; ')
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('; ')
35
+ else
36
+ error_text("cookie", @url.to_s, 'auth/session')
37
+ end
29
38
  end
30
39
 
31
40
  def error_text(method_name, url, wanted)
@@ -38,10 +47,19 @@ class Stoarray
38
47
  }
39
48
  end
40
49
 
41
- def flippy(temp_hash)
50
+ def flippy(temp_hash, testy: false)
42
51
  flippy = temp_hash['to-snapshot-set-id'] + '_347'
43
52
  url = 'https://sa0319xms01/api/json/v2/types/snapshot-sets'
44
- x = Stoarray.new(headers: @headers, meth: 'Get', params: {}, url: url).snap
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
45
63
  if x['response']['snapshot-sets'].any? { |y| y['name'].include?(flippy) }
46
64
  temp_hash['snapshot-set-name'] = temp_hash['to-snapshot-set-id']
47
65
  temp_hash['to-snapshot-set-id'] = flippy
@@ -1,3 +1,3 @@
1
1
  class Stoarray
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  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.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kody Wilson