1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
import sys, xmlrpclib
rpc_srv = xmlrpclib.ServerProxy("https://admin:admin@localhost:8080")
if len(sys.argv) == 1:
print "%s list_users <server>" % (sys.argv[0])
print "%s create_user <server> <username> <fullname> <password> <source> <session>" % (sys.argv[0])
print "%s delete_user <server> <username>" % (sys.argv[0])
sys.exit(1)
if len(sys.argv) > 1 and sys.argv[1] not in ['list_users','create_user','delete_user']:
print "Invalid command: %s" % sys.argv[1]
sys.exit(1)
if sys.argv[1] == "list_users":
if len(sys.argv) != 3 and len(sys.argv) != 4:
print "Invalid parameters"
sys.exit(1)
else:
if len(sys.argv) == 3:
for user in rpc_srv.vmmanager.list_users(sys.argv[2]):
print "%s - %s - %s - %s (%s)" % (user['username'],user['fullname'],user['source'],user['session'],user['created'])
else:
for user in rpc_srv.vmmanager.list_users(sys.argv[2],False):
print "%s - %s - %s - %s (%s)" % (user['username'],user['fullname'],user['source'],user['session'],user['created'])
if sys.argv[1] == "create_user":
if len(sys.argv) != 8:
print "Invalid parameters"
sys.exit(1)
else:
print rpc_srv.vmmanager.create_user(sys.argv[2],sys.argv[3],sys.argv[4],sys.argv[5],sys.argv[6],sys.argv[7])
if sys.argv[1] == "delete_user":
if len(sys.argv) != 4:
print "Invalid parameters"
sys.exit(1)
else:
print rpc_srv.vmmanager.delete_user(sys.argv[2],sys.argv[3])
|