Merge from trunk
[plcapi.git] / trunk / PLC / Methods / DeleteRole.py
diff --git a/trunk/PLC/Methods/DeleteRole.py b/trunk/PLC/Methods/DeleteRole.py
new file mode 100644 (file)
index 0000000..f707280
--- /dev/null
@@ -0,0 +1,38 @@
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.Roles import Role, Roles
+from PLC.Auth import Auth
+
+class DeleteRole(Method):
+    """
+    Deletes a role.
+
+    WARNING: This will remove the specified role from all accounts
+    that possess it, and from all node and slice attributes that refer
+    to it.
+
+    Returns 1 if successful, faults otherwise.
+    """
+
+    roles = ['admin']
+
+    accepts = [
+        Auth(),
+        Mixed(Role.fields['role_id'],
+              Role.fields['name'])
+        ]
+
+    returns = Parameter(int, '1 if successful')
+
+    
+    def call(self, auth, role_id_or_name):
+        roles = Roles(self.api, [role_id_or_name])
+        if not roles:
+            raise PLCInvalidArgument, "No such role"
+        role = roles[0]
+
+        role.delete()
+       self.event_objects = {'Role': [role['role_id']]}
+
+        return 1