Sha256: 1d32193001ada715066af2ad94f59b6ddf22c8e60d64b4993e6e6911d37fa974

Contents?: true

Size: 2 KB

Versions: 1

Compression:

Stored size: 2 KB

Contents

module Fog
  module Compute
    class OneAndOne

      class Real

        ##
        # Modify a block storage
        # URL: [https://cloudpanel-api.1and1.com/documentation/v1/en/api/documentation.html#block_storages__block_storage_id__put]
        ##
        def update_block_storage(block_storage_id: nil, name: nil,
          description: nil, size: nil)

          # Build PUT body
          new_block_storage = {
            'name' => name,
            'description' => description,
            'size' => size
          }

          # Clean out null values from PUT body
          body = clean_hash(new_block_storage)

          # Stringify the PUT body
          string_body = Fog::JSON.encode(body)

          # Request
          params = {
            'method' => :put,
            'endpoint' => "/block_storages/#{block_storage_id}",
            'body' => string_body
          }

          request(params)

        end

      end # Real

      
      class Mock

        def update_block_storage(block_storage_id: nil, name: nil,
          description: nil, size: nil)
          
          # Search for block storage to update
          if block_storage = self.data[:block_storages].find {
            |hash| hash['id'] == block_storage_id
          }
            # Create parameter hash 
            params = {
              'name' => name,
              'description' => description,
              'size' => size
            }
            
            # Update the block storage we found with new values
            params.each do |key, value|
              if value
                block_storage[key] = value
              end
            end
          else
            raise Fog::Errors::NotFound.new('The requested resource could
              not be found.')
          end

          # Return Response Object to User
          response = Excon::Response.new
          response.status = 202
          response.body = block_storage
          response

        end

      end # Mock

    end # OneAndOne
  end # Compute
end # Fog

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fog-oneandone-1.2 lib/oneandone/requests/compute/update_block_storage.rb