Sha256: 15ccb6fcbdf0ee3ef6a130bca83c969a174dca606f29878d8df0e410d9cb24ab

Contents?: true

Size: 912 Bytes

Versions: 3

Compression:

Stored size: 912 Bytes

Contents

require 'ostruct'

class Etcd
  class Maintenance
    # Sadly these are the only alarm types supported by the api right now.
    ALARM_TYPES = {
      NONE: 0,
      NOSPACE: 1
    }

    ALARM_ACTIONS = {
      get: 0,
      activate: 1, # Should only be used in testing. Not a stable feature...
      deactivate: 2
    }

    def initialize(hostname, credentials, metadata = {})
      @stub = Etcdserverpb::Maintenance::Stub.new(hostname, credentials)
      @metadata = metadata
    end

    def member_status
      @stub.status(Etcdserverpb::StatusRequest.new, metadata: @metadata)
    end

    def alarms(action, member_id, alarm=:NONE)
      alarm = ALARM_TYPES[alarm]
      request = Etcdserverpb::AlarmRequest.new(
        action: ALARM_ACTIONS[action],
        memberID: member_id,
        alarm: action == :deactivate ? ALARM_TYPES[:NOSPACE] : alarm
      )
      @stub.alarm(request)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
etcdv3-0.2.0 lib/etcdv3/maintenance.rb
etcdv3-0.1.5 lib/etcdv3/maintenance.rb
etcdv3-0.1.4 lib/etcdv3/maintenance.rb