fixed: encodes boolean and double type values for the requests
[plcapi.git] / PLC / Methods / GetNodeFlavour.py
index d481de7..f357b2f 100644 (file)
@@ -1,5 +1,6 @@
 import traceback
 
+from PLC.Logger import logger
 from PLC.Method import Method
 from PLC.Auth import Auth
 from PLC.Faults import *
@@ -52,23 +53,23 @@ class GetNodeFlavour(Method):
     # parse PLC_FLAVOUR_VIRT_MAP 
     known_virts=['vs','lxc']
     default_virt='vs'
-    def virt_from_virt_map (self, fcdistro):
+    def virt_from_virt_map (self, node_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
+                    logger.error("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()
+            logger.exception("GetNodeFlavour, issue with parsing PLC_FLAVOUR_VIRT_MAP=%s - returning '%s'"%\
+                             (self.api.config.PLC_FLAVOUR_VIRT_MAP, GetNodeFlavour.default_virt))
             return GetNodeFlavour.default_virt
-        if fcdistro in map:  return map[fcdistro]
+#        print 'virt_from_virt_map, using map',map
+        if node_fcdistro in map:  return map[node_fcdistro]
         if 'default' in map: return map['default']
         return GetNodeFlavour.default_virt
             
@@ -109,7 +110,9 @@ class GetNodeFlavour(Method):
         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)
+            # do not save in node - if a node was e.g. f14 and it gets set to f16
+            # we do not want to have to re-set virt
+            # SetNodeVirt (self.api, self.caller).call (auth, node_id, virt)
 
         # xxx could use some sanity checking, and could provide fallbacks
         return {