Class: Stoarray
- Inherits:
-
Object
- Object
- Stoarray
- Defined in:
- lib/arraycalls.rb,
lib/stoarray/version.rb
Constant Summary collapse
- VERBS =
{ 'delete' => :Delete, 'get' => :Get, 'post' => :Post, 'put' => :Put }
- VERSION =
"0.3.0"
Instance Method Summary collapse
- #array ⇒ Object
- #cookie ⇒ Object
- #error_text(method_name, url, wanted) ⇒ Object
- #flippy(temp_hash) ⇒ Object
- #host ⇒ Object
-
#initialize(headers: {}, meth: 'Get', params: {}, url: 'https://array/') ⇒ Stoarray
constructor
A new instance of Stoarray.
- #make_call ⇒ Object
- #pgroup ⇒ Object
- #refresh ⇒ Object
- #responder(response) ⇒ Object
- #snap ⇒ Object
- #volume ⇒ Object
Constructor Details
#initialize(headers: {}, meth: 'Get', params: {}, url: 'https://array/') ⇒ Stoarray
Returns a new instance of Stoarray.
10 11 12 13 14 15 |
# File 'lib/arraycalls.rb', line 10 def initialize(headers: {}, meth: 'Get', params: {}, url: 'https://array/') @headers = headers @meth = meth @params = params @url = url end |
Instance Method Details
#array ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/arraycalls.rb', line 17 def array if @url.to_s =~ /array/ responder(make_call) else error_text("array", @url.to_s, "array") end end |
#cookie ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/arraycalls.rb', line 41 def if @url =~ /auth\/session/ response = make_call raise 'There was an issue getting a cookie!' unless response.code == 200 = (response..map{|key,val| key + '=' + val})[0] else error_text("cookie", @url.to_s, 'auth/session') end end |
#error_text(method_name, url, wanted) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/arraycalls.rb', line 51 def error_text(method_name, url, wanted) response = { "response" => "ERROR: Wrong url for the #{method_name} method.\n"\ "Sent: #{url}\n"\ "Expected: \"#{wanted}\" as part of the url.", "status" => 400 } end |
#flippy(temp_hash) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/arraycalls.rb', line 61 def flippy(temp_hash) # This method is to get around a "feature" of Xtremio where it renames the # target snapshot set. We flip between name and name_347. Comprende? flippy = temp_hash['to-snapshot-set-id'] + '_347' url = 'https://' + URI.parse(@url).host + '/api/json/v2/types/snapshot-sets' x = Stoarray.new(headers: @headers, meth: 'Get', params: {}, url: url).snap if x['response']['snapshot-sets'].any? { |y| y['name'].include?(flippy) } temp_hash['snapshot-set-name'] = temp_hash['to-snapshot-set-id'] temp_hash['to-snapshot-set-id'] = flippy else temp_hash['snapshot-set-name'] = flippy end temp_hash['no-backup'] = true temp_hash end |
#host ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/arraycalls.rb', line 77 def host if @url.to_s =~ /host/ responder(make_call) else error_text("host", @url.to_s, "host") end end |
#make_call ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/arraycalls.rb', line 25 def make_call @params = @params.to_json unless @meth.downcase == 'get' || @meth.downcase == 'delete' begin response = RestClient::Request.execute(headers: @headers, method: VERBS[@meth.downcase], payload: @params, timeout: 30, url: @url, verify_ssl: false) rescue => e e.response else response end end |
#pgroup ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/arraycalls.rb', line 85 def pgroup if @url.to_s =~ /pgroup/ responder(make_call) else error_text("pgroup", @url.to_s, "pgroup") end end |
#refresh ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/arraycalls.rb', line 93 def refresh case @url.to_s when /snapshot/ # Xtremio tgt = @params['to-snapshot-set-id'] @params = flippy(@params) src = @params['from-consistency-group-id'] cln = responder(make_call) if cln['status'] == 201 cln['response'] = 'SUCCESS: Xtremio refresh completed from consistency group ' \ + src + ' to snapshot set ' + tgt + '.' cln else cln end when /1.4/ # Pure, handle the interim snap automagically error_state = false url = 'https://' + URI.parse(@url).host + '/api/1.4/pgroup' source = @params['source'] suffix = 'interim' pam = { :snap => true, :source => source, :suffix => suffix } snap = Stoarray.new(headers: @headers, meth: 'Post', params: pam, url: url).pgroup respond = { "response" => { "snap" => { "response" => snap['response'] } }, "status" => { "snap" => { "status" => snap['status'] } } } if snap['status'] >= 200 && snap['status'] <= 299 @params['snap_pairs'].each do |key, val| tgt = 'clone_' + val # used only for logging! src = source[0] + '.' + suffix + '.' + key pam = { :overwrite => true, :source => src } url = 'https://' + URI.parse(@url).host + '/api/1.4/volume/' + val clone = Stoarray.new(headers: @headers, meth: 'Post', params: pam, url: url).volume respond['response'][tgt] = { "response" => clone['response'] } respond['status'][tgt] = { "status" => clone['status'] } end url = 'https://' + URI.parse(@url).host + '/api/1.4/pgroup/' + source[0] + '.' + suffix zappy = Stoarray.new(headers: @headers, meth: 'Delete', params: {}, url: url).pgroup respond['response']['destroy'] = { "response" => zappy['response'] } respond['status']['destroy'] = { "status" => zappy['status'] } url = url + '?eradicate=true' disintegrate = Stoarray.new(headers: @headers, meth: 'Delete', params: {}, url: url).pgroup respond['response']['eradicate'] = { "response" => disintegrate['response'] } respond['status']['eradicate'] = { "status" => disintegrate['status'] } end respond['status'].each do |key, val| error_state = true if val.any? { |status, code| code.to_i < 200 || code.to_i > 299 } end if error_state == true respond else response = { "response" => "SUCCESS: Pure refresh completed from #{source[0]} protection group.\n", "status" => 201 } end else error_text("refresh", @url.to_s, "snapshot or 1.4") end end |
#responder(response) ⇒ Object
174 175 176 177 178 179 |
# File 'lib/arraycalls.rb', line 174 def responder(response) response = { "response" => JSON.parse(response.body), "status" => response.code.to_i } end |
#snap ⇒ Object
181 182 183 184 185 186 187 |
# File 'lib/arraycalls.rb', line 181 def snap if @url.to_s =~ /snapshot/ responder(make_call) else error_text("snap", @url.to_s, "snapshot") end end |
#volume ⇒ Object
189 190 191 192 193 194 195 |
# File 'lib/arraycalls.rb', line 189 def volume if @url.to_s =~ /volume/ responder(make_call) else error_text("volume", @url.to_s, "volume") end end |