Skip to main content

Python Client

Python version

The BlueMind Python client supports Python 2.7 or the current version of Python 3. We recommend Python 3 for all new projects.

Installation

The Python client is installed via pip, if possible in a virtual environment (virtualenv or venv) so as not to interfere with the system:

aptitude install python-pip pip install --upgrade setuptools pip install netbluemind5


:::tip[Client version]

Version history can be viewed on the Python Package Index site: https://pypi.org/project/netbluemind5/#history

:::

## Usage

### Authentication

The client is initialized with the BMClient class:

```bash
from netbluemind.python.client import BMClient

# BEGIN CONF
URL="http://localhost:8090/api"
# END CONF

f = open('/etc/bm/bm-core.tok', 'r')
KEY = f.readline()
f.close()

client = BMClient(URL, KEY)
  • URL : defines the access url to the BlueMind server; from the outside, the url will be https://bluemind.domain.net/api.
  • KEY : corresponds to the password or token of admin0; in this example, we use the admin0 token available on the server to have extended rights to the API. It is possible to authenticate as a user with :
    from netbluemind.python.client import BMClient

    # BEGIN CONF
    URL="http://localhost:8090/api"
    # END CONF

    client = BMClient(URL)
    client.login( login@domain.net', 'password')
It is also possible to use a user's API key instead of their password.

Usage

BMClient

The BMClient class is a helper which also provides access to the various classes for handling users, groups, etc. :

from netbluemind.python.client import BMClient

# BEGIN CONF
URL="http://localhost:8090/api"
# END CONF

client = BMClient(URL)
client.login("login@domain.net", "password")
print client.apiKey

iUser = client.users("domain.net")
user = iUser.byEmail("login@domain.net")
print user.value.login

Users

iUser (instance of IUser) lets you access and modify all user information (password, photo, contact, archived status, etc.). The various methods return an instance of an object ItemValue which provides access to the object in question via the valueattribute.

Domains

You can create or modify domains using the IDomains interface. When creating a domain, it's important that the domain uid is its name; this is how it's created:

domain = Domain()
domain.name = "local.lan"
domain.label = "local.lan"
domain.description = "Domain of " + "local.lan"
domain.properties = {}
# global must always be set to False
domain.global_ = False
# defines domain aliases
domain.aliases = []

idomains.create("local.lan", domain)

Parameter settings for ImportLDAP and ImportAD add-ons can be defined using the properties attribute. Example with LDAP :

properties = dict()
properties['import_ldap_hostname'] = 'ldap.local'
properties['import_ldap_password'] = 'ldap-password'
properties['import_ldap_user_filter'] = '(mail=\*)'
properties['import_ldap_accept_certificate'] = True
properties['import_ldap_ext_id_attribute'] = 'entryUUID'
properties['import_ldap_relay_mailbox_group'] = ''
properties['import_ldap_enabled'] = True
properties['import_ldap_group_filter'] = '(objectClass=posixGroup)'
properties['import_ldap_protocol'] = 'tls'
properties['import_ldap_base_dn'] = 'dc=lan,dc=local'
properties['import_ldap_login_dn'] = 'uid=admin,cn=users,cn=accounts,dc=lan,dc=local'
properties['lang'] = 'en'
properties['im_public_auth'] = True # allow Instant messaging for all users
properties['domain_max_users'] = None
properties['mail_routing_relay'] = ''
properties['mailbox_max_user_quota'] = '0'
properties['mailbox_default_user_quota'] = '0'
properties['mailbox_max_publicfolder_quota'] = '0'
properties['mailbox_default_publicfolder_quota'] = '0'
properties['filehosting_max_filesize'] = '0'
properties['filehosting_retention'] = '365'
properties['mail_autoDetachmentLimit'] = '0'
properties['mail_forward_unknown_to_relay'] = False

Import AD

For an Active Directory import, simply remplace ldap with ad.

Examples

Many examples of possibilities are available in the BlueMind repository: https://gitlab.bluemind.net/bluemind-public/bluemind-samples/-/tree/master/python-api-examples

Starting a backup

client = BMClient(URL, KEY)
idataprotect = client.instance(IDataProtect)

taskRef = idataprotect.saveAll()
status = client.waitTask(taskRef)
print "\nBackup done with status [" + status.state.value + "]"