Agent Stubs

So I think this has the most functionality we can expect of a stub
at this point, it accepts a configured transport URL and node id
then takes rpc commands to modify the state of the agent.

What needs to be added is a accelerator handler class that runs
in the main loop to perform the various ongoing tasks of the Agent
but I can't really write that until I have a driver to link against.

Change-Id: I35438c01ca2765ca3dd2575bf2fac63099a30d29
This commit is contained in:
jkilpatr 2017-06-12 10:40:05 -04:00 committed by Justin Kilpatrick
parent 90799f60c8
commit 39db6fae39
5 changed files with 141 additions and 0 deletions

19
cyborg/agent/__init__.py Normal file
View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# 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
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import pbr.version
__version__ = pbr.version.VersionInfo(
'cyborg-agent').version_string()

3
cyborg/agent/agent.conf Normal file
View File

@ -0,0 +1,3 @@
[DEFAULT]
transport_url=
server_id=

61
cyborg/agent/agent.py Normal file
View File

@ -0,0 +1,61 @@
# -*- coding: utf-8 -*-
#
# 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
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import conf
import eventlet
from oslo_config import cfg
from oslo_log import log as logging
import oslo_messaging as messaging
import rpcapi
import time
eventlet.monkey_patch()
CONF = cfg.CONF
conf.register_opts(CONF)
LOG = logging.getLogger(__name__)
logging.register_options(CONF)
logging.setup(CONF, 'Cyborg.Agent')
url = messaging.TransportURL.parse(CONF, url=CONF.transport_url)
transport = messaging.get_notification_transport(CONF, url)
notifier = messaging.Notifier(transport,
driver='messaging',
publisher_id='Cyborg.Agent',
topic='info')
rpc_targets = messaging.Target(topic='cyborg_control', server=CONF.server_id)
rpc_endpoints = [
rpcapi.RPCEndpoint()
]
access_policy = messaging.ExplicitRPCAccessPolicy
rpc_server = messaging.get_rpc_server(transport,
rpc_targets,
rpc_endpoints,
executor='eventlet',
access_policy=access_policy)
try:
print("Cyborg Agent running")
rpc_server.start()
while True:
time.sleep(1)
except KeyboardInterrupt:
print("Stopping server")
rpc_server.stop()
rpc_server.wait()

28
cyborg/agent/conf.py Normal file
View File

@ -0,0 +1,28 @@
#
# 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
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo_config import cfg
import uuid
default_opts = [
cfg.StrOpt('transport_url',
default='',
help='Transport url to use for messaging'),
cfg.StrOpt('server_id',
default=uuid.uuid4(),
help='Unique identifier for this agent'),
]
def register_opts(conf):
conf.register_opts(default_opts)

30
cyborg/agent/rpcapi.py Normal file
View File

@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
#
# 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
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
class RPCEndpoint(object):
# Conductor functions exposed for external calls
def __init__(self):
pass
def list_accelerators(self, ctxt):
pass
def update_accelerator(self, ctxt, accelerator):
pass
def discover_accelerators(self, ctxt):
pass