def home(): """display status information about the blockchain. Eventually, this might be its own app. """ try: timestamp = get_ledger_uptime()["time_stamp"] # remove microseconds and timezone information timestamp_no_us = timestamp.split(".")[0] # calculate difference until now startup_time = datetime.datetime.strptime(timestamp_no_us, "%Y-%m-%d %H:%M:%S") uptime_duration = str(datetime.datetime.now() - startup_time) # remove microseconds from uptime uptime = ".".join(uptime_duration.split(".")[:-1]) # envelope_count=len(envelopes), \ # supplier_count=len(suppliers), \ # part_count=len(parts)) return render_page("home", \ uptime=uptime, \ apps=get_blockchain_apps(), \ nodes=get_blockchain_nodes() , \ ledger_api_address=get_ledger_address(), \ envelope_count=0, \ supplier_count=0, \ part_count=0) except APIError as error: return render_page("error", error_message=str(error))
def home(): """display status information about the blockchain. Eventually, this might be its own app. """ try: return render_page("home", \ uptime=get_ledger_uptime(), \ apps=get_blockchain_apps(), \ nodes=get_blockchain_nodes() , \ ledger_api_address=get_ledger_address(), \ envelope_count=0, \ supplier_count=0, \ part_count=0) except APIError as error: return render_page("error", error_message=str(error))
def home(): """display status information about the blockchain. Eventually, this might be its own app. """ uptime_sample = str(datetime.datetime.now() - datetime.datetime(2017, 7, 9, 12, 44)) uptime_sample = ".".join(uptime_sample.split(".")[:-1]) # dict supplier.id -> list of part instances by this supplier supplier_parts = {} # dict supplier.id -> supplier instance apps = ["Sparts", "BC Dash"] try: ledger_ip, ledger_port = get_ledger_api_address() # envelope_count=len(envelopes), \ # supplier_count=len(suppliers), \ # part_count=len(parts)) return render_page("home", uptime=uptime_sample, \ apps=apps, \ nodes=get_blockchain_nodes(), \ ledger_api_address="http://" + ledger_ip + ":" + str(ledger_port) + "/api/sparts", \ envelope_count=0, \ supplier_count=0, \ part_count=0) except ConnectionError: return render_page("error", error_message="The conductor service refused connection." \ + " Could not query blockchain status at this time. Please try again later.") except APIError as error: return render_page("error", error_message="Failed to call the conductor API service. " \ + str(error))
def get_node_status(uuid): """json route for pinging a node and returning its status """ selected_node = None for node in get_blockchain_nodes(): if node["uuid"] == uuid: selected_node = node break if selected_node is None: return jsonify({"status": "Down. Node UUID was not found on the network."}) if "api_address" not in node: return jsonify({"status": "Invalid conductor response. No api_address."}) try: node_status = ping_node(node["api_address"], timeout=5) except ReadTimeout: node_status = "Down. Timed out." except ConnectionError: node_status = "Down. Connection refused." return jsonify({"status": node_status})