1 from PLC.Method import Method
2 from PLC.Auth import Auth
3 from PLC.Faults import *
4 from PLC.Parameter import *
5 from PLC.Nodes import Node, Nodes
7 class GetNodeFlavour(Method):
9 Returns detailed information on a given node's flavour, i.e. its
12 This depends on the global PLC settings in the PLC_FLAVOUR area,
13 optionnally overridden by any of the following tags if set on that node:
15 'arch', 'pldistro', 'fcdistro',
16 'deployment', 'extensions',
19 roles = ['admin', 'user', 'node']
23 Mixed(Node.fields['node_id'],
24 Node.fields['hostname']),
28 'nodefamily' : Parameter (str, "the nodefamily this node should be based upon"),
29 'fcdistro': Parameter (str, "the fcdistro this node should be based upon"),
30 'extensions' : [ Parameter (str, "extensions to add to the base install") ],
31 'plain' : Parameter (bool, "use plain bootstrapfs image if set (for tests)" ) ,
36 def nodefamily (self, auth, node_id, fcdistro, arch):
38 # the deployment tag, if set, wins
39 # xxx Thierry: this probably is wrong; we need fcdistro to be set anyway
40 # for generating the proper yum config....
41 deployment = GetNodeDeployment (self.api,self.caller).call(auth,node_id)
42 if deployment: return deployment
44 pldistro = GetNodePldistro (self.api,self.caller).call(auth, node_id)
46 pldistro = self.api.config.PLC_FLAVOUR_NODE_PLDISTRO
47 SetNodePldistro(self.api,self.caller).call(auth,node_id,pldistro)
49 # xxx would make sense to check the corresponding bootstrapfs is available
50 return "%s-%s-%s"%(pldistro,fcdistro,arch)
52 def extensions (self, auth, node_id, fcdistro, arch):
54 return [ "%s-%s-%s"%(e,fcdistro,arch) for e in GetNodeExtensions(self.api,self.caller).call(auth,node_id).split() ]
58 def plain (self, auth, node_id):
59 return not not GetNodePlainBootstrapfs(self.api,self.caller).call(auth,node_id)
61 def call(self, auth, node_id_or_name):
62 # Get node information
63 nodes = Nodes(self.api, [node_id_or_name])
65 raise PLCInvalidArgument, "No such node %r"%node_id_or_name
67 node_id = node['node_id']
69 arch = GetNodeArch (self.api,self.caller).call(auth,node_id)
70 # if not set, use the global default and tag the node, in case the global default changes later on
72 arch = self.api.config.PLC_FLAVOUR_NODE_ARCH
73 SetNodeArch (self.api,self.caller).call(auth,node_id,arch)
75 fcdistro = GetNodeFcdistro (self.api,self.caller).call(auth, node_id)
77 fcdistro = self.api.config.PLC_FLAVOUR_NODE_FCDISTRO
78 SetNodeFcdistro (self.api,self.caller).call (auth, node_id, fcdistro)
80 # xxx could use some sanity checking, and could provide fallbacks
81 return { 'nodefamily' : self.nodefamily(auth,node_id, fcdistro, arch),
82 'fcdistro' : fcdistro,
83 'extensions' : self.extensions(auth,node_id, fcdistro, arch),
84 'plain' : self.plain(auth,node_id),