Database interface using sqlalchemy
This commit adds sqlalchemy as a database backend, the database connection url is loaded from the config file in the same format as any other service. The accelerator class has been given tags that allow sqlalchemy to map it to a table in the database and perform saving out/queries automatically. For further work I'll want either an api or a driver to start integrating with don't want to get too deep into buisness logic before we know exactly what those will look like. Change-Id: I6a9712de0b4f985bab80178845f59e10c05032a5
This commit is contained in:
parent
0cbb31f02c
commit
6fcf94b969
@ -16,4 +16,4 @@ import pbr.version
|
||||
|
||||
|
||||
__version__ = pbr.version.VersionInfo(
|
||||
'nomad').version_string()
|
||||
'cyborg').version_string()
|
||||
|
@ -14,9 +14,19 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from sqlalchemy import Column, Integer, String
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
# A common internal acclerator object for internal use.
|
||||
class accelerator(object):
|
||||
class accelerator(Base):
|
||||
__tablename__ = 'accelerators'
|
||||
accelerator_id = Column(String, primary_key=True)
|
||||
device_type = Column(String)
|
||||
remoteable = Column(Integer)
|
||||
vender_id = Column(String)
|
||||
product_id = Column(String)
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.accelerator_id = kwargs['accelerator_id']
|
||||
|
@ -1,3 +1,3 @@
|
||||
[DEFAULT]
|
||||
[cyborg]
|
||||
transport_url=
|
||||
server_id=
|
||||
|
@ -31,7 +31,9 @@ LOG = logging.getLogger(__name__)
|
||||
logging.register_options(CONF)
|
||||
logging.setup(CONF, 'Cyborg.Agent')
|
||||
|
||||
url = messaging.TransportURL.parse(CONF, url=CONF.transport_url)
|
||||
CONF(['--config-file', 'agent.conf'])
|
||||
|
||||
url = messaging.TransportURL.parse(CONF, url=CONF.cyborg.transport_url)
|
||||
transport = messaging.get_notification_transport(CONF, url)
|
||||
|
||||
notifier = messaging.Notifier(transport,
|
||||
@ -39,7 +41,8 @@ notifier = messaging.Notifier(transport,
|
||||
publisher_id='Cyborg.Agent',
|
||||
topic='info')
|
||||
|
||||
rpc_targets = messaging.Target(topic='cyborg_control', server=CONF.server_id)
|
||||
rpc_targets = messaging.Target(topic='cyborg_control',
|
||||
server=CONF.cyborg.server_id)
|
||||
rpc_endpoints = [
|
||||
rpcapi.RPCEndpoint()
|
||||
]
|
||||
|
@ -25,4 +25,4 @@ default_opts = [
|
||||
|
||||
|
||||
def register_opts(conf):
|
||||
conf.register_opts(default_opts)
|
||||
conf.register_opts(default_opts, group='cyborg')
|
||||
|
@ -1,3 +1,4 @@
|
||||
[DEFAULT]
|
||||
[cyborg]
|
||||
transport_url=
|
||||
server_id=
|
||||
database_url=
|
||||
|
@ -19,6 +19,7 @@ from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
import oslo_messaging as messaging
|
||||
import rpcapi
|
||||
from sqlalchemy import create_engine
|
||||
import time
|
||||
|
||||
eventlet.monkey_patch()
|
||||
@ -30,7 +31,8 @@ LOG = logging.getLogger(__name__)
|
||||
logging.register_options(CONF)
|
||||
logging.setup(CONF, 'Cyborg.Conductor')
|
||||
|
||||
url = messaging.TransportURL.parse(CONF, url=CONF.transport_url)
|
||||
CONF(['--config-file', 'conductor.conf'])
|
||||
url = messaging.TransportURL.parse(CONF, url=CONF.cyborg.transport_url)
|
||||
transport = messaging.get_notification_transport(CONF, url)
|
||||
|
||||
message_endpoints = [
|
||||
@ -42,7 +44,8 @@ message_targets = [
|
||||
messaging.Target(topic='warn'),
|
||||
messaging.Target(topic='error')
|
||||
]
|
||||
rpc_targets = messaging.Target(topic='cyborg_control', server=CONF.server_id)
|
||||
rpc_targets = messaging.Target(topic='cyborg_control',
|
||||
server=CONF.cyborg.server_id)
|
||||
rpc_endpoints = [
|
||||
rpcapi.RPCEndpoint()
|
||||
]
|
||||
@ -59,6 +62,9 @@ message_server = messaging.get_notification_listener(transport,
|
||||
executor='eventlet',
|
||||
allow_requeue=True)
|
||||
|
||||
engine = create_engine(CONF.cyborg.connection, echo=True)
|
||||
engine.connect()
|
||||
|
||||
try:
|
||||
message_server.start()
|
||||
rpc_server.start()
|
||||
|
@ -17,7 +17,12 @@ import uuid
|
||||
default_opts = [
|
||||
cfg.StrOpt('transport_url',
|
||||
default='',
|
||||
help='Transport url for messating'),
|
||||
help='Transport url for messating, copy from transport_url= in \
|
||||
your Nova config default section'),
|
||||
cfg.StrOpt('database_url',
|
||||
default='',
|
||||
help='Database url for storage, copy from connection= in your \
|
||||
Nova db config section'),
|
||||
cfg.StrOpt('server_id',
|
||||
default=uuid.uuid4(),
|
||||
help='Unique ID for this conductor instance'),
|
||||
@ -25,4 +30,4 @@ default_opts = [
|
||||
|
||||
|
||||
def register_opts(conf):
|
||||
conf.register_opts(default_opts)
|
||||
conf.register_opts(default_opts, group='cyborg')
|
||||
|
Loading…
Reference in New Issue
Block a user