本文整理汇总了Python中trove.guestagent.common.operating_system.chown函数的典型用法代码示例。如果您正苦于以下问题:Python chown函数的具体用法?Python chown怎么用?Python chown使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了chown函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: post_restore
def post_restore(self):
self._run_prepare()
operating_system.chown(self.restore_location, 'mysql', None,
force=True, as_root=True)
self._delete_old_binlogs()
self.reset_root_password()
self.app.start_mysql()
开发者ID:Tesora,项目名称:tesora-trove,代码行数:7,代码来源:mysql_impl.py
示例2: post_restore
def post_restore(self):
"""
To restore from backup, all we need to do is untar the compressed
database files into the database directory and change its ownership.
"""
operating_system.chown(service.COUCHDB_LIB_DIR, "couchdb", "couchdb", as_root=True)
self.app.restart()
开发者ID:Tesora-Release,项目名称:tesora-trove,代码行数:7,代码来源:couchdb_impl.py
示例3: _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
示例4: _write_standby_recovery_file
def _write_standby_recovery_file(self, snapshot, sslmode='prefer'):
LOG.info("Snapshot data received:" + str(snapshot))
logging_config = snapshot['log_position']
conninfo_params = \
{'host': snapshot['master']['host'],
'port': snapshot['master']['port'],
'repl_user': logging_config['replication_user']['name'],
'password': logging_config['replication_user']['password'],
'sslmode': sslmode}
conninfo = 'host=%(host)s ' \
'port=%(port)s ' \
'dbname=os_admin ' \
'user=%(repl_user)s ' \
'password=%(password)s ' \
'sslmode=%(sslmode)s ' % conninfo_params
recovery_conf = "standby_mode = 'on'\n"
recovery_conf += "primary_conninfo = '" + conninfo + "'\n"
recovery_conf += "trigger_file = '/tmp/postgresql.trigger'\n"
recovery_conf += "recovery_target_timeline='latest'\n"
operating_system.write_file(self.PGSQL_RECOVERY_CONFIG, recovery_conf,
codec=stream_codecs.IdentityCodec(),
as_root=True)
operating_system.chown(self.PGSQL_RECOVERY_CONFIG, user="postgres",
group="postgres", as_root=True)
开发者ID:paramtech,项目名称:tesora-trove,代码行数:28,代码来源:postgresql_impl.py
示例5: change_ownership
def change_ownership(self, mount_point):
LOG.debug("Changing ownership of the Oracle data directory.")
operating_system.chown(mount_point,
system.ORACLE_INSTANCE_OWNER,
system.ORACLE_GROUP_OWNER,
force=True,
as_root=True)
开发者ID:cdelatte,项目名称:tesora-trove,代码行数:7,代码来源:service.py
示例6: prepare
def prepare(self, context, packages, databases, memory_mb, users,
device_path=None, mount_point=None, backup_info=None,
config_contents=None, root_password=None, overrides=None,
cluster_config=None, snapshot=None):
"""Makes ready DBAAS on a Guest container."""
MySqlAppStatus.get().begin_install()
# status end_mysql_install set with secure()
app = MySqlApp(MySqlAppStatus.get())
app.install_if_needed(packages)
if device_path:
# stop and do not update database
app.stop_db()
device = volume.VolumeDevice(device_path)
# unmount if device is already mounted
device.unmount_device(device_path)
device.format()
if os.path.exists(mount_point):
# rsync existing data to a "data" sub-directory
# on the new volume
device.migrate_data(mount_point, target_subdir="data")
# mount the volume
device.mount(mount_point)
operating_system.chown(mount_point, 'mysql', 'mysql',
recursive=False, as_root=True)
LOG.debug("Mounted the volume at %s." % mount_point)
# We need to temporarily update the default my.cnf so that
# mysql will start after the volume is mounted. Later on it
# will be changed based on the config template and restart.
app.update_overrides("[mysqld]\ndatadir=%s/data\n"
% mount_point)
app.start_mysql()
if backup_info:
self._perform_restore(backup_info, context,
mount_point + "/data", app)
LOG.debug("Securing MySQL now.")
app.secure(config_contents, overrides)
enable_root_on_restore = (backup_info and
MySqlAdmin().is_root_enabled())
if root_password and not backup_info:
app.secure_root(secure_remote_root=True)
MySqlAdmin().enable_root(root_password)
elif enable_root_on_restore:
app.secure_root(secure_remote_root=False)
MySqlAppStatus.get().report_root(context, 'root')
else:
app.secure_root(secure_remote_root=True)
app.complete_install_or_restart()
if databases:
self.create_database(context, databases)
if users:
self.create_user(context, users)
if snapshot:
self.attach_replica(context, snapshot, snapshot['config'])
LOG.info(_('Completed setup of MySQL database instance.'))
开发者ID:cp16net,项目名称:trove,代码行数:60,代码来源:manager.py
示例7: prepare
def prepare(self, context, packages, databases, memory_mb, users,
device_path=None, mount_point=None, backup_info=None,
config_contents=None, root_password=None, overrides=None,
cluster_config=None, snapshot=None):
"""Makes ready DBAAS on a Guest container."""
LOG.debug("Preparing MongoDB instance.")
self.status.begin_install()
self.app.install_if_needed(packages)
self.app.stop_db()
self.app.clear_storage()
mount_point = system.MONGODB_MOUNT_POINT
if device_path:
device = volume.VolumeDevice(device_path)
# unmount if device is already mounted
device.unmount_device(device_path)
device.format()
if os.path.exists(system.MONGODB_MOUNT_POINT):
device.migrate_data(mount_point)
device.mount(mount_point)
operating_system.chown(mount_point,
system.MONGO_USER, system.MONGO_USER,
as_root=True)
LOG.debug("Mounted the volume %(path)s as %(mount)s." %
{'path': device_path, "mount": mount_point})
self.app.secure(cluster_config)
conf_changes = self.get_config_changes(cluster_config, mount_point)
config_contents = self.app.update_config_contents(
config_contents, conf_changes)
if cluster_config is None:
self.app.start_db_with_conf_changes(config_contents)
if backup_info:
self._perform_restore(backup_info, context,
mount_point, self.app)
else:
if cluster_config['instance_type'] == "query_router":
self.app.reset_configuration({'config_contents':
config_contents})
self.app.write_mongos_upstart()
self.app.status.is_query_router = True
# don't start mongos until add_config_servers is invoked
elif cluster_config['instance_type'] == "config_server":
self.app.status.is_config_server = True
self.app.start_db_with_conf_changes(config_contents)
elif cluster_config['instance_type'] == "member":
self.app.start_db_with_conf_changes(config_contents)
else:
LOG.error(_("Bad cluster configuration; instance type "
"given as %s.") % cluster_config['instance_type'])
self.status.set_status(ds_instance.ServiceStatuses.FAILED)
return
self.status.set_status(ds_instance.ServiceStatuses.BUILD_PENDING)
LOG.info(_('Completed setup of MongoDB database instance.'))
开发者ID:mulupuru,项目名称:trove,代码行数:60,代码来源:manager.py
示例8: initial_setup
def initial_setup(self):
self.ip_address = netutils.get_my_ipv4()
mount_point = CONF.couchbase.mount_point
try:
LOG.info(_('Couchbase Server change data dir path.'))
operating_system.chown(mount_point, 'couchbase', 'couchbase',
as_root=True)
pwd = CouchbaseRootAccess.get_password()
utils.execute_with_timeout(
(system.cmd_node_init
% {'data_path': mount_point,
'IP': self.ip_address,
'PWD': pwd}), shell=True)
operating_system.remove(system.INSTANCE_DATA_DIR, force=True,
as_root=True)
LOG.debug('Couchbase Server initialize cluster.')
utils.execute_with_timeout(
(system.cmd_cluster_init
% {'IP': self.ip_address, 'PWD': pwd}),
shell=True)
utils.execute_with_timeout(system.cmd_set_swappiness, shell=True)
utils.execute_with_timeout(system.cmd_update_sysctl_conf,
shell=True)
LOG.info(_('Couchbase Server initial setup finished.'))
except exception.ProcessExecutionError:
LOG.exception(_('Error performing initial Couchbase setup.'))
raise RuntimeError("Couchbase Server initial setup failed")
开发者ID:HoratiusTang,项目名称:trove,代码行数:27,代码来源:service.py
示例9: 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
示例10: 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
示例11: do_prepare
def do_prepare(self, context, packages, databases, memory_mb, users,
device_path, mount_point, backup_info,
config_contents, root_password, overrides,
cluster_config, snapshot):
"""This is called from prepare in the base class."""
if device_path:
device = volume.VolumeDevice(device_path)
# unmount if device is already mounted
device.unmount_device(device_path)
device.format()
device.mount(mount_point)
operating_system.chown(mount_point, 'redis', 'redis',
as_root=True)
LOG.debug('Mounted the volume.')
self._app.install_if_needed(packages)
LOG.info(_('Writing redis configuration.'))
if cluster_config:
config_contents = (config_contents + "\n"
+ "cluster-enabled yes\n"
+ "cluster-config-file cluster.conf\n")
self._app.configuration_manager.save_configuration(config_contents)
self._app.apply_initial_guestagent_configuration()
if backup_info:
persistence_dir = self._app.get_working_dir()
self._perform_restore(backup_info, context, persistence_dir,
self._app)
else:
# If we're not restoring, we have to force a restart of the
# server manually so that the configuration stuff takes effect
self._app.restart()
if snapshot:
self.attach_replica(context, snapshot, snapshot['config'])
开发者ID:Hopebaytech,项目名称:trove,代码行数:32,代码来源:manager.py
示例12: 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
示例13: _run_restore
def _run_restore(self):
metadata = self.storage.load_metadata(self.location, self.checksum)
self.db_name = metadata['db_name']
operating_system.create_directory(ORA_FAST_RECOVERY_PATH,
user='oracle', group='oinstall', force=True,
as_root=True)
operating_system.create_directory(ORA_AUDIT_PATH % {'db': self.db_name},
user='oracle', group='oinstall',
force=True, as_root=True)
operating_system.create_directory(ORA_FAST_RECOVERY_PATH + '/' + self.db_name,
user='oracle', group='oinstall',
force=True, as_root=True)
operating_system.create_directory(ORA_DATA_PATH + '/' + self.db_name,
user='oracle', group='oinstall',
force=True, as_root=True)
# the backup set will restore directly to ORADATA/backupset_files
self._unpack_backup_files(self.location, self.checksum)
operating_system.chown(ORA_BACKUP_PATH, 'oracle', 'oinstall',
recursive=True, force=True, as_root=True)
operating_system.chown(ORA_FAST_RECOVERY_PATH, 'oracle', 'oinstall',
recursive=True, force=True, as_root=True)
self._perform_restore()
self._perform_recover()
self._open_database()
开发者ID:cdelatte,项目名称:tesora-trove,代码行数:26,代码来源:oracle_impl.py
示例14: prepare
def prepare(self, context, packages, databases, memory_mb, users,
device_path=None, mount_point=None, backup_info=None,
config_contents=None, root_password=None, overrides=None,
cluster_config=None, snapshot=None):
"""
This is called when the trove instance first comes online.
It is the first rpc message passed from the task manager.
prepare handles all the base configuration of the redis instance.
"""
try:
app = RedisApp(RedisAppStatus.get())
RedisAppStatus.get().begin_install()
if device_path:
device = volume.VolumeDevice(device_path)
# unmount if device is already mounted
device.unmount_device(device_path)
device.format()
device.mount(mount_point)
operating_system.chown(mount_point, 'redis', 'redis',
as_root=True)
LOG.debug('Mounted the volume.')
app.install_if_needed(packages)
LOG.info(_('Writing redis configuration.'))
app.write_config(config_contents)
app.restart()
LOG.info(_('Redis instance has been setup and configured.'))
except Exception:
LOG.exception(_("Error setting up Redis instance."))
app.status.set_status(rd_instance.ServiceStatuses.FAILED)
raise RuntimeError("prepare call has failed.")
开发者ID:cretta,项目名称:trove,代码行数:30,代码来源:manager.py
示例15: _write_standby_recovery_file
def _write_standby_recovery_file(self, service, snapshot, sslmode="prefer"):
LOG.info("Snapshot data received:" + str(snapshot))
logging_config = snapshot["log_position"]
conninfo_params = {
"host": snapshot["master"]["host"],
"port": snapshot["master"]["port"],
"repl_user": logging_config["replication_user"]["name"],
"password": logging_config["replication_user"]["password"],
"sslmode": sslmode,
}
conninfo = (
"host=%(host)s "
"port=%(port)s "
"dbname=os_admin "
"user=%(repl_user)s "
"password=%(password)s "
"sslmode=%(sslmode)s " % conninfo_params
)
recovery_conf = "standby_mode = 'on'\n"
recovery_conf += "primary_conninfo = '" + conninfo + "'\n"
recovery_conf += "trigger_file = '/tmp/postgresql.trigger'\n"
recovery_conf += "recovery_target_timeline='latest'\n"
operating_system.write_file(
service.pgsql_recovery_config, recovery_conf, codec=stream_codecs.IdentityCodec(), as_root=True
)
operating_system.chown(
service.pgsql_recovery_config, user=service.pgsql_owner, group=service.pgsql_owner, as_root=True
)
开发者ID:Tesora-Release,项目名称:tesora-trove,代码行数:32,代码来源:postgresql_impl.py
示例16: 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
示例17: 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
示例18: 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
示例19: init_config
def init_config(self):
if not operating_system.exists(MOUNT_POINT, True):
operating_system.create_directory(MOUNT_POINT,
system.DB2_INSTANCE_OWNER,
system.DB2_INSTANCE_OWNER,
as_root=True)
"""
The database manager configuration file - db2systm is stored under the
/home/db2inst1/sqllib directory. To update the configuration
parameters, DB2 recommends using the command - UPDATE DBM CONFIGURATION
commands instead of directly updating the config file.
The existing PropertiesCodec implementation has been reused to handle
text-file operations. Configuration overrides are implemented using
the ImportOverrideStrategy of the guestagent configuration manager.
"""
LOG.debug("Initialize DB2 configuration")
revision_dir = (
guestagent_utils.build_file_path(
os.path.join(MOUNT_POINT,
os.path.dirname(system.DB2_INSTANCE_OWNER)),
ConfigurationManager.DEFAULT_STRATEGY_OVERRIDES_SUB_DIR)
)
if not operating_system.exists(FAKE_CFG):
operating_system.write_file(FAKE_CFG, '', as_root=True)
operating_system.chown(FAKE_CFG, system.DB2_INSTANCE_OWNER,
system.DB2_INSTANCE_OWNER, as_root=True)
self.configuration_manager = (
ConfigurationManager(FAKE_CFG, system.DB2_INSTANCE_OWNER,
system.DB2_INSTANCE_OWNER,
PropertiesCodec(delimiter='='),
requires_root=True,
override_strategy=ImportOverrideStrategy(
revision_dir, "cnf"))
)
'''
Below we are getting the database manager default configuration and
saving it to the DB2_DEFAULT_CFG file. This is done to help with
correctly resetting the configurations to the original values when
user wants to detach a user-defined configuration group from an
instance. DB2 provides a command to reset the database manager
configuration parameters (RESET DBM CONFIGURATION) but this command
resets all the configuration parameters to the system defaults. When
we build a DB2 guest image there are certain configurations
parameters like SVCENAME which we set so that the instance can start
correctly. Hence resetting this value to the system default will
render the instance in an unstable state. Instead, the recommended
way for resetting a subset of configuration parameters is to save
the output of GET DBM CONFIGURATION of the original configuration
and then call UPDATE DBM CONFIGURATION to reset the value.
http://www.ibm.com/support/knowledgecenter/SSEPGG_10.5.0/
com.ibm.db2.luw.admin.cmd.doc/doc/r0001970.html
'''
if not operating_system.exists(DB2_DEFAULT_CFG):
run_command(system.GET_DBM_CONFIGURATION % {
"dbm_config": DB2_DEFAULT_CFG})
self.process_default_dbm_config()
开发者ID:Tesora,项目名称:tesora-trove,代码行数:57,代码来源:service.py
示例20: _create_oratab_entry
def _create_oratab_entry(self):
"""Create in the /etc/oratab file entries for the databases being
restored"""
file_content = operating_system.read_file(ORATAB_PATH)
file_content += ("\n%(db_name)s:%(ora_home)s:N\n" %
{'db_name': self.db_name, 'ora_home': ORACLE_HOME})
operating_system.write_file(ORATAB_PATH, file_content, as_root=True)
operating_system.chown(ORATAB_PATH, 'oracle', 'oinstall',
recursive=True, force=True, as_root=True)
开发者ID:cdelatte,项目名称:tesora-trove,代码行数:9,代码来源:oracle_impl.py
注:本文中的trove.guestagent.common.operating_system.chown函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论