Python scripting UCS


I want to automate DNS updates using a Python script. What’s the best way to procede? By re-using existing Univention Python modules below /usr/lib/python3/dist-packages/univention/admin or by exec’ing the command line tools and parsing the output? And if the former: how? The latter seems a little primitive to me.

At the moment, I get the necessary data as a JSON but I could also provide it as a CSV table.


Hello Masin,

using the interface of univention.admin is very error prone. Instead use the univention.udm package:

>>> from univention.udm import UDM
>>> dns_forward_mod = UDM.admin().version(1).get("dns/forward_zone")
>>> for obj in
...   print(obj)
GenericObject('dns/forward_zone', 'zoneName=uni.dtr,cn=dns,dc=uni,dc=dtr')

>>> dns_host_mod = UDM.admin().version(1).get("dns/host_record")
>>> for obj in"relativeDomainName=*7*"):
...   print(obj)
GenericObject('dns/host_record', 'relativeDomainName=m70,zoneName=uni.dtr,cn=dns,dc=uni,dc=dtr')
GenericObject('dns/host_record', 'relativeDomainName=b71,zoneName=uni.dtr,cn=dns,dc=uni,dc=dtr')

Object values are what you see on the cmdline:

obj.dn: 'relativeDomainName=b71,zoneName=uni.dtr,cn=dns,dc=uni,dc=dtr'
obj.options: ['default']
obj.policies: []
obj.position: 'zoneName=uni.dtr,cn=dns,dc=uni,dc=dtr'
obj.props.a: [''] [] 'b71'
obj.props.txt: []
obj.props.zonettl: None
obj.superordinate: 'zoneName=uni.dtr,cn=dns,dc=uni,dc=dtr'

After changing a property run to write the changes to LDAP.

Daniel Tröder

1 Like

That looks very promising! Thank you very much!