Python Client
Python version
The BlueMind python client supports python 2.7 or the current version of python 3. We recommend that you use Python 3 for all new projects, Python 2 being on the way out.
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.
- Debian/Ubuntu
- CentOS/Redhat
- macOS
aptitude install python-pip
pip install --upgrade setuptools
pip install netbluemind4
yum install python-pip
pip install --upgrade setuptools
pip install netbluemind4
curl -O https://bootstrap.pypa.io/get-pip.py
sudo /usr/bin/python get-pip.py
sudo /usr/local/bin/pip install --upgrade pip
pip install --upgrade setuptools
sudo /usr/local/bin/pip install netbluemind4
Usage
Authentication
The client uses the BMClient class to start:
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 behttps://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')
Note: 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 is important that the uid of the domain is equal to its name; this is how it is created:
domain = Domain()
domain.name = "local.lan"
domain.label = "local.lan"
domain.description = "Domain of " + "local.lan"
domain.properties = {}
# global doit toujours être à False
domain.global_ = False
# permet de définir les alias du domaine
domain.aliases = []
idomains.create("local.lan", domain)
→ Parameter settings for the ImportLDAP and ImportAD plugins can be defined using the properties attribute:
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'] = 'fr'
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
For an Active Directory import, simply remplace ldap with ad.
Examples
Many examples of possibilities are available in the BlueMind repository: https://forge.bluemind.net/stash/projects/BA/repos/bluemind-samples/browse/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 + "]"