Sha256: 82f5aa11ec5563a206e9ef3aed264be9495e3c0800850e93991565d4fc3f6c28

Contents?: true

Size: 1.07 KB

Versions: 9

Compression:

Stored size: 1.07 KB

Contents

# class represents a Docker Volume
class Docker::Volume
  include Docker::Base

  # /volumes/volume_name doesnt return anything
  def remove(opts = {}, conn = Docker.connection)
    conn.delete("/volumes/#{id}")
  end

  def normalize_hash(hash)
    hash['id'] ||= hash['Name']
  end

  class << self

    # get details for a single volume
    def get(name, conn = Docker.connection)
      resp = conn.get("/volumes/#{name}")
      hash = Docker::Util.parse_json(resp) || {}
      new(conn, hash)
    end

    # /volumes endpoint returns an array of hashes incapsulated in an Volumes tag
    def all(opts = {}, conn = Docker.connection)
      resp = conn.get('/volumes')
      json = Docker::Util.parse_json(resp) || {}
      hashes = json['Volumes'] || []
      hashes.map { |hash| new(conn, hash) }
    end

    # creates a volume with an arbitrary name
    def create(name, opts = {}, conn = Docker.connection)
      opts['Name'] = name
      resp = conn.post('/volumes/create', {}, :body => opts.to_json)
      hash = Docker::Util.parse_json(resp) || {}
      new(conn, hash)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
docker-api-1.33.6 lib/docker/volume.rb
docker-api-1.33.5 lib/docker/volume.rb
docker-api-1.33.4 lib/docker/volume.rb
docker-api-1.33.3 lib/docker/volume.rb
docker-api-1.33.2 lib/docker/volume.rb
docker-api-1.33.1 lib/docker/volume.rb
docker-api-1.33.0 lib/docker/volume.rb
docker-api-1.32.1 lib/docker/volume.rb
docker-api-1.32.0 lib/docker/volume.rb