new GetNodeFlavour method based on PLC_FLAVOUR category + optional node tags
[plcapi.git] / PLC / Methods / GetSliceFamily.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.Slices import Slice, Slices
8
9 from PLC.Accessors.Accessors_standard import *                  # import slice accessors
10
11 class GetSliceFamily(Method):
12     """
13     Returns the slice vserver reference image that a given slice
14     should be based on. This depends on the global PLC settings in the
15     PLC_FLAVOUR area, optionnally overridden by any of the 'vref',
16     'arch', 'pldistro', 'fcdistro' tag if set on the slice.
17     """
18
19     roles = ['admin', 'user', 'node']
20
21     # don't support sliver-specific settings yet
22     accepts = [
23         Auth(),
24         Mixed(Slice.fields['slice_id'],
25               Slice.fields['name']),
26         ]
27
28     returns = Parameter (str, "the slicefamily this slice should be based upon")
29
30     # 
31     ### system slices - at least planetflow - still rely on 'vref'
32     # 
33     def call(self, auth, slice_id_or_name):
34         # Get slice information
35         slices = Slices(self.api, [slice_id_or_name])
36         if not slices:
37             raise PLCInvalidArgument, "No such slice %r"%slice_id_or_name
38         slice = slices[0]
39         slice_id = slice['slice_id']
40
41         # the vref tag, if set, wins
42         vref = GetSliceVref (self.api).call(auth,slice_id)
43         if vref: return vref
44
45         arch = GetSliceArch (self.api).call(auth,slice_id)
46         if not arch: arch = self.api.config.PLC_FLAVOUR_SLICE_ARCH
47
48         pldistro = GetSlicePldistro (self.api).call(auth, slice_id)
49         if not pldistro: pldistro = self.api.config.PLC_FLAVOUR_SLICE_PLDISTRO
50
51         fcdistro = GetSliceFcdistro (self.api).call(auth, slice_id)
52         if not fcdistro: fcdistro = self.api.config.PLC_FLAVOUR_SLICE_FCDISTRO
53
54         # xxx would make sense to check the corresponding vserver rpms are available
55         # in all node-families yum repos (and yumgroups, btw)
56         return "%s-%s-%s"%(pldistro,fcdistro,arch)