conf_files has support for @SLICEFAMILY@ in sources
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Wed, 25 Jun 2008 08:17:57 +0000 (08:17 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Wed, 25 Jun 2008 08:17:57 +0000 (08:17 +0000)
new functions for reading node's arch, node_id and the like have moved in tools.py

conf_files.py
sliver_vs.py
tools.py

index 64e18c2..8b0119f 100644 (file)
@@ -19,17 +19,6 @@ class conf_files:
         self.cond = threading.Condition()
         self.data = None
 
-    # get node_id from /etc/planetlab/node_id and cache it
-    _node_id=None
-    @staticmethod 
-    def node_id():
-        if conf_files._node_id is None:
-            try:
-                conf_files._node_id=int(file("/etc/planetlab/node_id").read())
-            except:
-                conf_files._node_id=""
-        return conf_files._node_id
-
     def checksum(self, path):
         try:
             f = open(path)
@@ -62,10 +51,15 @@ class conf_files:
             return
         url = 'https://%s/%s' % (self.config.PLC_BOOT_HOST, cf_rec['source'])
         # set node_id at the end of the request - hacky
-        if conf_files.node_id():
+        if tools.node_id():
             if url.find('?') >0: url += '&'
             else:                url += '?'
-            url += "node_id=%d"%conf_files.node_id()
+            url += "node_id=%d"%tools.node_id()
+        else:
+            logger.log('%s -- WARNING, cannot add node_id to request'%dest)
+        # replace @SLICEFAMILY@ with what's stored on the node
+        if tools.slicefamily():
+            url = url.replace("@SLICEFAMILY@",tools.slicefamily())
         try:
             logger.log("retrieving URL=%s"%url)
             contents = curlwrapper.retrieve(url, self.config.cacert)
index 91f696a..2bc49d6 100644 (file)
@@ -19,7 +19,6 @@ don't have to guess if there is a running process or not.
 import errno
 import os, os.path
 import time
-import commands
 
 import vserver
 
@@ -70,20 +69,6 @@ class Sliver_VS(accounts.Account, vserver.VServer):
         self.initscriptchanged = False
         self.configure(rec)
 
-    _root_context_arch=None
-    @staticmethod 
-    def root_context_arch():
-        if not Sliver_VS._root_context_arch:
-            Sliver_VS._root_context_arch=commands.getoutput("uname -i")
-        return Sliver_VS._root_context_arch
-
-    @staticmethod
-    def personality (arch):
-        personality="linux32"
-        if arch.find("64")>=0:
-            personality="linux64"
-        return personality
-
     @staticmethod
     def create(name, vref = None):
         logger.verbose('Sliver_VS:create - name=%s'%name)
@@ -144,13 +129,19 @@ class Sliver_VS(accounts.Account, vserver.VServer):
             refname="default"
             arch="i386"
             
+        def personality (arch):
+            personality="linux32"
+            if arch.find("64")>=0:
+                personality="linux64"
+            return personality
+
         logger.log_call('/usr/sbin/vuseradd', '-t', refname, name)
         # export slicename to the slice in /etc/slicename
         file('/vservers/%s/etc/slicename' % name, 'w').write(name)
         # set personality: only if needed (if arch's differ)
-        if Sliver_VS.root_context_arch() != arch:
-            file('/etc/vservers/%s/personality' % name, 'w').write(Sliver_VS.personality(arch))
-            logger.log('%s: set personality to %s'%(name,Sliver_VS.personality(arch)))
+        if tools.root_context_arch() != arch:
+            file('/etc/vservers/%s/personality' % name, 'w').write(personality(arch))
+            logger.log('%s: set personality to %s'%(name,personality(arch)))
 
     @staticmethod
     def destroy(name): logger.log_call('/usr/sbin/vuserdel', name)
index 776a8d4..bc4b49e 100644 (file)
--- a/tools.py
+++ b/tools.py
@@ -7,6 +7,7 @@ import pwd
 import tempfile
 import threading
 import fcntl
+import commands
 
 import logger
 
@@ -91,6 +92,38 @@ def write_temp_file(do_write, mode=None, uidgid=None):
     finally: f.close()
     return temporary_filename
 
+# utilities functions to get (cached) information from the node
+
+# get node_id from /etc/planetlab/node_id and cache it
+_node_id=None
+def node_id():
+    global _node_id
+    if _node_id is None:
+        try:
+            _node_id=int(file("/etc/planetlab/node_id").read())
+        except:
+            _node_id=""
+    return _node_id
+
+# get slicefamily from /etc/planetlab/slicefamily and cache it
+# http://svn.planet-lab.org/wiki/SliceFamily
+_slicefamily=None
+def slicefamily():
+    global _slicefamily
+    if _slicefamily is None:
+        try:
+            _slicefamily=file("/etc/planetlab/slicefamily").read().strip()
+        except:
+            _slicefamily=""
+    return _slicefamily
+
+_root_context_arch=None
+def root_context_arch():
+    global _root_context_arch
+    if not _root_context_arch:
+        _root_context_arch=commands.getoutput("uname -i")
+    return _root_context_arch
+
 
 class NMLock:
     def __init__(self, file):