option skip verif

This commit is contained in:
Pascal Engélibert 2026-03-03 09:28:53 +01:00
commit 76c1b9c08c
3 changed files with 77 additions and 17 deletions

49
g5kwatt.py Normal file
View file

@ -0,0 +1,49 @@
import getpass, time, requests
def fetch(site, node, start, stop, user, psw):
start_str = time.strftime("%Y-%m-%dT%H:%M", time.localtime(int(start)))
stop_str = time.strftime("%Y-%m-%dT%H:%M", time.localtime(int(stop+61)))
auth = requests.auth.HTTPBasicAuth(user, psw)
resp = requests.get(f"https://api.grid5000.fr/stable/sites/{site}/metrics?nodes={node}&metrics=bmc_node_power_watt&start_time={start_str}&end_time={stop_str}", auth=auth)
if resp.status_code != 200:
print("Status: ", resp.status_code)
print(resp.content)
exit(1)
data = resp.json()
energy = 0
last_power = None
last_time = 0
for sample in data:
t = time.mktime(time.strptime(sample["timestamp"], "%Y-%m-%dT%H:%M:%S.%f%z"))
if last_power != None:
energy += last_power * (t - last_time)
last_power = None
if t >= start and t <= stop:
last_power = sample["value"]
last_time = t
return energy
def get_psw():
psw = None
try:
f = open("/dev/shm/g5k_psw", "r")
psw = f.read()
f.close()
except:
pass
if psw:
return psw
psw = getpass.getpass("Psw: ")
f = open("/dev/shm/g5k_psw", "w")
f.write(psw)
f.close()
return psw
def main():
user = "pengelib"
psw = get_psw()
print(fetch("nancy", "gros-69", 1772205368.593937, 1772206568.6941307, user, psw))
if __name__ == "__main__":
main()