moved rspec managers here from and named them aggregate managers
[sfa.git] / sfa / managers / aggregate_manager_pl.py
1 ### $Id: slices.py 15842 2009-11-22 09:56:13Z anil $
2 ### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/plc/slices.py $
3
4 import datetime
5 import time
6 import traceback
7 import sys
8
9 from types import StringTypes
10 from sfa.util.misc import *
11 from sfa.util.rspec import *
12 from sfa.util.specdict import *
13 from sfa.util.faults import *
14 from sfa.util.record import GeniRecord
15 from sfa.util.policy import Policy
16 from sfa.util.prefixTree import prefixTree
17 from sfa.util.debug import log
18 from sfa.server.registry import Registries
19 import sfa.plc.peers as peers
20
21 def delete_slice(api, hrn):
22     slicename = hrn_to_pl_slicename(hrn)
23     slices = api.plshell.GetSlices(api.plauth, {'name': slicename})
24     if not slices:
25         return 1
26     slice = slices[0]
27
28     # determine if this is a peer slice
29     peer = peers.get_peer(api, hrn)
30     if peer:
31         api.plshell.UnBindObjectFromPeer(api.plauth, 'slice', slice['slice_id'], peer)
32     api.plshell.DeleteSliceFromNodes(api.plauth, slicename, slice['node_ids'])
33     if peer:
34         api.plshell.BindObjectToPeer(api.plauth, 'slice', slice['slice_id'], peer, slice['peer_slice_id'])
35     return 1
36
37 def create_slice(api, hrn, rspec):
38     # XX just import the legacy module and excute that until
39     # we transition the code to this module
40     from sfa.plc.slices import Slices
41     slices = Slices(api)
42     slices.create_slice(hrn, rspec)
43
44 def start_slice(api, hrn):
45     slicename = hrn_to_pl_slicename(hrn)
46     slices = api.plshell.GetSlices(api.plauth, {'name': slicename}, ['slice_id'])
47     if not slices:
48         raise RecordNotFound(hrn)
49     slice_id = slices[0]
50     attributes = api.plshell.GetSliceTags(api.plauth, {'slice_id': slice_id, 'name': 'enabled'}, ['slice_attribute_id'])
51     attribute_id = attreibutes[0]['slice_attribute_id']
52     api.plshell.UpdateSliceTag(api.plauth, attribute_id, "1" )
53
54     return 1
55  
56 def stop_slice(api, hrn):
57     slicename = hrn_to_pl_slicename(hrn)
58     slices = api.plshell.GetSlices(api.plauth, {'name': slicename}, ['slice_id'])
59     if not slices:
60         raise RecordNotFound(hrn)
61     slice_id = slices[0]['slice_id']
62     attributes = api.plshell.GetSliceTags(api.plauth, {'slice_id': slice_id, 'name': 'enabled'}, ['slice_attribute_id'])
63     attribute_id = attributes[0]['slice_attribute_id']
64     api.plshell.UpdateSliceTag(api.plauth, attribute_id, "0")
65     return 1
66
67 def reset_slice(api, hrn):
68     # XX not implemented at this interface
69     return 1
70
71 def get_slices(api):
72     # XX just import the legacy module and excute that until
73     # we transition the code to this module
74     from sfa.plc.slices import Slices
75     slices = Slices(api)
76     slices.refresh()
77     return slices['hrn']
78      
79    
80 def get_rspec(api, hrn=None):
81     nodes = Nodes(api)
82     if hrn:
83         rspec = nodes.get_rspec(hrn)
84     else:
85         nodes.refresh()
86         rspec = nodes['rspec'] 
87
88     return rspec