def active_controller(self): pool = eventlet.greenpool.GreenPool() coroutines = {} active = None standby_offline = [] for controller in self.controllers: coroutines[controller] = pool.spawn(self.auth, controller) while coroutines: completed = None for controller in coroutines.keys(): if coroutines[controller].dead: completed = controller break eventlet.sleep(0.1) if completed: coro = coroutines.pop(completed) try: cookie = coro.wait() url = 'core/controller/role' res = rest_lib.get(cookie, url, controller, self.port)[2] if 'active' in res: active = controller self.cookie = cookie else: standby_offline.append((cookie, controller)) self.logout(cookie, controller) except: standby_offline.append(('', controller)) if active: pool.spawn(self.cleanup_remaining, standby_offline, coroutines) return active # none responded in time, return first in list return self.controllers[0]
def _initSystem(self): logger.info("[Stage %d] Initializing system" % self._nextStage()) # Set admin password pw = urllib.quote(self.configMap[pdesc.PARAM_MASTER_PASSWORD], '') hp = json.loads( rest_lib.get("core/aaa/hash-password[password=\"%s\"]" % (pw))) if len(hp) == 0: raise Exception("Failed to update password") rest_lib.put("core/aaa/local-user[user-name=\"admin\"]/password", json.dumps(hp[0]['hashed-password'])) # Set recovery password setPass = { "user-name": "recovery", "password": self.configMap[pdesc.PARAM_RECOVERY_PASSWORD] } rest_lib.post("os/action/system-user/reset-password", json.dumps(setPass)) # Initialize SSL certificate and SSH key logger.info(" Generating cryptographic keys") regenerateKeys = {"action": ["web-ssl", "ssh"]} rest_lib.post("os/action/services/regenerate-keys", json.dumps(regenerateKeys))
def getTestPath(self, src, dst): url = (URL_TEST_PATH % {'src-tenant': src['tenant'], 'src-segment': src['segment'], 'src-ip': src['ip'], 'dst-ip': dst['ip']}) controller = self.active_controller ret = rest_lib.get(self.cookie, url, controller, self.port) data = list() if ret[0] in range(200, 300): data = json.loads(ret[2]) return data
def getTestPath(self, src, dst): url = (URL_TEST_PATH % { 'src-tenant': src['tenant'], 'src-segment': src['segment'], 'src-ip': src['ip'], 'dst-ip': dst['ip'] }) controller = self.active_controller ret = rest_lib.get(self.cookie, url, controller, self.port) data = list() if ret[0] in range(200, 300): data = json.loads(ret[2]) return data
def _initSystem(self): logger.info("[Stage %d] Initializing system" % self._nextStage()) # Set admin password pw = urllib.quote(self.configMap[pdesc.PARAM_MASTER_PASSWORD], '') hp = json.loads(rest_lib.get("core/aaa/hash-password[password=\"%s\"]" % (pw))) if len(hp) == 0: raise Exception("Failed to update password") rest_lib.put("core/aaa/local-user[user-name=\"admin\"]/password", json.dumps(hp[0]['hashed-password'])) # Set recovery password setPass = {"user-name": "recovery", "password": self.configMap[pdesc.PARAM_RECOVERY_PASSWORD]} rest_lib.post("os/action/system-user/reset-password", json.dumps(setPass)) # Initialize SSL certificate and SSH key logger.info(" Generating cryptographic keys") regenerateKeys = {"action": ["web-ssl", "ssh"]} rest_lib.post("os/action/services/regenerate-keys", json.dumps(regenerateKeys))
def _getClusterStatus(self): cs = json.loads(rest_lib.get("cluster/status")) if (len(cs) > 0): self.clusterStatus = cs[0] else: self.clusterStatus = None