Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

services endpoints were started #464

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/docker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ module Docker
require 'docker/util'
require 'docker/version'
require 'docker/volume'
require 'docker/service'
require 'docker/task'
require 'docker/rake_task' if defined?(Rake::Task)

def default_socket_url
Expand Down
47 changes: 47 additions & 0 deletions lib/docker/service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This class represents a Docker Service

class Docker::Service
include Docker::Base

# refresh current Service
def refresh!(opts = {}, conn = Docker.connection)
resp = conn.get("/services/#{URI.encode(self.id)}", opts)
hash = Docker::Util.parse_json(resp) || {}
info.merge!(hash)
self
end

# destroy current Service
def delete!(opts = {}, conn = Docker.connection)
resp = conn.delete("/services/#{URI.encode(self.id)}", opts)
Docker::Util.parse_json(resp) || {}
end

# Get all Services
def self.all(opts = {}, conn = Docker.connection)
resp = conn.get('/services', opts)
hashes = Docker::Util.parse_json(resp) || []
hashes.map { |hash| new(conn, hash) }
end

# Create new Service
def self.create(opts = {}, conn = Docker.connection)
resp = conn.post('/services/create', {}, :body => opts.to_json)
hash = Docker::Util.parse_json(resp) || {}
new(conn, hash)
end

# get a Service
def self.get(id_or_name, opts = {}, conn = Docker.connection)
resp = conn.get("/services/#{URI.encode(id_or_name)}", opts)
hash = Docker::Util.parse_json(resp) || {}
new(conn, hash)
end

# TODO: create the "update" method
# according to this doc:
# https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/update-a-service

# TODO: create "ps" when it is available on the docker api
# https://docs.docker.com/engine/reference/commandline/service_ps
end
33 changes: 33 additions & 0 deletions lib/docker/task.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This class represents a Docker Service Tasks

class Docker::Task
include Docker::Base

# refresh current Task
def refresh!(opts = {}, conn = Docker.connection)
resp = conn.get("/tasks/#{URI.encode(self.id)}", opts)
hash = Docker::Util.parse_json(resp) || {}
info.merge!(hash)
self
end

# Get all Tasks
# example: Docker::Task.all({filters: '{"service":["user3-nginx"]}'})
#
def self.all(opts = {}, conn = Docker.connection)
resp = conn.get('/tasks', opts)
hashes = Docker::Util.parse_json(resp) || []
hashes.map { |hash| new(conn, hash) }
end

# get a Service
def self.get(id, opts = {}, conn = Docker.connection)
resp = conn.get("/tasks/#{URI.encode(id)}", opts)
hash = Docker::Util.parse_json(resp) || {}
new(conn, hash)
end

# TODO: to think how to link it to the Docker::Service class
end