new GetNodeFlavour method based on PLC_FLAVOUR category + optional node tags
[plcapi.git] / PLC / Methods / GetNodeFlavour.py
1 # $Id$
2 # $URL$
3 from PLC.Method import Method
4 from PLC.Auth import Auth
5 from PLC.Faults import *
6 from PLC.Parameter import *
7 from PLC.Nodes import Node, Nodes
8
9 from PLC.Accessors.Accessors_standard import *                  # import node accessors
10
11 class GetNodeFlavour(Method):
12     """
13     Returns detailed information on a given node's flavour, i.e. its
14     base installation. 
15
16     This depends on the global PLC settings in the PLC_FLAVOUR area,
17     optionnally overridden by any of the following tags if set on that node:
18
19     'arch', 'pldistro', 'fcdistro', (xxx fcdistro not yet supported)
20     'deployment', 'extensions',
21     """
22
23     roles = ['admin', 'user', 'node']
24
25     accepts = [
26         Auth(),
27         Mixed(Node.fields['node_id'],
28               Node.fields['name']),
29         ]
30
31     returns = { 'nodefamily' : Parameter (str, "the node-family this node should be based upon"),
32                 'extensions' : [ Parameter (str, "extension to add to the base install") ],
33                 'uncompressed' : Parameter (bool, "for tests : use uncompressed bootstrapfs" ) ,
34                 }
35
36     
37     ########## nodefamily
38     def nodefamily (self, auth, nodeid):
39
40         # the deployment tag, if set, wins
41         deployment = GetNodeDeployment (self.api).call(auth,node_id)
42         if deployment: return deployment
43
44         arch = GetNodeArch (self.api).call(auth,node_id)
45         if not arch: arch = self.api.config.PLC_FLAVOUR_NODE_ARCH
46
47         pldistro = GetNodePldistro (self.api).call(auth, node_id)
48         if not pldistro: pldistro = self.api.config.PLC_FLAVOUR_NODE_PLDISTRO
49
50         ###fcdistro = GetNodeFcdistro (self.api).call(auth, node_id)
51         ###if not fcdistro: fcdistro = self.api.config.PLC_FLAVOUR_NODE_FCDISTRO
52
53         # xxx would make sense to check the corresponding bootstrapfs is available
54         ###return "%s-%s-%s"%(pldistro,fcdistro,arch)
55         return "%s-%s"%(pldistro,arch)
56
57     def extensions (self, auth, node_id):
58         return GetNodeExtensions(self.api).call(auth,node_id).split()
59
60     def compressed (self, auth, node_id):
61         return not PlainBootstrapfs(self.api).call(auth,node_id)
62
63     def call(self, auth, node_id_or_name):
64         # Get node information
65         nodes = Nodes(self.api, [node_id_or_name])
66         if not nodes:
67             raise PLCInvalidArgument, "No such node %r"%node_id_or_name
68         node = nodes[0]
69         node_id = node['node_id']
70
71         return { 'nodefamily' : self.nodefamily(auth,node_id),
72                  'extensions' : self.extensions(auth,node_id),
73                  'compressed' : self.compressed(auth,node_id),
74                  }