• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.execute_with_timeout函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中trove.common.utils.execute_with_timeout函数的典型用法代码示例。如果您正苦于以下问题:Python execute_with_timeout函数的具体用法?Python execute_with_timeout怎么用?Python execute_with_timeout使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了execute_with_timeout函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _truncate_backup_chain

    def _truncate_backup_chain(self):
        """Truncate all backups in the backup chain after the
        specified parent backup."""

        with LocalOracleClient(self.db_name, service=True) as client:
            max_recid = sql_query.Query()
            max_recid.columns = ["max(recid)"]
            max_recid.tables = ["v$backup_piece"]
            max_recid.where = ["handle like '%%%s%%'" % self.parent_id]

            q = sql_query.Query()
            q.columns = ["recid"]
            q.tables = ["v$backup_piece"]
            q.where = ["recid > (%s)" % str(max_recid)]
            client.execute(str(q))
            delete_list = [ str(row[0]) for row in client ]

        if delete_list:
            cmd = ("""\"\
rman target %(admin_user)s/%(admin_pswd)[email protected]/%(db_name)s <<EOF
run {
delete force noprompt backupset %(delete_list)s;
}
EXIT;
EOF\"
""" % {'admin_user': ADMIN_USER, 'admin_pswd': self.oracnf.admin_password,
       'db_name': self.db_name, 'delete_list': ",".join(delete_list)})
            utils.execute_with_timeout("su - oracle -c " + cmd,
                                       run_as_root=True,
                                       root_helper='sudo',
                                       timeout=LARGE_TIMEOUT,
                                       shell=True,
                                       log_output_on_error=True)
开发者ID:cdelatte,项目名称:tesora-trove,代码行数:33,代码来源:oracle_impl.py


示例2: _get_actual_db_status

 def _get_actual_db_status(self):
     try:
         out, err = utils.execute_with_timeout(
             "/usr/bin/mysqladmin",
             "ping", run_as_root=True, root_helper="sudo",
             log_output_on_error=True)
         LOG.info(_("MySQL Service Status is RUNNING."))
         return rd_instance.ServiceStatuses.RUNNING
     except exception.ProcessExecutionError:
         LOG.exception(_("Failed to get database status."))
         try:
             out, err = utils.execute_with_timeout("/bin/ps", "-C",
                                                   "mysqld", "h")
             pid = out.split()[0]
             # TODO(rnirmal): Need to create new statuses for instances
             # where the mysql service is up, but unresponsive
             LOG.info(_('MySQL Service Status %(pid)s is BLOCKED.') %
                      {'pid': pid})
             return rd_instance.ServiceStatuses.BLOCKED
         except exception.ProcessExecutionError:
             LOG.exception(_("Process execution failed."))
             mysql_args = load_mysqld_options()
             pid_file = mysql_args.get('pid_file',
                                       ['/var/run/mysqld/mysqld.pid'])[0]
             if os.path.exists(pid_file):
                 LOG.info(_("MySQL Service Status is CRASHED."))
                 return rd_instance.ServiceStatuses.CRASHED
             else:
                 LOG.info(_("MySQL Service Status is SHUTDOWN."))
                 return rd_instance.ServiceStatuses.SHUTDOWN
开发者ID:zjtheone,项目名称:trove,代码行数:30,代码来源:service.py


示例3: clear_storage

 def clear_storage(self):
     mount_point = "/var/lib/mongodb/*"
     try:
         cmd = "sudo rm -rf %s" % mount_point
         utils.execute_with_timeout(cmd, shell=True)
     except exception.ProcessExecutionError as e:
         LOG.error(_("Process execution %s") % e)
开发者ID:ShaguftaMethwani,项目名称:trove,代码行数:7,代码来源:service.py


示例4: start_db

    def start_db(self, update_db=False):
        """
        Start the Couchbase Server.
        """
        LOG.info(_("Starting Couchbase Server..."))

        self._enable_db_on_boot()
        try:
            couchbase_service = operating_system.service_discovery(
                system.SERVICE_CANDIDATES)
            utils.execute_with_timeout(
                couchbase_service['cmd_start'], shell=True)
        except exception.ProcessExecutionError:
            pass
        except KeyError:
            raise RuntimeError("Command to start Couchbase Server not found.")

        if not self.status.wait_for_real_status_to_change_to(
                rd_instance.ServiceStatuses.RUNNING,
                self.state_change_wait_time, update_db):
            LOG.error(_("Start up of Couchbase Server failed!"))
            try:
                utils.execute_with_timeout(system.cmd_kill)
            except exception.ProcessExecutionError as p:
                LOG.error('Error killing stalled Couchbase start command.')
                LOG.error(p)
            self.status.end_install_or_restart()
            raise RuntimeError("Could not start Couchbase Server")
开发者ID:B-Rich,项目名称:trove,代码行数:28,代码来源:service.py


示例5: _write_mycnf

    def _write_mycnf(self, admin_password, config_contents, overrides=None):
        """
        Install the set of mysql my.cnf templates.
        Update the os_admin user and password to the my.cnf
        file for direct login from localhost.
        """
        LOG.info(_("Writing my.cnf templates."))
        if admin_password is None:
            admin_password = get_auth_password()

        with open(TMP_MYCNF, 'w') as t:
            t.write(config_contents)
        utils.execute_with_timeout("sudo", "mv", TMP_MYCNF,
                                   MYSQL_CONFIG)

        self._write_temp_mycnf_with_admin_account(MYSQL_CONFIG,
                                                  TMP_MYCNF,
                                                  admin_password)
        utils.execute_with_timeout("sudo", "mv", TMP_MYCNF,
                                   MYSQL_CONFIG)

        self.wipe_ib_logfiles()

        # write configuration file overrides
        if overrides:
            self._write_config_overrides(overrides)
开发者ID:schivuk,项目名称:trove,代码行数:26,代码来源:service.py


示例6: _run_post_backup

 def _run_post_backup(self):
     try:
         for cmd in self.post_backup_commands:
             utils.execute_with_timeout(*cmd)
     except exception.ProcessExecutionError as p:
         LOG.error(p)
         raise p
开发者ID:HoratiusTang,项目名称:trove,代码行数:7,代码来源:couchbase_impl.py


示例7: update_owner

 def update_owner(self, path):
     LOG.info(_("Set owner to 'mongodb' for %s ") % system.CONFIG)
     utils.execute_with_timeout("chown", "-R", "mongodb", path,
                                run_as_root=True, root_helper="sudo")
     LOG.info(_("Set group to 'mongodb' for %s ") % system.CONFIG)
     utils.execute_with_timeout("chgrp", "-R", "mongodb", path,
                                run_as_root=True, root_helper="sudo")
开发者ID:B-Rich,项目名称:trove,代码行数:7,代码来源:service.py


示例8: _spawn_with_init_file

 def _spawn_with_init_file(self, temp_file):
     child = pexpect.spawn("sudo mysqld_safe --init-file=%s" %
                           temp_file.name)
     try:
         i = child.expect(['Starting mysqld daemon'])
         if i == 0:
             LOG.info(_("Starting MySQL"))
     except pexpect.TIMEOUT:
         LOG.exception(_("Got a timeout launching mysqld_safe"))
     finally:
         # There is a race condition here where we kill mysqld before
         # the init file been executed. We need to ensure mysqld is up.
         self.poll_until_then_raise(
             self.mysql_is_running,
             base.RestoreError("Reset root password failed: "
                               "mysqld did not start!"))
         LOG.info(_("Root password reset successfully."))
         LOG.debug("Cleaning up the temp mysqld process.")
         utils.execute_with_timeout("mysqladmin", "-uroot",
                                    "--protocol=tcp", "shutdown")
         utils.execute_with_timeout("killall", "mysqld_safe",
                                    root_helper="sudo", run_as_root=True)
         self.poll_until_then_raise(
             self.mysql_is_not_running,
             base.RestoreError("Reset root password failed: "
                               "mysqld did not stop!"))
开发者ID:AlexeyDeyneko,项目名称:trove,代码行数:26,代码来源:mysql_impl.py


示例9: _perform_recover

    def _perform_recover(self):
        recover_cmd = ("""\"export ORACLE_SID=%(db_name)s
rman target %(admin_user)s/%(admin_pswd)s <<EOF
run {
recover database;
}
EXIT;
EOF\"
""" % {'admin_user': ADMIN_USER, 'admin_pswd': ADMIN_PSWD,
       'db_name': self.db_name})
        cmd = "su - oracle -c " + recover_cmd
        try:
            utils.execute_with_timeout(cmd,
                                       run_as_root=True, root_helper='sudo',
                                       timeout=LARGE_TIMEOUT,
                                       shell=True, log_output_on_error=True)
        except exception.ProcessExecutionError as p:
            # Ignore the "media recovery requesting unknown archived log" error
            # because RMAN would throw this error even when recovery is
            # successful.
            # If there are in fact errors when recovering the database, the
            # database open step following will fail anyway.
            if str(p).find('media recovery requesting unknown archived log') != -1:
                pass
            else:
                raise(p)
开发者ID:cdelatte,项目名称:tesora-trove,代码行数:26,代码来源:oracle_impl.py


示例10: _disable_mysql_on_boot

 def _disable_mysql_on_boot(self):
     try:
         utils.execute_with_timeout(self.mysql_service['cmd_disable'],
                                    shell=True)
     except KeyError:
         LOG.exception(_("Error disabling MySQL start on boot."))
         raise RuntimeError(_("Service is not discovered."))
开发者ID:Tesora,项目名称:tesora-trove,代码行数:7,代码来源:service.py


示例11: _disable_db_on_boot

 def _disable_db_on_boot(self):
     LOG.info(_("Disabling MongoDB on boot."))
     try:
         mongo_service = self._get_service()
         utils.execute_with_timeout(mongo_service["cmd_disable"], shell=True)
     except KeyError:
         raise RuntimeError("MongoDB service is not discovered.")
开发者ID:bbgw,项目名称:trove,代码行数:7,代码来源:service.py


示例12: init_storage_structure

 def init_storage_structure(self, mount_point):
     try:
         cmd = system.INIT_FS % mount_point
         utils.execute_with_timeout(cmd, shell=True)
     except exception.ProcessExecutionError as e:
         LOG.error(_("Error while initiating storage structure."))
         LOG.error(e)
开发者ID:B-Rich,项目名称:trove,代码行数:7,代码来源:service.py


示例13: _execute_shell_cmd

def _execute_shell_cmd(cmd, options, *args, **kwargs):
    """Execute a given shell command passing it
    given options (flags) and arguments.

    Takes optional keyword arguments:
    :param as_root:        Execute as root.
    :type as_root:         boolean

    :param timeout:        Number of seconds if specified,
                           default if not.
                           There is no timeout if set to None.
    :type timeout:         integer

    :raises:               class:`UnknownArgumentError` if passed unknown args.
    """

    exec_args = {}
    if kwargs.pop('as_root', False):
        exec_args['run_as_root'] = True
        exec_args['root_helper'] = 'sudo'

    if 'timeout' in kwargs:
        exec_args['timeout'] = kwargs.pop('timeout')

    if kwargs:
        raise UnknownArgumentError(_("Got unknown keyword args: %r") % kwargs)

    cmd_flags = _build_command_options(options)
    cmd_args = cmd_flags + list(args)
    utils.execute_with_timeout(cmd, *cmd_args, **exec_args)
开发者ID:jjmob,项目名称:trove,代码行数:30,代码来源:operating_system.py


示例14: _post_restore

 def _post_restore(self):
     utils.execute_with_timeout("sudo", "chown", "-R", "-f",
                                "mysql", self.restore_location)
     self._delete_old_binlogs()
     self._reset_root_password()
     app = dbaas.MySqlApp(dbaas.MySqlAppStatus.get())
     app.start_mysql()
开发者ID:CiscoSystems,项目名称:openstack-trove,代码行数:7,代码来源:impl.py


示例15: pre_restore

 def pre_restore(self):
     try:
         utils.execute_with_timeout("rm -rf " + system.COUCHBASE_DUMP_DIR,
                                    shell=True)
     except exception.ProcessExecutionError as p:
         LOG.error(p)
         raise p
开发者ID:CMSS-BCRDB,项目名称:RDSV1.0,代码行数:7,代码来源:couchbase_impl.py


示例16: _run_post_backup

 def _run_post_backup(self):
     try:
         for cmd in self.post_backup_commands:
             utils.execute_with_timeout(*cmd)
     except exception.ProcessExecutionError:
         LOG.exception(_("Error during post-backup phase."))
         raise
开发者ID:Hopebaytech,项目名称:trove,代码行数:7,代码来源:couchbase_impl.py


示例17: _run_pre_backup

    def _run_pre_backup(self):
        """Create archival contents in dump dir"""
        try:
            est_dump_size = self.estimate_dump_size()
            avail = operating_system.get_bytes_free_on_fs(MONGODB_DBPATH)
            if est_dump_size > avail:
                self.cleanup()
                # TODO(atomic77) Though we can fully recover from this error
                # BackupRunner will leave the trove instance in a BACKUP state
                raise OSError(_("Need more free space to run mongodump, "
                                "estimated %(est_dump_size)s"
                                " and found %(avail)s bytes free ") %
                              {'est_dump_size': est_dump_size,
                               'avail': avail})

            operating_system.create_directory(MONGO_DUMP_DIR, as_root=True)
            operating_system.chown(MONGO_DUMP_DIR, mongo_system.MONGO_USER,
                                   mongo_system.MONGO_USER, as_root=True)

            # high timeout here since mongodump can take a long time
            utils.execute_with_timeout(
                'mongodump', '--out', MONGO_DUMP_DIR,
                *(self.app.admin_cmd_auth_params()),
                run_as_root=True, root_helper='sudo',
                timeout=LARGE_TIMEOUT
            )
        except exception.ProcessExecutionError as e:
            LOG.debug("Caught exception when creating the dump")
            self.cleanup()
            raise e
开发者ID:HoratiusTang,项目名称:trove,代码行数:30,代码来源:mongo_impl.py


示例18: reset_configuration

    def reset_configuration(self, context, configuration):
        """Reset the PgSql configuration file to the one given.

        The configuration parameter is a string containing the full
        configuration file that should be used.
        """
        config_location = PGSQL_CONFIG.format(
            version=self._get_psql_version(),
        )
        LOG.debug(
            "{guest_id}: Writing configuration file to /tmp/pgsql_config."
            .format(
                guest_id=CONF.guest_id,
            )
        )
        with open('/tmp/pgsql_config', 'w+') as config_file:
            config_file.write(configuration)
        utils.execute_with_timeout(
            'sudo', 'chown', 'postgres', '/tmp/pgsql_config',
            timeout=30,
        )
        utils.execute_with_timeout(
            'sudo', 'mv', '/tmp/pgsql_config', config_location,
            timeout=30,
        )
开发者ID:CMSS-BCRDB,项目名称:RDSV1.0,代码行数:25,代码来源:config.py


示例19: _run_pre_backup

 def _run_pre_backup(self):
     try:
         for cmd in self.pre_backup_commands:
             utils.execute_with_timeout(*cmd)
         root = service.CouchbaseRootAccess()
         pw = root.get_password()
         self._save_buckets_config(pw)
         with open(OUTFILE, "r") as f:
             out = f.read()
             if out != "[]":
                 d = json.loads(out)
                 all_memcached = True
                 for i in range(len(d)):
                     bucket_type = d[i]["bucketType"]
                     if bucket_type != "memcached":
                         all_memcached = False
                         break
                 if not all_memcached:
                     self._backup(pw)
                 else:
                     LOG.info(_("All buckets are memcached.  "
                                "Skipping backup."))
         operating_system.move(OUTFILE, system.COUCHBASE_DUMP_DIR)
         if pw != "password":
             # Not default password, backup generated root password
             operating_system.copy(system.pwd_file,
                                   system.COUCHBASE_DUMP_DIR,
                                   preserve=True, as_root=True)
     except exception.ProcessExecutionError as p:
         LOG.error(p)
         raise p
开发者ID:HoratiusTang,项目名称:trove,代码行数:31,代码来源:couchbase_impl.py


示例20: set_db_to_listen

    def set_db_to_listen(self, context):
        """Allow remote connections with encrypted passwords."""
        # Using cat to read file due to read permissions issues.
        out, err = utils.execute_with_timeout(
            'sudo', 'cat',
            PGSQL_HBA_CONFIG.format(
                version=self._get_psql_version(),
            ),
            timeout=30,
        )
        LOG.debug(
            "{guest_id}: Writing hba file to /tmp/pgsql_hba_config.".format(
                guest_id=CONF.guest_id,
            )
        )
        with open('/tmp/pgsql_hba_config', 'w+') as config_file:
            config_file.write(out)
            config_file.write("host    all     all     0.0.0.0/0   md5\n")

        utils.execute_with_timeout(
            'sudo', 'chown', 'postgres', '/tmp/pgsql_hba_config',
            timeout=30,
        )
        utils.execute_with_timeout(
            'sudo', 'mv', '/tmp/pgsql_hba_config',
            PGSQL_HBA_CONFIG.format(
                version=self._get_psql_version(),
            ),
            timeout=30,
        )
开发者ID:CMSS-BCRDB,项目名称:RDSV1.0,代码行数:30,代码来源:config.py



注:本文中的trove.common.utils.execute_with_timeout函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.generate_random_password函数代码示例发布时间:2022-05-27
下一篇:
Python utils.execute函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap