本文整理汇总了Python中manila.utils.execute函数的典型用法代码示例。如果您正苦于以下问题:Python execute函数的具体用法?Python execute怎么用?Python execute使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了execute函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _change_file_mode
def _change_file_mode(self, filepath):
try:
utils.execute("chmod", "666", filepath, run_as_root=True)
except Exception as err:
LOG.error(_LE("Bad response from change file: %s.") % err)
raise err
示例2: reload_ganesha_config
def reload_ganesha_config(servers, sshlogin, service='ganesha.nfsd'):
"""Request ganesha server reload updated config."""
# Note: dynamic reload of ganesha config is not enabled
# in ganesha v2.0. Therefore, the code uses the ganesha service restart
# option to make sure the config changes are reloaded
for server in servers:
# Until reload is fully implemented and if the reload returns a bad
# status revert to service restart instead
LOG.info(_LI('Restart service %(service)s on %(server)s to force a '
'config file reload'),
{'service': service, 'server': server})
run_local = True
reload_cmd = ['service', service, 'restart']
localserver_iplist = socket.gethostbyname_ex(
socket.gethostname())[2]
if server not in localserver_iplist:
remote_login = sshlogin + '@' + server
reload_cmd = ['ssh', remote_login] + reload_cmd
run_local = False
try:
utils.execute(*reload_cmd, run_as_root=run_local)
except exception.ProcessExecutionError as e:
msg = (_('Could not restart service %(service)s on '
'%(server)s: %(excmsg)s')
% {'service': service,
'server': server,
'excmsg': six.text_type(e)})
LOG.error(msg)
raise exception.GPFSGaneshaException(msg)
示例3: copy_data
def copy_data(self, path):
if self.cancelled:
return
out, err = utils.execute(
"ls", "-pA1", "--group-directories-first", path,
run_as_root=True)
for line in out.split('\n'):
if self.cancelled:
return
if len(line) == 0:
continue
src_item = os.path.join(path, line)
dest_item = src_item.replace(self.src, self.dest)
if line[-1] == '/':
if line[0:-1] in self.ignore_list:
continue
utils.execute("mkdir", "-p", dest_item, run_as_root=True)
self.copy_data(src_item)
else:
if line in self.ignore_list:
continue
size, err = utils.execute("stat", "-c", "%s", src_item,
run_as_root=True)
self.current_copy = {'file_path': dest_item,
'size': int(size)}
self._copy_and_validate(src_item, dest_item)
self.current_size += int(size)
LOG.info(six.text_type(self.get_progress()))
示例4: _publish_local_config
def _publish_local_config(configpath, pre_lines, exports):
tmp_path = '%s.tmp.%s' % (configpath, time.time())
LOG.debug("tmp_path = %s", tmp_path)
cpcmd = ['install', '-m', '666', configpath, tmp_path]
try:
utils.execute(*cpcmd, run_as_root=True)
except exception.ProcessExecutionError as e:
msg = (_('Failed while publishing ganesha config locally. '
'Error: %s.') % six.text_type(e))
LOG.error(msg)
raise exception.GPFSGaneshaException(msg)
with open(tmp_path, 'w+') as f:
for l in pre_lines:
f.write('%s\n' % l)
for e in exports:
f.write('EXPORT\n{\n')
for attr in exports[e]:
f.write('%s = %s ;\n' % (attr, exports[e][attr]))
f.write('}\n')
mvcmd = ['mv', tmp_path, configpath]
try:
utils.execute(*mvcmd, run_as_root=True)
except exception.ProcessExecutionError as e:
msg = (_('Failed while publishing ganesha config locally. '
'Error: %s.') % six.text_type(e))
LOG.error(msg)
raise exception.GPFSGaneshaException(msg)
LOG.info(_LI('Ganesha config %s published locally.'), configpath)
示例5: _validate_item
def _validate_item(src_item, dest_item):
src_sum, err = utils.execute(
"sha256sum", "%s" % src_item, run_as_root=True)
dest_sum, err = utils.execute(
"sha256sum", "%s" % dest_item, run_as_root=True)
if src_sum.split()[0] != dest_sum.split()[0]:
msg = _("Data corrupted while copying. Aborting data copy.")
raise exception.ShareDataCopyFailed(reason=msg)
示例6: cleanup_unmount_temp_folder
def cleanup_unmount_temp_folder(self, instance, migration_info):
try:
utils.execute(*migration_info['umount'], run_as_root=True)
except Exception as utfe:
LOG.exception(six.text_type(utfe))
LOG.error(_LE("Could not unmount folder of instance"
" %(instance_id)s for migration of "
"share %(share_id)s") % {
'instance_id': instance['id'],
'share_id': self.share['id']})
示例7: mount_share_instance
def mount_share_instance(self, mount_template, mount_path,
share_instance_id):
path = os.path.join(mount_path, share_instance_id)
if not os.path.exists(path):
os.makedirs(path)
self._check_dir_exists(path)
mount_command = mount_template % {'path': path}
utils.execute(*(mount_command.split()), run_as_root=True)
示例8: cleanup_temp_folder
def cleanup_temp_folder(self, instance, mount_path):
try:
utils.execute('rmdir', mount_path + instance['id'],
check_exit_code=False)
except Exception as tfe:
LOG.exception(six.text_type(tfe))
LOG.error(_LE("Could not cleanup instance %(instance_id)s "
"temporary folders for migration of "
"share %(share_id)s") % {
'instance_id': instance['id'],
'share_id': self.share['id']})
示例9: _ovs_add_port
def _ovs_add_port(self, bridge, device_name, port_id, mac_address,
internal=True):
cmd = ['ovs-vsctl', '--', '--may-exist',
'add-port', bridge, device_name]
if internal:
cmd += ['--', 'set', 'Interface', device_name, 'type=internal']
cmd += ['--', 'set', 'Interface', device_name,
'external-ids:iface-id=%s' % port_id,
'--', 'set', 'Interface', device_name,
'external-ids:iface-status=active',
'--', 'set', 'Interface', device_name,
'external-ids:attached-mac=%s' % mac_address]
utils.execute(*cmd, run_as_root=True)
示例10: _publish_remote_config
def _publish_remote_config(server, sshlogin, sshkey, configpath):
dest = '%[email protected]%s:%s' % (sshlogin, server, configpath)
scpcmd = ['scp', '-i', sshkey, configpath, dest]
try:
utils.execute(*scpcmd, run_as_root=False)
except exception.ProcessExecutionError as e:
msg = (_('Failed while publishing ganesha config on remote server. '
'Error: %s.') % six.text_type(e))
LOG.error(msg)
raise exception.GPFSGaneshaException(msg)
LOG.info(_LI('Ganesha config %(path)s published to %(server)s.'),
{'path': configpath,
'server': server})
示例11: unmount_share_instance
def unmount_share_instance(self, unmount_template, mount_path,
share_instance_id):
path = os.path.join(mount_path, share_instance_id)
unmount_command = unmount_template % {'path': path}
utils.execute(*(unmount_command.split()), run_as_root=True)
try:
if os.path.exists(path):
os.rmdir(path)
self._check_dir_not_exists(path)
except Exception:
LOG.warning(_LW("Folder %s could not be removed."), path)
示例12: run_vsctl
def run_vsctl(self, args):
full_args = ["ovs-vsctl", "--timeout=2"] + args
try:
return utils.execute(*full_args, run_as_root=True)
except Exception:
LOG.exception(_LE("Unable to execute %(cmd)s."),
{'cmd': full_args})
示例13: get_progress
def get_progress(self):
if self.current_copy is not None:
try:
size, err = utils.execute("stat", "-c", "%s",
self.current_copy['file_path'],
run_as_root=True)
size = int(size)
except utils.processutils.ProcessExecutionError:
size = 0
total_progress = 0
if self.total_size > 0:
total_progress = self.current_size * 100 / self.total_size
current_file_progress = 0
if self.current_copy['size'] > 0:
current_file_progress = size * 100 / self.current_copy['size']
current_file_path = self.current_copy['file_path']
progress = {
'total_progress': total_progress,
'current_file_path': current_file_path,
'current_file_progress': current_file_progress
}
return progress
else:
return {'total_progress': 100}
示例14: _mount_for_migration
def _mount_for_migration(migration_info):
try:
utils.execute(*migration_info['mount'], run_as_root=True)
except Exception:
LOG.error(_LE("Failed to mount temporary folder for "
"migration of share instance "
"%(share_instance_id)s "
"to %(new_share_instance_id)s") % {
'share_instance_id': share_instance['id'],
'new_share_instance_id': new_share_instance['id']})
helper.cleanup_migration_access(
src_access_ref, src_access)
helper.cleanup_migration_access(
dest_access_ref, dest_access)
raise
示例15: _publish_access
def _publish_access(self, *cmd):
for server in self.configuration.gpfs_nfs_server_list:
localserver_iplist = socket.gethostbyname_ex(
socket.gethostname())[2]
run_local = True
if server not in localserver_iplist:
sshlogin = self.configuration.gpfs_ssh_login
remote_login = sshlogin + '@' + server
cmd = ['ssh', remote_login] + list(cmd)
run_local = False
try:
utils.execute(*cmd,
run_as_root=run_local,
check_exit_code=True)
except exception.ProcessExecutionError:
raise