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 netbluemind5
yum install python-pip
pip install --upgrade setuptools
pip install netbluemind5
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 netbluemind5
## Usage
### Authentication
The client is initialized with the BMClient class:
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're using the admin0 token available on the server, in order 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')
*NB: Note that it is also possible to use a user's API key instead of their password.*
### Usage
#### BMClient
The BMClient class is a *helper* that also provides access to various classes for manipulating 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 *value* attribute.
#### Domains
Domains can be created or modified using the *IDomains* interface.
When creating a domain, it is important that the domain uid is equal to the domain name:
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
is used to define domain aliases
domain.aliases = []
idomains.create("local.lan", domain)
→ Parameter settings for *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
:::note[Import AD]
To import Active Directory, simply replace *ldap* with *ad*.
:::
### Examples
Numerous examples of the possibilities are available in the BlueMind repository: [https://forge.bluemind.net/stash/projects/BA/repos/bluemind-samples/browse/python-api-examples](https://forge.bluemind.net/stash/projects/BA/repos/bluemind-samples/browse/python-api-examples)
#### Start 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 + "]"