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

Python utils.execute函数代码示例

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

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



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

示例1: clear_expired_password

def clear_expired_password():
    """
    Some mysql installations generate random root password
    and save it in /root/.mysql_secret, this password is
    expired and should be changed by client that supports expired passwords.
    """
    LOG.debug("Removing expired password.")
    secret_file = "/root/.mysql_secret"
    try:
        out, err = utils.execute("cat", secret_file,
                                 run_as_root=True, root_helper="sudo")
    except exception.ProcessExecutionError:
        LOG.exception(_("/root/.mysql_secret does not exist."))
        return
    m = re.match('# The random password set for the root user at .*: (.*)',
                 out)
    if m:
        try:
            out, err = utils.execute("mysqladmin", "-p%s" % m.group(1),
                                     "password", "", run_as_root=True,
                                     root_helper="sudo")
        except exception.ProcessExecutionError:
            LOG.exception(_("Cannot change mysql password."))
            return
        operating_system.remove(secret_file, force=True, as_root=True)
        LOG.debug("Expired password removed.")
开发者ID:zjtheone,项目名称:trove,代码行数:26,代码来源:service.py


示例2: _fix_package_selections

 def _fix_package_selections(self, packages, config_opts):
     """
     Sometimes you have to run this command before a package will install.
     This command sets package selections to configure package.
     """
     selections = ""
     for package in packages:
         m = re.match('(.+)=(.+)', package)
         if m:
             package_name = m.group(1)
         else:
             package_name = package
         std_out = getoutput("sudo", "debconf-show", package_name)
         for line in std_out.split("\n"):
             for selection, value in config_opts.items():
                 m = re.match(".* (.*/%s):.*" % selection, line)
                 if m:
                     selections += ("%s %s string '%s'\n" %
                                    (package_name, m.group(1), value))
     if selections:
         with NamedTemporaryFile(delete=False) as f:
             fname = f.name
             f.write(selections)
         try:
             utils.execute("debconf-set-selections", fname,
                           run_as_root=True, root_helper="sudo")
             utils.execute("dpkg", "--configure", "-a",
                           run_as_root=True, root_helper="sudo")
         except ProcessExecutionError:
             raise PkgConfigureError("Error configuring package.")
         finally:
             os.remove(fname)
开发者ID:Hopebaytech,项目名称:trove,代码行数:32,代码来源:pkg.py


示例3: _get_actual_db_status

 def _get_actual_db_status(self):
     """Get the status of dbaas and report it back."""
     try:
         out, err = utils.execute(
             "su",
             "-",
             "dbadmin",
             "-c",
             system.STATUS_ACTIVE_DB,
             run_as_root=True,
             root_helper="sudo")
         if out.strip() == DB_NAME:
             # UP status is confirmed
             LOG.info("Service Status is RUNNING.")
             return rd_instance.ServiceStatuses.RUNNING
         elif out.strip() == "":
             # nothing returned, means no db running lets verify
             out, err = utils.execute(
                 "su", "-",
                 "dbadmin",
                 "-c",
                 system.STATUS_DB_DOWN,
                 run_as_root=True,
                 root_helper="sudo")
             if out.strip() == DB_NAME:
                 # DOWN status is confirmed
                 LOG.info("Service Status is SHUTDOWN.")
                 return rd_instance.ServiceStatuses.SHUTDOWN
             else:
                 return rd_instance.ServiceStatuses.UNKNOWN
     except exception.ProcessExecutionError:
         LOG.error("Process execution ")
         return rd_instance.ServiceStatuses.FAILED
开发者ID:SlickNik,项目名称:trove,代码行数:33,代码来源:service.py


示例4: _fix

 def _fix(self, time_out):
     """Sometimes you have to run this command before a pkg will install."""
     try:
         utils.execute("dpkg", "--configure", "-a", run_as_root=True,
                       root_helper="sudo")
     except ProcessExecutionError:
         LOG.error(_("Error fixing dpkg"))
开发者ID:SlickNik,项目名称:trove-guestagent,代码行数:7,代码来源:pkg.py


示例5: prepare_for_install_vertica

 def prepare_for_install_vertica(self):
     """This method executes preparatory command for install_vertica."""
     utils.execute("VERT_DBA_USR=dbadmin", "VERT_DBA_HOME=/home/dbadmin",
                   "VERT_DBA_GRP=verticadba",
                   "/opt/vertica/oss/python/bin/python", "-m",
                   "vertica.local_coerce",
                   run_as_root=True, root_helper="sudo")
开发者ID:SlickNik,项目名称:trove,代码行数:7,代码来源:service.py


示例6: _fix_package_selections

 def _fix_package_selections(self, packages, config_opts):
     """
     Sometimes you have to run this command before a pkg will install.
     This command sets package selections to configure package.
     """
     selections = ""
     for package in packages:
         m = re.match('(.+)=(.+)', package)
         if m:
             package_name = m.group(1)
         else:
             package_name = package
         command = "sudo debconf-show %s" % package_name
         p = commands.getstatusoutput(command)
         std_out = p[1]
         for line in std_out.split("\n"):
             for selection, value in config_opts.items():
                 m = re.match(".* (.*/%s):.*" % selection, line)
                 if m:
                     selections += ("%s %s string '%s'\n" %
                                    (package_name, m.group(1), value))
     if selections:
         with NamedTemporaryFile(delete=False) as f:
             fname = f.name
             f.write(selections)
         utils.execute("debconf-set-selections %s && dpkg --configure -a"
                       % fname, run_as_root=True, root_helper="sudo",
                       shell=True)
         os.remove(fname)
开发者ID:SlickNik,项目名称:trove-guestagent,代码行数:29,代码来源:pkg.py


示例7: _incremental_restore

    def _incremental_restore(self, location, checksum):
        """Recursively apply backups from all parents.

        If we are the parent then we restore to the restore_location and
        we apply the logs to the restore_location only.

        Otherwise if we are an incremental we restore to a subfolder to
        prevent stomping on the full restore data. Then we run apply log
        with the '--incremental-dir' flag
        """
        metadata = self.storage.load_metadata(location, checksum)
        incremental_dir = None
        if 'parent_location' in metadata:
            LOG.info(_("Restoring parent: %(parent_location)s"
                       " checksum: %(parent_checksum)s") % metadata)
            parent_location = metadata['parent_location']
            parent_checksum = metadata['parent_checksum']
            # Restore parents recursively so backup are applied sequentially
            self._incremental_restore(parent_location, parent_checksum)
            # for *this* backup set the incremental_dir
            # just use the checksum for the incremental path as it is
            # sufficently unique /var/lib/mysql/<checksum>
            incremental_dir = os.path.join(self.restore_location, checksum)
            utils.execute("mkdir", "-p", incremental_dir,
                          root_helper="sudo",
                          run_as_root=True)
            command = self._incremental_restore_cmd(incremental_dir)
        else:
            # The parent (full backup) use the same command from InnobackupEx
            # super class and do not set an incremental_dir.
            command = self.restore_cmd

        self.content_length += self._unpack(location, checksum, command)
        self._incremental_prepare(incremental_dir)
开发者ID:NeCTAR-RC,项目名称:trove,代码行数:34,代码来源:mysql_impl.py


示例8: _run_post_backup

 def _run_post_backup(self):
     """Get rid of WAL data we don't need any longer"""
     arch_cleanup_bin = os.path.join(self.app.pgsql_extra_bin_dir,
                                     "pg_archivecleanup")
     bk_file = os.path.basename(self.most_recent_backup_file())
     cmd_full = " ".join((arch_cleanup_bin, WAL_ARCHIVE_DIR, bk_file))
     utils.execute("sudo", "su", "-", self.app.pgsql_owner, "-c",
                   "%s" % cmd_full)
开发者ID:Tesora,项目名称:tesora-trove,代码行数:8,代码来源:postgresql_impl.py


示例9: resize_fs

 def resize_fs(self):
     """Resize the filesystem on the specified device"""
     self._check_device_exists()
     try:
         utils.execute("sudo", "resize2fs", self.device_path)
     except ProcessExecutionError as err:
         LOG.error(err)
         raise GuestError("Error resizing the filesystem: %s" %
                          self.device_path)
开发者ID:ReVolly,项目名称:trove,代码行数:9,代码来源:volume.py


示例10: migrate_data

 def migrate_data(self, mysql_base):
     """Synchronize the data from the mysql directory to the new volume """
     self.mount(TMP_MOUNT_POINT, write_to_fstab=False)
     if not mysql_base[-1] == '/':
         mysql_base = "%s/" % mysql_base
     utils.execute("sudo", "rsync", "--safe-links", "--perms",
                   "--recursive", "--owner", "--group", "--xattrs",
                   "--sparse", mysql_base, TMP_MOUNT_POINT)
     self.unmount(TMP_MOUNT_POINT)
开发者ID:Simplit-openapps,项目名称:trove,代码行数:9,代码来源:volume.py


示例11: unmount

 def unmount(self, mount_point):
     if operating_system.is_mount(mount_point):
         try:
             utils.execute("umount", mount_point,
                           run_as_root=True, root_helper='sudo')
         except exception.ProcessExecutionError:
             msg = _("Error unmounting '%s'.") % mount_point
             log_and_raise(msg)
     else:
         LOG.debug("'%s' is not a mounted fs, cannot unmount", mount_point)
开发者ID:Tesora,项目名称:tesora-trove,代码行数:10,代码来源:volume.py


示例12: migrate_data

 def migrate_data(self, mysql_base):
     """ Synchronize the data from the mysql directory to the new volume """
     # Use sudo to have access to this spot.
     utils.execute("sudo", "mkdir", "-p", TMP_MOUNT_POINT)
     self._tmp_mount(TMP_MOUNT_POINT)
     if not mysql_base[-1] == '/':
         mysql_base = "%s/" % mysql_base
     utils.execute("sudo", "rsync", "--safe-links", "--perms",
                   "--recursive", "--owner", "--group", "--xattrs",
                   "--sparse", mysql_base, TMP_MOUNT_POINT)
     self.unmount()
开发者ID:ReVolly,项目名称:trove,代码行数:11,代码来源:volume.py


示例13: resize_fs

 def resize_fs(self, mount_point):
     """Resize the filesystem on the specified device."""
     self._check_device_exists()
     try:
         # check if the device is mounted at mount_point before e2fsck
         if not os.path.ismount(mount_point):
             utils.execute("e2fsck", "-f", "-n", self.device_path, run_as_root=True, root_helper="sudo")
         utils.execute("resize2fs", self.device_path, run_as_root=True, root_helper="sudo")
     except ProcessExecutionError:
         LOG.exception(_("Error resizing file system."))
         raise GuestError(_("Error resizing the filesystem: %s") % self.device_path)
开发者ID:rmyers,项目名称:trove,代码行数:11,代码来源:volume.py


示例14: _rpm_remove_nodeps

 def _rpm_remove_nodeps(self, package_name):
     """
     Sometimes transaction errors happens, easy way is to remove
     conflicted package without dependencies and hope it will replaced
     by anoter package
     """
     try:
         utils.execute("rpm", "-e", "--nodeps", package_name,
                       run_as_root=True, root_helper="sudo")
     except ProcessExecutionError:
         LOG.error(_("Error removing conflict %s") % package_name)
开发者ID:SlickNik,项目名称:trove-guestagent,代码行数:11,代码来源:pkg.py


示例15: migrate_data

 def migrate_data(self, source_dir):
     """Synchronize the data from the source directory to the new
     volume.
     """
     self.mount(TMP_MOUNT_POINT, write_to_fstab=False)
     if not source_dir[-1] == '/':
         source_dir = "%s/" % source_dir
     utils.execute("sudo", "rsync", "--safe-links", "--perms",
                   "--recursive", "--owner", "--group", "--xattrs",
                   "--sparse", source_dir, TMP_MOUNT_POINT)
     self.unmount(TMP_MOUNT_POINT)
开发者ID:CMSS-BCRDB,项目名称:RDSV1.0,代码行数:11,代码来源:volume.py


示例16: set_readahead_size

 def set_readahead_size(self, readahead_size):
     """Set the readahead size of disk."""
     self._check_device_exists()
     try:
         utils.execute("blockdev", "--setra",
                       readahead_size, self.device_path,
                       run_as_root=True, root_helper="sudo")
     except exception.ProcessExecutionError:
         msg = _("Error setting readahead size to %(size)s "
                 "for device %(device)s.") % {
             'size': readahead_size, 'device': self.device_path}
         log_and_raise(msg)
开发者ID:Tesora,项目名称:tesora-trove,代码行数:12,代码来源:volume.py


示例17: resize_fs

 def resize_fs(self, mount_point):
     """Resize the filesystem on the specified device"""
     self._check_device_exists()
     try:
         # check if the device is mounted at mount_point before e2fsck
         if not os.path.ismount(mount_point):
             utils.execute("sudo", "e2fsck", "-f", "-n", self.device_path)
         utils.execute("sudo", "resize2fs", self.device_path)
     except ProcessExecutionError as err:
         LOG.error(err)
         raise GuestError("Error resizing the filesystem: %s" %
                          self.device_path)
开发者ID:NeCTAR-RC,项目名称:trove,代码行数:12,代码来源:volume.py


示例18: mount

 def mount(self):
     if not os.path.exists(self.mount_point):
         utils.execute("sudo", "mkdir", "-p", self.mount_point)
     LOG.debug(_("Mounting volume. Device path:{0}, mount_point:{1}, "
                 "volume_type:{2}, mount options:{3}").format(
                     self.device_path, self.mount_point, self.volume_fstype,
                     self.mount_options))
     cmd = ("sudo mount -t %s -o %s %s %s" %
            (self.volume_fstype, self.mount_options, self.device_path,
             self.mount_point))
     child = pexpect.spawn(cmd)
     child.expect(pexpect.EOF)
开发者ID:Simplit-openapps,项目名称:trove,代码行数:12,代码来源:volume.py


示例19: write_to_fstab

 def write_to_fstab(self):
     fstab_line = ("%s\t%s\t%s\t%s\t0\t0" %
                   (self.device_path, self.mount_point, self.volume_fstype,
                    self.mount_options))
     LOG.debug(_("Writing new line to fstab:%s") % fstab_line)
     with open('/etc/fstab', "r") as fstab:
         fstab_content = fstab.read()
     with NamedTemporaryFile(delete=False) as tempfstab:
         tempfstab.write(fstab_content + fstab_line)
     utils.execute("sudo", "install", "-o", "root", "-g", "root", "-m",
                   "644", tempfstab.name, "/etc/fstab")
     utils.execute("sudo", "rm", tempfstab.name)
开发者ID:Simplit-openapps,项目名称:trove,代码行数:12,代码来源:volume.py


示例20: write_to_fstab

 def write_to_fstab(self):
     fstab_line = ("%s\t%s\t%s\t%s\t0\t0" %
                   (self.device_path, self.mount_point, self.volume_fstype,
                    self.mount_options))
     LOG.debug("Writing new line to fstab:%s" % fstab_line)
     utils.execute("sudo", "cp", "/etc/fstab", "/etc/fstab.orig")
     utils.execute("sudo", "cp", "/etc/fstab", "/tmp/newfstab")
     utils.execute("sudo", "chmod", "666", "/tmp/newfstab")
     with open("/tmp/newfstab", 'a') as new_fstab:
         new_fstab.write("\n" + fstab_line)
     utils.execute("sudo", "chmod", "640", "/tmp/newfstab")
     utils.execute("sudo", "mv", "/tmp/newfstab", "/etc/fstab")
开发者ID:ReVolly,项目名称:trove,代码行数:12,代码来源:volume.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python utils.execute_with_timeout函数代码示例发布时间:2022-05-27
下一篇:
Python utils.correct_id_with_req函数代码示例发布时间: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