Ejemplo n.º 1
0
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)
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:d:p:hv")
        except getopt.GetoptError:
            help()
        for opt, arg in opts:
            if opt == '-h':
                help()
            elif opt == '-e':
                engine_ip = arg
            elif opt == '-p':
                engine_pass = arg
            elif opt == '-d':
                key_path = arg + '/engine_key.pub'
            elif opt == '-v':
                version()

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

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

        sys_server = system_serversess(engine_ip, "sysadmin", engine_pass)
        system_info = system.get(sys_server)
        print_info(system_info.ssh_public_key)
        print_info("Writing to " + key_path)
        target = open(key_path, 'w')
        target.write(system_info.ssh_public_key)
        target.close
        print_info("File saved")
        elapsed_minutes = time_elapsed()
        print_info("Script took " + str(elapsed_minutes) + " minutes to get this far.")

    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()
        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)