Added resolve/shutdown files
authorJosh Karlin <jkarlin@bbn.com>
Tue, 20 Apr 2010 15:35:18 +0000 (15:35 +0000)
committerJosh Karlin <jkarlin@bbn.com>
Tue, 20 Apr 2010 15:35:18 +0000 (15:35 +0000)
sfa/methods/Resolve.py [new file with mode: 0644]
sfa/methods/Shutdown.py [new file with mode: 0644]

diff --git a/sfa/methods/Resolve.py b/sfa/methods/Resolve.py
new file mode 100644 (file)
index 0000000..b694bc8
--- /dev/null
@@ -0,0 +1,42 @@
+from sfa.util.faults import *
+from sfa.util.namespace import *
+from sfa.util.method import Method
+from sfa.util.parameter import Parameter
+
+
+class Resolve(Method):
+    """
+    Lookup a URN and return information about the corresponding object.
+    @param slice_urn (string) URN of slice to renew
+    @param credentials ([string]) of credentials
+    
+    """
+    interfaces = ['registry']
+    accepts = [
+        Parameter(str, "URN"),
+        Parameter(type([str]), "List of credentials"),
+        ]
+    returns = Parameter(bool, "Success or Failure")
+
+    def call(self, xrn, creds):
+        for cred in creds:
+            try:
+                self.api.auth.check(cred, 'resolve')
+                found = True
+                break
+            except:
+                continue
+            
+        if not found:
+            raise InsufficientRights('Resolve: Credentials either did not verify, were no longer valid, or did not have appropriate privileges')
+        
+
+        manager_base = 'sfa.managers'
+
+        if self.api.interface in ['registry']:
+            mgr_type = self.api.config.SFA_REGISTRY_TYPE
+            manager_module = manager_base + ".registry_manager_%s" % mgr_type
+            manager = __import__(manager_module, fromlist=[manager_base])
+            return manager.Resolve(self.api, xrn, creds)
+               
+        return {}
\ No newline at end of file
diff --git a/sfa/methods/Shutdown.py b/sfa/methods/Shutdown.py
new file mode 100644 (file)
index 0000000..4445ae2
--- /dev/null
@@ -0,0 +1,49 @@
+from sfa.util.faults import *
+from sfa.util.namespace import *
+from sfa.util.method import Method
+from sfa.util.parameter import Parameter
+
+
+class Shutdown(Method):
+    """
+    Perform an emergency shut down of a sliver. This operation is intended for administrative use. 
+    The sliver is shut down but remains available for further forensics.
+
+    @param slice_urn (string) URN of slice to renew
+    @param credentials ([string]) of credentials    
+    """
+    interfaces = ['geni_am']
+    accepts = [
+        Parameter(str, "Slice URN"),
+        Parameter(type([str]), "List of credentials"),
+        ]
+    returns = Parameter(bool, "Success or Failure")
+
+    def call(self, slice_xrn, creds, expiration_time):
+        hrn, type = urn_to_hrn(slice_xrn)
+
+        self.api.logger.info("interface: %s\ttarget-hrn: %s\tcaller-creds: %s\tmethod-name: %s"%(self.api.interface, hrn, creds, self.name))
+
+        # Validate that at least one of the credentials is good enough
+        found = False
+        for cred in creds:
+            try:
+                self.api.auth.check(cred, 'shutdown')
+                found = True
+                break
+            except:
+                continue
+            
+        if not found:
+            raise InsufficientRights('Shutdown: Credentials either did not verify, were no longer valid, or did not have appropriate privileges')
+            
+        manager_base = 'sfa.managers'
+
+        if self.api.interface in ['geni_am']:
+            mgr_type = self.api.config.SFA_GENI_AGGREGATE_TYPE
+            manager_module = manager_base + ".geni_am_%s" % mgr_type
+            manager = __import__(manager_module, fromlist=[manager_base])
+            return manager.Shutdown(self.api, slice_xrn, creds)
+
+        return ''
+