Managing connections¶
The API exposes DSS connections, which can be created, modified and deleted through the API. These operations are restricted to API keys with the “admin rights” flag.
A list of the connections can by obtained with the list_connections method:
client = DSSClient(host, apiKey)
dss_connections = client.list_connections()
prettyprinter.pprint(dss_connections)
outputs
{ 'filesystem_managed': { 'allowManagedDatasets': True,
'allowMirror': False,
'allowWrite': True,
'allowedGroups': [],
'maxActivities': 0,
'name': 'filesystem_managed',
'params': { 'root': '${dip.home}/managed_datasets'},
'type': 'Filesystem',
'usableBy': 'ALL',
'useGlobalProxy': True},
'hdfs_root': { 'allowManagedDatasets': True,
'allowMirror': False,
'allowWrite': True,
'allowedGroups': [],
'maxActivities': 0,
'name': 'hdfs_root',
'params': {'database': 'dataik', 'root': '/'},
'type': 'HDFS',
'usableBy': 'ALL',
'useGlobalProxy': False},
'local_postgress': { 'allowManagedDatasets': True,
'allowMirror': False,
'allowWrite': True,
'allowedGroups': [],
'maxActivities': 0,
'name': 'local_postgress',
'params': { 'db': 'testdb',
'host': 'localhost',
'password': 'admin',
'port': '5432',
'properties': { },
'user': 'admin'},
'type': 'PostgreSQL',
'usableBy': 'ALL',
'useGlobalProxy': False},
...
}
Connections can be added:
new_connection_params = {'db':'mysql_test', 'host': 'localhost', 'password': 'admin', 'properties': { }, 'user': 'admin'}
new_connection = client.create_connection('test_connection', type='MySql', params=new_connection_params, usable_by='ALLOWED', allowed_groups=['data_scientists'])
prettyprinter.pprint(client.list_connections()['test_connection'])
outputs
{ 'allowManagedDatasets': True,
'allowMirror': True,
'allowWrite': True,
'allowedGroups': ['data_scientists'],
'maxActivities': 0,
'name': 'test_connection',
'params': { 'db': 'mysql_test',
'host': 'localhost',
'password': 'admin',
'properties': { },
'user': 'admin'},
'type': 'MySql',
'usableBy': 'ALLOWED',
'useGlobalProxy': True}
To modify a connection, it is advised to first retrieve the connection definition with a get_definition call, alter the definition, and set it back into DSS:
connection_definition = new_connection.get_definition()
connection_definition['usableBy'] = 'ALL'
connection_definition['allowWrite'] = False
new_connection.set_definition(connection_definition)
prettyprinter.pprint(new_connection.get_definition())
outputs
{ 'allowManagedDatasets': True,
'allowMirror': True,
'allowWrite': False,
'allowedGroups': ['data_scientists'],
'maxActivities': 0,
'name': 'test_connection',
'params': { 'db': 'mysql_test',
'host': 'localhost',
'password': 'admin',
'properties': { },
'user': 'admin'},
'type': 'MySql',
'usableBy': 'ALL',
'useGlobalProxy': True}
Connections can be deleted through their handle:
connection = client.get_connection('test_connection')
connection.delete()
Reference documentation¶
-
class
dataikuapi.dss.admin.
DSSConnection
(client, name)¶ A connection on the DSS instance
-
get_location_info
()¶ Gets information about this connection.
Note: this call requires either an admin API key or a personal API key that corresponds to a user who belongs to a group who has the rights to read connection details
Returns: a dict containing connection information
-
delete
()¶ Delete the connection
Note: this call requires an API key with admin rights
-
get_definition
()¶ Get the connection’s definition (type, name, params, usage restrictions) Note: this call requires an API key with admin rights
Returns: The connection definition, as a dict. The exact structure of the returned dict is not documented and depends on the connection type. Create connections using the DSS UI and call
get_definition()
to see the fields that are in it.
-
set_definition
(description)¶ Set the connection’s definition. Note: this call requires an API key with admin rights
You should only
set_definition()
using an object that you obtained throughget_definition()
, not create a new dict.:param dict the definition for the connection, as a dict.
-