Class: Docker::API::Plugin

Inherits:
Base
  • Object
show all
Defined in:
lib/docker/api/plugin.rb

Overview

This class represents the Docker API endpoints regarding plugins.

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Docker::API::Base

Instance Method Details

#configure(name, config) ⇒ Object

Configure a plugin

Docker API: POST /plugins/name/set

Parameters:

  • name (String)

    : The ID or name of the plugin.

  • config (Array)

    : Plugin configuration to be sent as json in request body.

See Also:



156
157
158
# File 'lib/docker/api/plugin.rb', line 156

def configure name, config
    @connection.request(method: :post, path: "/plugins/#{name}/set", headers: {"Content-Type": "application/json"}, body:config.to_json)
end

#create(name, path) ⇒ Object

Create a plugin

Docker API: POST /plugins/create

Parameters:

  • name (String)

    : The ID or name of the plugin.

  • path (String)

    : Path to tar file that contains rootfs folder and config.json file.

See Also:



123
124
125
126
127
128
# File 'lib/docker/api/plugin.rb', line 123

def create name, path
    file = File.open( File.expand_path( path ) , "r")
    response = @connection.request(method: :post, path: "/plugins/create?name=#{name}", body: file.read.to_s )
    file.close        
    response
end

#details(name) ⇒ Object

Inspect a plugin

Docker API: GET /plugins/name/json

Parameters:

  • name (String)

    : The ID or name of the plugin.

See Also:



54
55
56
# File 'lib/docker/api/plugin.rb', line 54

def details name 
    @connection.get("/plugins/#{name}/json")
end

#disable(name) ⇒ Object

Disable a plugin

Docker API: POST /plugins/name/disable

Parameters:

  • name (String)

    : The ID or name of the plugin.

See Also:



91
92
93
# File 'lib/docker/api/plugin.rb', line 91

def disable name
    @connection.post("/plugins/#{name}/disable")
end

#enable(name, params = {}) ⇒ Object

Enable a plugin

Docker API: POST /plugins/name/enable

Parameters:

  • name (String)

    : The ID or name of the plugin.

  • params (Hash) (defaults to: {})

    : Parameters that are appended to the URL.

See Also:



80
81
82
# File 'lib/docker/api/plugin.rb', line 80

def enable name, params = {}
    @connection.post(build_path("/plugins/#{name}/enable", params))
end

#install(params = {}, privileges = [], authentication = {}) ⇒ Object

Install a plugin

Pulls and installs a plugin. After the plugin is installed, it can be enabled using the POST /plugins/name/enable endpoint.

Docker API: POST /plugins/pull

Parameters:

  • params (Hash) (defaults to: {})

    : Parameters that are appended to the URL.

  • privileges (Array) (defaults to: [])

    : Plugin privileges to be sent as json in request body.

  • authentication (Hash) (defaults to: {})

    : Authentication parameters.

See Also:



41
42
43
44
45
# File 'lib/docker/api/plugin.rb', line 41

def install params = {}, privileges = [], authentication = {}
    headers = {"Content-Type": "application/json"}
    headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0
    @connection.request(method: :post, path: build_path("/plugins/pull", params), headers: headers, body: privileges.to_json )
end

#list(params = {}) ⇒ Object

List plugins

Docker API: GET /plugins

Parameters:

  • params (Hash) (defaults to: {})

    : Parameters that are appended to the URL.

See Also:



13
14
15
# File 'lib/docker/api/plugin.rb', line 13

def list params = {}
    @connection.get(build_path("/plugins", params))
end

#privileges(params = {}) ⇒ Object

Get plugin privileges

Docker API: GET /plugins/privileges

Parameters:

  • params (Hash) (defaults to: {})

    : Parameters that are appended to the URL.

See Also:



24
25
26
# File 'lib/docker/api/plugin.rb', line 24

def privileges params = {}
    @connection.get(build_path("/plugins/privileges", params))
end

#push(name, authentication = {}) ⇒ Object

Push a plugin to the registry.

Docker API: POST /plugins/name/push

Parameters:

  • name (String)

    : The ID or name of the plugin.

  • authentication (Hash) (defaults to: {})

    : Authentication parameters.

See Also:



139
140
141
142
143
144
145
# File 'lib/docker/api/plugin.rb', line 139

def push name, authentication = {}
    if authentication.keys.size > 0
        @connection.request(method: :post, path: "/plugins/#{name}/push", headers: {"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)})
    else
        @connection.post("/plugins/#{name}/push")
    end
end

#remove(name, params = {}) ⇒ Object

Remove a plugin

Docker API: DELETE /plugins/name

Parameters:

  • name (String)

    : The ID or name of the plugin.

  • params (Hash) (defaults to: {})

    : Parameters that are appended to the URL.

See Also:



67
68
69
# File 'lib/docker/api/plugin.rb', line 67

def remove name, params = {}
    @connection.delete(build_path("/plugins/#{name}",params))
end

#upgrade(name, params = {}, privileges = [], authentication = {}) ⇒ Object

Upgrade a plugin

Docker API: POST /plugins/name/upgrade

Parameters:

  • name (String)

    : The ID or name of the plugin.

  • params (Hash) (defaults to: {})

    : Parameters that are appended to the URL.

  • privileges (Array) (defaults to: [])

    : Plugin privileges to be sent as json in request body.

  • authentication (Hash) (defaults to: {})

    : Authentication parameters.

See Also:



108
109
110
111
112
# File 'lib/docker/api/plugin.rb', line 108

def upgrade name, params = {}, privileges = [], authentication = {}
    headers = {"Content-Type": "application/json"}
    headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0
    @connection.request(method: :post, path: build_path("/plugins/#{name}/upgrade", params), headers: headers, body: privileges.to_json )
end