Adding a new route for epoptes-srv.

This commit is contained in:
Emiliano Vavassori 2015-09-11 21:01:50 +02:00
parent 8ff650ab6d
commit 32c368acaa
2 changed files with 20 additions and 7 deletions

View File

@ -43,13 +43,13 @@ Actually, the server responds to the following routes:
network. network.
* `/vaultpass`: provides encrypted password for the decription of vaulted * `/vaultpass`: provides encrypted password for the decription of vaulted
files within [Ansible configuration repository][client-pull-installation]. files within [Ansible configuration repository][client-pull-installation].
* `/ansible_list`: replies with the hostname list to be used with a dynamic
## TODO List ## inventory script for Ansible, please see [this
page][ansible-dynamic-inventory].
* Implement methods for dynamic inventory for Ansible * `/ansible_host`: receives a `host` parameter, but returns anyways additional
* Verify RPM packaging to automatically start daemon as soon as it is variables based on the MAC address of the client contacting it, to be used
installed with dynamic inventory script for Ansible and `ansible-pull`.
* Verify NethServer script for `runlevel-adjust` * `/epoptes-srv`: replies with the hostname of the local [Epoptes][epoptes] controller.
[bglug]: http://bglug.it "BgLUG Homepage" [bglug]: http://bglug.it "BgLUG Homepage"
[ubuntu]: http://www.ubuntu.com [ubuntu]: http://www.ubuntu.com
@ -62,3 +62,5 @@ Actually, the server responds to the following routes:
[sqlite]: https://www.sqlite.org/ [sqlite]: https://www.sqlite.org/
[gplv2]: https://www.gnu.org/licenses/gpl-2.0.html [gplv2]: https://www.gnu.org/licenses/gpl-2.0.html
[enrico bacis]: https://github.com/enricobacis [enrico bacis]: https://github.com/enricobacis
[ansible-dynamic-inventory]: http://docs.ansible.com/ansible/developing_inventory.html
[epoptes]: http://www.epoptes.org/

View File

@ -63,6 +63,7 @@ class MyApp:
self.__app.get('/vaultpass', callback=self.vaultpass) self.__app.get('/vaultpass', callback=self.vaultpass)
self.__app.get('/ansible_list', callback=self.ansible_list) self.__app.get('/ansible_list', callback=self.ansible_list)
self.__app.get('/ansible_host', callback=self.ansible_host) self.__app.get('/ansible_host', callback=self.ansible_host)
self.__app.get('/epoptes-srv', callback=self.epoptes_srv)
def __init_tables(self): def __init_tables(self):
with self.__getcursor() as cursor: with self.__getcursor() as cursor:
@ -204,6 +205,16 @@ class MyApp:
role = self.__getrole() role = self.__getrole()
return dumps(self.__rolevars(role)) return dumps(self.__rolevars(role))
def epoptes_srv(self):
hostname = None
try:
with self.__getcursor() as cursor:
(hostname,) = cursor.execute('SELECT hostname FROM client WHERE role = \'docenti\' ORDER BY id DESC LIMIT 1').fetchone()
except TypeError:
return 'none'
return hostname
def start(self): def start(self):
# Opens up a PID file # Opens up a PID file
pid = os.getpid() pid = os.getpid()