debuggers.hg

view tools/python/xen/xm/dumppolicy.py @ 0:7d21f7218375

Exact replica of unstable on 051908 + README-this
author Mukesh Rathor
date Mon May 19 15:34:57 2008 -0700 (2008-05-19)
parents
children
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 #============================================================================
18 """Display currently enforced policy (low-level hypervisor representation).
19 """
20 import os
21 import sys
22 import base64
23 import tempfile
24 import commands
25 from xen.util.xsm.xsm import XSMError, err, dump_policy, dump_policy_file
26 from xen.xm.opts import OptionError
27 from xen.xm import main as xm_main
28 from xen.xm.main import server
29 from xen.util import xsconstants
31 DOM0_UUID = "00000000-0000-0000-0000-000000000000"
33 def help():
34 return """
35 Retrieve and print currently enforced hypervisor policy information
36 (low-level)."""
38 def main(argv):
39 if len(argv) != 1:
40 raise OptionError("No arguments expected.")
42 if xm_main.serverType == xm_main.SERVER_XEN_API:
43 try:
44 bin_pol = server.xenapi.ACMPolicy.get_enforced_binary()
45 if bin_pol:
46 dom0_ssid = server.xenapi.ACMPolicy.get_VM_ssidref(DOM0_UUID)
47 bin = base64.b64decode(bin_pol)
48 try:
49 fd, filename = tempfile.mkstemp(suffix=".bin")
50 os.write(fd, bin)
51 os.close(fd)
52 dump_policy_file(filename, dom0_ssid)
53 finally:
54 os.unlink(filename)
55 else:
56 err("No policy is installed.")
57 except Exception, e:
58 err("An error occurred getting the running policy: %s" % str(e))
59 else:
60 dump_policy()
62 if __name__ == '__main__':
63 try:
64 main(sys.argv)
65 except Exception, e:
66 sys.stderr.write('Error: %s\n' % str(e))
67 sys.exit(-1)