106 lines
3.1 KiB
Plaintext
106 lines
3.1 KiB
Plaintext
|
|
|
|
Projects will need to do e.g.
|
|
|
|
-- nova.config:
|
|
|
|
from oslo import messaging
|
|
|
|
TRANSPORT_DRIVER = None
|
|
|
|
|
|
def parse_args(argv, ...):
|
|
messaging.set_transport_defaults(control_exchange='nova')
|
|
cfg.CONF(...)
|
|
TRANSPORT_DRIVER = transport.get_transport(cfg.CONF)
|
|
|
|
-- nova.scheduler.rpcapi:
|
|
|
|
from oslo.config import cfg
|
|
from oslo import messaging
|
|
|
|
from nova import config
|
|
|
|
CONF = cfg.CONF
|
|
|
|
|
|
class SchedulerAPI(messaging.RPCClient):
|
|
|
|
def __init__(self):
|
|
target = messaging.Target(topic=CONF.scheduler_topic, version='2.0')
|
|
super(SchedulerAPI, self).__init__(config.TRANSPORT_DRIVER, target)
|
|
|
|
....
|
|
|
|
def select_hosts(self, ctxt, request_spec, filter_properties):
|
|
# FIXME(markmc): ctxt
|
|
cctxt = self.prepare(version='2.6')
|
|
return ctxt.call('select_hosts',
|
|
request_spec=request_spec,
|
|
filter_properties=filter_properties)
|
|
|
|
-- nova.service:
|
|
|
|
from oslo import messaging
|
|
|
|
from nova import baserpc
|
|
from nova import config
|
|
|
|
def start(self):
|
|
...
|
|
target = messaging.Target(topic=self.topic, self.server)
|
|
|
|
base_rpc = baserpc.BaseRPCAPI(self.service_name, backdoor_port)
|
|
|
|
self.rpcserver = messaging.get_rpc_server(config.TRANSPORT_DRIVER,
|
|
target,
|
|
[self.manager, base_rpc],
|
|
executor='eventlet')
|
|
|
|
LOG.debug(_("Starting RPC server for %(topic)s on %(server)s") %
|
|
dict(topic=self.topic, host=self.server))
|
|
|
|
self.rpcserver.start()
|
|
|
|
...
|
|
self.rpcserver.stop()
|
|
self.rpcserver.wait()
|
|
|
|
|
|
== notifier ==
|
|
|
|
Will need e.g.
|
|
|
|
from oslo import messaging
|
|
|
|
from nova import config
|
|
|
|
def get_notifier(host=None):
|
|
global _NOTIFIER
|
|
if _NOTIFIER is None:
|
|
_NOTIFIER = messaging.Notifier(cfg.CONF,
|
|
'compute.%s' % (host or cfg.host,
|
|
transport=config.TRANSPORT_DRIVER)
|
|
return _NOTIFIER
|
|
|
|
|
|
def notify_about_instance_usage(context, instance, event, ..., host=None):
|
|
usage_info = notifications.info_from_instance(context, instance, ...)
|
|
|
|
notifier = get_notifier(host)
|
|
notify = notifier.error if event.endswith("error") else notifier.info
|
|
notify(context, 'compute.instance.%s' % event, usage_info)
|
|
|
|
Misc changes vs openstack.common.notifier.api:
|
|
|
|
- jsonutil.to_primitive(payload, convert_instances=True) is no longer called,
|
|
I'm figuring that you should supply a serializer instead
|
|
- need to construct a Notifier object, there is no global notifier state
|
|
- you'll need a Notifier object per-service, since publisher_id is an object
|
|
attribute
|
|
- publisher_id() has been removed, so you do 'service.host' manually
|
|
- the log levels aren't exposed by the API, instead use the info() etc.
|
|
methods on the Notifier class
|
|
- notifiy_decorator has been removed, see:
|
|
https://github.com/markmc/oslo-incubator/tree/oslo-messaging-notify-decorator
|