• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python operating_system.exists函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中trove.guestagent.common.operating_system.exists函数的典型用法代码示例。如果您正苦于以下问题:Python exists函数的具体用法?Python exists怎么用?Python exists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了exists函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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,
        )
开发者ID:mmasaki,项目名称:trove,代码行数:26,代码来源:test_operating_system.py


示例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()
开发者ID:Tesora,项目名称:tesora-trove,代码行数:57,代码来源:service.py


示例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
        }
开发者ID:Tesora,项目名称:tesora-trove,代码行数:29,代码来源:manager.py


示例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
开发者ID:Tesora,项目名称:tesora-trove,代码行数:7,代码来源:module_manager.py


示例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()
开发者ID:Tesora-Release,项目名称:tesora-trove,代码行数:7,代码来源:postgresql_impl.py


示例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
开发者ID:Tesora-Release,项目名称:tesora-trove,代码行数:29,代码来源:postgresql_impl.py


示例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}
开发者ID:Tesora,项目名称:tesora-trove,代码行数:25,代码来源:mysql_ee_binlog.py


示例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))
开发者ID:Tesora-Release,项目名称:tesora-trove,代码行数:7,代码来源:configuration.py


示例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']))
开发者ID:Tesora,项目名称:tesora-trove,代码行数:30,代码来源:service.py


示例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)
开发者ID:paramtech,项目名称:tesora-trove,代码行数:8,代码来源:postgresql_impl.py


示例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()
开发者ID:Tesora,项目名称:tesora-trove,代码行数:8,代码来源:service.py


示例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
         )
开发者ID:cdelatte,项目名称:tesora-trove,代码行数:11,代码来源:service.py


示例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
开发者ID:HoratiusTang,项目名称:trove,代码行数:12,代码来源:manager.py


示例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)
开发者ID:HoratiusTang,项目名称:trove,代码行数:21,代码来源:manager.py


示例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
开发者ID:cdelatte,项目名称:tesora-trove,代码行数:15,代码来源:service.py


示例16: 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)
开发者ID:Tesora,项目名称:tesora-trove,代码行数:24,代码来源:test_operating_system.py


示例17: establish_ssh_user_equivalency

 def establish_ssh_user_equivalency(self, host_ip_pairs):
     """Establish SSH user equivalency by using ssh-keyscan against the
     cluster hostnames and IPs.
     :arg host_ip_pairs: list of (hostname, ip) tuples to add
     """
     filepath = path.join(self.user_home_dir, '.ssh', 'known_hosts')
     data = []
     if operating_system.exists(filepath, as_root=True):
         data.append(operating_system.read_file(filepath, as_root=True))
     for host_ip_pair in host_ip_pairs:
         host = host_ip_pair[0]
         ip = host_ip_pair[1]
         (stdout, stderr) = run_sys_command(
             'ssh-keyscan {host},{ip}'.format(host=host, ip=ip))
         data.append(stdout.strip())
     self.write_oracle_user_file(filepath, '\n'.join(data))
开发者ID:Tesora,项目名称:tesora-trove,代码行数:16,代码来源:service.py


示例18: mount

 def mount(self):
     if not operating_system.exists(self.mount_point, is_directory=True,
                                    as_root=True):
         operating_system.create_directory(self.mount_point, as_root=True)
     LOG.debug("Mounting volume. Device path:{0}, mount_point:{1}, "
               "volume_type:{2}, mount options:{3}".format(
                   self.device_path, self.mount_point, self.volume_fstype,
                   self.mount_options))
     try:
         utils.execute("mount", "-t", self.volume_fstype,
                       "-o", self.mount_options,
                       self.device_path, self.mount_point,
                       run_as_root=True, root_helper="sudo")
     except exception.ProcessExecutionError:
         msg = _("Could not mount '%s'.") % self.mount_point
         log_and_raise(msg)
开发者ID:Tesora,项目名称:tesora-trove,代码行数:16,代码来源:volume.py


示例19: post_upgrade

    def post_upgrade(self, context, upgrade_info):
        app = self.mysql_app(self.mysql_app_status.get())
        app.stop_db()
        if 'device' in upgrade_info:
            self.mount_volume(context, mount_point=upgrade_info['mount_point'],
                              device_path=upgrade_info['device'])

        if operating_system.exists(upgrade_info['save_etc_dir'],
                                   is_directory=True, as_root=True):
            operating_system.copy("%s/." % upgrade_info['save_etc_dir'],
                                  "/etc", preserve=True, as_root=True)

        operating_system.copy("%s/." % upgrade_info['save_dir'], "/etc/mysql",
                              preserve=True, as_root=True)
        operating_system.copy("%s/." % upgrade_info['home_save'],
                              os.path.expanduser('~'),
                              preserve=True, as_root=True)
        app.start_mysql()
开发者ID:cdelatte,项目名称:tesora-trove,代码行数:18,代码来源:manager.py


示例20: remove_module

    def remove_module(cls, driver, module_type, module_id, name,
                      datastore, ds_version):
        datastore = datastore or cls.MODULE_APPLY_TO_ALL
        ds_version = ds_version or cls.MODULE_APPLY_TO_ALL
        module_dir = cls.build_module_dir(module_type, module_id)
        contents_file = cls.build_contents_filename(module_dir)

        if not operating_system.exists(cls.get_result_filename(module_dir)):
            raise exception.NotFound(
                _("Module '%s' has not been applied") % name)
        try:
            removed, message = driver.remove(
                name, datastore, ds_version, contents_file)
            cls.remove_module_result(module_dir)
        except Exception:
            LOG.exception(_("Could not remove module '%s'") % name)
            raise
        return removed, message
开发者ID:ISCAS-VDI,项目名称:trove-base,代码行数:18,代码来源:module_manager.py



注:本文中的trove.guestagent.common.operating_system.exists函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python operating_system.get_os函数代码示例发布时间:2022-05-27
下一篇:
Python operating_system.create_directory函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap