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 $
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
21 def delete_slice(api, hrn):
22 slicename = hrn_to_pl_slicename(hrn)
23 slices = api.plshell.GetSlices(api.plauth, {'name': slicename})
28 # determine if this is a peer slice
29 peer = peers.get_peer(api, hrn)
31 api.plshell.UnBindObjectFromPeer(api.plauth, 'slice', slice['slice_id'], peer)
32 api.plshell.DeleteSliceFromNodes(api.plauth, slicename, slice['node_ids'])
34 api.plshell.BindObjectToPeer(api.plauth, 'slice', slice['slice_id'], peer, slice['peer_slice_id'])
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
42 slices.create_slice(hrn, rspec)
44 def start_slice(api, hrn):
45 slicename = hrn_to_pl_slicename(hrn)
46 slices = api.plshell.GetSlices(api.plauth, {'name': slicename}, ['slice_id'])
48 raise RecordNotFound(hrn)
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" )
56 def stop_slice(api, hrn):
57 slicename = hrn_to_pl_slicename(hrn)
58 slices = api.plshell.GetSlices(api.plauth, {'name': slicename}, ['slice_id'])
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")
67 def reset_slice(api, hrn):
68 # XX not implemented at this interface
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
80 def get_rspec(api, hrn=None, caller_cred=None):
81 from sfa.plc.nodes import Nodes
82 nodes = Nodes(api, caller_cred=caller_cred)
84 rspec = nodes.get_rspec(hrn)
87 rspec = nodes['rspec']
92 Returns the request context required by sfatables. At some point, this mechanism should be changed
93 to refer to "contexts", which is the information that sfatables is requesting. But for now, we just
94 return the basic information needed in a dict.
96 def fetch_context(slice_hrn, user_hrn, contexts):
97 base_context = {'sfa':{'user':{'hrn':user_hrn}}}
102 r.parseFile(sys.argv[1])
104 create_slice(None,'plc.princeton.tmacktestslice',rspec)
106 if __name__ == "__main__":