Sha256: b854ffc8d0474b6d5678875c546ba338110d599e3c582e4568273d0c56ff6a52

Contents?: true

Size: 1.69 KB

Versions: 5

Compression:

Stored size: 1.69 KB

Contents

require 'json'
require 'etcdv3'

module RubyPitaya

  class EtcdConnector

    def initialize(server_uuid, desktop_name, server_name, etcd_prefix,
                  etcd_address, allow_reconnect)
      @server_uuid = server_uuid
      @server_name = server_name
      @desktop_name = desktop_name
      @etcd_prefix = etcd_prefix
      @etcd_address = etcd_address
      @allow_reconnect = allow_reconnect
    end

    def connect
      @connection = Etcdv3.new(endpoints: @etcd_address,
                              allow_reconnect: @allow_reconnect)
      @connection.put(connection_key, connection_value)
    end

    def disconnect
      @connection.del(connection_key)
    end

    private

    def connection_key
      "#{@etcd_prefix}servers/#{@server_name}/#{@server_uuid}"
    end

    def connection_value
      JSON.generate(get_server_data)
    end

    def get_server_data
      {
        id: @server_uuid,
        hostname: @desktop_name,
        type: @server_name,
        frontend: false,
        metadata: {
          stack: 'default',
          stackInfo: JSON.generate({
            Maintenance: false,
            Platforms: {
              android: {
                  Max: '9.9.9',
                  Min: '0.0.0'
              },
              ios: {
                  Max: '9.9.9',
                  Min: '0.0.0'
              },
              iphoneplayer: {
                  Max: '9.9.9',
                  Min: '0.0.0'
              },
              mac: {
                  Max: '9.9.9',
                  Min: '0.0.0'
              },
              osxeditor: {
                  Max: '9.9.9',
                  Min: '0.0.0'
              }
            }
          })
        }
      }
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rubypitaya-1.3.1 ./lib/rubypitaya/core/etcd_connector.rb
rubypitaya-1.3.0 ./lib/rubypitaya/core/etcd_connector.rb
rubypitaya-1.2.9 ./lib/rubypitaya/core/etcd_connector.rb
rubypitaya-1.2.7 ./lib/rubypitaya/core/etcd_connector.rb
rubypitaya-1.1.0 ./lib/rubypitaya/core/etcd_connector.rb