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


Python operating_system.move函数代码示例

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


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

示例1: _run_pre_backup

 def _run_pre_backup(self):
     try:
         for cmd in self.pre_backup_commands:
             utils.execute_with_timeout(*cmd)
         root = service.CouchbaseRootAccess()
         pw = root.get_password()
         self._save_buckets_config(pw)
         with open(OUTFILE, "r") as f:
             out = f.read()
             if out != "[]":
                 d = json.loads(out)
                 all_memcached = True
                 for i in range(len(d)):
                     bucket_type = d[i]["bucketType"]
                     if bucket_type != "memcached":
                         all_memcached = False
                         break
                 if not all_memcached:
                     self._backup(pw)
                 else:
                     LOG.info(_("All buckets are memcached.  "
                                "Skipping backup."))
         operating_system.move(OUTFILE, system.COUCHBASE_DUMP_DIR)
         if pw != "password":
             # Not default password, backup generated root password
             operating_system.copy(system.pwd_file,
                                   system.COUCHBASE_DUMP_DIR,
                                   preserve=True, as_root=True)
     except exception.ProcessExecutionError as p:
         LOG.error(p)
         raise p
开发者ID:HoratiusTang,项目名称:trove,代码行数:31,代码来源:couchbase_impl.py

示例2: _rewind_against_master

    def _rewind_against_master(self, service):
        """Call pg_rewind to resync datadir against state of new master
        We should already have a recovery.conf file in PGDATA
        """
        rconf = operating_system.read_file(
            service.pgsql_recovery_config, codec=stream_codecs.KeyValueCodec(line_terminator="\n"), as_root=True
        )
        conninfo = rconf["primary_conninfo"].strip()

        # The recovery.conf file we want should already be there, but pg_rewind
        # will delete it, so copy it out first
        rec = service.pgsql_recovery_config
        tmprec = "/tmp/recovery.conf.bak"
        operating_system.move(rec, tmprec, as_root=True)

        cmd_full = " ".join(
            [
                "pg_rewind",
                "-D",
                service.pgsql_data_dir,
                "--source-pgdata=" + service.pgsql_data_dir,
                "--source-server=" + conninfo,
            ]
        )
        out, err = utils.execute("sudo", "su", "-", service.pgsql_owner, "-c", "%s" % cmd_full, check_exit_code=0)
        LOG.debug("Got stdout %s and stderr %s from pg_rewind" % (str(out), str(err)))

        operating_system.move(tmprec, rec, as_root=True)
开发者ID:Tesora-Release,项目名称:tesora-trove,代码行数:28,代码来源:postgresql_impl.py

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

示例4: _write_mycnf

    def _write_mycnf(self, admin_password, config_contents, overrides=None):
        """
        Install the set of mysql my.cnf templates.
        Update the os_admin user and password to the my.cnf
        file for direct login from localhost.
        """
        LOG.info(_("Writing my.cnf templates."))
        if admin_password is None:
            admin_password = get_auth_password()

        try:
            with open(TMP_MYCNF, 'w') as t:
                t.write(config_contents)

            operating_system.move(TMP_MYCNF, MYSQL_CONFIG, as_root=True)
            self._write_temp_mycnf_with_admin_account(MYSQL_CONFIG,
                                                      TMP_MYCNF,
                                                      admin_password)
            operating_system.move(TMP_MYCNF, MYSQL_CONFIG, as_root=True)
        except Exception:
            os.unlink(TMP_MYCNF)
            raise

        self.wipe_ib_logfiles()

        # write configuration file overrides
        if overrides:
            self._write_config_overrides(overrides)
开发者ID:cp16net,项目名称:trove,代码行数:28,代码来源:service.py

示例5: write_config

 def write_config(self, config_contents):
     """
     Write the redis config.
     """
     LOG.debug("Writing Redis config.")
     with open(TMP_REDIS_CONF, "w") as fd:
         fd.write(config_contents)
     operating_system.move(TMP_REDIS_CONF, system.REDIS_CONFIG, as_root=True)
开发者ID:cretta,项目名称:trove,代码行数:8,代码来源:service.py

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

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

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

示例9: write_mongos_upstart

    def write_mongos_upstart(self):
        upstart_contents = system.MONGOS_UPSTART_CONTENTS.format(config_file_placeholder=CONFIG_FILE)

        LOG.info(_("Writing %s.") % system.TMP_MONGOS_UPSTART)

        with open(system.TMP_MONGOS_UPSTART, "w") as t:
            t.write(upstart_contents)

        LOG.info(_("Moving %(a)s to %(b)s.") % {"a": system.TMP_MONGOS_UPSTART, "b": system.MONGOS_UPSTART})
        operating_system.move(system.TMP_MONGOS_UPSTART, system.MONGOS_UPSTART, as_root=True)
        operating_system.remove("/etc/init/mongodb.conf", force=True, as_root=True)
开发者ID:jachinpy,项目名称:trove,代码行数:11,代码来源:service.py

示例10: reset_configuration

    def reset_configuration(self, context, configuration):
        """Reset the PgSql configuration file to the one given.

        The configuration parameter is a string containing the full
        configuration file that should be used.
        """
        config_location = PGSQL_CONFIG.format(version=self._get_psql_version())
        LOG.debug("{guest_id}: Writing configuration file to /tmp/pgsql_config.".format(guest_id=CONF.guest_id))
        with open("/tmp/pgsql_config", "w+") as config_file:
            config_file.write(configuration)
        operating_system.chown("/tmp/pgsql_config", "postgres", None, recursive=False, as_root=True)
        operating_system.move("/tmp/pgsql_config", config_location, timeout=30, as_root=True)
开发者ID:jjmob,项目名称:trove,代码行数:12,代码来源:config.py

示例11: _clear_mysql_config

 def _clear_mysql_config(self):
     """Clear old configs, which can be incompatible with new version."""
     LOG.debug("Clearing old MySQL config.")
     random_uuid = str(uuid.uuid4())
     configs = ["/etc/my.cnf", "/etc/mysql/conf.d", "/etc/mysql/my.cnf"]
     for config in configs:
         try:
             old_conf_backup = "%s_%s" % (config, random_uuid)
             operating_system.move(config, old_conf_backup, as_root=True)
             LOG.debug("%s saved to %s_%s." %
                       (config, config, random_uuid))
         except exception.ProcessExecutionError:
             pass
开发者ID:zjtheone,项目名称:trove,代码行数:13,代码来源:service.py

示例12: set_db_to_listen

    def set_db_to_listen(self, context):
        """Allow remote connections with encrypted passwords."""
        # Using cat to read file due to read permissions issues.
        out, err = utils.execute_with_timeout(
            "sudo", "cat", PGSQL_HBA_CONFIG.format(version=self._get_psql_version()), timeout=30
        )
        LOG.debug("{guest_id}: Writing hba file to /tmp/pgsql_hba_config.".format(guest_id=CONF.guest_id))
        with open("/tmp/pgsql_hba_config", "w+") as config_file:
            config_file.write(out)
            config_file.write("host    all     all     0.0.0.0/0   md5\n")

        operating_system.chown("/tmp/pgsql_hba_config", "postgres", None, recursive=False, as_root=True)
        operating_system.move(
            "/tmp/pgsql_hba_config", PGSQL_HBA_CONFIG.format(version=self._get_psql_version()), timeout=30, as_root=True
        )
开发者ID:jjmob,项目名称:trove,代码行数:15,代码来源:config.py

示例13: _write_config

    def _write_config(self, config_contents):
        """
        Update contents of MongoDB configuration file
        """
        LOG.info(_("Updating MongoDB config."))
        if config_contents:
            LOG.info(_("Writing %s.") % system.TMP_CONFIG)
            try:
                with open(system.TMP_CONFIG, "w") as t:
                    t.write(config_contents)

                LOG.info(_("Moving %(a)s to %(b)s.") % {"a": system.TMP_CONFIG, "b": CONFIG_FILE})
                operating_system.move(system.TMP_CONFIG, CONFIG_FILE, as_root=True)
            except Exception:
                os.unlink(system.TMP_CONFIG)
                raise
        else:
            LOG.debug("Empty config_contents. Do nothing.")
开发者ID:jachinpy,项目名称:trove,代码行数:18,代码来源:service.py

示例14: write_password_to_file

    def write_password_to_file(self, root_password):
        operating_system.create_directory(system.COUCHBASE_CONF_DIR,
                                          as_root=True)
        try:
            tempfd, tempname = tempfile.mkstemp()
            os.fchmod(tempfd, stat.S_IRUSR | stat.S_IWUSR)
            os.write(tempfd, root_password)
            os.fchmod(tempfd, stat.S_IRUSR)
            os.close(tempfd)
        except OSError as err:
            message = _("An error occurred in saving password "
                        "(%(errno)s). %(strerror)s.") % {
                            "errno": err.errno,
                            "strerror": err.strerror}
            LOG.exception(message)
            raise RuntimeError(message)

        operating_system.move(tempname, system.pwd_file, as_root=True)
开发者ID:HoratiusTang,项目名称:trove,代码行数:18,代码来源:service.py

示例15: write_password_to_file

    def write_password_to_file(self, root_password):
        utils.execute_with_timeout('mkdir', '-p', system.COUCHBASE_CONF_DIR,
                                   run_as_root=True, root_helper='sudo')

        try:
            tempfd, tempname = tempfile.mkstemp()
            os.fchmod(tempfd, stat.S_IRUSR | stat.S_IWUSR)
            os.write(tempfd, root_password)
            os.fchmod(tempfd, stat.S_IRUSR)
            os.close(tempfd)
        except OSError as err:
            message = _("An error occurred in saving password "
                        "(%(errno)s). %(strerror)s.") % {
                            "errno": err.errno,
                            "strerror": err.strerror}
            LOG.exception(message)
            raise RuntimeError(message)

        operating_system.move(tempname, system.pwd_file, as_root=True)
开发者ID:shaikapsar,项目名称:trove,代码行数:19,代码来源:service.py


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