cosmostat python comment enrichment
This commit is contained in:
@ -1,9 +1,16 @@
|
||||
# This will be a class definitation for the cosmostat server
|
||||
# On the server, there will be a Cosmostat Class Object
|
||||
# This will have an array of System Class Objects
|
||||
# These will be created based on API input from remote systems
|
||||
# The remote systems will submit a json of their state to a private API
|
||||
# this will define the System Class
|
||||
|
||||
#################################################################
|
||||
#################################################################
|
||||
### Cosmostat Classes
|
||||
### The Cosmostat Server is a Class for the API running on the
|
||||
### dashboard. This keeps track of all active systems that are
|
||||
### actively reporting back to the Cosmostat Server Dashboard
|
||||
### The static and active data is maintained in a single
|
||||
### Cosmostat Server Object, and this Object contains a List
|
||||
### of Cosmostat Client Objects. This is where the data actually
|
||||
### lives
|
||||
#################################################################
|
||||
#################################################################
|
||||
|
||||
import subprocess
|
||||
import json
|
||||
@ -11,14 +18,15 @@ import time
|
||||
import weakref
|
||||
import base64, hashlib
|
||||
from typing import Dict, Any, List
|
||||
# Import Cosmos Settings
|
||||
from Cosmos_Settings import *
|
||||
|
||||
|
||||
|
||||
#################################################################
|
||||
#################################################################
|
||||
# Cosmostat Class
|
||||
#################################################################
|
||||
### Cosmostat Server Class
|
||||
### This Class is for maintaining a list of Client Objects.
|
||||
### Each Object is a remote System reporting back
|
||||
### The Class Functions are for the main application to interact
|
||||
### with client Object data.
|
||||
#################################################################
|
||||
|
||||
class CosmostatServer:
|
||||
@ -106,22 +114,30 @@ class CosmostatServer:
|
||||
return result
|
||||
|
||||
def get_client_hostnames(self, send_age = False):
|
||||
self.purge_stale_hostnames()
|
||||
result = []
|
||||
for system in self.systems:
|
||||
if send_age:
|
||||
result.append({"hostname": system.hostname, "data_age": age})
|
||||
else:
|
||||
result.append(system.hostname)
|
||||
return result
|
||||
|
||||
def purge_stale_hostnames(self):
|
||||
now = time.time()
|
||||
fresh_systems = []
|
||||
result = []
|
||||
|
||||
for system in self.systems:
|
||||
age = now - system.data_timestamp
|
||||
if age <= 60: # keep only fresh servers
|
||||
fresh_systems.append(system)
|
||||
if send_age:
|
||||
result.append({"hostname": system.hostname, "data_age": age})
|
||||
else:
|
||||
result.append(system.hostname)
|
||||
|
||||
self.systems = fresh_systems # replace the old list
|
||||
return result
|
||||
self.systems = fresh_systems # replace the old list
|
||||
|
||||
#################################################################
|
||||
### Cosmostat Client Class
|
||||
### Each Class Object contains static and active data as well as
|
||||
### the hostname and uuid/short_id.
|
||||
### The timestamp is for removing stale Clients
|
||||
#################################################################
|
||||
|
||||
class CosmostatClient:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user