X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fmanagers%2Fslice_manager.py;h=685e67a7bddce0893a4f9999160f7e92ecfd1fa4;hb=fd26329a0ce5139c6e4938157fc54fafe431f3bc;hp=31753106da4ada922a553599c54ddb1d7c8c4650;hpb=b28b70593bb5ac1d3017910736b64d8f3140a90f;p=sfa.git diff --git a/sfa/managers/slice_manager.py b/sfa/managers/slice_manager.py index 31753106..685e67a7 100644 --- a/sfa/managers/slice_manager.py +++ b/sfa/managers/slice_manager.py @@ -1,33 +1,23 @@ -# import sys -import time,datetime +import time from StringIO import StringIO -from types import StringTypes -from copy import deepcopy from copy import copy from lxml import etree -from sfa.util.sfalogging import logger -from sfa.util.rspecHelper import merge_rspecs -from sfa.util.xrn import Xrn, urn_to_hrn, hrn_to_urn -from sfa.util.plxrn import hrn_to_pl_slicename -from sfa.util.specdict import * -from sfa.util.faults import * -from sfa.util.record import SfaRecord -from sfa.rspecs.rspec_converter import RSpecConverter -from sfa.client.client_helper import sfa_to_pg_users_arg -from sfa.rspecs.version_manager import VersionManager -from sfa.rspecs.rspec import RSpec -from sfa.util.policy import Policy -from sfa.util.prefixTree import prefixTree -from sfa.util.sfaticket import * +from sfa.trust.sfaticket import SfaTicket from sfa.trust.credential import Credential -from sfa.util.threadmanager import ThreadManager -import sfa.util.xmlrpcprotocol as xmlrpcprotocol -import sfa.plc.peers as peers + +from sfa.util.sfalogging import logger +from sfa.util.xrn import Xrn, urn_to_hrn from sfa.util.version import version_core from sfa.util.callids import Callids +from sfa.server.threadmanager import ThreadManager + +from sfa.rspecs.rspec_converter import RSpecConverter +from sfa.rspecs.version_manager import VersionManager +from sfa.rspecs.rspec import RSpec +from sfa.client.client_helper import sfa_to_pg_users_arg def _call_id_supported(api, server): """ @@ -91,7 +81,7 @@ def drop_slicemgr_stats(rspec): for node in stats_elements: node.getparent().remove(node) except Exception, e: - api.logger.warn("drop_slicemgr_stats failed: %s " % (str(e))) + logger.warn("drop_slicemgr_stats failed: %s " % (str(e))) def add_slicemgr_stat(rspec, callname, aggname, elapsed, status): try: @@ -103,7 +93,7 @@ def add_slicemgr_stat(rspec, callname, aggname, elapsed, status): etree.SubElement(stats_tag, "aggregate", name=str(aggname), elapsed=str(elapsed), status=str(status)) except Exception, e: - api.logger.warn("add_slicemgr_stat failed on %s: %s" %(aggname, str(e))) + logger.warn("add_slicemgr_stat failed on %s: %s" %(aggname, str(e))) def ListResources(api, creds, options, call_id): version_manager = VersionManager() @@ -160,7 +150,7 @@ def ListResources(api, creds, options, call_id): # get the rspec from the aggregate interface = api.aggregates[aggregate] - server = api.get_server(interface, cred) + server = api.server_proxy(interface, cred) threads.run(_ListResources, aggregate, server, [cred], options, call_id) @@ -218,9 +208,9 @@ def CreateSliver(api, xrn, creds, rspec_str, users, call_id): # The schema used here needs to aggregate the PL and VINI schemas # schema = "/var/www/html/schemas/pl.rng" rspec = RSpec(rspec_str) - schema = None - if schema: - rspec.validate(schema) +# schema = None +# if schema: +# rspec.validate(schema) # if there is a section, the aggregates don't care about it, # so delete it. @@ -242,7 +232,7 @@ def CreateSliver(api, xrn, creds, rspec_str, users, call_id): if caller_hrn == aggregate and aggregate != api.hrn: continue interface = api.aggregates[aggregate] - server = api.get_server(interface, cred) + server = api.server_proxy(interface, cred) # Just send entire RSpec to each aggregate threads.run(_CreateSliver, aggregate, server, xrn, [cred], rspec.toxml(), users, call_id) @@ -284,7 +274,7 @@ def RenewSliver(api, xrn, creds, expiration_time, call_id): if caller_hrn == aggregate and aggregate != api.hrn: continue interface = api.aggregates[aggregate] - server = api.get_server(interface, cred) + server = api.server_proxy(interface, cred) threads.run(_RenewSliver, server, xrn, [cred], expiration_time, call_id) # 'and' the results return reduce (lambda x,y: x and y, threads.get_results() , True) @@ -314,7 +304,7 @@ def DeleteSliver(api, xrn, creds, call_id): if caller_hrn == aggregate and aggregate != api.hrn: continue interface = api.aggregates[aggregate] - server = api.get_server(interface, cred) + server = api.server_proxy(interface, cred) threads.run(_DeleteSliver, server, xrn, [cred], call_id) threads.get_results() return 1 @@ -337,7 +327,7 @@ def SliverStatus(api, slice_xrn, creds, call_id): threads = ThreadManager() for aggregate in api.aggregates: interface = api.aggregates[aggregate] - server = api.get_server(interface, cred) + server = api.server_proxy(interface, cred) threads.run (_SliverStatus, server, slice_xrn, [cred], call_id) results = threads.get_results() @@ -396,7 +386,7 @@ def ListSlices(api, creds, call_id): if caller_hrn == aggregate and aggregate != api.hrn: continue interface = api.aggregates[aggregate] - server = api.get_server(interface, cred) + server = api.server_proxy(interface, cred) threads.run(_ListSlices, server, [cred], call_id) # combime results @@ -438,13 +428,13 @@ def get_ticket(api, xrn, creds, rspec, users): continue interface = api.aggregates[aggregate] - server = api.get_server(interface, cred) + server = api.server_proxy(interface, cred) threads.run(server.GetTicket, xrn, [cred], aggregate_rspec, users) results = threads.get_results() # gather information from each ticket - rspecs = [] + rspec = None initscripts = [] slivers = [] object_gid = None @@ -453,15 +443,17 @@ def get_ticket(api, xrn, creds, rspec, users): attrs = agg_ticket.get_attributes() if not object_gid: object_gid = agg_ticket.get_gid_object() - rspecs.append(agg_ticket.get_rspec()) + if not rspec: + rspec = RSpec(agg_ticket.get_rspec()) + else: + rspec.version.merge(agg_ticket.get_rspec()) initscripts.extend(attrs.get('initscripts', [])) slivers.extend(attrs.get('slivers', [])) # merge info attributes = {'initscripts': initscripts, 'slivers': slivers} - merged_rspec = merge_rspecs(rspecs) - + # create a new ticket ticket = SfaTicket(subject = slice_hrn) ticket.set_gid_caller(api.auth.client_gid) @@ -470,7 +462,7 @@ def get_ticket(api, xrn, creds, rspec, users): ticket.set_pubkey(object_gid.get_pubkey()) #new_ticket.set_parent(api.auth.hierarchy.get_auth_ticket(auth_hrn)) ticket.set_attributes(attributes) - ticket.set_rspec(merged_rspec) + ticket.set_rspec(rspec.toxml()) ticket.encode() ticket.sign() return ticket.save_to_string(save_parents=True) @@ -493,7 +485,7 @@ def start_slice(api, xrn, creds): if caller_hrn == aggregate and aggregate != api.hrn: continue interface = api.aggregates[aggregate] - server = api.get_server(interface, cred) + server = api.server_proxy(interface, cred) threads.run(server.Start, xrn, cred) threads.get_results() return 1 @@ -516,7 +508,7 @@ def stop_slice(api, xrn, creds): if caller_hrn == aggregate and aggregate != api.hrn: continue interface = api.aggregates[aggregate] - server = api.get_server(interface, cred) + server = api.server_proxy(interface, cred) threads.run(server.Stop, xrn, cred) threads.get_results() return 1 @@ -539,11 +531,12 @@ def status(api, xrn, creds): """ return 1 -def main(): - r = RSpec() - r.parseFile(sys.argv[1]) - rspec = r.toDict() - CreateSliver(None,'plc.princeton.tmacktestslice',rspec,'create-slice-tmacktestslice') +# this is plain broken +#def main(): +# r = RSpec() +# r.parseFile(sys.argv[1]) +# rspec = r.toDict() +# CreateSliver(None,'plc.princeton.tmacktestslice',rspec,'create-slice-tmacktestslice') if __name__ == "__main__": main()