basic rpc api
Change-Id: I89fd51a2fa79e827888564b59a91f4aaf8c2df40
This commit is contained in:
parent
df11ca7909
commit
0373cf684d
@ -7,6 +7,8 @@ Babel>=1.3
|
|||||||
python-dateutil>=2.4.2
|
python-dateutil>=2.4.2
|
||||||
python-novaclient>=2.26.0
|
python-novaclient>=2.26.0
|
||||||
networkx>=1.10
|
networkx>=1.10
|
||||||
|
oslo.config>=2.7.0 # Apache-2.0
|
||||||
|
oslo.messaging!=2.8.0,>2.6.1 # Apache-2.0
|
||||||
oslo.log>=1.12.0 # Apache-2.0
|
oslo.log>=1.12.0 # Apache-2.0
|
||||||
oslo.policy>=0.3.0
|
oslo.policy>=0.3.0
|
||||||
oslo.service>=1.0.0 # Apache-2.0
|
oslo.service>=1.0.0 # Apache-2.0
|
||||||
|
@ -14,6 +14,8 @@ oslo.log>=1.12.0 # Apache-2.0
|
|||||||
oslosphinx>=2.5.0 # Apache-2.0
|
oslosphinx>=2.5.0 # Apache-2.0
|
||||||
oslotest>=1.10.0 # Apache-2.0
|
oslotest>=1.10.0 # Apache-2.0
|
||||||
oslo.service>=1.0.0 # Apache-2.0
|
oslo.service>=1.0.0 # Apache-2.0
|
||||||
|
oslo.config>=2.7.0 # Apache-2.0
|
||||||
|
oslo.messaging!=2.8.0,>2.6.1 # Apache-2.0
|
||||||
oslo.i18n>=2.1.0
|
oslo.i18n>=2.1.0
|
||||||
testrepository>=0.0.18
|
testrepository>=0.0.18
|
||||||
testscenarios>=0.4
|
testscenarios>=0.4
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
# Copyright 2016 - Alcatel-Lucent
|
||||||
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
# not use this file except in compliance with the License. You may obtain
|
# not use this file except in compliance with the License. You may obtain
|
||||||
# a copy of the License at
|
# a copy of the License at
|
||||||
@ -12,13 +14,17 @@
|
|||||||
|
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import pecan
|
|
||||||
|
|
||||||
from networkx.readwrite import json_graph
|
from networkx.readwrite import json_graph
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
import oslo_messaging
|
||||||
|
import pecan
|
||||||
from pecan.core import abort
|
from pecan.core import abort
|
||||||
from pecan import rest
|
from pecan import rest
|
||||||
|
|
||||||
from vitrage.api.policy import enforce
|
from vitrage.api.policy import enforce
|
||||||
|
|
||||||
# noinspection PyProtectedMember
|
# noinspection PyProtectedMember
|
||||||
from vitrage.i18n import _LI
|
from vitrage.i18n import _LI
|
||||||
|
|
||||||
@ -26,6 +32,14 @@ LOG = log.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class TopologyController(rest.RestController):
|
class TopologyController(rest.RestController):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
transport = oslo_messaging.get_transport(cfg.CONF)
|
||||||
|
cfg.CONF.set_override('rpc_backend', 'rabbit')
|
||||||
|
target = oslo_messaging.Target(topic='rpcapiv1')
|
||||||
|
self.client = oslo_messaging.RPCClient(transport, target)
|
||||||
|
self.ctxt = {}
|
||||||
|
|
||||||
@pecan.expose('json')
|
@pecan.expose('json')
|
||||||
def post(self, depth, graph_type, query, root):
|
def post(self, depth, graph_type, query, root):
|
||||||
enforce("get topology", pecan.request.headers,
|
enforce("get topology", pecan.request.headers,
|
||||||
@ -39,20 +53,19 @@ class TopologyController(rest.RestController):
|
|||||||
|
|
||||||
return self.get_graph(graph_type)
|
return self.get_graph(graph_type)
|
||||||
|
|
||||||
@staticmethod
|
def get_graph(self, graph_type):
|
||||||
def get_graph(graph_type):
|
graph_data = self.client.call(self.ctxt, 'get_topology', arg=None)
|
||||||
# TODO(eyal) temporary mock
|
LOG.info(graph_data)
|
||||||
graph_file = pecan.request.cfg.find_file('graph.sample.json')
|
|
||||||
|
# graph_file = pecan.request.cfg.find_file('graph.sample.json')
|
||||||
try:
|
try:
|
||||||
with open(graph_file) as data_file:
|
if graph_type == 'graph':
|
||||||
graph = json.load(data_file)
|
return json.loads(graph_data)
|
||||||
if graph_type == 'graph':
|
if graph_type == 'tree':
|
||||||
return graph
|
return json_graph.tree_data(
|
||||||
if graph_type == 'tree':
|
json_graph.node_link_graph(json.loads(graph_data)),
|
||||||
return json_graph.tree_data(
|
root='RESOURCE:node')
|
||||||
json_graph.node_link_graph(graph).reverse(),
|
|
||||||
root=0)
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.exception("failed to open file ", e)
|
LOG.exception("failed to open file %s ", e)
|
||||||
abort(404, str(e))
|
abort(404, str(e))
|
||||||
|
@ -12,7 +12,9 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
import oslo_messaging
|
||||||
from oslo_service import service as os_service
|
from oslo_service import service as os_service
|
||||||
|
|
||||||
|
|
||||||
@ -30,6 +32,31 @@ class VitrageApiHandlerService(os_service.Service):
|
|||||||
|
|
||||||
super(VitrageApiHandlerService, self).start()
|
super(VitrageApiHandlerService, self).start()
|
||||||
|
|
||||||
|
transport = oslo_messaging.get_transport(cfg.CONF)
|
||||||
|
|
||||||
|
# TODO(Dany) add real server
|
||||||
|
target = oslo_messaging.Target(topic='rpcapiv1', server='localhost')
|
||||||
|
|
||||||
|
# TODO(Dany) add rabbit configuratipn
|
||||||
|
# target = om.Target(topic='testme', server='192.168.56.102')
|
||||||
|
# target = oslo_messaging.Target(
|
||||||
|
# topic='testme', server='135.248.18.223')
|
||||||
|
# cfg.CONF.set_override('rabbit_host', '135.248.18.223')
|
||||||
|
# cfg.CONF.set_override('rabbit_port', 5672)
|
||||||
|
# cfg.CONF.set_override('rabbit_userid', 'guest')
|
||||||
|
# cfg.CONF.set_override('rabbit_password', 'cloud')
|
||||||
|
# cfg.CONF.set_override('rabbit_login_method', 'AMQPLAIN')
|
||||||
|
# cfg.CONF.set_override('rabbit_virtual_host', '/')
|
||||||
|
cfg.CONF.set_override('rpc_backend', 'rabbit')
|
||||||
|
|
||||||
|
endpoints = [EntityGraphApis(self.entity_graph), ]
|
||||||
|
|
||||||
|
# TODO(Dany) use eventlet instead of threading
|
||||||
|
server = oslo_messaging.get_rpc_server(transport, target,
|
||||||
|
endpoints, executor='threading')
|
||||||
|
|
||||||
|
server.start()
|
||||||
|
|
||||||
LOG.info("Finish start VitrageApiHandlerService")
|
LOG.info("Finish start VitrageApiHandlerService")
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
@ -38,3 +65,11 @@ class VitrageApiHandlerService(os_service.Service):
|
|||||||
super(VitrageApiHandlerService, self).stop()
|
super(VitrageApiHandlerService, self).stop()
|
||||||
|
|
||||||
LOG.info("Finish stop VitrageApiHandlerService")
|
LOG.info("Finish stop VitrageApiHandlerService")
|
||||||
|
|
||||||
|
|
||||||
|
class EntityGraphApis(object):
|
||||||
|
def __init__(self, entity_graph):
|
||||||
|
self.entity_graph = entity_graph
|
||||||
|
|
||||||
|
def get_topology(self, ctx, arg):
|
||||||
|
return self.entity_graph.output_graph()
|
||||||
|
Loading…
Reference in New Issue
Block a user