bug fixes
[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 from PLC.SliceTags import SliceTag, SliceTags
7
8 class GetSliceFamily(Method):
9     """
10     Returns the slice vserver reference image that a given slice
11     should be based on. This depends on the global PLC settings in the
12     PLC_FLAVOUR area, optionnally overridden by any of the 'vref',
13     'arch', 'pldistro', 'fcdistro' tag if set on the slice.
14     """
15
16     roles = ['admin', 'user', 'node']
17
18     # don't support sliver-specific settings yet
19     accepts = [
20         Auth(),
21         Mixed(Slice.fields['slice_id'],
22               Slice.fields['name']),
23         ]
24
25     returns = Parameter (str, "the slicefamily this slice should be based upon")
26
27     #
28     ### system slices - at least planetflow - still rely on 'vref'
29     #
30     def call(self, auth, slice_id_or_name):
31         # default values
32         arch = self.api.config.PLC_FLAVOUR_SLICE_ARCH
33         pldistro = self.api.config.PLC_FLAVOUR_SLICE_PLDISTRO
34         fcdistro = self.api.config.PLC_FLAVOUR_SLICE_FCDISTRO
35         vref = None
36  
37         # Get slice information
38         slices = Slices(self.api, [slice_id_or_name])
39         if not slices:
40             raise PLCInvalidArgument, "No such slice %r"%slice_id_or_name
41         slice = slices[0]
42         slice_tags = SliceTags(self.api, slice['slice_tag_ids'])
43        
44         for slice_tag in slice_tags:
45             if slice_tag['tagname'] == 'arch':
46                 arch = slice_tag['value']
47             elif slice_tag['tagname'] == 'pldistro':
48                 pldistro = slice_tag['value']
49             elif slice_tag['tagname'] == 'fcdistro':
50                 fcdistro = slice_tag['value']
51             elif slice_tag['tagname'] == 'vref':
52                 vref = slice_tag['value']
53
54         # omf-control'ed slivers need the omf vserver reference image
55         # we used to issue SetSliceVref (self.api) (auth,slice_id,'omf')
56         # to avoid asking users to set both tags 'omf_control' and 'vref'
57         # however we can't use SetSliceVref here because a node is only allowed 
58         # to set a sliver tag, not a slice tag
59         # and this somehow gets called from GetSlivers
60         # anyways it was a bad idea, let's have the UI do that instead
61
62         # xxx would make sense to check the corresponding vserver rpms are available
63         # in all node-families yum repos (and yumgroups, btw)
64         if vref:
65             return "%s-%s-%s"%(vref,fcdistro,arch)
66         else:
67             return "%s-%s-%s"%(pldistro,fcdistro,arch)