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]
collection_exists(collection, *options)[source]

Checks for existence of a collection. This will fetch a manifest and then interrogate it to check that the scope name exists and then that the collection name exists within that scope.

Parameters

collection (ICollectionSpec) – spec of the collection.

Timeout or timeoutMillis (int/duration) - the time allowed for the operation to be terminated. This is controlled by the client. :param options: :return whether the collection exists. :rtype bool :raises: InvalidArgumentsException Uri GET /pools/default/buckets/<bucket>/collections

create_collection(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(scope_name, options)[source]

Create Scope Creates a new scope. Signature Void CreateScope(string scopeName, [options]) Parameters Required: scopeName: 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(collection, options)[source]

Drop Collection Removes a collection. Signature void DropCollection(ICollectionSpec collection, [options]) Parameters Required: collection: ICollectionSpec - 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(scopeName, options)[source]

Drop Scope Removes a scope. Signature void DropScope(string scopeName, [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_all_scopes(options)[source]

Get All Scopes Gets all scopes. This will fetch a manifest and then pull the scopes out of it. Signature iterable<IScopeSpec> GetAllScopes([options]) Parameters Required: Optional: Timeout or timeoutMillis (int/duration) - the time allowed for the operation to be terminated. This is controlled by the client. Returns Throws Any exceptions raised by the underlying platform Uri GET /pools/default/buckets/<bucket>/collections

Return type

_GenericAlias[IScopeSpec]

get_scope(scopeName, options)[source]

Get Scope Gets a scope. This will fetch a manifest and then pull the scope out of it. Signature IScopeSpec GetScope(string scopeName, [options]) Parameters Required: scopeName: 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

Return type

IScopeSpec

scope_exists(scope_name, *options)[source]

Scope Exists Checks for existence of a scope. This will fetch a manifest and then interrogate it to check that the scope name exists. Signature boolean ScopeExists(String scopeName, [options]) Parameters Required: scopeName: 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 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(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(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(bucket_name, *options)[source]

Removes a bucket.

Parameters

bucket_name (str) – the name of the bucket.

Raises

BucketNotFoundException

Raises

InvalidArgumentsException

flush_bucket(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(*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(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(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(group_name, *options, **kwargs)[source]

Removes a group.

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

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

Raises

GroupNotFoundException

Raises

InvalidArgumentsException

drop_user(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 (Duration) – the time allowed for the operation to be terminated. This is controlled by the client.

Returns

Raises

UserNotFoundException

Raises

InvalidArgumentsException

get_all_groups(*options, **kwargs)[source]

Get all groups.

Parameters

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

Returns

An iterable collection of Group.

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

  • options

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

Returns

An iterable collection of UserAndMetadata.

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

Get info about the named group.

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

  • timeout (Duration) – 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(*options, **kwargs)[source]

Returns the roles supported by the server.

Parameters
  • options – misc options

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

Returns

An iterable collection of RoleAndDescription.

get_user(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 (Duration) – 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(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 (Duration) – the time allowed for the operation to be terminated. This is controlled by the client.

Raises

InvalidArgumentsException

upsert_user(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 (Duration) – the time allowed for the operation to be terminated. This is controlled by the client.

Raises

InvalidArgumentsException