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


Python DiskFileManager.get_diskfile_from_audit_location方法代码示例

本文整理汇总了Python中swift.obj.diskfile.DiskFileManager.get_diskfile_from_audit_location方法的典型用法代码示例。如果您正苦于以下问题:Python DiskFileManager.get_diskfile_from_audit_location方法的具体用法?Python DiskFileManager.get_diskfile_from_audit_location怎么用?Python DiskFileManager.get_diskfile_from_audit_location使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在swift.obj.diskfile.DiskFileManager的用法示例。


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

示例1: ObjectCrawler

# 需要导入模块: from swift.obj.diskfile import DiskFileManager [as 别名]
# 或者: from swift.obj.diskfile.DiskFileManager import get_diskfile_from_audit_location [as 别名]
class ObjectCrawler(Daemon):
    """Update object information in container listings."""

    def __init__(self, conf):
        self.conf = conf
        self.logger = get_logger(conf, log_route='object-updater')
        self.devices = conf.get('devices', '/srv/node')
        self.ip = conf.get('md-server-ip', '127.0.0.1')
        self.port = conf.get('md-server-port', '6090')
        self.mount_check = config_true_value(conf.get('mount_check', 'true'))
        self.swift_dir = conf.get('swift_dir', '/etc/swift')
        self.interval = int(conf.get('interval', 30))
        #self.container_ring = None
        #self.concurrency = int(conf.get('concurrency', 1))
        #self.slowdown = float(conf.get('slowdown', 0.01))
        #self.node_timeout = int(conf.get('node_timeout', 10))
        #self.conn_timeout = float(conf.get('conn_timeout', .5))
        self.last_time_ran = 0
        self.diskfile_mgr = DiskFileManager(conf, self.logger)

    def run_forever(self, *args, **kwargs):
        """Run the updater continuously."""
        time.sleep(random() * self.interval)
        while True:
            with open("/opt/swift/OBJLOG.txt", "a+") as f:
                f.write("START\n")
            try:
                self.object_sweep()
                self.last_time_ran = time.time()
            except (Exception, Timeout):
                pass
            time.sleep(self.interval)



    def run_once(self, *args, **kwargs):
        """Run the updater once."""
        self.object_sweep()

    def object_sweep(self):
        """
        Scan through all objects and send metadata dict of ones with updates.
        """

        all_locs = self.diskfile_mgr.object_audit_location_generator()
        metaList = []
        for location in all_locs:
            try:
                metaDict = self.collect_object(location)

                metaDict = self.format_metadata(metaDict)
                if metaDict != {}:
                    modtime = metaDict["object_last_modified_time"]
                    if modtime != 'NULL' and float(modtime) > self.last_time_ran:
                        metaList.append(metaDict)
            except Exception:
                pass
            
        if metaList != []:
            ObjectSender = Sender(self.conf)
            ObjectSender.sendData(
                metaList, 'object_crawler', self.ip, self.port)

    def collect_object(self, location):
        """
        Process the object metadata
        """
        metadata = {}
        try:
            df = self.diskfile_mgr.get_diskfile_from_audit_location(location)
            metadata = df.read_metadata()
        except DiskFileNotExist:
            pass
        return metadata

    def format_metadata(self, data):
        metadata = {}
        uri = data['name'].split("/")
        metadata['object_uri'] = data['name']
        metadata['object_name'] = ("/".join(uri[3:]))
        metadata['object_account_name'] = uri[1]
        metadata['object_container_name'] = uri[2]
        metadata['object_location'] = 'NULL'  # Not implemented yet
        metadata['object_uri_create_time'] = \
            data.setdefault('X-Timestamp', 'NULL')

        metadata['object_last_modified_time'] = \
            data.setdefault('X-Timestamp', 'NULL')

        metadata['object_last_changed_time'] = 'NULL'

        metadata['object_delete_time'] = 'NULL'

        metadata['object_last_activity_time'] = \
            data.setdefault('X-Timestamp', 'NULL')

        metadata['object_etag_hash'] = \
            data.setdefault('ETag', 'NULL')

        metadata['object_content_type'] = \
#.........这里部分代码省略.........
开发者ID:ucsc-hp-group,项目名称:swift,代码行数:103,代码来源:crawler.py


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