From 2d26feb620d723e5003f6cc0909cb50b45cca967 Mon Sep 17 00:00:00 2001
From: Thierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Date: Fri, 20 Feb 2009 14:55:47 +0000
Subject: [PATCH] new API call for planetflow central to solve slice names from
 ids

---
 PLC/Methods/ResolveSlices.py | 41 ++++++++++++++++++++++++++++++++++++
 PLC/Methods/__init__.py      |  1 +
 2 files changed, 42 insertions(+)
 create mode 100644 PLC/Methods/ResolveSlices.py

diff --git a/PLC/Methods/ResolveSlices.py b/PLC/Methods/ResolveSlices.py
new file mode 100644
index 00000000..5574fede
--- /dev/null
+++ b/PLC/Methods/ResolveSlices.py
@@ -0,0 +1,41 @@
+# $Id$
+
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.Filter import Filter
+from PLC.Auth import Auth
+from PLC.Slices import Slice, Slices
+
+class ResolveSlices(Method):
+    """
+    This method is similar to GetSlices, except the the returned
+    columns are restricted to 'name' and 'slice_id'. This is method
+    designed to help third-party software solve slice names from their
+    slice_id (e.g. PlanetFlow Central).  For this reason it is
+    accessible with anonymous authentication (among others)
+    """
+
+    roles = ['admin', 'pi', 'user', 'tech', 'anonymous' ]
+
+    applicable_fields = { 
+        'slice_id' : Slice.fields['slice_id'],
+        'name' : Slice.fields['name'],
+        }
+
+    accepts = [
+        Auth(),
+        Mixed([Mixed(Slice.fields['slice_id'],
+                     Slice.fields['name'])],
+              Parameter(str,"name"),
+              Parameter(int,"slice_id"),
+              Filter(applicable_fields))
+        ]
+
+    returns = [applicable_fields]
+
+    def call(self, auth, slice_filter = None):
+
+        # Must query at least slice_id (see below)
+        return_fields = applicable_fields.keys()
+        slices = Slices(self.api, slice_filter, return_fields)
+        return slices
diff --git a/PLC/Methods/__init__.py b/PLC/Methods/__init__.py
index 8e5a3346..2cec615e 100644
--- a/PLC/Methods/__init__.py
+++ b/PLC/Methods/__init__.py
@@ -187,6 +187,7 @@ RebootNode
 RebootNodeWithPCU
 RefreshPeer
 ResetPassword
+ResolveSlices
 SetPersonPrimarySite
 SliceCreate
 SliceDelete
-- 
2.47.0