6 from types import StringTypes
7 from sfa.util.xrn import urn_to_hrn, Xrn
8 from sfa.util.plxrn import hrn_to_pl_slicename
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.vini_aggregate import ViniAggregate
20 from sfa.rspecs.version_manager import VersionManager
21 from sfa.plc.api import SfaAPI
22 from sfa.plc.slices import *
23 from sfa.managers.aggregate_manager_pl import __get_registry_objects, __get_hostnames
24 from sfa.util.version import version_core
25 from sfa.util.callids import Callids
27 # VINI aggregate is almost identical to PLC aggregate for many operations,
28 # so lets just import the methods form the PLC manager
29 from sfa.managers.aggregate_manager_pl import (
30 start_slice, stop_slice, RenewSliver, reset_slice, ListSlices, get_ticket, SliverStatus)
35 return version_core({'interface':'aggregate',
36 'testbed':'myplc.vini',
40 def DeleteSliver(api, xrn, creds, call_id):
41 if Callids().already_handled(call_id): return ""
42 (hrn, type) = urn_to_hrn(xrn)
43 slicename = hrn_to_pl_slicename(hrn)
44 slices = api.plshell.GetSlices(api.plauth, {'name': slicename})
49 api.plshell.DeleteSliceFromNodes(api.plauth, slicename, slice['node_ids'])
52 def CreateSliver(api, xrn, creds, xml, users, call_id):
54 Verify HRN and initialize the slice record in PLC if necessary.
57 if Callids().already_handled(call_id): return ""
59 hrn, type = urn_to_hrn(xrn)
61 reg_objects = __get_registry_objects(xrn, creds, users)
63 peer = slices.get_peer(hrn)
64 sfa_peer = slices.get_sfa_peer(hrn)
65 registries = Registries(api)
66 registry = registries[api.hrn]
67 credential = api.getCredential()
68 site_id, remote_site_id = slices.verify_site(registry, credential, hrn,
69 peer, sfa_peer, reg_objects)
70 slice = slices.verify_slice(registry, credential, hrn, site_id,
71 remote_site_id, peer, sfa_peer, reg_objects)
73 network = ViniNetwork(api)
75 slice = network.get_slice(api, hrn)
76 current = __get_hostnames(slice.get_nodes())
78 network.addRSpec(xml, "/var/www/html/schemas/vini.rng")
79 #network.addRSpec(xml, "/root/SVN/sfa/trunk/sfa/managers/vini/vini.rng")
80 request = __get_hostnames(network.nodesWithSlivers())
82 # remove nodes not in rspec
83 deleted_nodes = list(set(current).difference(request))
85 # add nodes from rspec
86 added_nodes = list(set(request).difference(current))
88 api.plshell.AddSliceToNodes(api.plauth, slice.name, added_nodes)
89 api.plshell.DeleteSliceFromNodes(api.plauth, slice.name, deleted_nodes)
90 network.updateSliceTags()
92 # xxx - check this holds enough data for the client to understand what's happened
93 return network.toxml()
95 def ListResources(api, creds, options,call_id):
96 if Callids().already_handled(call_id): return ""
97 # get slice's hrn from options
98 xrn = options.get('geni_slice_urn', '')
99 hrn, type = urn_to_hrn(xrn)
101 version_manager = VersionManager()
102 # get the rspec's return format from options
103 rspec_version = version_manager.get_version(options.get('rspec_version'))
104 version_string = "rspec_%s" % (rspec_version.to_string())
106 # look in cache first
107 if api.cache and not xrn:
108 rspec = api.cache.get(version_string)
110 api.logger.info("aggregate.ListResources: returning cached value for hrn %s"%hrn)
113 aggregate = ViniAggregate(api, options)
114 rspec = aggregate.get_rspec(slice_xrn=xrn, version=rspec_version)
117 if api.cache and not xrn:
118 api.cache.add('nodes', rspec)
125 #rspec = ListResources(api, None, None,)
126 rspec = ListResources(api, "plc.princeton.iias", None, 'vini_test')
129 f = open(sys.argv[1])
132 CreateSliver(api, "plc.princeton.iias", xml, 'call-id-iias')
134 if __name__ == "__main__":