#!/usr/bin/ensim-python
#
# Copyright (c) Ensim Corporation 2000, 2001   All Rights Reserved.
#
# This software is furnished under a license and may be used and copied
# only  in  accordance  with  the  terms  of such  license and with the
# inclusion of the above copyright notice. This software or any other
# copies thereof may not be provided or otherwise made available to any
# other person. No title to and ownership of the software is hereby
# transferred.
#
# The information in this software is subject to change without notice
# and  should  not be  construed  as  a commitment by Ensim Corporation.
# Ensim assumes no responsibility for the use or  reliability  of its
# software on equipment which is not supplied by Ensim.
#
#
# This function disables a virtual domain on a WEBppliance
#
# Usage:
#
# DisableVirtDomain <domainname>
#
# Example:
#
# DisableVirtDomain mydomain.com

import getopt
import sys
import traceback
from vh3 import virthost
import ensimapplpath
import be_vherrordisp
import string

# check for force flag
    
if (len(sys.argv) < 2 or (sys.argv[1] == "--help")):
    print "usage: DisableVirtDomain <domainname> ..."
    sys.exit(0)

if __name__ == '__main__':
    # checks to see if we are in maintenance mode
    virthost.checkMaintenance()

    options, args = getopt.getopt(sys.argv[1:],"")

    status = be_vherrordisp.CLIError.SUCCESS
    for domain in args:
        siteindex = virthost.get_site_from_anything(string.lower(domain))
        if not siteindex:
            sys.stderr.write("Domain %s does not exist on this server." % domain)
        else:
           virthost.lock_domain(siteindex)
           try:
               errs = virthost.disable_virtual_domain(siteindex)
               status = virthost.cli_display_status_list(errs)
           except:
               try:
                   edisp = be_vherrordisp.CLIError()
                   edisp.push_traceback(sys.exc_info()[0])
                   status = virthost.cli_display_status(edisp)
               except:
                   traceback.print_exc()
           virthost.unlock_domain(domain)
    sys.exit(status)
