def ensure_connection(self): if self.__token is not None: RETOKEN_MARGIN = datetime.timedelta(minutes=5) now = datetime.datetime.utcnow() if self.__expires - now > RETOKEN_MARGIN: return self.__ms_info = self.get_ms_info() ms_info = self.__ms_info if ms_info is None: logger.error("Not found: MonitoringServerInfo.") raise hap.Signal() auth_url = ms_info.url + "/tokens" ext_info_type = haplib.MonitoringServerInfo.EXTENDED_INFO_JSON ext_info = ms_info.get_extended_info(ext_info_type) data = { "auth": { "tenantName": ext_info["tenantName"], "passwordCredentials": { "username": ms_info.user_name, "password": ms_info.password, } } } headers = {"Content-Type": "application/json"} response = self.__request(auth_url, headers, use_token=False, data=json.dumps(data)) self.__token = response["access"]["token"]["id"] expires = response["access"]["token"]["expires"] self.__expires = datetime.datetime.strptime(expires, "%Y-%m-%dT%H:%M:%SZ") logger.info("Got token, expires: %s" % self.__expires) # Extract endpoints target_eps = { "nova": self.__set_nova_ep, "ceilometer": self.__set_ceilometer_ep } for catalog in response["access"]["serviceCatalog"]: if len(target_eps) == 0: break name = catalog["name"] ep_setter = target_eps.get(name) if ep_setter is None: continue ep_setter(catalog["endpoints"][0]["publicURL"]) del target_eps[name] if len(target_eps) > 0: logger.error("Not found Endpoints: Nova: %s, Ceiloemeter: %s" % \ (self.__nova_ep, self.__ceilometer_ep)) raise hap.Signal() logger.info("EP: Nova: %s", self.__nova_ep) logger.info("EP: Ceiloemeter: %s", self.__ceilometer_ep)
def __set_ms_info(self, ms_info): HapiProcessor.set_ms_info(self, ms_info) self.__pollingInterval = ms_info.polling_interval_sec self.__retryInterval = ms_info.retry_interval_sec logger.info("Polling inverval: %d/%d", self.__pollingInterval, self.__retryInterval) raise hap.Signal(restart=True)
def __fluentd_manager_main_in_try_block(self): logging.info("Started fluentd manger process.") fluentd = subprocess.Popen(self.__launch_args, stdout=subprocess.PIPE) while True: line = fluentd.stdout.readline() if len(line) == 0: logging.warning("The child process seems to have gone away.") fluentd.kill() # To make sure that the child terminates raise hap.Signal() timestamp, tag, raw_msg = self.__parse_line(line) if timestamp is None: continue if not self.__accept_tag_pattern.match(tag): continue self.__put_event(timestamp, tag, raw_msg) self.__arm_info.success()
def handler(signum, frame): logger.warning("Got SIGCHLD") raise hap.Signal()