Functions | Variables
lemmon_tools Namespace Reference

Functions

def runMachineCheck ()
 machine information More...
 
def runStatusCheck (MAX_ATTEMPTS=3, verbose=False)
 run LEM status check More...
 
def appendToFile (status, prefix="/nusoft/app/web/htdoc/nova/lem/")
 append a status to a file More...
 
def appendStatus (history, new)
 append status to statuses More...
 

Variables

list SERVERS = ["lem.hep.caltech.edu"]
 
 PORTS = range(1024, 1032)
 

Function Documentation

def lemmon_tools.appendStatus (   history,
  new 
)

append status to statuses

Definition at line 87 of file lemmon_tools.py.

Referenced by appendToFile().

87 def appendStatus(history, new):
88  history["machine"].append( new["machine"])
89  history["time"].append( new["time"])
90  history["year"].append( new["year"])
91  history["month"].append( new["month"])
92  history["day"].append( new["day"])
93  history["hour"].append( new["hour"])
94  history["minute"].append( new["minute"])
95  history["second"].append( new["second"])
96  history["results"].append( new["results"])
97  return history
98 
def appendStatus(history, new)
append status to statuses
Definition: lemmon_tools.py:87
def lemmon_tools.appendToFile (   status,
  prefix = "/nusoft/app/web/htdoc/nova/lem/" 
)

append a status to a file

Definition at line 60 of file lemmon_tools.py.

References appendStatus(), and open().

Referenced by nova::database::Table.BulkInsertInDB(), nova::dbi::Table.LoadFromCSV(), nutools::dbi::Table.LoadFromCSV(), nova::database::Table.UpdateFromSSV(), nova::dbi::Table.WriteToCSV(), and nutools::dbi::Table.WriteToCSV().

60 def appendToFile(status, prefix="/nusoft/app/web/htdoc/nova/lem/"):
61  import os, json
62  output_name = "%s/lemmon.json"%(prefix)
63  if not os.path.exists(output_name):
64  print "tools: output file %s doesn't exist, making a fresh file"%output_name
65  statuses = {}
66  statuses["servers"] = SERVERS
67  statuses["ports"] = PORTS
68  statuses["machine"] = []
69  statuses["time"] = []
70  statuses["year"] = []
71  statuses["month"] = []
72  statuses["day"] = []
73  statuses["hour"] = []
74  statuses["minute"] = []
75  statuses["second"] = []
76  statuses["results"] = []
77  else:
78  print "tools: loading output file"
79  statuses = json.load(open(output_name,"r"))
80  print "tools: Appending to list of %i statuses"%len(statuses["time"])
81  statuses = appendStatus(statuses, status)
82  with open(output_name, "w") as outfile:
83  json.dump(statuses, outfile)
84  print "tools: written to %s"%output_name
def appendStatus(history, new)
append status to statuses
Definition: lemmon_tools.py:87
def appendToFile(status, prefix="/nusoft/app/web/htdoc/nova/lem/")
append a status to a file
Definition: lemmon_tools.py:60
procfile open("FD_BRL_v0.txt")
def lemmon_tools.runMachineCheck ( )

machine information

Definition at line 6 of file lemmon_tools.py.

Referenced by runStatusCheck().

7  status = {}
8  import socket, time
9  machine = socket.gethostname()
10  status["machine"] = machine
11  this_time = time.localtime()
12  time_str = time.strftime("%Y-%m-%d %H:%M:%S", this_time)
13  status["time"] = time_str
14  status["year"] = this_time.tm_year
15  status["month"] = this_time.tm_mon
16  status["day"] = this_time.tm_mday
17  status["hour"] = this_time.tm_hour
18  status["minute"] = this_time.tm_min
19  status["second"] = this_time.tm_sec
20  return status
def runMachineCheck()
machine information
Definition: lemmon_tools.py:6
def lemmon_tools.runStatusCheck (   MAX_ATTEMPTS = 3,
  verbose = False 
)

run LEM status check

Definition at line 23 of file lemmon_tools.py.

References runMachineCheck(), and runNovaSAM.str.

23 def runStatusCheck(MAX_ATTEMPTS=3, verbose=False):
24  status = runMachineCheck()
25  import urllib2
26  results = {}
27  for server in SERVERS:
28  for port in PORTS:
29  url = "http://%s:%i/status"%(server,port)
30  results[url] = {"status" :False,
31  "status_text" :False,
32  "exception" :False,
33  "exception_text":False}
34  if verbose: print "lem : determining status of %s"%url
35  attempts = 0
36  while (attempts < MAX_ATTEMPTS):
37  try:
38  response = urllib2.urlopen(url)
39  content = response.read()
40  if verbose: print "lem : ---\n%s\nlem : ---\n"%content
41  results[url]["status"] = "good"
42  results[url]["status_text"] = content
43  results[url]["exception"] = False
44  results[url]["exception_text"] = False
45  break
46  except urllib2.URLError as exception:
47  attempts += 1
48  if verbose:
49  print "lem : attempt[%i/%i] failed"%(attempts,MAX_ATTEMPTS)
50  print "lem : exception type: ",type(exception)
51  print "lem : ---\n%s\nlem : ---\n"%str(exception.reason)
52  results[url]["status"] = "bad"
53  results[url]["status_text"] = False
54  results[url]["exception"] = str(type(exception))
55  results[url]["exception_text"] = str(exception.reason)
56  status["results"] = results
57  return status
::xsd::cxx::tree::type type
Definition: Database.h:110
def runMachineCheck()
machine information
Definition: lemmon_tools.py:6
def runStatusCheck(MAX_ATTEMPTS=3, verbose=False)
run LEM status check
Definition: lemmon_tools.py:23

Variable Documentation

lemmon_tools.PORTS = range(1024, 1032)

Definition at line 3 of file lemmon_tools.py.

list lemmon_tools.SERVERS = ["lem.hep.caltech.edu"]

Definition at line 2 of file lemmon_tools.py.