6 from types import StringTypes
7 from sfa.util.namespace import hrn_to_pl_slicename, urn_to_hrn
8 from sfa.util.rspec import *
9 from sfa.util.specdict import *
10 from sfa.util.faults import *
11 from sfa.util.record import SfaRecord
12 from sfa.util.policy import Policy
13 from sfa.util.record import *
14 from sfa.util.sfaticket import SfaTicket
15 from sfa.server.registry import Registries
16 from sfa.plc.slices import Slices
17 import sfa.plc.peers as peers
18 from sfa.managers.vini.vini_network import *
19 from sfa.plc.api import SfaAPI
20 from sfa.plc.slices import *
21 from sfa.managers.aggregate_manager_pl import __get_registry_objects, __get_hostnames
23 # VINI aggregate is almost identical to PLC aggregate for many operations,
24 # so lets just import the methods form the PLC manager
26 from sfa.managers.aggregate_manager_pl import (
27 start_slice, stop_slice, renew_slice, reset_slice, get_slices, get_ticket)
32 version['geni_api'] = 1
36 def slice_status(api, slice_xrn, creds):
38 result['geni_urn'] = slice_xrn
39 result['geni_status'] = 'unknown'
40 result['geni_resources'] = {}
44 def delete_slice(api, xrn, creds):
45 hrn, type = urn_to_hrn(xrn)
46 slicename = hrn_to_pl_slicename(hrn)
47 slices = api.plshell.GetSlices(api.plauth, {'name': slicename})
52 api.plshell.DeleteSliceFromNodes(api.plauth, slicename, slice['node_ids'])
55 def create_slice(api, xrn, creds, xml, users):
57 Verify HRN and initialize the slice record in PLC if necessary.
60 hrn, type = urn_to_hrn(xrn)
62 reg_objects = __get_registry_objects(slice_xrn, creds, users)
64 peer = slices.get_peer(hrn)
65 sfa_peer = slices.get_sfa_peer(hrn)
66 registries = Registries(api)
67 registry = registries[api.hrn]
68 credential = api.getCredential()
69 site_id, remote_site_id = slices.verify_site(registry, credential, hrn,
70 peer, sfa_peer, reg_objects)
71 slice = slices.verify_slice(registry, credential, hrn, site_id,
72 remote_site_id, peer, sfa_peer, reg_objects)
74 network = ViniNetwork(api)
76 slice = network.get_slice(api, hrn)
77 current = __get_hostnames(slice.get_nodes())
79 network.addRSpec(xml, "/var/www/html/schemas/vini.rng")
80 #network.addRSpec(xml, "/root/SVN/sfa/trunk/sfa/managers/vini/vini.rng")
81 request = __get_hostnames(network.nodesWithSlivers())
83 # remove nodes not in rspec
84 deleted_nodes = list(set(current).difference(request))
86 # add nodes from rspec
87 added_nodes = list(set(request).difference(current))
89 api.plshell.AddSliceToNodes(api.plauth, slice.name, added_nodes)
90 api.plshell.DeleteSliceFromNodes(api.plauth, slice.name, deleted_nodes)
91 network.updateSliceTags()
93 # print network.toxml()
97 def get_rspec(api, creds, options):
98 # get slice's hrn from options
99 xrn = options.get('geni_slice_urn', None)
100 hrn, type = urn_to_hrn(xrn)
102 # look in cache first
103 if api.cache and not xrn:
104 rspec = api.cache.get('nodes')
108 network = ViniNetwork(api)
110 if network.get_slice(api, hrn):
113 rspec = network.toxml()
116 if api.cache and not xrn:
117 api.cache.add('nodes', rspec)
124 #rspec = get_rspec(api, None, None)
125 rspec = get_rspec(api, "plc.princeton.iias", None)
128 f = open(sys.argv[1])
131 create_slice(api, "plc.princeton.iias", xml)
133 if __name__ == "__main__":