Commit 88e61ae3 authored by David Johnson's avatar David Johnson

Support for accessing the v4 NM via a nm-controller slice account. Now,

for each delegated slice we create, we set the 'delegations' attribute to
'utah_nmcontrol', the name of our nm-controller slice that has permissions
to talk to the NM.

Also, a few other fixes.
parent 055b8769
......@@ -139,6 +139,7 @@ PLAB_SVC_SLICEDESC = "Emulab management service slice. Performs periodic " \
PLABMON_PID = "emulab-ops"
PLABMON_EID = "plab-monitor"
DEF_SLICE_DESC = "Slice created by Emulab"
DEF_EMULAB_URL = "http://www.emulab.net"
PLABEXPIREWARN = 1*WEEK # one week advance warning for slice expiration.
NODEEXPIREWARN = 2*WEEK+2*DAY # about two weeks advance warning for slivers.
......@@ -312,12 +313,14 @@ class Plab:
slice._create()
return slice
def createSliceNoDB(self,name,description,userlist=[],nodelist=[]):
def createSliceNoDB(self,name,description,userlist=[],nodelist=[],
instmethod=None):
"""
Slice factory function that doesn't use the Emulab db.
"""
slice = Slice(self,usedb=False,slicename=name,slicedescr=description,
userlist=userlist,nodelist=nodelist)
userlist=userlist,nodelist=nodelist,
instmethod=instmethod)
slice._create()
return slice
......@@ -329,11 +332,15 @@ class Plab:
slice._load()
return slice
def loadSliceNoDB(self,name):
def loadSliceNoDB(self,slicename,slicedescr=None,sliceurl=None,
userlist=[],nodelist=[],instmethod=None):
"""
Slice factory function that doesn't use the Emulab db.
"""
slice = Slice(self,usedb=False,slicename=name)
slice = Slice(self,usedb=False,slicename=slicename,
slicedescr=slicedescr,sliceurl=sliceurl,
userlist=userlist,nodelist=nodelist,
instmethod=instmethod)
slice._load()
return slice
......@@ -1168,7 +1175,8 @@ class Slice:
def __init__(self, plab, pid = None, eid = None, exptidx = None,
usedb = True, slicename = None, slicedescr = DEF_SLICE_DESC,
sliceurl = None, userlist = [], nodelist = []):
sliceurl = DEF_EMULAB_URL, userlist = [], nodelist = [],
instmethod = None):
self.plab = plab
self.pid, self.eid = pid, eid
self.slicemeta = None
......@@ -1180,6 +1188,7 @@ class Slice:
self.usedb = usedb
self.userlist = userlist
self.nodelist = nodelist
self.instmethod = instmethod
# Rules for arguments.
if usedb and (pid == None or eid == None):
......@@ -1284,6 +1293,9 @@ class Slice:
pass
pass
except:
print "slice create(slice %s): exception\n%s" \
% (self.slicename,traceback.format_exc())
self.plab.agent.deleteSlice(self)
if compat_mode:
......
......@@ -65,6 +65,7 @@ EMULABMAN_EMAIL = "emulabman@emulab.net"
DEF_SLICE_DESC = "Slice created by Emulab"
DEF_EMULAB_URL = "http://www.emulab.net"
INSTMETHOD_NMCONTROLLER = "nm-controller"
INSTMETHOD_DELEGATED = "delegated"
INSTMETHOD_PLCINST = "plc-instantiated"
DEF_EMULAB_INSTMETHOD = INSTMETHOD_DELEGATED
......@@ -115,8 +116,8 @@ class NM3agent:
pass
DEF_NM_DELEGATE_ACCT = "utah_elab_delegate"
DEF_NM_DELEGATE_KEY = "/root/.ssh/id_rsa.plabdel"
DEF_NM_DELEGATE_ACCT = "utah_nmcontrol"
DEF_NM_DELEGATE_KEY = "/root/.ssh/id_rsa"
DEF_NM_SSHCMD = "/usr/bin/ssh -q -oStrictHostKeyChecking=no" \
" -oPasswordAuthentication=no -l %s -i %s %s"
......@@ -575,9 +576,22 @@ class mod_PLC4:
res = None
now = calendar.timegm(time.gmtime())
# fix up some slice info just in case
if slice.sliceurl == None:
slice.sliceurl = DEF_EMULAB_URL
pass
if slice.description == None:
slice.description = DEF_SLICE_DESC
pass
if slice.instmethod == None:
slice.instmethod = DEF_EMULAB_INSTMETHOD
pass
try:
# XXX: fix to take desc and url args! (i.e., SliceUpdate)
res = tryXmlrpcCmd(agent.SliceCreate)
res = tryXmlrpcCmd(agent.SliceCreate,(slice.sliceurl,
slice.description,
slice.instmethod))
if debug:
print "SliceCreate result: %s" % res
pass
......@@ -585,6 +599,22 @@ class mod_PLC4:
except:
print "Failed to create slice %s" % slice.slicename
raise
# If the slice is delegated, make sure to set the `delegations` attr
# to our nm-controller slice
if slice.instmethod == INSTMETHOD_DELEGATED:
try:
res = tryXmlrpcCmd(agent.SliceAddAttribute,
('delegations',DEF_NM_DELEGATE_ACCT))
if debug:
print "SliceAddAttribute(delegations) result: %s" % res
pass
pass
except:
print "Failed to set 'delegations' attribute on slice %s" \
% slice.slicename
raise
pass
try:
userlist = slice.getSliceUsers()
......@@ -611,13 +641,14 @@ class mod_PLC4:
# like that... so we must add the nodes to the slice.
try:
tnodelist = slice.getSliceNodes()
if tnodelist == None:
tnodelist = []
if tnodelist == None or tnodelist == []:
pass
nodelist = map(lambda x: x[2], tnodelist)
res = tryXmlrpcCmd(agent.SliceNodesAdd, nodelist)
if debug:
print "SliceNodesAdd result: %s" % res
else:
nodelist = map(lambda x: x[2], tnodelist)
res = tryXmlrpcCmd(agent.SliceNodesAdd, nodelist)
if debug:
print "SliceNodesAdd result: %s" % res
pass
pass
pass
except:
......@@ -646,18 +677,21 @@ class mod_PLC4:
# raise
(PLCticket,PLCticket_legacy) = ('','')
try:
# XXX - fix for new NM and rollout.
PLCticket = tryXmlrpcCmd(agent.SliceGetTicket)
PLCticket_legacy = tryXmlrpcCmd(agent.SliceGetTicketLegacy)
if debug:
print "ticket = %s" % str(PLCticket)
print "legacy ticket = %s" % str(PLCticket_legacy)
# We can only get the tickets if the slice is in delegated mode.
if slice.instmethod == INSTMETHOD_DELEGATED:
try:
# XXX - fix for new NM and rollout.
PLCticket = tryXmlrpcCmd(agent.SliceGetTicket)
PLCticket_legacy = tryXmlrpcCmd(agent.SliceGetTicketLegacy)
if debug:
print "ticket = %s" % str(PLCticket)
print "legacy ticket = %s" % str(PLCticket_legacy)
pass
pass
except:
print "Failed to get PLC ticket for slice %s" % slice.slicename
raise
pass
except:
print "Failed to get PLC ticket for slice %s" % slice.slicename
raise
# XXX: fix for PLC 4
leaseend = now + MAX_PLC_LEASELEN
......@@ -754,6 +788,10 @@ class mod_PLC4:
def getSliceMetaLegacy(self, slice):
agent = self.__getAgent(slice.slicename)
# We can only get the tickets if the slice is in delegated mode.
if slice.instmethod != INSTMETHOD_DELEGATED:
return cPickle.dumps('')
try:
PLCticket = tryXmlrpcCmd(agent.SliceGetTicketLegacy)
......@@ -769,7 +807,7 @@ class mod_PLC4:
def getSliceMeta(self,slice):
agent = self.__getAgent(slice.slicename)
try:
retval = tryXmlrpcCmd(agent.SliceGetTicket)
if debug:
......
......@@ -14,8 +14,8 @@ import libplab
usage = "%prog [-vd] {create|destroy} pid eid\n" \
" Without Emulab DB:\n" \
"%prog [-vd] [-u <user1,...>] [-n <node1,...>] -c <slicedesc> \\\n" \
" {create|destroy} slicename"
"%prog [-vd] [-u <user1,...>] [-n <node1,...>] [-m <instmethod>] \n" \
" -c <slicedesc> {create|destroy} slicename"
# [-w <url>]
def main(args):
......@@ -29,6 +29,8 @@ def main(args):
"the slice",default=None)
parser.add_option("-c","--slicedesc",dest="slicedesc",action="store",
help="Slice description",default=None)
parser.add_option("-m","--instmethod",dest="instmethod",action="store",
help="Slice instantiation method",default=None)
# parser.add_option("-w","--sliceurl",dest="sliceurl",action="store_true",
# help="Slice URL",default=None)
userlist,nodelist = None,None
......@@ -46,9 +48,15 @@ def main(args):
if opts.nodes != None:
nodelist = opts.nodes.split(',')
pass
else:
nodelist = []
pass
if opts.users != None:
userlist = opts.nodes.split(',')
pass
else:
userlist = []
pass
pass
elif len(args) == 3:
command,pid,eid = args
......@@ -64,7 +72,8 @@ def main(args):
pass
else:
slice = plab.createSliceNoDB(slicename,opts.slicedesc,
userlist=userlist,nodelist=nodelist)
userlist=userlist,nodelist=nodelist,
instmethod=opts.instmethod)
pass
pass
elif command == "destroy":
......@@ -72,7 +81,9 @@ def main(args):
slice = plab.loadSlice(pid, eid)
pass
else:
slice = plab.loadSliceNoDB(slicename)
slice = plab.loadSliceNoDB(slicename,slicedescr=opts.slicedesc,
userlist=userlist,nodelist=nodelist,
instmethod=opts.instmethod)
pass
slice.destroy()
pass
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment