try:
return lambda *params : method(self.auth, *params)
- except ProtocolError:
+ except xmlrpclib.ProtocolError:
traceback.print_exc()
global_error_count += 1
if global_error_count >= 10:
def __repr__(self):
return self.api.__repr__()
-api = PLC(auth.auth, auth.server)
class CachedPLC(PLC):
return run_or_returncached
+api = PLC(auth.auth, auth.server)
+cacheapi = CachedPLC(auth.auth, auth.server)
+
def getAPI(url):
return xmlrpclib.Server(url, verbose=False, allow_none=True)
nodeauth = Auth(session=session)
return PLC(nodeauth.auth, auth.server)
-def getAuthAPI():
- return PLC(auth.auth, auth.server)
+def getAuthAPI(url=None):
+ if url:
+ return PLC(auth.auth, url)
+ else:
+ return PLC(auth.auth, auth.server)
def getCachedAuthAPI():
return CachedPLC(auth.auth, auth.server)
+def getSessionAPI(session, server):
+ nodeauth = Auth(session=session)
+ return PLC(nodeauth.auth, server)
+def getUserAPI(username, password, server):
+ auth = Auth(username,password)
+ return PLC(auth.auth, server)
+
def getTechEmails(loginbase):
"""
For the given site, return all user email addresses that have the 'tech' role.
#'last_updated', 'peer_node_id', 'ssh_rsa_key' ])
return nodes
+
+# Check if the site is a pending site that needs to be approved.
+def isPendingSite(loginbase):
+ api = xmlrpclib.Server(auth.server, verbose=False)
+ try:
+ site = api.GetSites(auth.auth, loginbase)[0]
+ except Exception, exc:
+ login.info("ERROR: No site %s" % loginbase)
+ return False
+
+ def all_disabled(person_ids):
+ persons = api.GetPersons(auth.auth, person_ids)
+ for person in persons:
+ if person['enabled']:
+ return False
+ return True
+
+ if not site['max_slices'] and not site['node_ids'] and all_disabled(site['person_ids']):
+ return True
+
+ return False
+
+
'''
Sets boot state of a node.
'''
def enableSlices(nodename):
api = xmlrpclib.Server(auth.server, verbose=False, allow_none=True)
+
for slice in slices(siteId(nodename)):
logger.info("Enabling slices %s" % slice)
try:
logger.info("enableSlices: %s" % exc)
print "exception: %s" % exc
+
#I'm commenting this because this really should be a manual process.
#'''
#Enable suspended site slices.
# api.SliceAttributeAdd(auth.auth, slice, "plc_slice_state", {"state" : "suspended"})
#
def enableSiteSliceCreation(loginbase):
+ if isPendingSite(loginbase):
+ msg = "INFO: enableSiteSliceCreation: Pending Site (%s)" % loginbase
+ print msg
+ logger.info(msg)
+ return
+
api = xmlrpclib.Server(auth.server, verbose=False, allow_none=True)
try:
logger.info("Enabling slice creation for site %s" % loginbase)
api = xmlrpclib.Server(auth.server, verbose=False, allow_none=True)
try:
loginbase = siteId(nodename)
- logger.info("Enabling slice creation for site %s" % loginbase)
- if not debug:
- logger.info("\tcalling UpdateSite(%s, enabled=True)" % loginbase)
- api.UpdateSite(auth.auth, loginbase, {'enabled': True})
+ enableSiteSliceCreation(loginbase)
except Exception, exc:
print "ERROR: enableSliceCreation: %s" % exc
logger.info("ERROR: enableSliceCreation: %s" % exc)