- Change .py files to use 4-space indents and no hard tab characters.
[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 from PLC.Accessors.Accessors_omf import *                       # import slice accessors
11
12 class GetSliceFamily(Method):
13     """
14     Returns the slice vserver reference image that a given slice
15     should be based on. This depends on the global PLC settings in the
16     PLC_FLAVOUR area, optionnally overridden by any of the 'vref',
17     'arch', 'pldistro', 'fcdistro' tag if set on the slice.
18     """
19
20     roles = ['admin', 'user', 'node']
21
22     # don't support sliver-specific settings yet
23     accepts = [
24         Auth(),
25         Mixed(Slice.fields['slice_id'],
26               Slice.fields['name']),
27         ]
28
29     returns = Parameter (str, "the slicefamily this slice should be based upon")
30
31     #
32     ### system slices - at least planetflow - still rely on 'vref'
33     #
34     def call(self, auth, slice_id_or_name):
35         # Get slice information
36         slices = Slices(self.api, [slice_id_or_name])
37         if not slices:
38             raise PLCInvalidArgument, "No such slice %r"%slice_id_or_name
39         slice = slices[0]
40         slice_id = slice['slice_id']
41
42         arch = GetSliceArch (self.api).call(auth,slice_id)
43         if not arch: arch = self.api.config.PLC_FLAVOUR_SLICE_ARCH
44
45         pldistro = GetSlicePldistro (self.api).call(auth, slice_id)
46         if not pldistro: pldistro = self.api.config.PLC_FLAVOUR_SLICE_PLDISTRO
47
48         fcdistro = GetSliceFcdistro (self.api).call(auth, slice_id)
49         if not fcdistro: fcdistro = self.api.config.PLC_FLAVOUR_SLICE_FCDISTRO
50
51         # the vref tag, if set, wins over pldistro
52         vref = GetSliceVref (self.api).call(auth,slice_id)
53
54         # omf-control'ed slivers need the omf vserver reference image
55         # this is to avoid asking users to set both tags 'omf_control' and 'vref'
56         if not vref and GetSliceOmfControl(self.api).call(auth,slice_id):
57             SetSliceVref (self.api) (auth,slice_id,'omf')
58             vref='omf'
59
60         # xxx would make sense to check the corresponding vserver rpms are available
61         # in all node-families yum repos (and yumgroups, btw)
62         if vref:
63             return "%s-%s-%s"%(vref,fcdistro,arch)
64         else:
65             return "%s-%s-%s"%(pldistro,fcdistro,arch)