new global PLC_FLAVOUR category to globally chose sliver vref image
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 19 Jan 2010 22:38:26 +0000 (22:38 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 19 Jan 2010 22:38:26 +0000 (22:38 +0000)
new method GetSliceFamily, value passed in GetSlivers
NodeManager does not have this logic anymore

conf_files.py
nm.py
sliver_vs.py

index b3b65f8..7e86e75 100644 (file)
@@ -54,7 +54,7 @@ class conf_files:
             url += "node_id=%d"%tools.node_id()
         else:
             logger.log('%s -- WARNING, cannot add node_id to request'%dest)
-        # pass slicefamily as well, as stored in /etc/planetlab/slicefamily ont the node
+        # pass slicefamily as well, as stored in /etc/planetlab/slicefamily on the node
         if tools.slicefamily():
             if url.find('?') >0: url += '&'
             else:                url += '?'
diff --git a/nm.py b/nm.py
index 5531554..b12f0b6 100755 (executable)
--- a/nm.py
+++ b/nm.py
@@ -59,7 +59,9 @@ def GetSlivers(config, plc):
     try: 
         logger.log("Syncing w/ PLC")
         data = plc.GetSlivers()
-        if (options.verbose): logger.log_slivers(data)
+        # used to be done only in verbose; very helpful though, and tedious to obtain,
+        # so let's dump this unconditionnally
+        logger.log_slivers(data)
         getPLCDefaults(data, config)
     except: 
         logger.log_exc()
@@ -82,13 +84,19 @@ def getPLCDefaults(data, config):
         if slice['name'] == config.PLC_SLICE_PREFIX+"_default":
             attr_dict = {}
             for attr in slice.get('attributes'): attr_dict[attr['tagname']] = attr['value'] 
+            # GetSlivers exposes the result of GetSliceFamily() as an separate key in data
+            # It is safe to override the attributes with this, as this method has the right logic
+            try:
+                attr_dict['vref']=slice.get('GetSliceFamily')
+            except:
+                pass
             if len(attr_dict):
                 logger.verbose("Found default slice overrides.\n %s" % attr_dict)
                 config.OVERRIDES = attr_dict
                 return
     # NOTE: if an _default slice existed, it would have been found above and
-       #               the routine would return.  Thus, if we've gotten here, then no default
-       #               slice is bound to this node.
+    #      the routine would return.  Thus, if we've gotten here, then no default
+    #      slice is bound to this node.
     if 'OVERRIDES' in dir(config): del config.OVERRIDES
 
 
index 4c4d109..f8ebd4a 100644 (file)
@@ -75,60 +75,27 @@ class Sliver_VS(accounts.Account, vserver.VServer):
     def create(name, vref = None):
         logger.verbose('Sliver_VS:create - name=%s'%name)
         if vref is None:
+            logger.log("creating %s : no vref attached, this is unexpected"%name)
             vref='default'
+        # used to look in /etc/planetlab/family, now relies on the 'family' extra attribute in GetSlivers()
+        # which for legacy is still exposed here as the 'vref' key
+        
+        # check the template exists -- there's probably a better way..
+        if not os.path.isdir ("/vservers/.vref/%s"%vref):
+            # find a resonable default
+            if os.path.isfile ("/etc/planetlab/slicefamily"):
+                default=file("/etc/planetlab/slicefamily").read().strip()
+            else:
+                default='default'
+                logger.log("creating %s : /etc/planetlab/slicefamily not found, this is unexpected"%name)
+            logger.log("creating %s - vref %s not found, using default %s"%(name,vref,default))
+            vref=default
+
+        # guess arch
         try:
-            ### locating the right slicefamily
-            # this is a first draft, and more a proof of concept thing
-            # the idea is to parse vref for dash-separated wishes,
-            # and to project these against the defaults
-            # so e.g. if the default slice family (as found in /etc/planetlab/slicefamily)
-            # is planetlab-f8-i386, then here is what we get
-            # vref=x86_64             -> vuseradd -t planetlab-f8-x86_64 
-            # vref=centos5            -> vuseradd -t planetlab-centos5-i386 
-            # vref=centos5-onelab     -> vuseradd -t onelab-centos5-i386 
-            # vref=planetflow         -> vuseradd -t planetflow-f8-i386
-            # vref=x86_64-planetflow  -> vuseradd -t planetflow-f8-x86_64
-
-            # default
-            default=file("/etc/planetlab/slicefamily").read().strip()
-            (pldistro,fcdistro,arch) = default.split("-")
-
-            known_archs = [ 'i386', 'x86_64' ]
-            known_fcdistros = [ 'centos5', 'f8', 'f9', 'f10', 'f11', 'f12' ]
-            # from the slice attribute: cut dashes and try to figure the meaning
-            slice_wishes = vref.split("-")
-            for wish in slice_wishes:
-                if wish in known_archs:
-                    arch=wish
-                elif wish in known_fcdistros:
-                    fcdistro=wish
-                else:
-                    pldistro=wish
-
-            # rejoin the parts
-            refname="-".join( (pldistro,fcdistro,arch) )
-
-            # check the template exists -- there's probably a better way..
-            if not os.path.isdir ("/vservers/.vref/%s"%refname):
-                logger.log("%s (%s) : vref %s not found, using default %s"%(
-                        name,vref,refname,default))
-                refname=default
-                # reset so arch is right
-                (pldistro,fcdistro,arch) = default.split("-")
-                # could check again, but as we have /etc/slicefamily 
-                # there's probably no /vservers/.vref/default
-
-        except IOError:
-            # have not found slicefamily
-            logger.log("%s (%s): legacy node - using fallback vrefname 'default'"%(name,vref))
-            # for legacy nodes
-            refname="default"
-            arch="i386"
+            (x,y,arch)=vref.split('-')
         except:
-            logger.log("%s (%s) : unexpected error follows - using 'default'"%(name,vref))
-            logger.log(traceback.format_exc())
-            refname="default"
-            arch="i386"
+            arch='i386'
             
         def personality (arch):
             personality="linux32"
@@ -136,9 +103,10 @@ class Sliver_VS(accounts.Account, vserver.VServer):
                 personality="linux64"
             return personality
 
-        logger.log_call('/usr/sbin/vuseradd', '-t', refname, name)
+        logger.log_call('/usr/sbin/vuseradd', '-t', vref, name)
         # export slicename to the slice in /etc/slicename
         file('/vservers/%s/etc/slicename' % name, 'w').write(name)
+        file('/vservers/%s/etc/slicefamily' % name, 'w').write(vref)
         # set personality: only if needed (if arch's differ)
         if tools.root_context_arch() != arch:
             file('/etc/vservers/%s/personality' % name, 'w').write(personality(arch))