本文整理汇总了Python中trove.guestagent.common.operating_system.chmod函数的典型用法代码示例。如果您正苦于以下问题:Python chmod函数的具体用法?Python chmod怎么用?Python chmod使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了chmod函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: write_config
def write_config(
self,
config_contents,
execute_function=utils.execute_with_timeout,
mkstemp_function=tempfile.mkstemp,
unlink_function=os.unlink,
):
# first securely create a temp file. mkstemp() will set
# os.O_EXCL on the open() call, and we get a file with
# permissions of 600 by default.
(conf_fd, conf_path) = mkstemp_function()
LOG.debug("Storing temporary configuration at %s." % conf_path)
# write config and close the file, delete it if there is an
# error. only unlink if there is a problem. In normal course,
# we move the file.
try:
os.write(conf_fd, config_contents)
operating_system.move(conf_path, system.CASSANDRA_CONF, as_root=True)
# TODO(denis_makogon): figure out the dynamic way to discover
# configs owner since it can cause errors if there is
# no cassandra user in operating system
operating_system.chown(system.CASSANDRA_CONF, "cassandra", "cassandra", recursive=False, as_root=True)
operating_system.chmod(system.CASSANDRA_CONF, FileMode.ADD_READ_ALL, as_root=True)
except Exception:
LOG.exception(_("Exception generating Cassandra configuration %s.") % conf_path)
unlink_function(conf_path)
raise
finally:
os.close(conf_fd)
LOG.info(_("Wrote new Cassandra configuration."))
开发者ID:pombredanne,项目名称:trove,代码行数:34,代码来源:service.py
示例2: base_backup_metadata
def base_backup_metadata(self, f):
"""Parse the contents of the .backup file"""
meta = {}
operating_system.chmod(f, FileMode(add=[stat.S_IROTH]), as_root=True)
start_re = re.compile("START WAL LOCATION: (.*) \(file (.*)\)")
stop_re = re.compile("STOP WAL LOCATION: (.*) \(file (.*)\)")
checkpt_re = re.compile("CHECKPOINT LOCATION: (.*)")
label_re = re.compile("LABEL: (.*)")
with open(f, 'r') as base_metadata:
lines = "\n".join(base_metadata.readlines())
match = start_re.search(lines)
if match:
self.start_segment = meta['start-segment'] = match.group(1)
self.start_wal_file = meta['start-wal-file'] = match.group(2)
match = stop_re.search(lines)
if match:
self.stop_segment = meta['stop-segment'] = match.group(1)
self.stop_wal_file = meta['stop-wal-file'] = match.group(2)
match = checkpt_re.search(lines)
if match:
self.checkpoint_location \
= meta['checkpoint-location'] = match.group(1)
match = label_re.search(lines)
if match:
self.label = meta['label'] = match.group(1)
return meta
开发者ID:paramtech,项目名称:tesora-trove,代码行数:32,代码来源:postgresql_impl.py
示例3: write_oracle_user_file
def write_oracle_user_file(self, filepath, contents,
filemode=operating_system.FileMode.SET_USR_RW):
operating_system.write_file(filepath, contents, as_root=True)
operating_system.chown(filepath, INSTANCE_OWNER, INSTANCE_OWNER_GROUP,
force=True, as_root=True)
operating_system.chmod(filepath, filemode,
force=True, as_root=True)
开发者ID:Tesora,项目名称:tesora-trove,代码行数:7,代码来源:service.py
示例4: reset_root_password
def reset_root_password(self):
"""Reset the password of the localhost root account used by Trove
for initial datastore configuration.
"""
with tempfile.NamedTemporaryFile(mode='w') as init_file:
operating_system.write_file(init_file.name,
self.RESET_ROOT_MYSQL_COMMANDS)
operating_system.chmod(init_file.name, FileMode.ADD_READ_ALL,
as_root=True)
# Do not attempt to delete the file as the 'trove' user.
# The process writing into it may have assumed its ownership.
# Only owners can delete temporary
# files (restricted deletion).
err_log_file = tempfile.NamedTemporaryFile(
suffix=self._ERROR_LOG_SUFFIX,
delete=False)
try:
# As of MySQL 5.7.6, for MySQL installation using an RPM
# distribution, server startup and shutdown is managed by
# systemd on several Linux platforms. On these platforms,
# mysqld_safe is no longer installed because it is
# unnecessary.
if self._mysqld_safe_cmd_exists():
self._start_mysqld_safe_with_init_file(
init_file, err_log_file)
else:
self._start_mysqld_with_init_file(init_file)
finally:
err_log_file.close()
operating_system.remove(
err_log_file.name, force=True, as_root=True)
开发者ID:Tesora,项目名称:tesora-trove,代码行数:32,代码来源:mysql_impl.py
示例5: apply
def apply(self, group_name, change_id, options):
self._initialize_import_directory()
revision_file = self._find_revision_file(group_name, change_id)
if revision_file is None:
# Create a new file.
last_revision_index = self._get_last_file_index(group_name)
revision_file = guestagent_utils.build_file_path(
self._revision_dir,
'%s-%03d-%s' % (group_name, last_revision_index + 1,
change_id),
self._revision_ext)
else:
# Update the existing file.
current = operating_system.read_file(
revision_file, codec=self._codec, as_root=self._requires_root)
options = guestagent_utils.update_dict(options, current)
operating_system.write_file(
revision_file, options, codec=self._codec,
as_root=self._requires_root)
operating_system.chown(
revision_file, self._owner, self._group,
as_root=self._requires_root)
operating_system.chmod(
revision_file, FileMode.ADD_READ_ALL, as_root=self._requires_root)
开发者ID:Tesora-Release,项目名称:tesora-trove,代码行数:25,代码来源:configuration.py
示例6: save_configuration
def save_configuration(self, options):
"""Write given contents to the base configuration file.
Remove all existing overrides (both system and user).
:param contents Contents of the configuration file.
:type contents string or dict
"""
if isinstance(options, dict):
# Serialize a dict of options for writing.
self.save_configuration(self._codec.serialize(options))
else:
self._override_strategy.remove(self.USER_GROUP)
self._override_strategy.remove(self.SYSTEM_PRE_USER_GROUP)
self._override_strategy.remove(self.SYSTEM_POST_USER_GROUP)
operating_system.write_file(
self._base_config_path, options, as_root=self._requires_root)
operating_system.chown(
self._base_config_path, self._owner, self._group,
as_root=self._requires_root)
operating_system.chmod(
self._base_config_path, FileMode.ADD_READ_ALL,
as_root=self._requires_root)
self.refresh_cache()
开发者ID:Tesora,项目名称:tesora-trove,代码行数:25,代码来源:configuration.py
示例7: pre_restore
def pre_restore(self):
self.app.stop_db()
LOG.info(_("Cleaning out restore location: %s."),
self.restore_location)
operating_system.chmod(self.restore_location, FileMode.SET_FULL,
as_root=True)
utils.clean_out(self.restore_location)
开发者ID:Tesora,项目名称:tesora-trove,代码行数:7,代码来源:mysql_impl.py
示例8: clear_file
def clear_file(filename):
LOG.debug("Creating clean file %s" % filename)
if operating_system.file_discovery([filename]):
operating_system.remove(filename)
# force file creation by just opening it
open(filename, "wb")
operating_system.chmod(filename, operating_system.FileMode.SET_USR_RW, as_root=True)
开发者ID:jachinpy,项目名称:trove,代码行数:7,代码来源:service.py
示例9: __init__
def __init__(self, log_context, log_name, log_type, log_user, log_file,
log_exposed):
self._context = log_context
self._name = log_name
self._type = log_type
self._user = log_user
self._file = log_file
self._exposed = log_exposed
self._size = None
self._published_size = None
self._header_digest = 'abc'
self._published_header_digest = None
self._status = None
self._cached_context = None
self._cached_swift_client = None
self._enabled = log_type == LogType.SYS
self._file_readable = False
self._container_name = None
self._codec = stream_codecs.JsonCodec()
self._set_status(self._type == LogType.USER,
LogStatus.Disabled, LogStatus.Enabled)
# The directory should already exist - make sure we have access to it
log_dir = os.path.dirname(self._file)
operating_system.chmod(
log_dir, FileMode.ADD_GRP_RX_OTH_RX, as_root=True)
开发者ID:Tesora,项目名称:tesora-trove,代码行数:27,代码来源:guest_log.py
示例10: enable_as_master
def enable_as_master(self, service, master_config, for_failover=False):
"""For a server to be a master in postgres, we need to enable
the replication user in pg_hba and ensure that WAL logging is
at the appropriate level (use the same settings as backups)
"""
LOG.debug("Enabling as master, with cfg: %s " % master_config)
self._get_or_create_replication_user()
hba_entry = "host replication replicator 0.0.0.0/0 md5 \n"
# TODO(atomic77) Remove this hack after adding cfg manager for pg_hba
tmp_hba = '/tmp/pg_hba'
operating_system.copy(self.PGSQL_HBA_CONFIG, tmp_hba,
force=True, as_root=True)
operating_system.chmod(tmp_hba, FileMode.OCTAL_MODE("0777"),
as_root=True)
with open(tmp_hba, 'a+') as hba_file:
hba_file.write(hba_entry)
operating_system.copy(tmp_hba, self.PGSQL_HBA_CONFIG,
force=True, as_root=True)
operating_system.chmod(self.PGSQL_HBA_CONFIG,
FileMode.OCTAL_MODE("0600"),
as_root=True)
operating_system.remove(tmp_hba, as_root=True)
pgutil.psql("SELECT pg_reload_conf()")
开发者ID:paramtech,项目名称:tesora-trove,代码行数:25,代码来源:postgresql_impl.py
示例11: apply_next
def apply_next(self, options):
revision_num = self.count_revisions() + 1
revision_file_path = guestagent_utils.build_file_path(
self._revision_dir, self._base_config_name, str(revision_num), self._revision_ext
)
operating_system.write_file(revision_file_path, options, codec=self._codec, as_root=self._requires_root)
operating_system.chown(revision_file_path, self._owner, self._group, as_root=self._requires_root)
operating_system.chmod(revision_file_path, FileMode.ADD_READ_ALL, as_root=self._requires_root)
开发者ID:cretta,项目名称:trove,代码行数:8,代码来源:configuration.py
示例12: pre_restore
def pre_restore(self):
app = dbaas.MySqlApp(dbaas.MySqlAppStatus.get())
app.stop_db()
LOG.info(_("Cleaning out restore location: %s."),
self.restore_location)
operating_system.chmod(self.restore_location, FileMode.SET_FULL,
as_root=True)
utils.clean_out(self.restore_location)
开发者ID:cretta,项目名称:trove,代码行数:8,代码来源:mysql_impl.py
示例13: store_key
def store_key(self, key):
"""Store the cluster key."""
LOG.debug("Storing key for MongoDB cluster.")
with tempfile.NamedTemporaryFile() as f:
f.write(key)
f.flush()
operating_system.copy(f.name, system.MONGO_KEY_FILE, force=True, as_root=True)
operating_system.chmod(system.MONGO_KEY_FILE, operating_system.FileMode.SET_USR_RO, as_root=True)
operating_system.chown(system.MONGO_KEY_FILE, system.MONGO_USER, system.MONGO_USER, as_root=True)
开发者ID:jachinpy,项目名称:trove,代码行数:9,代码来源:service.py
示例14: store_key
def store_key(self, key):
"""Store the cluster key."""
LOG.debug('Storing key for MongoDB cluster.')
operating_system.write_file(system.MONGO_KEY_FILE, key, as_root=True)
operating_system.chmod(system.MONGO_KEY_FILE,
operating_system.FileMode.SET_USR_RO,
as_root=True)
operating_system.chown(system.MONGO_KEY_FILE,
system.MONGO_USER, system.MONGO_USER,
as_root=True)
开发者ID:Hopebaytech,项目名称:trove,代码行数:10,代码来源:service.py
示例15: _write_replication_overrides
def _write_replication_overrides(self, overrideValues, cnf_file):
LOG.info(_("Writing replication.cnf file."))
with open(MYCNF_REPLCONFIG_TMP, 'w') as overrides:
overrides.write(overrideValues)
LOG.debug("Moving temp replication.cnf into correct location.")
operating_system.move(MYCNF_REPLCONFIG_TMP, cnf_file, as_root=True)
LOG.debug("Setting permissions on replication.cnf.")
operating_system.chmod(cnf_file, FileMode.SET_GRP_RW_OTH_R,
as_root=True)
开发者ID:cp16net,项目名称:trove,代码行数:10,代码来源:service.py
示例16: _write_config_overrides
def _write_config_overrides(self, overrideValues):
LOG.info(_("Writing new temp overrides.cnf file."))
with open(MYCNF_OVERRIDES_TMP, 'w') as overrides:
overrides.write(overrideValues)
LOG.info(_("Moving overrides.cnf into correct location."))
operating_system.move(MYCNF_OVERRIDES_TMP, MYCNF_OVERRIDES,
as_root=True)
LOG.info(_("Setting permissions on overrides.cnf."))
operating_system.chmod(MYCNF_OVERRIDES, FileMode.SET_GRP_RW_OTH_R,
as_root=True)
开发者ID:cp16net,项目名称:trove,代码行数:11,代码来源:service.py
示例17: pre_restore
def pre_restore(self):
self.app.stop_db()
LOG.info(_("Cleaning out restore location: %s."),
self.restore_location)
operating_system.chmod(self.restore_location, FileMode.SET_FULL,
as_root=True)
utils.clean_out(self.restore_location)
# IF AOF is set, we need to turn it off temporarily
if self.aof_set:
self.app.configuration_manager.apply_system_override(
self.aof_off_cfg, change_id=self.CONF_LABEL_AOF_TEMP_OFF)
开发者ID:magictour,项目名称:trove,代码行数:11,代码来源:redis_impl.py
示例18: validate_log_file
def validate_log_file(self, log_file, owner):
"""Make sure the log file exists and is accessible by owner.
"""
if not operating_system.exists(log_file, as_root=True):
operating_system.write_file(log_file, '', as_root=True)
operating_system.chown(log_file, user=owner, group=owner,
as_root=True)
operating_system.chmod(log_file, FileMode.ADD_USR_RW_GRP_RW_OTH_R,
as_root=True)
LOG.debug("Set log file '%s' as readable" % log_file)
return log_file
开发者ID:HoratiusTang,项目名称:trove,代码行数:12,代码来源:manager.py
示例19: pre_restore
def pre_restore(self):
self.app.stop_db()
LOG.info(_("Removing old persistence file: %s."),
self.restore_location)
operating_system.remove(self.restore_location, force=True,
as_root=True)
dir = os.path.dirname(self.restore_location)
operating_system.create_directory(dir, as_root=True)
operating_system.chmod(dir, FileMode.SET_FULL, as_root=True)
# IF AOF is set, we need to turn it off temporarily
if self.aof_set:
self.app.configuration_manager.apply_system_override(
self.aof_off_cfg, change_id=self.CONF_LABEL_AOF_TEMP_OFF)
开发者ID:Hopebaytech,项目名称:trove,代码行数:13,代码来源:redis_impl.py
示例20: _read_last_master_gtid
def _read_last_master_gtid(self):
INFO_FILE = ('%s/xtrabackup_binlog_info' % MySqlApp.get_data_dir())
LOG.info(_("Setting read permissions on %s") % INFO_FILE)
operating_system.chmod(INFO_FILE, FileMode.ADD_READ_ALL, as_root=True)
LOG.info(_("Reading last master GTID from %s") % INFO_FILE)
try:
with open(INFO_FILE, 'rb') as f:
row = f.read().split('\t')
return row[2]
except (IOError, IndexError) as ex:
LOG.exception(ex)
raise self.UnableToDetermineLastMasterGTID(
{'binlog_file': INFO_FILE})
开发者ID:Hopebaytech,项目名称:trove,代码行数:13,代码来源:mysql_gtid.py
注:本文中的trove.guestagent.common.operating_system.chmod函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论