def main(argv):
    try:
        logging_est()
        global time_start
        time_start = time.time()
        engine_ip = ""
        engine_pass = ""
        old_engine_pass = ""
        try:
            opts, args = getopt.getopt(argv, "e:o:p:hv")
        except getopt.GetoptError:
            help()
        for opt, arg in opts:
            if opt == '-h':
                help()
            elif opt == '-e':
                engine_ip = arg
            elif opt == '-o':
                old_engine_pass = arg
            elif opt == '-p':
                engine_pass = arg
            elif opt == '-v':
                version()

        if (engine_ip == "" or engine_pass == "" or old_engine_pass == ""):
            help()

        sys_server = system_serversess(engine_ip, "sysadmin", old_engine_pass)

        if user.get(sys_server, "USER-1").email_address == None:
            print_info("Setting sysadmin's email address")
            sysadmin_user = User()
            sysadmin_user.email_address = "*****@*****.**"
            user.update(sys_server, 'USER-1', sysadmin_user)
            print_info("Setting sysadmin's password")
            sysadmin_credupdate = CredentialUpdateParameters()
            sysadmin_credupdate.new_credential = PasswordCredential()
            sysadmin_credupdate.new_credential.password = engine_pass
            user.update_credential(sys_server, 'USER-1', sysadmin_credupdate)
        else:
            print_info("sysadmin user has already been configured")

        try:
            sys_server = system_serversess(engine_ip, "sysadmin", engine_pass)
            domain.get(sys_server)
            print_info("domain0 already exists. Skipping domain0 creation.")
            elapsed_minutes = time_elapsed()
            print_info("Prime took " + str(elapsed_minutes) +
                       " minutes to get this far.")
            sys.exit(7)
        except HttpError as e:
            device_list = storage.device.get_all(sys_server)
            system_init_params = DomainCreateParameters()
            system_init_params.devices = [
                device.reference for device in device_list
                if not device.configured
            ]
            print_info("Creating storage domain")
            domain.set(sys_server, system_init_params)
    except SystemExit as e:
        sys.exit(e)
    except HttpError as e:
        print_error("Connection failed to the Delphix Engine")
        print_error("Please check the ERROR message below")
        print_error(e.message)
        sys.exit(2)
    except JobError as e:
        print_error("A job failed in the Delphix Engine")
        print_error(e.job)
        elapsed_minutes = time_elapsed()
        print_info("Prime took " + str(elapsed_minutes) +
                   " minutes to get this far.")
        sys.exit(2)
    except KeyboardInterrupt:
        print_debug("You sent a CTRL+C to interrupt the process")
        elapsed_minutes = time_elapsed()
        print_info("Prime took " + str(elapsed_minutes) +
                   " minutes to get this far.")
        sys.exit(2)
    except:
        print_error(sys.exc_info()[0])
        print_error(traceback.format_exc())
        elapsed_minutes = time_elapsed()
        print_info("Prime took " + str(elapsed_minutes) +
                   " minutes to get this far.")
        sys.exit(2)
def main(argv):
    try:
        logging_est()
        global time_start
        time_start = time.time()
        engine_ip = ""
        engine_pass = ""
        old_engine_pass = ""
        try:
            opts,args = getopt.getopt(argv,"e:o:p:hv")
        except getopt.GetoptError:
            help()
        for opt, arg in opts:
            if opt == '-h':
                help()
            elif opt == '-e':
                engine_ip = arg
            elif opt == '-o':
                old_engine_pass = arg
            elif opt == '-p':
                engine_pass = arg
            elif opt == '-v':
                version()

        if (engine_ip == "" or engine_pass == "" or old_engine_pass == "") :
            help()

        server = serversess(engine_ip, "delphix_admin", old_engine_pass)

        if user.get(server, "USER-2").email_address == None:
            print_debug("Setting delphix_admin's email address")
            delphix_admin_user = User()
            delphix_admin_user.email_address = "*****@*****.**"
            user.update(server, 'USER-2', delphix_admin_user)

            print_debug("Setting delphix_admin's password")
            delphix_admin_credupdate = CredentialUpdateParameters()
            delphix_admin_credupdate.new_credential = PasswordCredential()
            delphix_admin_credupdate.new_credential.password = engine_pass
            user.update_credential(server, 'USER-2', delphix_admin_credupdate)
        else:
            print_info("The delphix_admin user has already been setup")

    except SystemExit as e:
        sys.exit(e)
    except HttpError as e:
        print_error("Connection failed to the Delphix Engine")
        print_error( "Please check the ERROR message below")
        print_error(e.message)
        sys.exit(2)
    except JobError as e:
        print_error("A job failed in the Delphix Engine")
        print_error(e.job)
        elapsed_minutes = time_elapsed()
        print_info("Prime took " + str(elapsed_minutes) + " minutes to get this far.")
    except KeyboardInterrupt:
        print_debug("You sent a CTRL+C to interrupt the process")
        elapsed_minutes = time_elapsed()
        print_info("Prime took " + str(elapsed_minutes) + " minutes to get this far.")
    except:
        print_error(sys.exc_info()[0])
        print_error(traceback.format_exc())
        elapsed_minutes = time_elapsed()
        print_info("Prime took " + str(elapsed_minutes) + " minutes to get this far.")
def main(argv):
    try:
        logging_est()
        global time_start
        time_start = time.time()
        dx_session_obj = GetSession()
        engine_ip = ""
        engine_pass = ""
        old_engine_pass = ""
        try:
            opts,args = getopt.getopt(argv,"e:o:p:hv")
        except getopt.GetoptError:
            help()
        for opt, arg in opts:
            if opt == '-h':
                help()
            elif opt == '-e':
                engine_ip = arg
            elif opt == '-o':
                old_engine_pass = arg
            elif opt == '-p':
                engine_pass = arg
            elif opt == '-v':
                version()

        if (engine_ip == "" or engine_pass == "" or old_engine_pass == "") :
            help()

        dx_session_obj.serversess(engine_ip, 'sysadmin',
                                 old_engine_pass, 'SYSTEM')

        dx_session_obj.server_wait()

        sys_server = system_serversess(engine_ip, "sysadmin", old_engine_pass)

        if user.get(sys_server, "USER-1").email_address == None:
            print_info("Setting sysadmin's email address")
            sysadmin_user = User()
            sysadmin_user.email_address = "*****@*****.**"
            user.update(sys_server, 'USER-1', sysadmin_user)
            print_info("Setting sysadmin's password")
            sysadmin_credupdate = CredentialUpdateParameters()
            sysadmin_credupdate.new_credential = PasswordCredential()
            sysadmin_credupdate.new_credential.password = engine_pass
            user.update_credential(sys_server, 'USER-1', sysadmin_credupdate)
        else:
            print_info("sysadmin user has already been configured")

        try:
            sys_server = system_serversess(engine_ip, "sysadmin", engine_pass)
            domain.get(sys_server)
            print_info("domain0 already exists. Skipping domain0 creation.")
            elapsed_minutes = time_elapsed()
            print_info("Prime took " + str(elapsed_minutes) + " minutes to get this far.")
            sys.exit(7)
        except HttpError as e:
            device_list = storage.device.get_all(sys_server)
            system_init_params = DomainCreateParameters()
            system_init_params.devices = [ device.reference for device in device_list if not device.configured ]
            print_info("Creating storage domain")
            domain.set(sys_server, system_init_params)
            while True:
                try:
                    sys_server = system_serversess(engine_ip, "sysadmin", engine_pass)
                    domain.get(sys_server)
                except:    
                    break
                print_info("Waiting for Delphix Engine to go down")
                time.sleep(3)

        dx_session_obj.serversess(engine_ip, 'sysadmin',
                                 engine_pass, 'SYSTEM')

        dx_session_obj.server_wait()

    except SystemExit as e:
        sys.exit(e)
    except HttpError as e:
        print_error("Connection failed to the Delphix Engine")
        print_error( "Please check the ERROR message below")
        print_error(e.message)
        sys.exit(2)
    except JobError as e:
        print_error("A job failed in the Delphix Engine")
        print_error(e.job)
        elapsed_minutes = time_elapsed()
        print_info("Prime took " + str(elapsed_minutes) + " minutes to get this far.")
        sys.exit(2)
    except KeyboardInterrupt:
        print_debug("You sent a CTRL+C to interrupt the process")
        elapsed_minutes = time_elapsed()
        print_info("Prime took " + str(elapsed_minutes) + " minutes to get this far.")
        sys.exit(2)
    except:
        print_error(sys.exc_info()[0])
        print_error(traceback.format_exc())
        elapsed_minutes = time_elapsed()
        print_info("Prime took " + str(elapsed_minutes) + " minutes to get this far.")
        sys.exit(2)