class Etcdv3
Constants
- DEFAULT_TIMEOUT
- VERSION
Attributes
Public Class Methods
# 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
Disarm alarms on a specified member.
# File lib/etcdv3.rb, line 67 def alarm_deactivate @conn.handle(:maintenance, 'alarms', [:deactivate, leader_id]) end
List active alarms
# File lib/etcdv3.rb, line 62 def alarm_list @conn.handle(:maintenance, 'alarms', [:get, leader_id]) end
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
Enables authentication.
# File lib/etcdv3.rb, line 72 def auth_enable(timeout: nil) @conn.handle(:auth, 'auth_enable', [timeout: timeout]) true end
Store size in bytes.
# File lib/etcdv3.rb, line 52 def db_size @conn.handle(:maintenance, 'member_status').dbSize end
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
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
Cluster leader id
# File lib/etcdv3.rb, line 57 def leader_id @conn.handle(:maintenance, 'member_status').leader end
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
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
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
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
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
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
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
Delete role.
# File lib/etcdv3.rb, line 187 def role_delete(name, timeout: nil) @conn.handle(:auth, 'role_delete', [name, timeout: timeout]) end
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
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
List all roles.
# File lib/etcdv3.rb, line 172 def role_list(timeout: nil) @conn.handle(:auth, 'role_list', [timeout: timeout]) end
# 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
# File lib/etcdv3.rb, line 240 def transaction(timeout: nil, &block) @conn.handle(:kv, 'transaction', [block, timeout: timeout]) end
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
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
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
Delete specified user.
# File lib/etcdv3.rb, line 211 def user_delete(user, timeout: nil) @conn.handle(:auth, 'user_delete', [user, timeout: timeout]) end
Fetch specified user
# File lib/etcdv3.rb, line 201 def user_get(user, timeout: nil) @conn.handle(:auth, 'user_get', [user, timeout: timeout]) end
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
List all users.
# File lib/etcdv3.rb, line 221 def user_list(timeout: nil) @conn.handle(:auth, 'user_list', [timeout: timeout]) end
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 of Etcd running on member
# File lib/etcdv3.rb, line 47 def version @conn.handle(:maintenance, 'member_status').version end
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
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
# File lib/etcdv3.rb, line 246 def sanitized_endpoints (@options[:endpoints] || @options[:url]).split(',').map(&:strip) end