本文整理汇总了Python中swift.obj.diskfile.DiskFileManager.object_audit_location_generator方法的典型用法代码示例。如果您正苦于以下问题:Python DiskFileManager.object_audit_location_generator方法的具体用法?Python DiskFileManager.object_audit_location_generator怎么用?Python DiskFileManager.object_audit_location_generator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类swift.obj.diskfile.DiskFileManager
的用法示例。
在下文中一共展示了DiskFileManager.object_audit_location_generator方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ObjectCrawler
# 需要导入模块: from swift.obj.diskfile import DiskFileManager [as 别名]
# 或者: from swift.obj.diskfile.DiskFileManager import object_audit_location_generator [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'] = \
#.........这里部分代码省略.........