本文整理汇总了Python中trove.guestagent.common.operating_system.exists函数的典型用法代码示例。如果您正苦于以下问题:Python exists函数的具体用法?Python exists怎么用?Python exists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了exists函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_exists
def test_exists(self):
self.assertFalse(operating_system.exists(tempfile.gettempdir(), is_directory=False))
self.assertTrue(operating_system.exists(tempfile.gettempdir(), is_directory=True))
with tempfile.NamedTemporaryFile() as test_file:
self.assertTrue(operating_system.exists(test_file.name, is_directory=False))
self.assertFalse(operating_system.exists(test_file.name, is_directory=True))
self._assert_execute_call(
[["test -f path && echo 1 || echo 0"]],
[{"shell": True, "check_exit_code": False, "run_as_root": True, "root_helper": "sudo"}],
operating_system.exists,
None,
"path",
is_directory=False,
as_root=True,
)
self._assert_execute_call(
[["test -d path && echo 1 || echo 0"]],
[{"shell": True, "check_exit_code": False, "run_as_root": True, "root_helper": "sudo"}],
operating_system.exists,
None,
"path",
is_directory=True,
as_root=True,
)
示例2: 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()
示例3: pre_upgrade
def pre_upgrade(self, context):
app = self.mysql_app(self.mysql_app_status.get())
data_dir = app.get_data_dir()
mount_point, _data = os.path.split(data_dir)
save_dir = "%s/etc_mysql" % mount_point
save_etc_dir = "%s/etc" % mount_point
home_save = "%s/trove_user" % mount_point
app.status.begin_restart()
app.stop_db()
if operating_system.exists("/etc/my.cnf", as_root=True):
operating_system.create_directory(save_etc_dir, as_root=True)
operating_system.copy("/etc/my.cnf", save_etc_dir,
preserve=True, as_root=True)
operating_system.copy("/etc/mysql/.", save_dir,
preserve=True, as_root=True)
operating_system.copy("%s/." % os.path.expanduser('~'), home_save,
preserve=True, as_root=True)
self.unmount_volume(context, mount_point=data_dir)
return {
'mount_point': mount_point,
'save_dir': save_dir,
'save_etc_dir': save_etc_dir,
'home_save': home_save
}
示例4: build_module_dir
def build_module_dir(cls, module_type, module_id):
sub_dir = os.path.join(module_type, module_id)
module_dir = guestagent_utils.build_file_path(
cls.MODULE_BASE_DIR, sub_dir)
if not operating_system.exists(module_dir, is_directory=True):
operating_system.create_directory(module_dir, force=True)
return module_dir
示例5: connect_to_master
def connect_to_master(self, service, snapshot):
"""All that is required in postgresql to connect to a slave is to
restart with a recovery.conf file in the data dir, which contains
the connection information for the master.
"""
assert operating_system.exists(service.pgsql_recovery_config, as_root=True)
service.restart()
示例6: _get_or_create_replication_user
def _get_or_create_replication_user(self, service):
"""There are three scenarios we need to deal with here:
- This is a fresh master, with no replicator user created.
Generate a new u/p
- We are attaching a new slave and need to give it the login creds
Send the creds we have stored in PGDATA/.replpass
- This is a failed-over-to slave, who will have the replicator user
but not the credentials file. Recreate the repl user in this case
"""
LOG.debug("Checking for replicator user")
pwfile = os.path.join(service.pgsql_data_dir, ".replpass")
admin = service.build_admin()
if admin.user_exists(REPL_USER):
if operating_system.exists(pwfile, as_root=True):
LOG.debug("Found existing .replpass, returning pw")
pw = operating_system.read_file(pwfile, as_root=True)
else:
LOG.debug("Found user but not .replpass, recreate")
u = models.PostgreSQLUser(REPL_USER)
admin._drop_user(context=None, user=u)
pw = self._create_replication_user(service, admin, pwfile)
else:
LOG.debug("Found no replicator user, create one")
pw = self._create_replication_user(service, admin, pwfile)
repl_user_info = {"name": REPL_USER, "password": pw}
return repl_user_info
示例7: _read_log_position
def _read_log_position(self):
backup_var_file = ('%s/backup_variables.txt' %
MySqlApp.get_data_dir())
if operating_system.exists(backup_var_file):
try:
LOG.info(_("Reading log position from %s") % backup_var_file)
backup_vars = operating_system.read_file(
backup_var_file,
stream_codecs.PropertiesCodec(delimiter='='),
as_root=True)
binlog_position = backup_vars['binlog_position']
binlog_file, binlog_pos = binlog_position.split(':')
return {
'log_file': binlog_file,
'log_position': int(binlog_pos)
}
except Exception as ex:
LOG.exception(ex)
raise self.UnableToDetermineBinlogPosition(
{'binlog_file': backup_var_file})
else:
LOG.info(_("Log position detail not available. "
"Using default values."))
return {'log_file': '',
'log_position': 4}
示例8: has_revisions
def has_revisions(self):
"""Return True if there currently are any revision files.
"""
return (operating_system.exists(
self._revision_dir, is_directory=True,
as_root=self._requires_root) and
(len(self._collect_revision_files()) > 0))
示例9: mount_storage
def mount_storage(self, storage_info):
fstab = path.join('/etc', 'fstab')
default_mount_options = ('rw,bg,hard,nointr,tcp,vers=3,timeo=600,'
'rsize=32768,wsize=32768,actimeo=0')
data_mount_options = ('user,tcp,rsize=32768,wsize=32768,hard,intr,'
'noac,nfsvers=3')
if storage_info['type'] == 'nfs':
sources = storage_info['data']
data = list()
if operating_system.exists(fstab):
data.append(operating_system.read_file(fstab, as_root=True))
def _line(source, target, options=default_mount_options):
data.append('{source} {target} nfs {options} 0 0'.format(
source=source, target=target, options=options))
_line(sources['votedisk_mount'], SHARED_DISK_PATHS['votedisk'],)
_line(sources['registry_mount'], SHARED_DISK_PATHS['registry'],)
_line(sources['database_mount'], SHARED_DISK_PATHS['database'],
data_mount_options)
operating_system.write_file(fstab, '\n'.join(data),
as_root=True)
utils.execute_with_timeout('mount', '-a',
run_as_root=True,
root_helper='sudo',
timeout=service.ORACLE_TIMEOUT,
log_output_on_error=True)
else:
raise exception.GuestError(_(
"Storage type {t} not valid.").format(t=storage_info['type']))
示例10: connect_to_master
def connect_to_master(self, service, snapshot):
"""All that is required in postgresql to connect to a slave is to
restart with a recovery.conf file in the data dir, which contains
the connection information for the master.
"""
assert operating_system.exists(self.PGSQL_RECOVERY_CONFIG,
as_root=True)
self.restart(context=None)
示例11: __init__
def __init__(self, status, state_change_wait_time=None):
super(OracleVMApp, self).__init__(
status, OracleVMClient, OracleVMCursor, OracleVMAdmin,
state_change_wait_time)
self.paths = OracleVMPaths(self.admin.database_name)
self.configuration_manager = None
if operating_system.exists(self.paths.os_pfile):
self._init_configuration_manager()
示例12: update_spfile
def update_spfile(self):
"""Checks if there is a new SPFILE and replaces the old.
The database must be shutdown before running this.
"""
if operating_system.exists(self.new_spfile, as_root=True):
LOG.debug('Found a new SPFILE.')
operating_system.move(
self.new_spfile,
self.spfile,
force=True
)
示例13: 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
示例14: build_log_file_name
def build_log_file_name(self, log_name, owner, datastore_dir=None):
"""Build a log file name based on the log_name and make sure the
directories exist and are accessible by owner.
"""
if datastore_dir is None:
base_dir = self.GUEST_LOG_BASE_DIR
if not operating_system.exists(base_dir, is_directory=True):
operating_system.create_directory(
base_dir, user=owner, group=owner, force=True,
as_root=True)
datastore_dir = guestagent_utils.build_file_path(
base_dir, self.GUEST_LOG_DATASTORE_DIRNAME)
if not operating_system.exists(datastore_dir, is_directory=True):
operating_system.create_directory(
datastore_dir, user=owner, group=owner, force=True,
as_root=True)
log_file_name = guestagent_utils.build_file_path(
datastore_dir, '%s-%s.log' % (self.manager, log_name))
return self.validate_log_file(log_file_name, owner)
示例15: __init__
def __init__(self, status, state_change_wait_time=None):
LOG.debug("Initialize OracleApp.")
if state_change_wait_time:
self.state_change_wait_time = state_change_wait_time
else:
self.state_change_wait_time = CONF.state_change_wait_time
LOG.debug("state_change_wait_time = %s." % self.state_change_wait_time)
self.pfile = self._param_file_path(system.PFILE_NAME)
self.spfile = self._param_file_path(system.SPFILE_NAME)
self.new_spfile = self._param_file_path(system.NEW_SPFILE_NAME)
self.configuration_manager = None
if operating_system.exists(self.pfile):
self._init_configuration_manager()
self.status = status