2a6e83078dce4f8262f355314f2eee2249c5b6d2
[plcapi.git] / PLC / Methods / GetSliceFamily.py
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.Slices import Slice, Slices
6
7 from PLC.Accessors.Accessors_standard import *                  # import slice accessors
8 from PLC.Accessors.Accessors_sliverauth import *                # import slice accessors
9
10 class GetSliceFamily(Method):
11     """
12     Returns the slice vserver reference image that a given slice
13     should be based on. This depends on the global PLC settings in the
14     PLC_FLAVOUR area, optionnally overridden by any of the 'vref',
15     'arch', 'pldistro', 'fcdistro' tag if set on the slice.
16     """
17
18     roles = ['admin', 'user', 'node']
19
20     # don't support sliver-specific settings yet
21     accepts = [
22         Auth(),
23         Mixed(Slice.fields['slice_id'],
24               Slice.fields['name']),
25         ]
26
27     returns = Parameter (str, "the slicefamily this slice should be based upon")
28
29     #
30     ### system slices - at least planetflow - still rely on 'vref'
31     #
32     def call(self, auth, slice_id_or_name):
33         # Get slice information
34         slices = Slices(self.api, [slice_id_or_name])
35         if not slices:
36             raise PLCInvalidArgument, "No such slice %r"%slice_id_or_name
37         slice = slices[0]
38         slice_id = slice['slice_id']
39
40         arch = GetSliceArch (self.api,self.caller).call(auth,slice_id)
41         if not arch: arch = self.api.config.PLC_FLAVOUR_SLICE_ARCH
42
43         pldistro = GetSlicePldistro (self.api,self.caller).call(auth, slice_id)
44         if not pldistro: pldistro = self.api.config.PLC_FLAVOUR_SLICE_PLDISTRO
45
46         fcdistro = GetSliceFcdistro (self.api,self.caller).call(auth, slice_id)
47         if not fcdistro: fcdistro = self.api.config.PLC_FLAVOUR_SLICE_FCDISTRO
48
49         # the vref tag, if set, wins over pldistro
50         vref = GetSliceVref (self.api,self.caller).call(auth,slice_id)
51
52         # omf-control'ed slivers need the omf vserver reference image
53         # we used to issue SetSliceVref (self.api) (auth,slice_id,'omf')
54         # to avoid asking users to set both tags 'omf_control' and 'vref'
55         # however we can't use SetSliceVref here because a node is only allowed 
56         # to set a sliver tag, not a slice tag
57         # and this somehow gets called from GetSlivers
58         # anyways it was a bad idea, let's have the UI do that instead
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)