From b2aa1f8417138797dddf3813fcaed9b5ea4ba611 Mon Sep 17 00:00:00 2001 From: Wilder Rodrigues Date: Tue, 27 Oct 2015 13:31:31 +0100 Subject: [PATCH] CLOUDSTACK-8957 - Implement password server in configure.py --- .../debian/config/opt/cloud/bin/configure.py | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/systemvm/patches/debian/config/opt/cloud/bin/configure.py b/systemvm/patches/debian/config/opt/cloud/bin/configure.py index 8c39f75247c..20477443806 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/configure.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/configure.py @@ -41,27 +41,37 @@ from cs.CsApp import CsApache, CsDnsmasq from cs.CsMonitor import CsMonitor from cs.CsLoadBalancer import CsLoadBalancer from cs.CsConfig import CsConfig +from cs.CsProcess import CsProcess class CsPassword(CsDataBag): - """ - Update the password cache - - A stupid step really as we should just rewrite the password server to - use the databag - """ - cache = "/var/cache/cloud/passwords" - + + TOKEN_FILE="/tmp/passwdsrvrtoken" + def process(self): - file = CsFile(self.cache) for item in self.dbag: if item == "id": continue - self.__update(file, item, self.dbag[item]) - file.commit() + self.__update(item, self.dbag[item]) - def __update(self, file, ip, password): - file.search("%s=" % ip, "%s=%s" % (ip, password)) + def __update(self, vm_ip, password): + token = "" + try: + tokenFile = open(self.TOKEN_FILE) + token = tokenFile.read() + except IOError: + logging.debug("File %s does not exist" % self.TOKEN_FILE) + + ips_cmd = "ip addr show | grep inet | awk '{print $2}'" + ips = CsHelper.execute(ips_cmd) + for ip in ips: + server_ip = ip.split('/')[0] + proc = CsProcess(['/opt/cloud/bin/passwd_server_ip.py', server_ip]) + if proc.find(): + update_command = 'curl --header "DomU_Request: save_password" "http://{SERVER_IP}:8080/" -F "ip={VM_IP}" -F "password={PASSWORD}" ' \ + '-F "token={TOKEN}" >/dev/null 2>/dev/null &'.format(SERVER_IP=server_ip, VM_IP=vm_ip, PASSWORD=password, TOKEN=token) + result = CsHelper.execute(update_command) + logging.debug("Update password server result ==> %s" % result) class CsAcl(CsDataBag):