GetNodeFlavour exposes 'virt' based on node's 'virt' tag, or on PLC_FLAVOUR_VIRT_MAP
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Tue, 26 Feb 2013 16:10:28 +0000 (17:10 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Tue, 26 Feb 2013 16:10:28 +0000 (17:10 +0100)
PLC/Accessors/Accessors_standard.py
PLC/Methods/GetNodeFlavour.py

index 6e0f491..5e54437 100644 (file)
@@ -53,6 +53,12 @@ define_accessors(current_module, [Slice,Node], "Fcdistro", "fcdistro",
                  "node/slice/config", "Linux distribution to use for node or slivers",
                  set_roles=["admin","pi","user","tech","node"], expose_in_api=True)
 
+# the virtualization model to use - this is only used by the bootmanager for 
+# picking the right options e.g. prior to reinstalling
+# see PLC_FLAVOUR_VIRT_MAP to see how the default gets computed
+define_accessors(current_module, Node, "Virt", "virt",
+                 "node/operation", 'typically "vs" or "lxc"',
+                 set_roles=["admin"], expose_in_api=True)
 # node deployment (alpha, beta, ...)
 define_accessors(current_module, Node, "Deployment", "deployment",
                  "node/operation", 'typically "alpha", "beta", or "production"',
index 92c0fc4..d481de7 100644 (file)
@@ -1,3 +1,5 @@
+import traceback
+
 from PLC.Method import Method
 from PLC.Auth import Auth
 from PLC.Faults import *
@@ -15,7 +17,7 @@ class GetNodeFlavour(Method):
     optionnally overridden by any of the following tags if set on that node:
 
     'arch', 'pldistro', 'fcdistro',
-    'deployment', 'extensions',
+    'deployment', 'extensions', 'virt', 
     """
 
     roles = ['admin', 'user', 'node']
@@ -35,7 +37,7 @@ class GetNodeFlavour(Method):
 
 
     ########## nodefamily
-    def nodefamily (self, auth, node_id, fcdistro, arch):
+    def nodefamily (self, auth, node_id, fcdistro, pldistro, arch):
 
         # the deployment tag, if set, wins
         # xxx Thierry: this probably is wrong; we need fcdistro to be set anyway
@@ -43,14 +45,34 @@ class GetNodeFlavour(Method):
         deployment = GetNodeDeployment (self.api,self.caller).call(auth,node_id)
         if deployment: return deployment
 
-        pldistro = GetNodePldistro (self.api,self.caller).call(auth, node_id)
-        if not pldistro:
-            pldistro = self.api.config.PLC_FLAVOUR_NODE_PLDISTRO
-            SetNodePldistro(self.api,self.caller).call(auth,node_id,pldistro)
-
         # xxx would make sense to check the corresponding bootstrapfs is available
         return "%s-%s-%s"%(pldistro,fcdistro,arch)
 
+    ##########
+    # parse PLC_FLAVOUR_VIRT_MAP 
+    known_virts=['vs','lxc']
+    default_virt='vs'
+    def virt_from_virt_map (self, fcdistro):
+        map={}
+        try:
+            assigns=[x.strip() for x in self.api.config.PLC_FLAVOUR_VIRT_MAP.split(';')]
+            for assign in assigns:
+                (left,right)=[x.strip() for x in assign.split(':')]
+                if right not in GetNodeFlavour.known_virts:
+                    print "GetNodeFlavour, unknown 'virt' %s - ignored" % right
+                    continue
+                for fcdistro in [ x.strip() for x in left.split(',')]:
+                    map[fcdistro]=right
+        except:
+            print "GetNodeFlavour, issue with parsing PLC_FLAVOUR_VIRT_MAP=%s - returning '%s'"%\
+                (self.api.config.PLC_FLAVOUR_VIRT_MAP,GetNodeFlavour.default_virt)
+            traceback.print_exc()
+            return GetNodeFlavour.default_virt
+        if fcdistro in map:  return map[fcdistro]
+        if 'default' in map: return map['default']
+        return GetNodeFlavour.default_virt
+            
+
     def extensions (self, auth, node_id, fcdistro, arch):
         try:
             return [ "%s-%s-%s"%(e,fcdistro,arch) for e in GetNodeExtensions(self.api,self.caller).call(auth,node_id).split() ]
@@ -79,9 +101,23 @@ class GetNodeFlavour(Method):
             fcdistro = self.api.config.PLC_FLAVOUR_NODE_FCDISTRO
             SetNodeFcdistro (self.api,self.caller).call (auth, node_id, fcdistro)
 
+        pldistro = GetNodePldistro (self.api,self.caller).call(auth, node_id)
+        if not pldistro:
+            pldistro = self.api.config.PLC_FLAVOUR_NODE_PLDISTRO
+            SetNodePldistro(self.api,self.caller).call(auth,node_id,pldistro)
+
+        virt = GetNodeVirt (self.api,self.caller).call(auth, node_id)
+        if not virt:
+            virt = self.virt_from_virt_map (fcdistro)
+            SetNodeVirt (self.api, self.caller).call (auth, node_id, virt)
+
         # xxx could use some sanity checking, and could provide fallbacks
-        return { 'nodefamily' : self.nodefamily(auth,node_id, fcdistro, arch),
-                 'fcdistro' : fcdistro,
-                 'extensions' : self.extensions(auth,node_id, fcdistro, arch),
-                 'plain' : self.plain(auth,node_id),
-                 }
+        return {
+            'arch'      : arch,
+            'fcdistro'  : fcdistro,
+            'pldistro'  : pldistro,
+            'virt'      : virt,
+            'nodefamily': self.nodefamily(auth,node_id, fcdistro, pldistro, arch),
+            'extensions': self.extensions(auth,node_id, fcdistro, arch),
+            'plain'     : self.plain(auth,node_id),
+            }