Update swift / worker base
Change-Id: I512a3ecfb52c908e26b3b7a1e679d3303ee39338
This commit is contained in:
parent
778093da01
commit
a001829f55
|
@ -30,3 +30,16 @@ def upload_to_swift(filename, file_id):
|
||||||
container = config.swift.container.encode('utf-8')
|
container = config.swift.container.encode('utf-8')
|
||||||
file_id = str(file_id).encode('utf-8')
|
file_id = str(file_id).encode('utf-8')
|
||||||
swift_session.put_object(container, file_id, upload_file)
|
swift_session.put_object(container, file_id, upload_file)
|
||||||
|
|
||||||
|
|
||||||
|
def download_from_swift(file_uuid):
|
||||||
|
config = current_app.config['cfg']
|
||||||
|
auth_version = config.swift.auth_version
|
||||||
|
swift_session = swiftclient.Connection(authurl=config.swift.auth_uri,
|
||||||
|
user=config.swift.user,
|
||||||
|
key=config.swift.password,
|
||||||
|
tenant_name=config.swift.project,
|
||||||
|
auth_version=auth_version)
|
||||||
|
|
||||||
|
container = config.swift.container.encode('utf-8')
|
||||||
|
print(swift_session.get_object(container, file_uuid))
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
|
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
import oslo_messaging
|
import oslo_messaging
|
||||||
|
from python_nemesis.extensions import log
|
||||||
|
from python_nemesis.swift import download_from_swift
|
||||||
|
|
||||||
|
|
||||||
class NewFileEndpoint(object):
|
class NewFileEndpoint(object):
|
||||||
|
@ -21,7 +23,13 @@ class NewFileEndpoint(object):
|
||||||
event_type='nemsis.new_file')
|
event_type='nemsis.new_file')
|
||||||
|
|
||||||
def info(self, ctxt, publisher_id, event_type, payload, metadata):
|
def info(self, ctxt, publisher_id, event_type, payload, metadata):
|
||||||
print(payload)
|
file_uuid = payload['file_uuid']
|
||||||
|
file_id = payload['file_id']
|
||||||
|
log.logger.info("Fetched file_id %s to work on from the queue."
|
||||||
|
% file_id)
|
||||||
|
|
||||||
|
log.logger.info("Downloading file from Swift for analysis.")
|
||||||
|
download_from_swift(file_uuid)
|
||||||
|
|
||||||
|
|
||||||
def run_worker():
|
def run_worker():
|
||||||
|
@ -39,7 +47,6 @@ def run_worker():
|
||||||
server = oslo_messaging.get_notification_listener(transport,
|
server = oslo_messaging.get_notification_listener(transport,
|
||||||
targets,
|
targets,
|
||||||
endpoints,
|
endpoints,
|
||||||
executor='threading',
|
|
||||||
pool=pool)
|
pool=pool)
|
||||||
|
|
||||||
server.start()
|
server.start()
|
||||||
|
|
Loading…
Reference in New Issue