当前位置: 首页>>代码示例>>Python>>正文


Python operating_system.remove函数代码示例

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


在下文中一共展示了remove函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: remove_last

 def remove_last(self, num_revisions):
     revision_files = self._collect_revisions()
     deleted_files = []
     if num_revisions > 0:
         deleted_files = revision_files[-num_revisions:]
         for path in deleted_files:
             operating_system.remove(path, force=True, as_root=self._requires_root)
开发者ID:cretta,项目名称:trove,代码行数:7,代码来源:configuration.py

示例2: 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

示例3: assert_module_retrieve

 def assert_module_retrieve(
     self, client, instance_id, expected_count, expected_http_code=200, expected_results=None
 ):
     try:
         temp_dir = tempfile.mkdtemp()
         prefix = "contents"
         modretrieve_list = client.instances.module_retrieve(instance_id, directory=temp_dir, prefix=prefix)
         self.assert_client_code(expected_http_code, client)
         count = len(modretrieve_list)
         self.assert_equal(expected_count, count, "Wrong number of modules from retrieve")
         expected_results = expected_results or {}
         for module_name, filename in modretrieve_list.items():
             if module_name in expected_results:
                 expected = expected_results[module_name]
                 contents_name = "%s_%s_%s_%s" % (
                     prefix,
                     module_name,
                     expected["datastore"],
                     expected["datastore_version"],
                 )
                 expected_filename = guestagent_utils.build_file_path(temp_dir, contents_name, "dat")
                 self.assert_equal(expected_filename, filename, "Unexpected retrieve filename")
                 if "contents" in expected and expected["contents"]:
                     with open(filename, "rb") as fh:
                         contents = fh.read()
                     # convert contents into bytearray to work with py27
                     # and py34
                     contents = bytes([ord(item) for item in contents])
                     expected_contents = bytes([ord(item) for item in expected["contents"]])
                     self.assert_equal(expected_contents, contents, "Unexpected contents for %s" % module_name)
     finally:
         operating_system.remove(temp_dir)
开发者ID:mmasaki,项目名称:trove,代码行数:32,代码来源:module_runners.py

示例4: clear_expired_password

def clear_expired_password():
    """
    Some mysql installations generate random root password
    and save it in /root/.mysql_secret, this password is
    expired and should be changed by client that supports expired passwords.
    """
    LOG.debug("Removing expired password.")
    secret_file = "/root/.mysql_secret"
    try:
        out, err = utils.execute("cat", secret_file,
                                 run_as_root=True, root_helper="sudo")
    except exception.ProcessExecutionError:
        LOG.exception(_("/root/.mysql_secret does not exist."))
        return
    m = re.match('# The random password set for the root user at .*: (.*)',
                 out)
    if m:
        try:
            out, err = utils.execute("mysqladmin", "-p%s" % m.group(1),
                                     "password", "", run_as_root=True,
                                     root_helper="sudo")
        except exception.ProcessExecutionError:
            LOG.exception(_("Cannot change mysql password."))
            return
        operating_system.remove(secret_file, force=True, as_root=True)
        LOG.debug("Expired password removed.")
开发者ID:zjtheone,项目名称:trove,代码行数:26,代码来源:service.py

示例5: 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

示例6: 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

示例7: recreate_wal_archive_dir

 def recreate_wal_archive_dir():
     operating_system.remove(WAL_ARCHIVE_DIR, force=True, recursive=True,
                             as_root=True)
     operating_system.create_directory(WAL_ARCHIVE_DIR,
                                       user=PgSqlProcess.PGSQL_OWNER,
                                       group=PgSqlProcess.PGSQL_OWNER,
                                       force=True, as_root=True)
开发者ID:Hopebaytech,项目名称:trove,代码行数:7,代码来源:postgresql_impl.py

示例8: 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

示例9: clear_storage

 def clear_storage(self):
     mount_point = "/var/lib/mongodb/*"
     LOG.debug("Clearing storage at %s." % mount_point)
     try:
         operating_system.remove(mount_point, force=True, as_root=True)
     except exception.ProcessExecutionError:
         LOG.exception(_("Error clearing storage."))
开发者ID:Hopebaytech,项目名称:trove,代码行数:7,代码来源:service.py

示例10: post_restore

    def post_restore(self):
        """
        Restore from the directory that we untarred into
        """
        utils.execute_with_timeout("mongorestore", MONGO_DUMP_DIR,
                                   timeout=LARGE_TIMEOUT)

        operating_system.remove(MONGO_DUMP_DIR, force=True, as_root=True)
开发者ID:cretta,项目名称:trove,代码行数:8,代码来源:mongo_impl.py

示例11: recreate_wal_archive_dir

 def recreate_wal_archive_dir(cls):
     wal_archive_dir = CONF.postgresql.wal_archive_location
     operating_system.remove(wal_archive_dir, force=True, recursive=True,
                             as_root=True)
     operating_system.create_directory(wal_archive_dir,
                                       user=cls.PGSQL_OWNER,
                                       group=cls.PGSQL_OWNER,
                                       force=True, as_root=True)
开发者ID:paramtech,项目名称:tesora-trove,代码行数:8,代码来源:process.py

示例12: recreate_wal_archive_dir

 def recreate_wal_archive_dir(self):
     wal_archive_dir = self.wal_archive_location
     operating_system.remove(wal_archive_dir, force=True, recursive=True,
                             as_root=True)
     operating_system.create_directory(wal_archive_dir,
                                       user=self.pgsql_owner,
                                       group=self.pgsql_owner,
                                       force=True, as_root=True)
开发者ID:Tesora-Release,项目名称:tesora-trove,代码行数:8,代码来源:service.py

示例13: pre_restore

 def pre_restore(self):
     self.stop_db(context=None)
     PgBaseBackupUtil.recreate_wal_archive_dir()
     datadir = self.pgsql_data_dir
     operating_system.remove(datadir, force=True, recursive=True,
                             as_root=True)
     operating_system.create_directory(datadir, user=self.PGSQL_OWNER,
                                       group=self.PGSQL_OWNER, force=True,
                                       as_root=True)
开发者ID:Hopebaytech,项目名称:trove,代码行数:9,代码来源:postgresql_impl.py

示例14: remove

 def remove(self, group_name, change_id=None):
     self._import_strategy.remove(group_name, change_id=change_id)
     self._regenerate_base_configuration()
     if not self._import_strategy.has_revisions:
         # The base revision file is no longer needed if there are no
         # overrides. It will be regenerated based on the current
         # configuration file on the first 'apply()'.
         operating_system.remove(self._base_revision_file, force=True,
                                 as_root=self._requires_root)
开发者ID:cp16net,项目名称:trove,代码行数:9,代码来源:configuration.py

示例15: _delete_revisions

    def _delete_revisions(self, num_revisions):
        revision_files = self._collect_revisions()
        deleted_files = []
        if num_revisions > 0:
            deleted_files = revision_files[-num_revisions:]
            for path in deleted_files:
                operating_system.remove(path, force=True, as_root=self._requires_root)

        return [path for path in revision_files if path not in deleted_files]
开发者ID:cretta,项目名称:trove,代码行数:9,代码来源:configuration.py


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