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.namespace 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 SfaRecord
15 from sfa.util.policy import Policy
16 from sfa.util.record import *
17 from sfa.util.sfaticket import SfaTicket
18 from sfa.server.registry import Registries
19 from sfa.plc.slices import Slices
20 import sfa.plc.peers as peers
21 from sfa.managers.vini.vini_network import *
22 from sfa.plc.api import SfaAPI
23 from sfa.plc.slices import *
24 from sfa.managers.aggregate_manager_pl import __get_registry_objects, __get_hostnames
26 # VINI aggregate is almost identical to PLC aggregate for many operations,
27 # so lets just import the methods form the PLC manager
29 from sfa.managers.aggregate_manager_pl import (
30 start_slice, stop_slice, renew_slice, reset_slice, get_slices, get_ticket)
35 version['geni_api'] = 1
39 def slice_status(api, slice_xrn, creds):
41 result['geni_urn'] = slice_xrn
42 result['geni_status'] = 'unknown'
43 result['geni_resources'] = {}
47 def delete_slice(api, xrn, creds):
48 hrn, type = urn_to_hrn(xrn)
49 slicename = hrn_to_pl_slicename(hrn)
50 slices = api.plshell.GetSlices(api.plauth, {'name': slicename})
55 api.plshell.DeleteSliceFromNodes(api.plauth, slicename, slice['node_ids'])
58 def create_slice(api, xrn, creds, xml, users):
60 Verify HRN and initialize the slice record in PLC if necessary.
63 hrn, type = urn_to_hrn(xrn)
65 reg_objects = __get_registry_objects(slice_xrn, creds, users)
67 peer = slices.get_peer(hrn)
68 sfa_peer = slices.get_sfa_peer(hrn)
69 registries = Registries(api)
70 registry = registries[api.hrn]
71 credential = api.getCredential()
72 site_id, remote_site_id = slices.verify_site(registry, credential, hrn,
73 peer, sfa_peer, reg_objects)
74 slice = slices.verify_slice(registry, credential, hrn, site_id,
75 remote_site_id, peer, sfa_peer, reg_objects)
77 network = ViniNetwork(api)
79 slice = network.get_slice(api, hrn)
80 current = __get_hostnames(slice.get_nodes())
82 network.addRSpec(xml, "/var/www/html/schemas/vini.rng")
83 #network.addRSpec(xml, "/root/SVN/sfa/trunk/sfa/managers/vini/vini.rng")
84 request = __get_hostnames(network.nodesWithSlivers())
86 # remove nodes not in rspec
87 deleted_nodes = list(set(current).difference(request))
89 # add nodes from rspec
90 added_nodes = list(set(request).difference(current))
92 api.plshell.AddSliceToNodes(api.plauth, slice.name, added_nodes)
93 api.plshell.DeleteSliceFromNodes(api.plauth, slice.name, deleted_nodes)
94 network.updateSliceTags()
96 # print network.toxml()
100 def get_rspec(api, creds, options):
101 # get slice's hrn from options
102 xrn = options.get('geni_slice_urn', None)
103 hrn, type = urn_to_hrn(xrn)
105 # look in cache first
106 if api.cache and not xrn:
107 rspec = api.cache.get('nodes')
111 network = ViniNetwork(api)
113 if network.get_slice(api, hrn):
116 rspec = network.toxml()
119 if api.cache and not xrn:
120 api.cache.add('nodes', rspec)
127 #rspec = get_rspec(api, None, None)
128 rspec = get_rspec(api, "plc.princeton.iias", None)
131 f = open(sys.argv[1])
134 create_slice(api, "plc.princeton.iias", xml)
136 if __name__ == "__main__":