Added a remctl script listuser which an admin can use remctl listuser $user and list...
authorPaul Weaver <pweaver@mit.edu>
Tue, 20 Oct 2009 01:03:17 +0000 (21:03 -0400)
committerPaul Weaver <pweaver@mit.edu>
Tue, 20 Oct 2009 01:03:17 +0000 (21:03 -0400)
user has permissions on along with contact data of those machines.

This can be used for a remctl script 'list' which will allow a user list their own machines.

svn path=/trunk/packages/invirt-remote/; revision=2508

server/etc/remctl/conf.d/invirt-web
server/usr/sbin/invirt-remote-listuser [new file with mode: 0755]

index f8cfd7a..52fc1ec 100644 (file)
@@ -1,4 +1,5 @@
 web      ALL   /usr/sbin/invirt-remote-proxy-web  /etc/remctl/remconffs/adminacl
+listuser ALL   /usr/sbin/invirt-remote-listuser          /etc/remctl/remconffs/adminacl
 control  help  /usr/sbin/invirt-remctl-help       ANYUSER
 include /etc/remctl/remconffs/conf
 control  ALL   /usr/sbin/invirt-remote-vminvalid  ANYUSER
diff --git a/server/usr/sbin/invirt-remote-listuser b/server/usr/sbin/invirt-remote-listuser
new file mode 100755 (executable)
index 0000000..a43412f
--- /dev/null
@@ -0,0 +1,30 @@
+#!/usr/bin/python
+"""
+Lists what a user's VM's are
+"""
+
+from subprocess import PIPE, Popen, call
+import sys
+import yaml
+
+from invirt import database
+from invirt.database import Machine, MachineAccess
+
+
+def main(argv):
+    if len(argv) < 2:
+        print >>sys.stderr, "usage: invirt-remote-listuser <user>"
+        return 2
+    username = argv[1]
+
+    database.connect()
+    machines = Machine.query().join('acl').filter_by(user=username)
+    output = "Machine Name \t\t Owner \t\t contact \n\r"
+    for m in machines:
+        output +=  m.name + "\t" + m.owner +"\t" +  m.contact + "\n\r"
+    print output
+    return 0
+if __name__ == '__main__':
+    sys.exit(main(sys.argv))
+
+# vim:et:sw=4:ts=4