Class: Docker::Volume

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/docker/volume.rb

Overview

class represents a Docker Volume

Instance Attribute Summary

Attributes included from Base

#connection, #id, #info

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

#initialize

Class Method Details

.all(opts = {}, conn = Docker.connection) ⇒ Object

/volumes endpoint returns an array of hashes incapsulated in an Volumes tag



24
25
26
27
28
29
# File 'lib/docker/volume.rb', line 24

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

.create(name, opts = {}, conn = Docker.connection) ⇒ Object

creates a volume with an arbitrary name



32
33
34
35
36
37
# File 'lib/docker/volume.rb', line 32

def create(name, opts = {}, conn = Docker.connection)
  opts['Name'] = name
  resp = conn.post('/volumes/create', {}, body: MultiJson.dump(opts))
  hash = Docker::Util.parse_json(resp) || {}
  new(conn, hash)
end

.get(name, conn = Docker.connection) ⇒ Object

get details for a single volume



17
18
19
20
21
# File 'lib/docker/volume.rb', line 17

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

.prune(conn = Docker.connection) ⇒ Object



39
40
41
# File 'lib/docker/volume.rb', line 39

def prune(conn = Docker.connection)
  conn.post("/volumes/prune")
end

Instance Method Details

#normalize_hash(hash) ⇒ Object



10
11
12
# File 'lib/docker/volume.rb', line 10

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

#remove(opts = {}, conn = Docker.connection) ⇒ Object

/volumes/volume_name doesnt return anything



6
7
8
# File 'lib/docker/volume.rb', line 6

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