本文整理汇总了Python中trove.common.utils.execute函数的典型用法代码示例。如果您正苦于以下问题:Python execute函数的具体用法?Python execute怎么用?Python execute使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了execute函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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.")
示例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)
示例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
示例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"))
示例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")
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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()
示例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)
示例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)
示例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)