Management Operations

The :module:`~.couchbase.management` provides several convenience methods to perform common API requests.

Warning

The interface here is provided as a convenience only and its interface may change.

class couchbase.management.collections.CollectionManager(admin_bucket, bucket_name)[source]
create_collection(self, collection, *options)[source]

Create Collection Creates a new collection. Signature void CreateCollection(CollectionSpec collection, [options]) Parameters Required: collection: CollectionSpec - specification of the collection. Optional: Timeout or timeoutMillis (int/duration) - the time allowed for the operation to be terminated. This is controlled by the client. Returns Throws InvalidArgumentsException CollectionAlreadyExistsException ScopeNotFoundException Any exceptions raised by the underlying platform Uri POST http://localhost:8091/pools/default/buckets/<bucket>/collections/<scope_name> -d name=<collection_name>

create_scope(self, scope_name, *options)[source]

Create Scope Creates a new scope. Signature Void CreateScope(string scope_name, [options]) Parameters Required: scope_name: String - name of the scope. Optional: Timeout or timeoutMillis (int/duration) - the time allowed for the operation to be terminated. This is controlled by the client. Returns Throws InvalidArgumentsException Any exceptions raised by the underlying platform Uri POST http://localhost:8091/pools/default/buckets/<bucket>/collections -d name=<scope_name>

drop_collection(self, collection, *options)[source]

Drop Collection Removes a collection. Signature void DropCollection(CollectionSpec collection, [options]) Parameters Required: collection: CollectionSpec - namspece of the collection. Optional: Timeout or timeoutMillis (int/duration) - the time allowed for the operation to be terminated. This is controlled by the client. Returns Throws CollectionNotFoundException Any exceptions raised by the underlying platform Uri DELETE http://localhost:8091/pools/default/buckets/<bucket>/collections/<scope_name>/<collection_name>

drop_scope(self, scope_name, *options)[source]

Drop Scope Removes a scope. Signature void DropScope(string scope_name, [options]) Parameters Required: collectionName: string - name of the collection. Optional: Timeout or timeoutMillis (int/duration) - the time allowed for the operation to be terminated. This is controlled by the client. Returns Throws ScopeNotFoundException Any exceptions raised by the underlying platform Uri DELETE http://localhost:8091/pools/default/buckets/<bucket>/collections/<scope_name>

get_scope(self, scope_name, *options)[source]

Get Scope Gets a scope. This will fetch a manifest and then pull the scope out of it. Signature ScopeSpec GetScope(string scope_name, [options]) Parameters Required: scope_name: string - name of the scope. Optional: Timeout or timeoutMillis (int/duration) - the time allowed for the operation to be terminated. This is controlled by the client. Returns Throws ScopeNotFoundException Any exceptions raised by the underlying platform Uri GET /pools/default/buckets/<bucket>/collections

class couchbase.management.buckets.BucketManager(admin_bucket)[source]

Bucket Manager

Parameters

admin_bucket – Admin bucket

bucket_update(self, current, bucket_password=None, replicas=None, ram_quota=None, flush_enabled=None, **kwargs)[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 HttpResult object

Raise

HTTPError if the request could not be completed

Note

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)
create_bucket(self, settings, *options, **kwargs)[source]

Creates a new bucket.

Param

CreateBucketSettings settings - settings for the bucket.

Raises

BucketAlreadyExistsException (http 400 and content contains “Bucket with given name already exists”)

Raises

InvalidArgumentsException

drop_bucket(self, bucket_name, *options)[source]

Removes a bucket.

Parameters

bucket_name (str) – the name of the bucket.

Raises

BucketNotFoundException

Raises

InvalidArgumentsException

flush_bucket(self, bucket_name, *options)[source]

Flushes a bucket (uses the ns_server REST interface).

Parameters

bucket_name (str) – the name of the bucket.

Raises

BucketNotFoundException

Raises

InvalidArgumentsException

Raises

FlushDisabledException

get_all_buckets(self, *options)[source]

Gets all bucket settings. Note, # type: the ram quota returned is in bytes not mb so requires x / 1024 twice.

Returns

An iterable of settings for each bucket.

Return type

Iterable[IBucketSettings]

get_bucket(self, bucket_name, *options)[source]

Gets a bucket’s settings.

Parameters

bucket_name (str) – the name of the bucket.

Returns

settings for the bucket. Note: the ram quota returned is in bytes

not mb so requires x / 1024 twice. Also Note: FlushEnabled is not a setting returned by the server, if flush is enabled then the doFlush endpoint will be listed and should be used to populate the field.

Return type

IBucketSettings

Raises

BucketNotFoundException

Raises

InvalidArgumentsException

update_bucket(self, settings, *options)[source]

Updates a bucket. Every setting must be set to what the user wants it to be after the update. Any settings that are not set to their desired values may be reverted to default values by the server.

Parameters

settings (IBucketSettings) – settings for the bucket.

Raises

InvalidArgumentsException

Raises

BucketDoesNotExistException

class couchbase.management.users.UserManager(admin)[source]

User Manager Programmatic access to the user management REST API: https://docs.couchbase.com/server/current/rest-api/rbac.html

Unless otherwise indicated, all objects SHOULD be immutable. :param parent_cluster:

drop_group(self, group_name, *options, **kwargs)[source]

Removes a group.

Parameters
  • group_name (str) – name of the group.

  • timeout (timedelta) – the time allowed for the operation to be terminated. This is controlled by the client.

Raises

GroupNotFoundException

Raises

InvalidArgumentsException

drop_user(self, user_name, domain=<AuthDomain.Local: 0>, *options, **kwargs)[source]

Removes a user.

Parameters
  • user_name (str) – ID of the user.

  • domain (AuthDomain) – name of the user domain. Defaults to local.

  • timeout (timedelta) – the time allowed for the operation to be terminated. This is controlled by the client.

Returns

Raises

UserNotFoundException

Raises

InvalidArgumentsException

get_all_users(self, domain_name, *options, **kwargs)[source]
Parameters
  • domain_name – name of the user domain. Defaults to local.

  • options

  • timeout (timedelta) – the time allowed for the operation to be terminated. This is controlled by the client.

Returns

An iterable collection of UserAndMetadata.

get_group(self, group_name, *options, **kwargs)[source]

Get info about the named group.

Parameters
  • group_name (str) – name of the group to get.

  • timeout (timedelta) – the time allowed for the operation to be terminated. This is controlled by the client.

Returns

An instance of Group.

Raises

GroupNotFoundException

Raises

InvalidArgumentsException

get_roles(self, *options, **kwargs)[source]

Returns the roles supported by the server.

Parameters
  • options – misc options

  • timeout (timedelta) – the time allowed for the operation to be terminated. This is controlled by the client.

Returns

An iterable collection of RoleAndDescription.

get_user(self, username, domain_name=<AuthDomain.Local: 0>, *options, **kwargs)[source]

Gets a user.

Parameters
  • username (str) – ID of the user.

  • domain_name (AuthDomain) – name of the user domain. Defaults to local.

  • timeout (timedelta) – the time allowed for the operation to be terminated. This is controlled by the client.

Returns

An instance of UserAndMetadata.

Raises

UserNotFoundException

Raises

InvalidArgumentsException

Any exceptions raised by the underlying platform

upsert_group(self, group, *options, **kwargs)[source]

Add or replace a group.

Warning

Does not appear to work correctly yet - tracked here: https://issues.couchbase.com/browse/PYCBC-667

Parameters
  • group (Group) – the new version of the group.

  • timeout (timedelta) – the time allowed for the operation to be terminated. This is controlled by the client.

Raises

InvalidArgumentsException

upsert_user(self, user, domain=<AuthDomain.Local: 0>, *options, **kwargs)[source]

Creates or updates a user.

Parameters
  • user (IUser) – the new version of the user.

  • domain (AuthDomain) – name of the user domain (local | external). Defaults to local.

  • timeout (timedelta) – the time allowed for the operation to be terminated. This is controlled by the client.

Raises

InvalidArgumentsException

class couchbase.management.queries.QueryIndexManager(parent_cluster)[source]

Query Index Manager The Query Index Manager interface contains the means for managing indexes used for queries. :param parent_cluster: Parent cluster

build_deferred_indexes(self, bucket_name, *options, **kwargs)[source]

Build Deferred builds all indexes which are currently in deferred state.

Parameters
  • bucket_name – name of the bucket.

  • timeout – the time allowed for the operation to be terminated. This is controlled by the client.

Raise

InvalidArgumentsException

create_index(self, bucket_name, index_name, fields, *options, **kwargs)[source]

Creates a new index.

Param

str bucket_name: name of the bucket.

Parameters
  • index_name (str) – the name of the index.

  • fields (Iterable[str]) – the fields to create the index over.

  • ignore_if_exists (bool) – Don’t error/throw if the index already exists.

  • num_replicas (int) – The number of replicas that this index should have. Uses the WITH keyword and num_replica.

  • deferred (bool) – Whether the index should be created as a deferred index.

  • timeout (timedelta) – the time allowed for the operation to be terminated. This is controlled by the client.

  • condition – condition on which to filter

Raises

IndexAlreadyExistsException

Raises

InvalidArgumentsException

create_primary_index(self, bucket_name, *options, **kwargs)[source]

Creates a new primary index.

Parameters
  • bucket_name (str) – name of the bucket.

  • index_name (str) – name of the index.

  • deferred (book) – Whether the index should be created as a deferred index.

  • ignore_if_exists (bool) – Don’t error/throw if the index already exists.

  • num_replicas (int) – The number of replicas that this index should have. Uses the WITH keyword and num_replica.

Param

timedelta timeout: the time allowed for the operation to be terminated. This is controlled by the client.

Raises

QueryIndexAlreadyExistsException

Raises

InvalidArgumentsException

drop_index(self, bucket_name, index_name, *options, **kwargs)[source]

Drops an index.

Parameters
  • bucket_name (str) – name of the bucket.

  • index_name (str) – name of the index.

  • ignore_if_not_exists (bool) – Don’t error/throw if the index does not exist.

  • timeout (timedelta) – the time allowed for the operation to be terminated. This is controlled by the client.

Raises

QueryIndexNotFoundException

Raises

InvalidArgumentsException

drop_primary_index(self, bucket_name, *options, **kwargs)[source]

Drops a primary index.

Parameters
  • bucket_name – name of the bucket.

  • index_name – name of the index.

  • ignore_if_not_exists – Don’t error/throw if the index does not exist.

  • timeout – the time allowed for the operation to be terminated. This is controlled by the client.

Raises

QueryIndexNotFoundException

Raises

InvalidArgumentsException

get_all_indexes(self, bucket_name, *options, **kwargs)[source]

Fetches all indexes from the server.

Parameters
  • bucket_name (str) – the name of the bucket.

  • timeout (timedelta) – the time allowed for the operation to be terminated. This is controlled by the client.

Returns

A list of QueryIndex objects.

Raises

InvalidArgumentsException

watch_indexes(self, bucket_name, index_names, *options, **kwargs)[source]

Watch polls indexes until they are online.

Parameters
  • bucket_name (str) – name of the bucket.

  • index_names (Iterable[str]) – name(s) of the index(es).

  • timeout (timedelta) – the time allowed for the operation to be terminated. This is controlled by the client.

Param

bool watch_primary: whether or not to watch the primary index.

Raises

QueryIndexNotFoundException

Raises

InvalidArgumentsException