class Couchbase::Cluster

Public Class Methods

new(options = {}) click to toggle source

Establish connection to the cluster for administration

@param [Hash] options The connection parameter @option options [String] :username The username @option options [String] :password The password @option options [String] :pool (“default”) The pool name @option options [String] :hostname (“localhost”) The hostname @option options [String] :port (8091) The port

# File lib/couchbase/cluster.rb, line 30
def initialize(options = {})
  if options[:username].nil? || options[:password].nil?
    raise ArgumentError, "username and password mandatory to connect to the cluster"
  end
  @connection = Bucket.new(options.merge(:type => :cluster))
end

Public Instance Methods

create_bucket(name, options = {}) { |response| ... } click to toggle source

Create data bucket

@param [String] name The name of the bucket @param [Hash] options The bucket parameters @option options [String] :bucket_type (“couchbase”) The type of the

bucket. Possible values are "memcached" and "couchbase".

@option options [Fixnum] :ram_quota (100) The RAM quota in megabytes. @option options [Fixnum] :replica_number (1) The number of replicas of

each document

@option options [String] :auth_type (“sasl”) The authentication type.

Possible values are "sasl" and "none". Note you should specify free
port for "none"

@option options [Fixnum] :proxy_port The port for moxi

# File lib/couchbase/cluster.rb, line 50
def create_bucket(name, options = {})
  defaults = {
    :type => "couchbase",
    :ram_quota => 100,
    :replica_number => 1,
    :auth_type => "sasl",
    :sasl_password => "",
    :proxy_port => nil
  }
  options = defaults.merge(options)
  params = {"name" => name}
  params["bucketType"] = options[:type]
  params["ramQuotaMB"] = options[:ram_quota]
  params["replicaNumber"] = options[:replica_number]
  params["authType"] = options[:auth_type]
  params["saslPassword"] = options[:sasl_password]
  params["proxyPort"] = options[:proxy_port]
  payload = Utils.encode_params(params.reject!{|k, v| v.nil?})
  request = @connection.make_http_request("/pools/default/buckets",
                                          :content_type => "application/x-www-form-urlencoded",
                                          :type => :management,
                                          :method => :post,
                                          :extended => true,
                                          :body => payload)
  response = nil
  request.on_body do |r|
    response = r
    response.instance_variable_set("@operation", :create_bucket)
    yield(response) if block_given?
  end
  request.continue
  response
end
delete_bucket(name, options = {}) { |response| ... } click to toggle source

Delete the data bucket

@param [String] name The name of the bucket @param [Hash] options

# File lib/couchbase/cluster.rb, line 88
def delete_bucket(name, options = {})
  request = @connection.make_http_request("/pools/default/buckets/#{name}",
                                          :type => :management,
                                          :method => :delete,
                                          :extended => true)
  response = nil
  request.on_body do |r|
    response = r
    response.instance_variable_set("@operation", :delete_bucket)
    yield(response) if block_given?
  end
  request.continue
  response
end