Class: Purest::Volume
- Inherits:
-
Rest
- Object
- CustomExceptions
- Rest
- Purest::Volume
- Defined in:
- lib/purest/volume.rb
Constant Summary collapse
- GET_PARAMS =
[:action, :block_size, :connect, :historical, :length, :names, :pending, :pending_only, :pgrouplist, :private, :protect, :shared, :snap, :space]
Instance Method Summary collapse
-
#create(options = nil) ⇒ Object
Create a volume, POST.
-
#delete(options = nil) ⇒ Object
Delete a volume, DELETE.
-
#get(options = nil) ⇒ Object
Get a list of volumes, GET.
-
#update(options = nil) ⇒ Object
Update a volume, PUT.
Methods inherited from Rest
access_method?, #authenticated?, #concat_url, #initialize, #logout, method_missing, #use_named_parameter
Constructor Details
This class inherits a constructor from Purest::Rest
Instance Method Details
#create(options = nil) ⇒ Object
Create a volume, POST
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/purest/volume.rb', line 45 def create( = nil) = raw_resp = @conn.post do |req| url = "/api/#{Purest.configuration.api_version}/volume" url += "/#{@options[:name]}" if [:name] url += "/pgroup/#{@options[:pgroup]}" if [:pgroup] req.body = .to_json req.url url end JSON.parse(raw_resp.body, :symbolize_names => true) end |
#delete(options = nil) ⇒ Object
Delete a volume, DELETE
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/purest/volume.rb', line 86 def delete( = nil) = raw_resp = @conn.delete do |req| url = "/api/#{Purest.configuration.api_version}/volume/#{@options[:name]}" url += "/pgroup/#{@options[:pgroup]}" if [:pgroup] req.url url end if [:eradicate] raw_resp = @conn.delete do |req| url = ["/api/#{Purest.configuration.api_version}/volume/#{@options[:name]}"] req.body = .to_json req.url concat_url url end end JSON.parse(raw_resp.body, :symbolize_names => true) end |
#get(options = nil) ⇒ Object
Get a list of volumes, GET
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/purest/volume.rb', line 13 def get( = nil) = create_session unless authenticated? # Build up a url from parts, allowing for dynamic http calls # by simply passing in params accepted by Pure's API raw_resp = @conn.get do |req| url = ["/api/#{Purest.configuration.api_version}/volume"] url.map!{|u| u + "/#{@options[:name]}"} if !.nil? && [:name] # Map /diff, /hgroup, or /host depending on option passed [:show_diff, :show_hgroup, :show_host].each do |path| new_path = path.to_s.gsub('show_', '') url.map!{|u| u + "/#{new_path}"} if !.nil? && [path] end # Generate array, consisting of url parts, to be built # by concat_url method below GET_PARAMS.each do |param| url += self.send(:"use_#{param}",) end # Build url from array of parts, send request req.url concat_url url end JSON.parse(raw_resp.body, :symbolize_names => true) end |
#update(options = nil) ⇒ Object
Update a volume, PUT
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/purest/volume.rb', line 62 def update( = nil) = raw_resp = @conn.put do |req| # Here we construct the url first, because the options hash # may have to be manipulated below req.url "/api/#{Purest.configuration.api_version}/volume/#{@options[:name]}" # Repurpose @options[:name] so that it is now set to the new_name # allowing us to rename a volume. [:name] = .delete(:new_name) if [:new_name] # Remove name from @options which is sent in the body, # if size is passed in, because those two cannot be sent together. .delete(:name) if [:size] req.body = .to_json end JSON.parse(raw_resp.body, :symbolize_names => true) end |