def POST(self, host_id): host_table = dblayer.get_host_address_from_id(host_id) host_info = self.get_host_address(host_id) address = "http://{}:{}".format(host_info[0], host_info[1]) r = None try: r = requests.get(address + "/reboot", timeout=2) logging.info("reboot request sent") except requests.RequestException, e: logging.warning("reboot request to {} failed".format(address)) logging.exception(e)
def get_host_address(self, host_id): host_table = dblayer.get_host_address_from_id(host_id) host_addr = "" host_port = -1 count = 0 for a in host_table: count += 1 host_addr = a['address'] host_port = a['port'] if count > 1: logging.error("more than one host with id {}".format(host_id)) return [host_addr, host_port]