Ejemplo n.º 1
0
def resetpolicy():
    msg = None
    xs_type = xsconstants.XS_POLICY_ACM
    flags = xsconstants.XS_INST_LOAD

    if xm_main.serverType == xm_main.SERVER_XEN_API:
        if int(server.xenapi.XSPolicy.get_xstype()) & xs_type == 0:
            raise security.XSMError("ACM policy type not supported.")

        policystate = server.xenapi.XSPolicy.get_xspolicy()

        acmpol = ACMPolicy(xml=policystate['repr'])

        now_flags = int(policystate['flags'])

        if now_flags & xsconstants.XS_INST_BOOT == 0 and \
           not acmpol.is_default_policy():
            msg = "Old policy not found in bootloader file."

        try:
            policystate = server.xenapi.XSPolicy.reset_xspolicy(xs_type)
        except Exception, e:
            raise security.XSMError("An error occurred resetting the "
                                    "policy: %s" % str(e))

        xserr = int(policystate['xserr'])
        if xserr != xsconstants.XSERR_SUCCESS:
            raise security.XSMError("Could not reset the system's policy. "
                                    "Try to halt all guests.")
        else:
            print "Successfully reset the system's policy."
            if msg:
                print msg
Ejemplo n.º 2
0
            raise security.XSMError("Could not reset the system's policy. "
                                    "Try to halt all guests.")
        else:
            print "Successfully reset the system's policy."
            if msg:
                print msg
    else:
        if server.xend.security.get_xstype() & xs_type == 0:
           raise security.XSMError("ACM policy type not supported.")

        xml, now_flags = server.xend.security.get_policy()

        acmpol = ACMPolicy(xml=xml)

        if int(now_flags) & xsconstants.XS_INST_BOOT == 0 and \
           not acmpol.is_default_policy():
            msg = "Old policy not found in bootloader file."

        rc, errors = server.xend.security.reset_policy()
        if rc != xsconstants.XSERR_SUCCESS:
            raise security.XSMError("Could not reset the system's policy. "
                                    "Try to halt all guests.")
        else:
            print "Successfully reset the system's policy."
            if msg:
                print msg


def main(argv):
    if len(argv) != 1:
        raise OptionError("No arguments expected.")