Nested class for atlasapi.atlas::Atlas

Atlas._Clusters

class Atlas._Clusters(atlas)

Bases: object

Clusters API

see: https://docs.atlas.mongodb.com/reference/api/clusters/

Constructor

Parameters

atlas (Atlas) – Atlas instance

create_basic_rs(name: str, size: InstanceSizeName = InstanceSizeName.M10, disk_size: int = 10, provider: ProviderName = ProviderName.AWS, region: str = 'US_WEST_2', version: MongoDBMajorVersion = MongoDBMajorVersion.v4_0) AtlasBasicReplicaSet

Simplified method for creating a basic replica set with basic options.

Return type

AtlasBasicReplicaSet

Parameters
  • name (str) – The name for the cluster

  • size (InstanceSizeName) – The Atlas Instance size, found in The InstanceSizeName enum

  • disk_size (int) – The size in GB for disk

  • provider (ProviderName) – The cloud provider, found in ProviderName enum

  • region (str) – The provider region to place the cluster.

  • version (MongoDBMajorVersion) – The mongodb major version (enum)

Returns

AtlasBasicReplicaSet

create_cluster(cluster: ClusterConfig) dict

Create a cluster

url: POST /api/atlas/v1.0/groups/{GROUP-ID}/clusters

Parameters

cluster (ClusterConfig) – A Cluster Config Object

Returns

Response payload

Return type

dict

delete_cluster(cluster: str, areYouSure: bool = False)

Delete a Cluster

url: https://docs.atlas.mongodb.com/reference/api/clusters-delete-one/

Parameters

cluster (str :param cluster: Cluster name :param areYouSure: safe flag to don’t delete a cluster by mistake) – Cluster name

Keyword Arguments

areYouSure (bool) – safe flag to don’t delete a cluster by mistake

Returns

Response payload

Return type

dict

Raises

ErrConfirmationRequested – Need a confirmation to delete the cluster

Raises

type areYouSure: bool

get_all_clusters(pageNum=1, itemsPerPage=500, iterable=False)

Get All Clusters

url: https://docs.atlas.mongodb.com/reference/api/clusters-get-all/

Keyword Arguments
  • pageNum (int) – Page number

  • itemsPerPage (int) – Number of Users per Page

  • iterable (bool) – To return an iterable high level object instead of a low level API response

Returns

Iterable object representing this function OR Response payload

Return type

AtlasPagination or dict

Raises

ErrPaginationLimits – Out of limits

get_single_cluster(cluster: str) dict

Get a Single Cluster

url: https://docs.atlas.mongodb.com/reference/api/clusters-get-one/

Parameters

cluster (str) – The cluster name

Returns

Response payload

Return type

dict

get_single_cluster_advanced_options(cluster: str, as_obj: bool = True) Union[dict, AdvancedOptions]

Retrieves advanced options from a cluster, either as a obj, or optionally as a dict.

GET /groups/{GROUP-ID}/clusters/{CLUSTER-NAME}/processArgs

Parameters
  • cluster (str) –

  • as_obj (bool) – True to return, AdvancedOptions, false for a dict

Returns

AdvancedOptions object or dict

get_single_cluster_as_obj(cluster) Union[ClusterConfig, ShardedClusterConfig]

Get a Single Cluster as data

url: https://docs.atlas.mongodb.com/reference/api/clusters-get-one/

Parameters

cluster (str) – The cluster name

Returns

Response payload

Return type

ClusterConfig

is_existing_cluster(cluster) bool

Check if the cluster exists

Not part of Atlas api but provided to simplify some code

Parameters

cluster (str) – The cluster name

Returns

The cluster exists or not

Return type

bool

modify_cluster(cluster: str, cluster_config: Union[ClusterConfig, dict]) dict

Modify a Cluster

Modifies an existing cluster in the project. Either from a full ClusterConfig object, or from a simple dict which contains the elements desired.

url: https://docs.atlas.mongodb.com/reference/api/clusters-modify-one/

Return type

dict

Parameters
  • cluster (str) – The name of the cluster to modify

  • cluster_config – A ClusterConfig object containing the new configuration, or a dict containing fragment.

Returns

dict: A dictionary of the new cluster config

modify_cluster_advanced_options(cluster: str, advanced_options: AdvancedOptions, as_obj: bool = True) Union[AdvancedOptions, dict]

Modifies cluster advanced options using a AdvancedOptions object.

PATCH /groups/{GROUP-ID}/clusters/{CLUSTER-NAME}/processArgs

Parameters
  • cluster (str) – The clutster name

  • advanced_options (AdvancedOptions) – An AdvancedOptions object with the options to be set.

  • as_obj (bool) – Return the new AdvancedOptions as an object.

Returns

modify_cluster_instance_size(cluster: str, new_cluster_size: InstanceSizeName) dict

Modifies existing cluster by changing only the instance size.

Helper function using modify_cluster :rtype: dict :type new_cluster_size: InstanceSizeName :type cluster: str :param cluster: The cluster name :param new_cluster_size: InstanceSizeName: The new size to use. :return: dict: the new cluster configuration dict

modify_cluster_tls(cluster: str, TLS_protocol: TLSProtocols, as_obj: bool = True) TLSProtocols

Modifies cluster TLS settings.

pause_cluster(cluster: str, toggle_if_paused: bool = False) dict

Pauses/Unpauses a cluster.

If you wish to unpause, set the toggle_if_paused param to True. :rtype: dict :type toggle_if_paused: bool :type cluster: str :param cluster: The name of the cluster :param toggle_if_paused: Set to true to unpause a paused clsuter. :return: dict: The updated config

test_failover(cluster: str) Optional[dict]

Triggers a primary failover for a cluster

Used for testing cluster resiliency.

Return type

dict

Parameters

cluster (str) –

Returns

And empty dict

Atlas._DatabaseUsers

class Atlas._DatabaseUsers(atlas)

Bases: object

Database Users API

see: https://docs.atlas.mongodb.com/reference/api/database-users/

Constructor

Parameters

atlas (Atlas) – Atlas instance

create_a_database_user(permissions) dict

Create a Database User

url: https://docs.atlas.mongodb.com/reference/api/database-users-create-a-user/

Parameters

permissions (DatabaseUsersPermissionsSpec) – Permissions to apply

Returns

Response payload

Return type

dict

delete_a_database_user(user: str) dict

Delete a Database User

url: https://docs.atlas.mongodb.com/reference/api/database-users-delete-a-user/

Parameters

user (str) – User to delete

Returns

Response payload

Return type

dict

get_a_single_database_user(user: str) dict

Get a Database User

url: https://docs.atlas.mongodb.com/reference/api/database-users-get-single-user/

Parameters

user (str) – User

Returns

Response payload

Return type

dict

get_all_database_users(pageNum: int = 1, itemsPerPage: int = 500, iterable: bool = False)

Get All Database Users

url: https://docs.atlas.mongodb.com/reference/api/database-users-get-all-users/

Keyword Arguments
  • pageNum (int) – Page number

  • itemsPerPage (int) – Number of Users per Page

  • iterable (bool) – To return an iterable high level object instead of a low level API response

Returns

Iterable object representing this function OR Response payload

Return type

AtlasPagination or dict

Raises

ErrPaginationLimits – Out of limits

update_a_database_user(user: str, permissions: DatabaseUsersUpdatePermissionsSpecs) dict

Update a Database User

url: https://docs.atlas.mongodb.com/reference/api/database-users-update-a-user/

Parameters
Returns

Response payload

Return type

dict

Atlas._Alerts

class Atlas._Alerts(atlas)

Bases: object

Alerts API

see: https://docs.atlas.mongodb.com/reference/api/alerts/

Constructor

Parameters

atlas (Atlas) – Atlas instance

acknowledge_an_alert(alert, until, comment=None)

Acknowledge an Alert

url: https://docs.atlas.mongodb.com/reference/api/alerts-acknowledge-alert/

Parameters
  • alert (str) – The alert id

  • until (datetime) – Acknowledge until

Keyword Arguments

comment (str) – The acknowledge comment

Returns

Response payload :param comment:

Return type

dict

acknowledge_an_alert_forever(alert, comment=None)

Acknowledge an Alert forever

url: https://docs.atlas.mongodb.com/reference/api/alerts-acknowledge-alert/

Parameters

alert (str) – The alert id

Keyword Arguments

comment (str) – The acknowledge comment

Returns

Response payload

Return type

dict

get_all_alerts(status=None, pageNum=1, itemsPerPage=500, iterable=False)

Get All Alerts

url: https://docs.atlas.mongodb.com/reference/api/alerts-get-all-alerts/

Keyword Arguments
  • status (AlertStatusSpec) – filter on alerts status

  • pageNum (int) – Page number

  • itemsPerPage (int) – Number of Users per Page

  • iterable (bool) – To return an iterable high level object instead of a low level API response

Returns

Iterable object representing this function OR Response payload

Return type

AtlasPagination or dict

Raises

ErrPaginationLimits – Out of limits

get_an_alert(alert: str) Alert

Get an Alert

url: https://docs.atlas.mongodb.com/reference/api/alerts-get-alert/

Parameters

alert (str) – The alert id

Returns

Response payload

Return type

dict

unacknowledge_an_alert(alert)

Acknowledge an Alert

url: https://docs.atlas.mongodb.com/reference/api/alerts-acknowledge-alert/

Parameters

alert (str) – The alert id

Returns

Response payload

Return type

dict

Atlas._MaintenanceWindows

class Atlas._MaintenanceWindows(atlas)

Bases: object

Maintenance Windows API

see: https://docs.atlas.mongodb.com/reference/api/maintenance-windows/

The maintenanceWindow resource provides access to retrieve or update the current Atlas project maintenance

window. To learn more about Maintenance Windows, see the Set Preferred Cluster Maintenance Start Time setting on the View/Modify Project Settings page.

Parameters

atlas (Atlas) – Atlas instance

current_config() MaintenanceWindow

The current Maintainable Window configuration.

Returns: MaintainableWindow object

defer() dict

Defers the currently scheduled maintenance window.

Returns: bool:

set_config(new_config: MaintenanceWindow) bool

Sets the maint configuration to the values in the passed MaintWindow Object

Will only set those values which are not none in the MaintWindow Object. Currently you can not use this method to set a value as null. (This is not supported by the API anyway)

Parameters

new_config – A MaintainenceWindow Object

Returns: bool: True is success

Atlas._Hosts

class Atlas._Hosts(atlas)

Bases: object

Hosts API

see: https://docs.atlas.mongodb.com/reference/api/monitoring-and-logs/#monitoring-and-logs

Constructor

Parameters

atlas (Atlas) – Atlas instance

property cluster_list: Set[str]

Returns a list of clusters found in the hosts for this group.

Returns

A set of cluster names

Return type

Set[str}

fill_host_list(for_cluster: Optional[str] = None) List[Host]

Fills the self.hostname property with the current hosts for the project/group.

Optionally, one can specify the for_cluster parameter to fill the host list with hosts only from the specified cluster.

Parameters

for_cluster (str) – The name of the cluster for filter the host list.

Returns

A lost of Host objects

Return type

List[Host]

get_log_for_host(host_obj: Host, log_name: AtlasLogNames = AtlasLogNames.MONGODB, date_from: Optional[datetime] = None, date_to: Optional[datetime] = None) BinaryIO

Retrieves the designated logfile archive of designated log_name and for the designated dates, and returns a binary file like object.

Parameters
  • host_obj (Host) – And atlas Host object to retrieve logs for

  • log_name (AtlasLogNames) – an AtlasLogNames type

  • date_from (datetime.datetime) – The datetime to start from

  • date_to (datetime.datetime) – The datetime to gather till

Returns

A BinaryIO object containing the gzipped log file.

Return type

BinaryIO

get_loglines_for_host(host_obj: Host, log_name: AtlasLogNames = AtlasLogNames.MONGODB, date_from: Optional[datetime] = None, date_to: Optional[datetime] = None) Iterable[LogLine]

Gathers the designated log file from Atlas, and then returns the lines therein contained.

Does so by downloading the gzip file into memory, ungzipping and then unpacking each log line as a LogLine Object.

Parameters
  • host_obj (Host) – An atlas Host object to retrive logs for

  • log_name (str) – an AtlasLogNames type

  • date_from (datetime) – The datetime to start from

  • date_to (datetime) – The datetime to gather till

Returns

Yeilds LogLine objects, one for each logline found in the file.

Return type

Iterable[LogLine]

get_logs_for_cluster(cluster_name: str, log_name: AtlasLogNames = AtlasLogNames.MONGODB, date_from: Optional[datetime] = None, date_to: Optional[datetime] = None) Iterable[Host]

Yields A Host object per Host in the passed cluster with a File-like objects containing the gzipped log file requested for each host in the project using the same date filters and log_name (type) in the log_files property.

Currently the log_file property (List) is usually with only one item. :param log_name: The type of log to be retrieved :type log_name: AtlasLogNames :param date_from: Start of log entries :type date_from: datetime :param date_to: End of log entries :type date_to: datetime

Returns

Yields Host objects, with full host information as well as the logfile in the log_files property.

Return type

Iterable[Host]

get_logs_for_project(log_name: AtlasLogNames = AtlasLogNames.MONGODB, date_from: Optional[datetime] = None, date_to: Optional[datetime] = None) Iterable[Host]

Yields A Host object per Host in the project with a File-like objects containing the gzipped log file requested for each host in the project using the same date filters and log_name (type) in the log_files property.

Currently the log_file property (List) is usually with only one item. :param log_name: The type of log to be retrieved :type log_name: AtlasLogNames :param date_from: Start of log entries :type date_from: datetime :param date_to: End of log entries :type date_to: datetime

Returns

Yields Host objects, with full host information as well as the logfile in the log_files property.

Return type

Iterable[Host]

get_measurement_for_hosts(granularity: Optional[AtlasGranularities] = None, period: Optional[AtlasPeriods] = None, measurement: Optional[AtlasMeasurementTypes] = None, return_data: bool = False)

Get measurement(s) for all hosts in the host_list

Populates all hosts in the host_list with the requested metric.

Multiple calls will append additional metrics to the same host object.

Please note that using the return_data param will also return the updated host objects, which may unnecessarily consume memory.

Keyword Arguments
host_list_by_cluster(cluster_name: str) Iterable[Host]

Returns hosts belonging to the named cluster. :param cluster_name: :type cluster_name: str

Returns

An interator of Host Objects.

Return type

Iterable[Host]

property host_list_primaries: Iterable[Host]

Yields only hosts which are currently primary.

property host_list_secondaries: Iterable[Host]

Yields only hosts which are currently secondaries.

property host_names: Iterable[str]

Returns a simple list of host names without port

Return type

Iterator[str]

update_host_list(host_obj: Host) None

Places a host into the host_list property.

Parameters

host_obj – Host: A host object with measurements.

Return type

None

Atlas._Events

class Atlas._Events(atlas)

Bases: object

Events API

see: https://docs.atlas.mongodb.com/reference/api/events/

Constructor

Parameters

atlas (Atlas) – Atlas instance

property all: ListOfEvents

Returns all events for the current project/group.

Returns

A list of event objects.

Return type

ListOfEvents

all_by_type(event_type: AtlasEventTypes) Iterable[AtlasEvent]

Returns all events for the passed AtlasEventType

Parameters

event_type (AtlasEventTypes) –

Returns

Iterable[AtlasEvent]

since(since_datetime: datetime) ListOfEvents

Returns all events since the passed datetime. (UTC)

Return type

ListOfEvents

since_by_type(since_datetime: datetime, event_type: AtlasEventTypes)

Returns all events since the passed detetime (UTC) for the passed AtlasEvent Type

Parameters
  • since_datetime (datetime) –

  • event_type (AtlasEventTypes) –

Returns:

Atlas._Whitelist

class Atlas._Whitelist(atlas)

Bases: object

Whitelist API

see: https://docs.atlas.mongodb.com/reference/api/whitelist/

Constructor

Parameters

atlas (Atlas) – Atlas instance

create_whitelist_entry(ip_address: str, comment: str) List[WhitelistEntry]

Create a whitelist entry

url: https://docs.atlas.mongodb.com/reference/api/whitelist-add-one/

Parameters
  • ip_address (str) – ip address to add to whitelist

  • comment (str) – comment describing the whitelist entry

Returns

Response payload

Return type

List[WhitelistEntry]

delete_a_whitelist_entry(ip_address: str) dict

Delete a whitelist entry

url: https://docs.atlas.mongodb.com/reference/api/whitelist-delete-one/

Parameters

ip_address (str) – ip address to delete from whitelist

Returns

Response payload

Return type

dict

get_all_whitelist_entries(pageNum: int = 1, itemsPerPage: int = 500, iterable: bool = False) Iterable[WhitelistEntry]

Get All whitelist entries

url: https://docs.atlas.mongodb.com/reference/api/whitelist-get-all/

Keyword Arguments
  • pageNum (int) – Page number

  • itemsPerPage (int) – Number of Users per Page

  • iterable (bool) – To return an iterable high level object instead of a low level API response

Returns

Iterable object representing this function OR Response payload

Return type

AtlasPagination or dict

Raises

ErrPaginationLimits – Out of limits

get_whitelist_entry(ip_address: str) WhitelistEntry

Get a whitelist entry

url: https://docs.atlas.mongodb.com/reference/api/whitelist-get-one-entry/

Parameters

ip_address (str) – ip address to fetch from whitelist

Returns

Response payload

Return type

WhitelistEntry

Atlas._CloudBackups

class Atlas._CloudBackups(atlas)

Bases: object

Cloud Backup API

see: https://docs.atlas.mongodb.com/reference/api/cloud-backup/backup/backups/

The CloudBackups resource provides access to retrieve the Cloud provider backup snapshots.

Parameters

atlas (Atlas) – Atlas instance

cancel_snapshot_restore_request(cluster_name: str, restore_id: str)

Cancels a current backup restore request by restore_id.

Calls: https://docs.atlas.mongodb.com/reference/api/cloud-backup/restore/delete-one-restore-job/

Parameters
  • cluster_name – The name of the source cluster.

  • restore_id – The id of the (jobId) of the restore job.

create_snapshot_for_cluster(cluster_name: str, retention_days: int = 7, description: Optional[str] = None, as_obj: bool = True) Union[CloudBackupSnapshot, dict]

Creates and on demand snapshot for the passed cluster

Parameters
  • as_obj

  • cluster_name

  • retention_days

  • description

get_backup_snapshot_for_cluster(cluster_name: str, snapshot_id: str, as_obj: bool = True) Union[Iterable[CloudBackupSnapshot], Iterable[dict]]

Get singe backup snapshot for a cluster.

Retrieves url: https://docs.atlas.mongodb.com/reference/api/cloud-backup/backup/backups/

Keyword Arguments

cluster_name (str) – The cluster name to fetch

Returns

Iterable object representing this function OR Response payload

Return type

AtlasPagination or dict

get_backup_snapshots_for_cluster(cluster_name: str, as_obj: bool = True) Union[Iterable[CloudBackupSnapshot], Iterable[dict]]

Get backup snapshots for a cluster.

Retrieves url: https://docs.atlas.mongodb.com/reference/api/cloud-backup/backup/backups/

Keyword Arguments

cluster_name (str) – The cluster name to fetch

Returns

Iterable object representing this function OR Response payload

Return type

AtlasPagination or dict

get_snapshot_restore_requests(cluster_name: str, restore_id: Optional[str] = None, as_obj: bool = True) Union[List[Union[dict, SnapshotRestoreResponse]], SnapshotRestoreResponse, dict]
is_existing_snapshot(cluster_name: str, snapshot_id: str) bool
request_snapshot_restore(source_cluster_name: str, snapshot_id: str, target_cluster_name: str, delivery_type: DeliveryType = DeliveryType.automated, allow_same: bool = False) SnapshotRestoreResponse
request_snapshot_restore_to_group(source_cluster_name: str, snapshot_id: str, target_cluster_name: str, target_group_obj, delivery_type: DeliveryType = DeliveryType.automated) SnapshotRestoreResponse

Requests a snapshot restore to another group/project.

Uses the passed target_group_obj, which is an Atlas object, to restore a snapshot from one group/project to another.

This method does not check if the source and destination clusters have the same name, since this would not be dangerous when these are in two groups.

Parameters
  • source_cluster_name – the text name of the source cluster

  • snapshot_id – the uuid id of the snapshot to be restored

  • target_cluster_name – the txt name of the destination cluster

  • target_group_obj – Atlas: An Atlas object connected to the destination group.

  • delivery_type – DeliveryType: IF you want to download, or automatically restore on Atlas.

Returns:

Atlas._Projects

class Atlas._Projects(atlas)

Bases: object

Atlas Projects

see: https://www.mongodb.com/docs/atlas/reference/api/projects/

The groups resource provides access to retrieve or create Atlas projects.

Parameters

atlas (Atlas) – Atlas instance

get_project_teams(group_id: Optional[str] = None) Iterable[TeamRoles]

Retrieves all teams assigned to the passed project/group

Returns each team assigned to the project, along with the roles which are assigned.

Returns (Iterable[TeamRoles]): Yields TeamRole Objects.

get_project_users(group_id: Optional[str] = None, flatten_teams: Optional[bool] = None, include_org_users: Optional[bool] = None) Iterable[AtlasUser]

Yields all users (AtlasUser objects) associated with the group_id.

Parameters
  • group_id (str) – The group id to search, will use the configured group for the Atlas instance if instantiated in this way.

  • flatten_teams (bool) – Flag that indicates whether the returned list should include users who belong to a team that is assigned a role in this project. You might not have assigned the individual users a role in this project.

  • include_org_users (bool) – Flag that indicates whether the returned list should include users with implicit access to the project through the Organization Owner or Organization Read Only role. You might not have assigned the individual users a role in this project.

Returns (Iterable[AtlasUser]: An iterable of AtlasUser objects.

project_by_id(project_id: str) Project

Return project by name

Parameters

project_id (str) – The project id (group_id) to return

Returns (Project): A single Project

project_by_name(project_name: str) Project

Return project by name

Parameters

project_name (str) – The project name to return

Returns (Project): A single Project

property projects: Iterable[Project]

All Projects accessible by the current authed user/key Gets all projects for which the authed key has access.

Returns (Iterable[Project]): Yields Project Objects.

property settings: ProjectSettings
user_count(group_id: Optional[str] = None, flatten_teams: Optional[bool] = None, include_org_users: Optional[bool] = None) int

Returns count of users added to this project

Parameters
  • group_id (str) – The group id to search, will use the configured group for the Atlas instance if

  • way. (instantiated in this) –

  • flatten_teams (bool) – Flag that indicates whether the returned list should include users who belong to a team that is assigned a role in this project. You might not have assigned the individual users a role in this project.

  • include_org_users (bool) –

    Flag that indicates whether the returned list should include users with implicit access to the project through the Organization Owner or Organization Read Only role. You

    might not have assigned the individual users a role in this project.

Returns (int): Count of users.

Atlas._Organizations

class Atlas._Organizations(atlas)

Bases: object

Atlas Organizations

see: https://www.mongodb.com/docs/atlas/reference/api/organizations/

TThe orgs resource provides access to manage Atlas organizations.

Parameters

atlas (Atlas) – Atlas instance

property count: int

Count of Organizations accessible by the authed user/key.

Returns (int):

get_all_projects_for_org(org_id: str) Iterable[Project]

Get projects related to the current Org

url: https://www.mongodb.com/docs/atlas/reference/api/organization-get-all-projects/

Parameters

org_id (str) – The organization id which owns the projects.

Returns

Iterable containing projects

Return type

Iterable[Project]

organization_by_id(org_id: str) Organization

Single organization searched by org_id.

Parameters

org_id (str) –

Returns (Organization): a single Organization object.

organization_by_name(org_name: str) Organization

Single organization searched by name.

Parameters

org_name – Organization name with which to filter the returned list. Performs a case-insensitive search for organizations which exactly match the specified name.

Returns (Organization): a single Organization object.

property organizations: Iterable[Organization]

All Organizations accessible by the current authed user/key Gets all Organizations for which the authed key has access.

Returns (Iterable[Organization]): Yields Organization Objects.