class Etcdv3

Constants

DEFAULT_TIMEOUT
VERSION

Attributes

conn[R]
credentials[R]
options[R]

Public Class Methods

new(**options) click to toggle source
# File lib/etcdv3.rb, line 32
def initialize(**options)
  @options = options
  @timeout = options[:command_timeout] || DEFAULT_TIMEOUT
  @namespace = options[:namespace]
  @conn = ConnectionWrapper.new(
    @timeout,
    *sanitized_endpoints,
    @namespace,
    @options.fetch(:allow_reconnect, true),
  )
  warn "WARNING: `url` is deprecated. Please use `endpoints` instead." if @options.key?(:url)
  authenticate(@options[:user], @options[:password]) if @options.key?(:user)
end

Public Instance Methods

alarm_deactivate() click to toggle source

Disarm alarms on a specified member.

# File lib/etcdv3.rb, line 67
def alarm_deactivate
  @conn.handle(:maintenance, 'alarms', [:deactivate, leader_id])
end
alarm_list() click to toggle source

List active alarms

# File lib/etcdv3.rb, line 62
def alarm_list
  @conn.handle(:maintenance, 'alarms', [:get, leader_id])
end
auth_disable(timeout: nil) click to toggle source

Disables authentication. This will clear any active auth / token data.

# File lib/etcdv3.rb, line 79
def auth_disable(timeout: nil)
  @conn.handle(:auth, 'auth_disable', [timeout: timeout])
  @conn.clear_authentication
  true
end
auth_enable(timeout: nil) click to toggle source

Enables authentication.

# File lib/etcdv3.rb, line 72
def auth_enable(timeout: nil)
  @conn.handle(:auth, 'auth_enable', [timeout: timeout])
  true
end
db_size() click to toggle source

Store size in bytes.

# File lib/etcdv3.rb, line 52
def db_size
  @conn.handle(:maintenance, 'member_status').dbSize
end
del(key, opts={}) click to toggle source

Deletes a specified key key - string optional :range_end - string optional :timeout - integer

# File lib/etcdv3.rb, line 147
def del(key, opts={})
  @conn.handle(:kv, 'del', [key, opts])
end
get(key, opts={}) click to toggle source

key - string optional :range_end - string optional :limit - integer optional :revision - integer optional :sort_order - symbol - [:none, :ascend, :descend] optional :sort_target - symbol - [:key, :version, :create, :mode, :value] optional :serializable - boolean optional :keys_only - boolean optional :count_only - boolean optional :min_mod_revision - integer optional :max_mod_revision - integer optional :min_create_revision - integer optional :max_create_revision - integer optional :timeout - integer

# File lib/etcdv3.rb, line 99
def get(key, opts={})
  @conn.handle(:kv, 'get', [key, opts])
end
leader_id() click to toggle source

Cluster leader id

# File lib/etcdv3.rb, line 57
def leader_id
  @conn.handle(:maintenance, 'member_status').leader
end
lease_grant(ttl, timeout: nil) click to toggle source

Grant a lease with a specified TTL

# File lib/etcdv3.rb, line 152
def lease_grant(ttl, timeout: nil)
  @conn.handle(:lease, 'lease_grant', [ttl, timeout: timeout])
end
lease_keep_alive_once(id, timeout: nil) click to toggle source

Sends one lease keep-alive request

# File lib/etcdv3.rb, line 167
def lease_keep_alive_once(id, timeout: nil)
  @conn.handle(:lease, 'lease_keep_alive_once', [id, timeout: timeout])
end
lease_revoke(id, timeout: nil) click to toggle source

Revokes lease and delete all attached keys

# File lib/etcdv3.rb, line 157
def lease_revoke(id, timeout: nil)
  @conn.handle(:lease, 'lease_revoke', [id, timeout: timeout])
end
lease_ttl(id, timeout: nil) click to toggle source

Returns information regarding the current state of the lease

# File lib/etcdv3.rb, line 162
def lease_ttl(id, timeout: nil)
  @conn.handle(:lease, 'lease_ttl', [id, timeout: timeout])
end
lock(name, lease_id, timeout: nil) click to toggle source

Locks distributed lock with the given name. The lock will unlock automatically when lease with the given ID expires. If this is not desirable, provide a non-expiring lease ID as an argument. name - string lease_id - integer optional :timeout - integer

# File lib/etcdv3.rb, line 109
def lock(name, lease_id, timeout: nil)
  @conn.handle(:lock, 'lock', [name, lease_id, {timeout: timeout}])
end
put(key, value, opts={}) click to toggle source

Inserts a new key. key - string value - string optional :lease - integer optional :timeout - integer

# File lib/etcdv3.rb, line 139
def put(key, value, opts={})
  @conn.handle(:kv, 'put', [key, value, opts])
end
role_add(name, timeout: nil) click to toggle source

Add role with specified name.

# File lib/etcdv3.rb, line 177
def role_add(name, timeout: nil)
  @conn.handle(:auth, 'role_add', [name, timeout: timeout])
end
role_delete(name, timeout: nil) click to toggle source

Delete role.

# File lib/etcdv3.rb, line 187
def role_delete(name, timeout: nil)
  @conn.handle(:auth, 'role_delete', [name, timeout: timeout])
end
role_get(name, timeout: nil) click to toggle source

Fetches a specified role.

# File lib/etcdv3.rb, line 182
def role_get(name, timeout: nil)
  @conn.handle(:auth, 'role_get', [name, timeout: timeout])
end
role_grant_permission(name, permission, key, range_end: '', timeout: nil) click to toggle source

Grants a new permission to an existing role.

# File lib/etcdv3.rb, line 192
def role_grant_permission(name, permission, key, range_end: '', timeout: nil)
  @conn.handle(:auth, 'role_grant_permission', [name, permission, key, range_end, timeout: timeout])
end
role_list(timeout: nil) click to toggle source

List all roles.

# File lib/etcdv3.rb, line 172
def role_list(timeout: nil)
  @conn.handle(:auth, 'role_list', [timeout: timeout])
end
role_revoke_permission(name, permission, key, range_end: '', timeout: nil) click to toggle source
# File lib/etcdv3.rb, line 196
def role_revoke_permission(name, permission, key, range_end: '', timeout: nil)
  @conn.handle(:auth, 'role_revoke_permission', [name, permission, key, range_end, timeout: timeout])
end
transaction(timeout: nil, &block) click to toggle source
# File lib/etcdv3.rb, line 240
def transaction(timeout: nil, &block)
  @conn.handle(:kv, 'transaction', [block, timeout: timeout])
end
unlock(key, timeout: nil) click to toggle source

Unlock distributed lock using the key previously obtained from lock. key - string optional :timeout - integer

# File lib/etcdv3.rb, line 116
def unlock(key, timeout: nil)
  @conn.handle(:lock, 'unlock', [key, {timeout: timeout}])
end
user_add(user, password, timeout: nil) click to toggle source

Creates new user.

# File lib/etcdv3.rb, line 206
def user_add(user, password, timeout: nil)
  @conn.handle(:auth, 'user_add', [user, password, timeout: timeout])
end
user_change_password(user, new_password, timeout: nil) click to toggle source

Changes the specified users password.

# File lib/etcdv3.rb, line 216
def user_change_password(user, new_password, timeout: nil)
  @conn.handle(:auth, 'user_change_password', [user, new_password, timeout: timeout])
end
user_delete(user, timeout: nil) click to toggle source

Delete specified user.

# File lib/etcdv3.rb, line 211
def user_delete(user, timeout: nil)
  @conn.handle(:auth, 'user_delete', [user, timeout: timeout])
end
user_get(user, timeout: nil) click to toggle source

Fetch specified user

# File lib/etcdv3.rb, line 201
def user_get(user, timeout: nil)
  @conn.handle(:auth, 'user_get', [user, timeout: timeout])
end
user_grant_role(user, role, timeout: nil) click to toggle source

Grants role to an existing user.

# File lib/etcdv3.rb, line 226
def user_grant_role(user, role, timeout: nil)
  @conn.handle(:auth, 'user_grant_role', [user, role, timeout: timeout])
end
user_list(timeout: nil) click to toggle source

List all users.

# File lib/etcdv3.rb, line 221
def user_list(timeout: nil)
  @conn.handle(:auth, 'user_list', [timeout: timeout])
end
user_revoke_role(user, role, timeout: nil) click to toggle source

Revokes role from a specified user.

# File lib/etcdv3.rb, line 231
def user_revoke_role(user, role, timeout: nil)
  @conn.handle(:auth, 'user_revoke_role', [user, role, timeout: timeout])
end
version() click to toggle source

Version of Etcd running on member

# File lib/etcdv3.rb, line 47
def version
  @conn.handle(:maintenance, 'member_status').version
end
watch(key, range_end: nil, start_revision: nil, timeout: nil, &block) click to toggle source

Watches for changes on a specified key range.

# File lib/etcdv3.rb, line 236
def watch(key, range_end: nil, start_revision: nil, timeout: nil, &block)
  @conn.handle(:watch, 'watch', [key, range_end, start_revision, block, timeout: timeout])
end
with_lock(name, lease_id, timeout: nil) { || ... } click to toggle source

Yield into the critical section while holding lock with the given name. The lock will be unlocked even if the block throws. name - string lease_id - integer optional :timeout - integer

# File lib/etcdv3.rb, line 125
def with_lock(name, lease_id, timeout: nil)
  key = lock(name, lease_id, timeout: timeout).key
  begin
    yield
  ensure
    unlock(key, timeout: timeout)
  end
end

Private Instance Methods

sanitized_endpoints() click to toggle source
# File lib/etcdv3.rb, line 246
def sanitized_endpoints
  (@options[:endpoints] || @options[:url]).split(',').map(&:strip)
end