Administrative Operations¶
The Admin provides several convenience methods
to perform common API requests.
Warning
The interface here is provided as a convenience only and its interface may change.
To create an administrative handle, simply instantiate a new
Admin object. Note that unlike the Bucket,
the Admin constructor does not accept a connection string. This is
deliberate, as the administrative API communicates with a single node, on
a well defined port (whereas the Bucket object communicates with
one or more nodes using a variety of different protocols).
-
class
couchbase.admin.Admin(username, password, host='localhost', port=8091, **kwargs)[source]¶ An administrative connection to a Couchbase cluster.
With this object, you can do things which affect the cluster, such as modifying buckets, allocating nodes, or retrieving information about the cluster.
This object should not be used to perform Key/Value operations. The
Bucketis used for that.Connect to a cluster
Parameters: - username (string) – The administrative username for the cluster,
this is typically
Administrator - password (string) – The administrative password for the cluster, this is the password you entered when Couchbase was installed
- host (string) – The hostname or IP of one of the nodes which is currently a member of the cluster (or a newly allocated node, if you wish to operate on that)
- port (int) – The management port for the node
Raise: couchbase.exceptions.AuthErrorif incorrect credentials were suppliedcouchbase.exceptions.ConnectErrorif there was a problem establishing a connection to the provided hostReturns: an instance of
Admin-
bucket_create(name, bucket_type='couchbase', bucket_password='', replicas=0, ram_quota=1024, flush_enabled=False)[source]¶ Create a new bucket
Parameters: - name (string) – The name of the bucket to create
- bucket_type (string) – The type of bucket to create. This can either be couchbase to create a couchbase style bucket (which persists data and supports replication) or memcached (which is memory-only and does not support replication).
- bucket_password (string) – The bucket password. This can be
empty to disable authentication. This can be changed later on
using
bucket_update() - replicas (int) – The number of replicas to use for this
bucket. The maximum number of replicas is currently 3.
This setting can be changed via
bucket_update() - ram_quota (int) – The maximum amount of memory (per node) that this bucket
may use, in megabytes. The minimum for this value is 100.
This setting may be changed via
bucket_update(). - flush_enabled (bool) – Whether the flush API is enabled. When the flush API is
enabled, any client connected to the bucket is able to
clear its contents. This may be useful in development but
not recommended in production. This setting may be changed
via
bucket_update()
Returns: Raise: HTTPErrorif the bucket could not be created.
-
bucket_delete(name)¶ Remove an existing bucket from the cluster
Parameters: name (string) – The name of the bucket to remove Returns: A HttpResultRaise: HTTPErroron error
-
bucket_info(name)[source]¶ Retrieve information about the bucket.
Parameters: name (string) – The name of the bucket Returns: A HttpResultobject. The result’svalueattribute contains A dictionary containing the bucket’s information. The returned object is considered to be opaque, and is intended primarily for use withbucket_update(). Currently this returns the raw decoded JSON as emitted by the corresponding server-side APIRaise: HTTPErrorif the request failed
-
bucket_remove(name)[source]¶ Remove an existing bucket from the cluster
Parameters: name (string) – The name of the bucket to remove Returns: A HttpResultRaise: HTTPErroron error
-
bucket_update(name, current, bucket_password=None, replicas=None, ram_quota=None, flush_enabled=None)[source]¶ Update an existing bucket’s settings.
Parameters: - name (string) – The name of the bucket to update
- current (dict) – Current state of the bucket.
This can be retrieve from
bucket_info() - bucket_password (str) – Change the bucket’s password
- replicas (int) – The number of replicas for the bucket
- ram_quota (int) – The memory available to the bucket on each node.
- flush_enabled (bool) – Whether the flush API should be allowed from normal clients
Returns: A
HttpResultobjectRaise: HTTPErrorif the request could not be completedNote
The default value for all options in this method is
None. If a value is set to something else, it will modify the setting.Change the bucket password:
adm.bucket_update('a_bucket', adm.bucket_info('a_bucket'), bucket_password='n3wpassw0rd')
Enable the flush API:
adm.bucket_update('a_bucket', adm.bucket_info('a_bucket'), flush_enabled=True)
-
http_request(path, method='GET', content=None, content_type='application/json', response_format=33554432L)[source]¶ Perform an administrative HTTP request. This request is sent out to the administrative API interface (i.e. the “Management/REST API”) of the cluster.
Note that this is a fairly low level function. You should use one of the helper methods in this class to perform your task, if possible.
Parameters: - path (string) – The path portion (not including the host) of the rest call to perform. This should also include any encoded arguments.
- method (string) – This is the HTTP method to perform. Currently supported values are GET, POST, PUT, and DELETE
- content (bytes) – Content to be passed along in the request body. This is only applicable on PUT and POST methods.
- content_type (string) – Value for the HTTP
Content-Typeheader. Currently this isapplication-json, and should probably not be set to something else. - response_format (int) –
Hint about how to format the response. This goes into the
valuefield of theHttpResultobject. The default isFMT_JSON.Note that if the conversion fails, the content will be returned as
bytes
Raise: ArgumentErrorif the method supplied was incorrect.
ConnectErrorif there was a problem establishing a connection.
HTTPErrorif the server responded with a negative reply
Returns: a
HttpResultobject.See also
-
wait_ready(name, timeout=5.0, sleep_interval=0.2)[source]¶ Wait for a newly created bucket to be ready.
Parameters: - name (string) – the name to wait for
- timeout (seconds) – the maximum amount of time to wait
- sleep_interval (seconds) – the number of time to sleep between each probe
Raise: CouchbaseErroron internal HTTP errorRaise: NotReadyErrorif all nodes could not be ready in time
- username (string) – The administrative username for the cluster,
this is typically