ia64/xen-unstable

view tools/python/xen/xm/labels.py @ 9835:cf20dbbf5c2b

This patch adds new python access control management scripts, which
integrate into Xen Management and which support the new access control
labels (labels replace the ssidref numbers at the management user
interface).

Signed-off by: Reiner Sailer <sailer@us.ibm.com>
author smh22@firebug.cl.cam.ac.uk
date Mon Apr 24 10:58:25 2006 +0100 (2006-04-24)
parents
children 88dc1ae16d2b
line source
1 #============================================================================
2 # This library is free software; you can redistribute it and/or
3 # modify it under the terms of version 2.1 of the GNU Lesser General Public
4 # License as published by the Free Software Foundation.
5 #
6 # This library is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 # Lesser General Public License for more details.
10 #
11 # You should have received a copy of the GNU Lesser General Public
12 # License along with this library; if not, write to the Free Software
13 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 #============================================================================
15 # Copyright (C) 2006 International Business Machines Corp.
16 # Author: Reiner Sailer <sailer@us.ibm.com>
17 #============================================================================
19 """Listing available labels for a policy.
20 """
21 import sys
22 import traceback
23 import os
24 import commands
25 import shutil
26 import string
27 from xen.util.security import ACMError, err, list_labels, active_policy
28 from xen.util.security import vm_label_re, res_label_re, all_label_re
30 def usage():
31 print "\nUsage: xm labels [<policy>] [<type=dom|res|any>]\n"
32 print " Prints labels of the specified type (default is dom)"
33 print " that are defined in policy (default is current"
34 print " hypervisor policy).\n"
35 err("Usage")
38 def main(argv):
39 try:
40 policy = None
41 type = None
42 for i in argv[1:]:
43 i_s = string.split(i, '=')
44 if len(i_s) > 1:
45 if (i_s[0] == 'type') and (len(i_s) == 2):
46 if not type:
47 type = i_s[1]
48 else:
49 usage()
50 else:
51 usage()
52 else:
53 if not policy:
54 policy = i
55 else:
56 usage()
58 if not policy:
59 policy = active_policy
60 if active_policy in ['NULL', 'INACTIVE', 'DEFAULT']:
61 err("No policy active. Please specify the <policy> parameter.")
63 if not type or (type in ['DOM', 'dom']):
64 condition = vm_label_re
65 elif type in ['RES', 'res']:
66 condition = res_label_re
67 elif type in ['ANY', 'any']:
68 condition = all_label_re
69 else:
70 err("Unknown label type \'" + type + "\'")
72 labels = list_labels(policy, condition)
73 labels.sort()
74 for label in labels:
75 print label
76 except ACMError:
77 pass
78 except:
79 traceback.print_exc(limit=1)
82 if __name__ == '__main__':
83 main(sys.argv)