atlasbroker package¶
Subpackages¶
Submodules¶
atlasbroker.backend module¶
Backend module
Used by the broker and all sub-modules to - expose few common services (Storage, Config, Atlas, …) - dispatch some calls
-
class
atlasbroker.backend.
AtlasBrokerBackend
(config)¶ Bases:
object
Backend for the Atlas Broker
Expose all services to serve Broker requests
Constructor
Parameters: config (Config) – Configuration of the Atlas Broker -
bind
(binding, parameters)¶ Binding to an instance
Parameters: - binding (AtlasServiceBinding.Binding) – Existing or New binding
- parameters (dict) – Parameters for the binding
Returns: Status
Return type:
-
create
(instance, parameters, existing=True)¶ Create an instance
Parameters: - instance (AtlasServiceInstance.Instance) – Existing or New instance
- parameters (dict) – Parameters for the instance
Keyword Arguments: existing (bool) – True (use an existing cluster), False (create a new cluster)
Returns: Status
Return type: ProvisionedServiceSpec
-
delete
(instance)¶ Delete an instance
Parameters: instance (AtlasServiceInstance.Instance) – Existing instance Returns: Status Return type: DeprovisionServiceSpec
-
find
(_id, instance=None)¶ Find
Parameters: _id (str) – instance id or binding Id Keyword Arguments: instance (AtlasServiceInstance.Instance) – Existing instance Returns: An instance or binding. Return type: AtlasServiceInstance.Instance or AtlasServiceBinding.Binding
-
unbind
(binding)¶ Unbinding an instance
Parameters: binding (AtlasServiceBinding.Binding) – Existing binding
-
atlasbroker.broker module¶
broker module
atlasbroker.config module¶
config module
Permit to manage global configurations
-
class
atlasbroker.config.
Config
(atlas_credentials, mongo_credentials, clusters=None)¶ Bases:
object
Configuration for AtlasBroker and sub-modules
This class can be overriden and so adapted by every compagnies to set different policy about naming convention, password generation etc.
- You should check those main functions used by the broker:
- generate_instance_dbname generate_binding_credentials generate_binding_username generate_binding_permissions
Constructor
Parameters: - atlas_credentials (dict) – Atlas credentials eg: {“userame” : “”, “password”: “”, “group”: “”}
- mongo_credentials (dict) – Mongo credentials eg: {“uri”: “”, “db”: “”, “timeoutms”: 5000, “collection”: “”}
Keyword Arguments: clusters (list) – List of cluster with uri associated. If not provided, it will be populate from Atlas.
-
PARAMETER_CLUSTER
= 'cluster'¶
-
PARAMETER_DATABASE
= 'database'¶
-
UUID_PLANS_EXISTING_CLUSTER
= '8db474d1-3cc0-4f4d-b864-24e3bd49b874'¶
-
UUID_SERVICES_CLUSTER
= '2a04f349-4aab-4fcb-af6d-8e1749a77c13'¶
-
generate_binding_credentials
(binding)¶ Generate binding credentials
This function will permit to define the configuration to connect to the instance. Those credentials will be stored on a secret and exposed to a a Pod.
We should at least returns the ‘username’ and ‘password’.
Parameters: binding (AtlasServiceBinding.Binding) – A binding Returns: All credentials and secrets. Return type: dict Raises: ErrClusterConfig
– Connection string to the cluster is not available.
-
generate_binding_permissions
(binding, permissions)¶ Generate Users pemissions on the database
Defining roles to the database for the users. We can pass extra information into parameters of the binding if needed (see binding.parameters).
Parameters: - binding (AtlasServiceBinding.Binding) – A binding
- permissions (atlasapi.specs.DatabaseUsersPermissionsSpecs) – Permissions for Atlas
Returns: Permissions for the new user
Return type: atlasapi.specs.DatabaseUsersPermissionsSpecs
-
generate_binding_username
(binding)¶ Generate binding username
We don’t need anything static here. The UUID is a good way to create a username.
IMPORTANT: Multiple calls of this function with the same binding should return the same username.
Parameters: binding (AtlasServiceBinding.Binding) – A binding Returns: The username to the database Return type: str
-
generate_instance_dbname
(instance)¶ Generate a Database name
This function permit to define the database name for this instance.
IMPORTANT: Multiple calls of this function with the same instance should return the same database name.
The UUID is a good way to set it but if you need to share a database accross multiple namespaces, you need to return a static name independant of the UUID. It is not possible in the current broker api to bind to an instance from another namespace. So each namespace need its own instance object despite that we want to share a database.
Atlas Broker is able to manage muliple instance UUID set to a unique database with a static name.
You have 2 way to do it: - You can create each instance with the same parameters and to generate a static name based on those parameters only. - You can set a static name directly on instance parameters with the key value of Config.PARAMETER_DATABASE. If this key exists, this function will never be called.
Parameters: instance (AtlasServiceInstance.Instance) – An instance Returns: The database name Return type: str
-
isGenerateBindingCredentialsPredictible
()¶ Is generate_binding_credentials predictible ?
Permit to know if generate_binding_credentials call will generate same credentials for every calls with the same binding parameter.
During the binding, the first bind will send a 201 Created response with credentials in the paylod. All other calls to bind with same parameters should return a 200 OK with credentials payload. If a call to bind with different parameters is done, a 409 is returned without credentials payload.
However, some brokers do not respect 201/200/409 and some broker like UPS one will just send 200 for everything.
To better handle and/or workaround specs, we need to know if generate_binding_credentials for an identical binding will return the same credentials. That will permit the broker to decide if it can return credentials with 200 when it firstly created them with a 201 or to workaround the answer to avoid the service catalog to inject inaccurate credentials.
In the best world, it should be good to be able to generate “static” credentials and set the return to True on this function.
-
load_json
()¶ Load JSON file
Parameters: json_file (str) – filename of a json file Returns: content of the file Return type: dict
atlasbroker.errors module¶
errors module
All Specific Exceptions
-
exception
atlasbroker.errors.
ErrClusterConfig
(cluster)¶ Bases:
Exception
Cluster configuration not found
We need the configuration during the binding to set the connection string
Constructor
Parameters: cluster (str) – Atlas cluster name
-
exception
atlasbroker.errors.
ErrClusterNotFound
(cluster)¶ Bases:
Exception
Cluster not found
Constructor
Parameters: cluster (str) – Atlas cluster name
-
exception
atlasbroker.errors.
ErrPlanUnsupported
(plan_id)¶ Bases:
Exception
Plan not supported
Constructor
Parameters: plan_id (str) – UUID of the plan
-
exception
atlasbroker.errors.
ErrStorageFindInstance
(instance_id)¶ Bases:
Exception
Failed to find the instance
Constructor
Parameters: instance_id (str) – UUID of the instance
-
exception
atlasbroker.errors.
ErrStorageMongoConnection
(during)¶ Bases:
Exception
The storage is not able to communicate with MongoDB
Constructor
Parameters: during (str) – When the issue occurs
-
exception
atlasbroker.errors.
ErrStorageRemoveBinding
(binding_id)¶ Bases:
Exception
Failed to remove the binding
Constructor
Parameters: binding_id (str) – UUID of the binding
-
exception
atlasbroker.errors.
ErrStorageRemoveInstance
(instance_id)¶ Bases:
Exception
Failed to remove the instance
Constructor
Parameters: instance_id (str) – UUID of the instance
-
exception
atlasbroker.errors.
ErrStorageStore
¶ Bases:
Exception
Failed to store the instance or binding
-
exception
atlasbroker.errors.
ErrStorageTypeUnsupported
(type_obj)¶ Bases:
Exception
Type unsupported
Constructor
Parameters: type_obj (type) – Type of the object not supported (type(obj))
atlasbroker.service module¶
service module
Core of the Atlas broker
-
class
atlasbroker.service.
AtlasBroker
(config)¶ Bases:
openbrokerapi.service_broker.ServiceBroker
Atlas Broker
Implement a service broker by overriding methods of Service
Constructor
Parameters: config (config) – Configuration of the broker -
bind
(instance_id: str, binding_id: str, details: openbrokerapi.service_broker.BindDetails) → openbrokerapi.service_broker.Binding¶ Binding the instance
see openbrokerapi documentation
-
catalog
()¶ Returns the services information which is provided by this broker.
Returns: Service
-
deprovision
(instance_id: str, details: openbrokerapi.service_broker.DeprovisionDetails, async_allowed: bool) → openbrokerapi.service_broker.DeprovisionServiceSpec¶ Deprovision an instance
see openbrokerapi documentation
Raises: ErrInstanceDoesNotExist
– Instance does not exist.
-
last_operation
(instance_id: str, operation_data: str) → openbrokerapi.service_broker.LastOperation¶ Last Operation
Not implemented. We are not using asynchronous operation on Atlas Broker.
Raises: NotImplementedError
-
provision
(instance_id: str, service_details: openbrokerapi.service_broker.ProvisionDetails, async_allowed: bool) → openbrokerapi.service_broker.ProvisionedServiceSpec¶ Provision the new instance
see openbrokerapi documentation
Returns: ProvisionedServiceSpec
-
unbind
(instance_id: str, binding_id: str, details: openbrokerapi.service_broker.UnbindDetails)¶ Unbinding the instance
see openbrokerapi documentation
Raises: ErrBindingDoesNotExist
– Binding does not exist.
-
update
(instance_id: str, details: openbrokerapi.service_broker.UpdateDetails, async_allowed: bool) → openbrokerapi.service_broker.UpdateServiceSpec¶ Update
Not implemented. Not used by Kubernetes Service Catalog.
Raises: NotImplementedError
-
atlasbroker.servicebinding module¶
servicebinding module
Used to manage binding requests
-
class
atlasbroker.servicebinding.
AtlasServiceBinding
(backend)¶ Bases:
object
Service Catalog : Atlas Service Binding
Constructor
Parameters: backend (AtlasBrokerBackend) – Atlas Broker Backend -
class
Binding
(binding_id, instance)¶ Bases:
object
Constructor
Parameters: - binding_id (str) – UUID of the binding
- instance (AtlasServiceInstance.Instance) – An instance
-
isProvisioned
()¶ was it populated from the storage ?
Returns: True (populate from stored information), False (This is a new instance) Return type: bool
-
bind
(binding, parameters)¶ Create the binding
Parameters: - binding (AtlasServiceBinding.Binding) – Existing or New binding
- parameters (dict) – Parameters for the binding
Returns: Status
Return type: Raises: ErrBindingAlreadyExists
– If binding exists but with different parameters
-
find
(binding_id, instance)¶ find an instance
Create a new instance and populate it with data stored if it exists.
Parameters: - binding_id (string) – UUID of the binding
- instance (AtlasServiceInstance.Instance) – instance
Returns: A binding
Return type:
-
unbind
(binding)¶ Unbind the instance
Parameters: binding (AtlasServiceBinding.Binding) – Existing or New binding
-
class
atlasbroker.serviceinstance module¶
serviceinstance module
Used to manage instance requests
-
class
atlasbroker.serviceinstance.
AtlasServiceInstance
(backend)¶ Bases:
object
Service Catalog : Atlas Service Instance
Constructor
Parameters: backend (AtlasBrokerBackend) – Atlas Broker Backend -
class
Instance
(instance_id, backend, parameters=None)¶ Bases:
object
Constructor
Parameters: - instance_id (str) – UUID of the instance
- backend (AtlasBrokerBackend) – Atlas Broker Backend
Keyword Arguments: parameters (dict) – Parameters for the instance
-
get_cluster
()¶ Get the Atlas cluster
Returns: The Atlas cluster name Return type: str
-
get_dbname
()¶ Get the database name
Returns: The database name Return type: str
-
isProvisioned
()¶ was it populated from the storage ?
Returns: True (populate from stored information), False (This is a new instance) Return type: bool
-
create
(instance, parameters, existing)¶ Create the instance
Parameters: - instance (AtlasServiceInstance.Instance) – Existing or New instance
- parameters (dict) – Parameters for the instance
- existing (bool) – Create an instance on an existing Atlas cluster
Returns: Status
Return type: ProvisionedServiceSpec
Raises: ErrInstanceAlreadyExists
– If instance exists but with different parametersErrClusterNotFound
– Cluster does not exist
-
delete
(instance)¶ Delete the instance
Parameters: instance (AtlasServiceInstance.Instance) – an existing instance Returns: Status Return type: DeprovisionServiceSpec
-
find
(instance_id)¶ find an instance
Create a new instance and populate it with data stored if it exists.
Parameters: instance_id (str) – UUID of the instance Returns: An instance Return type: AtlasServiceInstance.Instance
-
class
atlasbroker.storage module¶
Storage module
-
class
atlasbroker.storage.
AtlasBrokerStorage
(uri, timeoutms, db, collection)¶ Bases:
object
Storage
Permit to store ServiceInstance and ServiceBinding into a MongoDB.
This is used for caching and to trace what is done by the broker. This is internally used to don’t create same instances/bindings and to return appropriate code like AlreadyExists That reducing the number of call to Atlas APIs too.
Constructor
Parameters: - uri (str) – MongoDB connection string
- timeoutms (int) – MongoDB requests timeout in ms
- db (str) – The DB name
- collection (str) – The collection name
Raises: ErrStorageMongoConnection
– Error during MongoDB communication.-
populate
(obj)¶ Populate
Query mongo to get information about the obj if it exists
Parameters: obj (AtlasServiceBinding.Binding or AtlasServiceInstance.Instance) – instance or binding
Raises: ErrStorageTypeUnsupported
– Type unsupported.ErrStorageMongoConnection
– Error during MongoDB communication.
-
remove
(obj)¶ Remove
Remove an object from the MongoDB storage for caching
Parameters: obj (AtlasServiceBinding.Binding or AtlasServiceInstance.Instance) – instance or binding Raises: ErrStorageTypeUnsupported
– Type unsupported.
-
remove_binding
(binding)¶ Remove a binding
Remove an object from the MongoDB storage for caching
Parameters: binding (AtlasServiceBinding.Binding) – binding
Raises: ErrStorageMongoConnection
– Error during MongoDB communication.ErrStorageRemoveBinding
– Failed to remove the binding
-
remove_instance
(instance)¶ Remove an instance
Remove an object from the MongoDB storage for caching
Parameters: instance (AtlasServiceInstance.Instance) – instance
Raises: ErrStorageMongoConnection
– Error during MongoDB communication.ErrStorageRemoveInstance
– Failed to remove the instance.
-
store
(obj)¶ Store
Store an object into the MongoDB storage for caching
Parameters: obj (AtlasServiceBinding.Binding or AtlasServiceInstance.Instance) – instance or binding
Returns: MongoDB _id
Return type: ObjectId
Raises: ErrStorageMongoConnection
– Error during MongoDB communication.ErrStorageTypeUnsupported
– Type unsupported.ErrStorageStore
– Failed to store the binding or instance.