From 7fc6edd3e87364689ca64ce77a54775a31f17de0 Mon Sep 17 00:00:00 2001 From: Josh Karlin Date: Fri, 23 Apr 2010 17:50:15 +0000 Subject: [PATCH] Fixing up for internal testing, about to merge with trunk again. --- sfa/managers/geni_am_pl.py | 23 +++++++++++++++++++---- sfa/methods/ListResources.py | 6 +++++- sfa/methods/get_credential.py | 1 - sfa/plc/network.py | 4 ---- sfa/trust/credential.py | 9 +++++---- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/sfa/managers/geni_am_pl.py b/sfa/managers/geni_am_pl.py index c91bf1dc..26e73f4a 100644 --- a/sfa/managers/geni_am_pl.py +++ b/sfa/managers/geni_am_pl.py @@ -7,7 +7,8 @@ from sfa.util.record import * from sfa.plc.slices import * from sfa.util.sfalogging import * -import zlib +from lxml import etree +from StringIO import StringIO def GetVersion(): version = {} @@ -29,11 +30,25 @@ def ListResources(api, creds, options): rspec = manager.get_rspec(api, xrn, None) - #outgoing_rules = SFATablesRules('OUTGOING') - if options.has_key('geni_compressed') and options['geni_compressed'] == True: - rspec = zlib.compress(rspec).encode('base64') + + # Filter out those objects that aren't allocated + if xrn: + tree = etree.parse(StringIO(rspec)) + used_nodes = [sliver.getparent() for sliver in tree.iterfind("./network/site/node/sliver")] + used_sites = [node.getparent() for node in used_nodes] + for node in tree.iterfind("./network/site/node"): + if node not in used_nodes: + parent = node.getparent() + parent.remove(node) + # Remove unused sites + for site in tree.iterfind("./network/site"): + if site not in used_sites: + parent = site.getparent() + parent.remove(site) + rspec = etree.tostring(tree) + return rspec diff --git a/sfa/methods/ListResources.py b/sfa/methods/ListResources.py index 78581726..ffc57cf7 100644 --- a/sfa/methods/ListResources.py +++ b/sfa/methods/ListResources.py @@ -5,7 +5,7 @@ from sfa.util.parameter import Parameter, Mixed from sfa.trust.credential import Credential from sfatables.runtime import SFATablesRules import sys - +import zlib class ListResources(Method): """ @@ -49,6 +49,10 @@ class ListResources(Method): context = {'sfa':{'user':{'hrn':origin_hrn}, 'slice':{'hrn':None}}} outgoing_rules.set_context(context) filtered_rspec = outgoing_rules.apply(rspec) + + if options.has_key('geni_compressed') and options['geni_compressed'] == True: + filtered_rspec = zlib.compress(rspec).encode('base64') + return filtered_rspec diff --git a/sfa/methods/get_credential.py b/sfa/methods/get_credential.py index 14b9d1a1..c624b1b6 100644 --- a/sfa/methods/get_credential.py +++ b/sfa/methods/get_credential.py @@ -42,7 +42,6 @@ class get_credential(Method): if not origin_hrn: origin_hrn = Credential(string=cred).get_gid_caller().get_hrn() self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name)) - self.api.logger.info("get_credential cred = %s" % cred) self.api.auth.check(cred, 'getcredential') self.api.auth.verify_object_belongs_to_me(hrn) diff --git a/sfa/plc/network.py b/sfa/plc/network.py index 9a1bdb1c..27f2f8cc 100644 --- a/sfa/plc/network.py +++ b/sfa/plc/network.py @@ -16,7 +16,6 @@ class Sliver: self.slice = node.network.slice def toxml(self, xml): - logger.info("sliver to xml!") with xml.sliver: self.slice.tags_to_xml(xml, self.node) @@ -65,7 +64,6 @@ class Node: self.sliver = Sliver(self) def toxml(self, xml): - logger.info("node.toxml(I)") slice = self.network.slice if self.whitelist and not self.sliver: if not slice or slice.id not in self.whitelist: @@ -199,8 +197,6 @@ class Slice: xml << (tag.tagname, tag.value) def toxml(self, xml): - logger.info("slice to xml!") - with xml.sliver_defaults: self.tags_to_xml(xml) diff --git a/sfa/trust/credential.py b/sfa/trust/credential.py index bb58407e..450c59f0 100644 --- a/sfa/trust/credential.py +++ b/sfa/trust/credential.py @@ -27,6 +27,7 @@ DEFAULT_CREDENTIAL_LIFETIME = 60 * 60 * 24 * 365 * 2 # TODO: +# . fix verify_issuer() and call it at the end of verify() # . make privs match between PG and PL # . Need to add support for other types of credentials, e.g. tickets @@ -673,8 +674,9 @@ class Credential(object): # Verify the parents (delegation) if self.parent: self.verify_parent(self.parent) + # Make sure the issuer is the target's authority - self.verify_issuer() + #self.verify_issuer() return True @@ -682,7 +684,6 @@ class Credential(object): # Make sure the issuer of this credential is the target's authority def verify_issuer(self): target_authority = get_authority(self.get_gid_object().get_urn()) - # Find the root credential's signature cur_cred = self @@ -697,8 +698,8 @@ class Credential(object): target_authority = hrn_to_urn(target_authority, 'authority') if root_issuer != target_authority: - raise CredentialNotVerifiable("issuer (%s) != authority of target (%s)" \ - % (root_issuer, target_authority)) + raise CredentialNotVerifiable("issuer (%s) != authority of target (%s) for target (%s)" \ + % (root_issuer, target_authority, self.get_gid_object().get_urn())) ## # -- For Delegates (credentials with parents) verify that: -- 2.47.0