class Docker::Network

This class represents a Docker Network.

Public Class Methods

all(opts = {}, conn = Docker.connection) click to toggle source
# File lib/docker/network.rb, line 61
def all(opts = {}, conn = Docker.connection)
  hashes = Docker::Util.parse_json(conn.get('/networks', opts)) || []
  hashes.map { |hash| new(conn, hash) }
end
create(name, opts = {}, conn = Docker.connection) click to toggle source
# File lib/docker/network.rb, line 45
def create(name, opts = {}, conn = Docker.connection)
  default_opts = MultiJson.dump({
    'Name' => name,
    'CheckDuplicate' => true
  }.merge(opts))
  resp = conn.post('/networks/create', {}, body: default_opts)
  response_hash = Docker::Util.parse_json(resp) || {}
  get(response_hash['Id'], {}, conn) || {}
end
delete(id, opts = {}, conn = Docker.connection)
Alias for: remove
get(id, opts = {}, conn = Docker.connection) click to toggle source
# File lib/docker/network.rb, line 55
def get(id, opts = {}, conn = Docker.connection)
  network_json = conn.get("/networks/#{id}", opts)
  hash = Docker::Util.parse_json(network_json) || {}
  new(conn, hash)
end
prune(conn = Docker.connection) click to toggle source
# File lib/docker/network.rb, line 72
def prune(conn = Docker.connection)
  conn.post("/networks/prune", {})
  nil
end
remove(id, opts = {}, conn = Docker.connection) click to toggle source
# File lib/docker/network.rb, line 66
def remove(id, opts = {}, conn = Docker.connection)
  conn.delete("/networks/#{id}", opts)
  nil
end
Also aliased as: delete

Public Instance Methods

connect(container, opts = {}, body_opts = {}) click to toggle source
# File lib/docker/network.rb, line 7
def connect(container, opts = {}, body_opts = {})
  body = MultiJson.dump({ container: container }.merge(body_opts))
  Docker::Util.parse_json(
    connection.post(path_for('connect'), opts, body: body)
  )
  reload
end
delete(opts = {})
Alias for: remove
disconnect(container, opts = {}) click to toggle source
# File lib/docker/network.rb, line 15
def disconnect(container, opts = {})
  body = MultiJson.dump(container: container)
  Docker::Util.parse_json(
    connection.post(path_for('disconnect'), opts, body: body)
  )
  reload
end
json(opts = {}) click to toggle source
# File lib/docker/network.rb, line 29
def json(opts = {})
  Docker::Util.parse_json(connection.get(path_for, opts))
end
reload() click to toggle source
# File lib/docker/network.rb, line 38
def reload
  network_json = @connection.get("/networks/#{@id}")
  hash = Docker::Util.parse_json(network_json) || {}
  @info = hash
end
remove(opts = {}) click to toggle source
# File lib/docker/network.rb, line 23
def remove(opts = {})
  connection.delete(path_for, opts)
  nil
end
Also aliased as: delete
to_s() click to toggle source
# File lib/docker/network.rb, line 33
def to_s
  "Docker::Network { :id => #{id}, :info => #{info.inspect}, "\
    ":connection => #{connection} }"
end

Private Instance Methods

path_for(resource = nil) click to toggle source

Convenience method to return the path for a particular resource.

# File lib/docker/network.rb, line 79
def path_for(resource = nil)
  ["/networks/#{id}", resource].compact.join('/')
end