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(collection, *options, **kwargs)[source]¶
Creates a new collection.
- Parameters
collection (CollectionSpec) – specification of the collection.
options (CreateCollectionOptions) – options (currently just timeout).
kwargs – keyword version of ‘options’
- Returns
- Raises
InvalidArgumentsException
- Raises
CollectionAlreadyExistsException
- Raises
ScopeNotFoundException
- create_scope(scope_name, *options, **kwargs)[source]¶
Creates a new scope.
- Parameters
scope_name (str) – name of the scope.
options (CreateScopeOptions) – options (currently just timeout).
kwargs (
Any
) – keyword version of options
- Return type
None
- Returns
- Raises
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, **kwargs)[source]¶
Removes a collection.
- Parameters
collection (CollectionSpec) – namspece of the collection.
options (DropCollectionOptions) – (currently just timeout).
kwargs (
Any
) – keyword version of options
- Raises
CollectionNotFoundException
- Return type
None
- drop_scope(scope_name, *options, **kwargs)[source]¶
Removes a scope.
- Parameters
scope_name (str) – name of the scope
options (DropScopeOptions) – (currently just timeout)
kwargs – keyword version of options
- Raises
ScopeNotFoundException
- get_scope(scope_name, *options, **kwargs)[source]¶
Gets a scope. This will fetch a manifest and then pull the scope out of it.
- param str scope_name
name of the scope.
- param GetScopeOptions options
scope options
- param GetScopeOptions kwargs
overrides for scope options
- return
a ScopeSpec containing information about the specified scope.
- raises
ScopeNotFoundException
- Warning
This is a deprecated API, use get_all_scopes instead.
- Return type
ScopeSpec
- class couchbase.management.buckets.BucketManager(admin_bucket)[source]¶
Bucket Manager
- Parameters
admin_bucket – Admin bucket
- create_bucket(settings, *options, **kwargs)[source]¶
Creates a new bucket.
- Param
CreateBucketSettings settings: settings for the bucket.
- Param
CreateBucketOptions options: options for setting the bucket.
- Param
Any kwargs: override corresponding values in the options.
- Raises
BucketAlreadyExistsException
- Raises
InvalidArgumentsException
- drop_bucket(bucket_name, *options, **kwargs)[source]¶
Removes a bucket.
- Parameters
bucket_name (str) – the name of the bucket.
options (DropBucketOptions) – options for dropping the bucket.
kwargs (Any) – override corresponding value in the options.
- Raises
BucketNotFoundException
- Raises
InvalidArgumentsException
- Return type
None
- flush_bucket(bucket_name, *options, **kwargs)[source]¶
Flushes a bucket (uses the ns_server REST interface).
- Parameters
bucket_name (str) – the name of the bucket.
options (FlushBucketOptions) – options for flushing the bucket.
kwargs (Any) – override corresponding value in options.
- Raises
BucketNotFoundException
- Raises
InvalidArgumentsException
- Raises
FlushDisabledException
- get_all_buckets(*options, **kwargs)[source]¶
Gets all bucket settings. Note, # type: the ram quota returned is in bytes not mb so requires x / 1024 twice.
- Parameters
options (GetAllBucketOptions) – options for getting all buckets.
kwargs (Any) – override corresponding value in options.
- Returns
An iterable of settings for each bucket.
- Return type
Iterable[BucketSettings]
- get_bucket(bucket_name, *options, **kwargs)[source]¶
Gets a bucket’s settings.
- Parameters
bucket_name (str) – the name of the bucket.
options (GetBucketOptions) – options for getting the bucket.
kwargs (Any) – override corresponding values in options.
- 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
BucketSettings
- Raises
BucketNotFoundException
- Raises
InvalidArgumentsException
- update_bucket(settings, *options, **kwargs)[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 (BucketSettings) – settings for updating the bucket.
options (UpdateBucketOptions) – options for updating the bucket.
kwargs (Any) – override corresponding values in the options.
- 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.
options – DropGroupOptions
kwargs (Any) – override corresponding values in the options.
- Raises
GroupNotFoundException
- Raises
InvalidArgumentsException
- drop_user(username, *options, **kwargs)[source]¶
Removes a user.
- Parameters
username (str) – ID of the user.
options – DropUserOptions
kwargs (Any) – override corresponding values in the options.
- Raises
UserNotFoundException
- Raises
InvalidArgumentsException
Any exceptions raised by the underlying platform
- get_all_groups(*options, **kwargs)[source]¶
Get all groups.
- Parameters
timeout (timedelta) – the time allowed for the operation to be terminated. This is controlled by the client.
- Return type
Iterable
[Group
]- Returns
An iterable collection of Group.
- get_all_users(*options, **kwargs)[source]¶
Gets all users.
- Parameters
options (
GetAllUsersOptions
) – GetAllUsersOptionskwargs (Any) – override corresponding values in the options.
- Return type
Iterable
[UserAndMetadata
]- Returns
An iterable collection of UserAndMetadata.
- get_group(group_name, *options, **kwargs)[source]¶
Gets a group.
- Parameters
group_name (str) – name of the group to get.
options (
GetGroupOptions
) – GetRolesOptionskwargs (Any) – override corresponding values in the options.
- Return type
Group
- Returns
An instance of Group.
- Raises
GroupNotFoundException
- Raises
InvalidArgumentsException
Any exceptions raised by the underlying platform
- get_roles(*options, **kwargs)[source]¶
Returns the roles supported by the server.
- Parameters
options (
GetRolesOptions
) – GetRolesOptionskwargs (Any) – override corresponding values in the options.
- Return type
Iterable
[RoleAndDescription
]- Returns
An iterable collection of RoleAndDescription.
- get_user(username, *options, **kwargs)[source]¶
Gets a user.
- Parameters
username (str) – ID of the user.
options (
GetUserOptions
) – GetUserOptionskwargs (Any) – override corresponding values in the options.
- Return type
UserAndMetadata
- Returns
An instance of UserAndMetadata.
- Raises
UserNotFoundException
- Raises
InvalidArgumentsException
Any exceptions raised by the underlying platform
- upsert_group(group, *options, **kwargs)[source]¶
Creates or updates a group.
- Parameters
group (Group) – the new version of the group.
options – UpsertGroupOptions
kwargs (Any) – override corresponding values in the options.
- Raises
InvalidArgumentsException
Any exceptions raised by the underlying platform
- 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(bucket_name, *options, **kwargs)[source]¶
Build Deferred builds all indexes which are currently in deferred state.
- Parameters
bucket_name (str) – name of the bucket.
options (BuildDeferredQueryIndexOptions) – Options for building deferred indexes.
kwargs (Any) – Override corresponding value in options.
- Raise
InvalidArgumentsException
- create_index(bucket_name, index_name, fields, *options, **kwargs)[source]¶
Creates a new index.
- Parameters
bucket_name (str) – name of the bucket.
index_name (str) – the name of the index.
fields (Iterable[str]) – Fields over which to create the index.
options (CreateQueryIndexOptions) – Options to use when creating index.
kwargs (Any) – Override corresponding value in options.
- Raises
QueryIndexAlreadyExistsException
- Raises
InvalidArgumentsException
- Return type
None
- create_primary_index(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.
options (CreatePrimaryQueryIndexOptions) – Options to use when creating primary index
kwargs (Any) – Override corresponding values in options.
- Raises
QueryIndexAlreadyExistsException
- Raises
InvalidArgumentsException
- drop_index(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.
options (DropQueryIndexOptions) – Options for dropping index.
kwargs (Any) – Override corresponding value in options.
- Raises
QueryIndexNotFoundException
- Raises
InvalidArgumentsException
- drop_primary_index(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(bucket_name, *options, **kwargs)[source]¶
Fetches all indexes from the server.
- Parameters
bucket_name (str) – the name of the bucket.
options (GetAllQueryIndexOptions) – Options to use for getting all indexes.
kwargs (Any) – Override corresponding value in options.
- Return type
List
[QueryIndex
]- Returns
A list of QueryIndex objects.
- Raises
InvalidArgumentsException
- watch_indexes(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).
options (WatchQueryIndexOptions) – Options for request to watch indexes.
kwargs (Any) – Override corresponding valud in options.
- Raises
QueryIndexNotFoundException
- Raises
WatchQueryIndexTimeoutException