# Faiyaz Ahmed <faiyaza@cs.princeton.edu>
# Copyright (C) 2006, 2007 The Trustees of Princeton University
#
-# $Id: plc.py,v 1.8 2007/02/12 19:15:08 mef Exp $
+# $Id: plc.py,v 1.11 2007/02/19 17:42:21 mef Exp $
#
from emailTxt import *
import sys
logger = logging.getLogger("monitor")
-XMLRPC_SERVER = 'https://www2.planet-lab.org/PLCAPI/'
+XMLRPC_SERVER = 'https://www.planet-lab.org/PLCAPI/'
api = xmlrpclib.Server(XMLRPC_SERVER, verbose=False, allow_none = True)
auth = None
else:
logger.info("Cant find node %s to send POD." % nodename)
+def suspendSlice(argv):
+ """Freeze specific slice."""
+ global api, auth
+ if auth is None:
+ printUsage("requires admin privs")
+ sys.exit(1)
+
+ slice = argv[0]
+ logger.info("Suspending slice %s" % slice)
+ try:
+ if not config.debug:
+ api.AddSliceAttribute(auth, slice, "enabled", "0")
+ except Exception, exc:
+ logger.info("suspendSlices: %s" % exc)
+
def suspendSlices(argv):
"""Freeze all site slices."""
-
global api, auth
if auth is None:
printUsage("requires admin privs")
else: siteslices = slices(argv)
for slice in siteslices:
- logger.info("Suspending slice %s" % slice)
- try:
- if not config.debug:
- api.AddSliceAttribute(auth, slice, "plc_slice_state", "suspended")
- except Exception, exc:
- logger.info("suspendSlices: %s" % exc)
+ suspendSlice([slice])
+
+def __enableSlice(slice):
+ logger.info("unfreezing slice %s" % slice['name'])
+ slice_attributes = api.GetSliceAttributes(auth,slice['slice_attribute_ids'])
+ for slice_attribute in slice_attributes:
+ if slice_attribute['name'] == "enabled":
+ api.DeleteSliceAttribute(auth, slice_attribute['slice_attribute_id'])
+
+def enableSlice(arg):
+ """Enable suspended slice."""
+ global api, auth
+ if auth is None:
+ printUsage("requires admin privs")
+ sys.exit(1)
+ slicename = arg[0]
+ gSlices = {'name':slicename}
+ slice = api.GetSlices(auth,gSlices)
+ if len(slice) == 1:
+ __enableSlice(slice[0])
+ else:
+ logger.info("slice %s not found" % slicename)
def enableSlices(argv):
"""Enable suspended site slices."""
slices = api.GetSlices(auth,gSlices)
for slice in slices:
- logger.info("unfreezing slice %s" % slice['name'])
- slice_attributes = api.GetSliceAttributes(auth,slice['slice_attribute_ids'])
- for slice_attribute in slice_attributes:
- if slice_attribute['name'] == "plc_slice_state":
- api.DeleteSliceAttribute(auth, slice_attribute['slice_attribute_id'])
+ __enableSlice(slice)
-def _SetSliceMax(argv):
+def setSliceMax(argv):
+ """Set max_slices for Slice. Returns previous max_slices"""
global api, auth
if auth is None:
printUsage("requires admin privs")
except Exception, exc:
logger.info("_SetSliceMax: %s" % exc)
-def removeSliceCreation(argv):
- """Removes ability to create slices. Returns previous max_slices"""
- argv.append(0)
- _SetSliceMax(argv)
-def enableSliceCreation(argv):
- """QED"""
- _SetSliceMax(argv)
+def authCheck(arg):
+ """Enable suspended slice."""
+ global api, auth
+ if auth is None:
+ printUsage("requires admin privs")
+ sys.exit(1)
+
+ if len(arg) != 2:
+ printUsage("incorrect arguments")
+ sys.exit(1)
+ user= arg[0]
+ pwd = arg[1]
+
+ check = {}
+ check['Username'] = user
+ check['AuthMethod'] = "password"
+ check['AuthString'] = pwd
+ for role in ['user','tech','pi','admin']:
+ check['Role'] = role
+ res = api.AdmAuthCheck(check)
+ print "%s -> %s %d" % (user,role,res)
+
USAGE = """
("siteNodes", getSiteNodes),
("nodeBootState", nodeBootState),
("nodePOD", nodePOD),
+ ("freezeSlice", suspendSlice),
+ ("unfreezeSlice", enableSlice),
("freezeSlices", suspendSlices),
("unfreezeSlices", enableSlices),
- ("disableSliceCreation",removeSliceCreation),
- ("enableSliceCreation", enableSliceCreation),
+ ("setSliceMax", setSliceMax),
+ ("authCheck", authCheck),
("renewAllSlices", renewAllSlices))
functbl = {}