Browse Source

Reorganize code

Reorganize code and fix some coding style violation.

Change-Id: Ie5e18cf65ad98f07cd2e4edd8690f53df9bedfeb
changes/73/248573/1
zhiyuan_cai 6 years ago
parent
commit
07bb2a1ba5
28 changed files with 38 additions and 102 deletions
  1. +2
    -2
      cmd/api.py
  2. +2
    -2
      devstack/plugin.sh
  3. +0
    -0
      requirements.txt
  4. +1
    -1
      tricircle/api/controllers/root.py
  5. +1
    -1
      tricircle/common/cascading_networking_api.py
  6. +4
    -4
      tricircle/common/config.py
  7. +0
    -0
      tricircle/common/context.py
  8. +1
    -1
      tricircle/common/exceptions.py
  9. +0
    -0
      tricircle/common/i18n.py
  10. +1
    -1
      tricircle/common/rpc.py
  11. +2
    -2
      tricircle/common/serializer.py
  12. +0
    -0
      tricircle/common/version.py
  13. +0
    -64
      tricircle/compute_tricircle/driver.py
  14. +1
    -1
      tricircle/db/client.py
  15. +1
    -0
      tricircle/db/core.py
  16. +9
    -9
      tricircle/dispatcher/compute.py
  17. +1
    -1
      tricircle/dispatcher/service.py
  18. +4
    -5
      tricircle/dispatcher/site_manager.py
  19. +0
    -0
      tricircle/networking/__init__.py
  20. +1
    -1
      tricircle/networking/plugin.py
  21. +0
    -0
      tricircle/networking/rpc.py
  22. +1
    -1
      tricircle/tests/unit/api/controllers/test_root.py
  23. +1
    -1
      tricircle/tests/unit/db/test_client.py
  24. +1
    -1
      tricircle/tests/unit/db/test_models.py
  25. +0
    -0
      tricircle/tests/unit/networking/__init__.py
  26. +2
    -2
      tricircle/tests/unit/networking/test_plugin.py
  27. +2
    -2
      tricircle/tests/unit/networking/test_rpc.py
  28. +0
    -0
      tricircle/tests/unit/networking_tricircle/__init__.py

+ 2
- 2
cmd/api.py View File

@ -27,8 +27,8 @@ from werkzeug import serving
from tricircle.api import app
from tricircle.common import config
from tricircle.i18n import _LI
from tricircle.i18n import _LW
from tricircle.common.i18n import _LI
from tricircle.common.i18n import _LW
CONF = cfg.CONF


+ 2
- 2
devstack/plugin.sh View File

@ -44,7 +44,7 @@ function configure_tricircle_plugin {
echo "Configuring Neutron for Tricircle"
if is_service_enabled q-svc ; then
Q_PLUGIN_CLASS="tricircle.networking_tricircle.plugin.TricirclePlugin"
Q_PLUGIN_CLASS="tricircle.networking.plugin.TricirclePlugin"
#NEUTRON_CONF=/etc/neutron/neutron.conf
iniset $NEUTRON_CONF DEFAULT core_plugin "$Q_PLUGIN_CLASS"
@ -61,7 +61,7 @@ function configure_tricircle_plugin {
iniset $TRICIRCLE_DISPATCHER_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
iniset $TRICIRCLE_DISPATCHER_CONF DEFAULT verbose True
setup_colorized_logging $TRICIRCLE_DISPATCHER_CONF DEFAULT tenant_name
setup_colorized_logging $TRICIRCLE_DISPATCHER_CONF DEFAULT tenant
iniset $TRICIRCLE_DISPATCHER_CONF DEFAULT bind_host $TRICIRCLE_DISPATCHER_LISTEN_ADDRESS
iniset $TRICIRCLE_DISPATCHER_CONF DEFAULT use_syslog $SYSLOG
iniset_rpc_backend tricircle $TRICIRCLE_DISPATCHER_CONF


+ 0
- 0
requirements.txt View File


+ 1
- 1
tricircle/api/controllers/root.py View File

@ -21,8 +21,8 @@ from pecan import request
from pecan import rest
from tricircle.common import cascading_site_api
import tricircle.common.context as t_context
from tricircle.common import utils
import tricircle.context as t_context
from tricircle.db import client
from tricircle.db import exception
from tricircle.db import models


+ 1
- 1
tricircle/common/cascading_networking_api.py View File

@ -18,8 +18,8 @@ from oslo_log import log as logging
import oslo_messaging
from neutron.common import rpc as n_rpc
from tricircle.common import topics
from tricircle.common.serializer import CascadeSerializer as Serializer
from tricircle.common import topics
LOG = logging.getLogger(__name__)


+ 4
- 4
tricircle/common/config.py View File

@ -24,11 +24,11 @@ from oslo_config import cfg
from oslo_log import log as logging
from paste import deploy
from tricircle.i18n import _
from tricircle.i18n import _LI
from tricircle.common.i18n import _
from tricircle.common.i18n import _LI
# from tricircle import policy
from tricircle import version
from tricircle.common import version
LOG = logging.getLogger(__name__)
@ -89,7 +89,7 @@ def reset_service():
# daemon mode.
setup_logging()
# (TODO) enforce policy later
# TODO(zhiyuan) enforce policy later
# policy.refresh()


tricircle/context.py → tricircle/common/context.py View File


+ 1
- 1
tricircle/common/exceptions.py View File

@ -19,7 +19,7 @@ Tricircle base exception handling.
from oslo_utils import excutils
import six
from tricircle.i18n import _
from tricircle.common.i18n import _
class TricircleException(Exception):


tricircle/i18n.py → tricircle/common/i18n.py View File


+ 1
- 1
tricircle/common/rpc.py View File

@ -91,7 +91,7 @@ class AutomaticRpcWrapper(object):
return cctx.call(context, method, payload=payload)
def send(self, cast):
""" Autowrap an API call with a send_message() call
"""Autowrap an API call with a send_message() call
This function uses python tricks to implement a passthrough call from
the calling API to the cascade service


+ 2
- 2
tricircle/common/serializer.py View File

@ -14,10 +14,10 @@
# limitations under the License.
import six
from oslo_messaging import Serializer
from neutron.api.v2.attributes import ATTR_NOT_SPECIFIED
from oslo_messaging import Serializer
import tricircle.context as t_context
import tricircle.common.context as t_context
class Mapping(object):


tricircle/version.py → tricircle/common/version.py View File


+ 0
- 64
tricircle/compute_tricircle/driver.py View File

@ -1,64 +0,0 @@
# Copyright 2015 Huawei Technologies Co., Ltd.
#
# 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 nova.virt import driver
from nova.virt.hardware import InstanceInfo
import nova.compute.power_state as power_state
from oslo_config import cfg
from oslo_log import log as logging
import oslo_messaging
TRANSPORT = oslo_messaging.get_transport(cfg.CONF)
LOG = logging.getLogger(__name__)
class TricircleComputeDriver(driver.ComputeDriver):
site_manager = None # will be set later by the ComputeHostManager
def __init__(self, virtapi):
super(TricircleComputeDriver, self).__init__(virtapi)
def init_host(self, host):
self.host = host
# NOTE(saggi) There is no way to pass arguments to the driver apart
# from the host It's a bit convoluted and if you find a better way
# please send a patch
self._site = TricircleComputeDriver.site_manager.get_site(host)
def get_available_nodes(self, refresh=False):
return [node.hypervisor_hostname for node in self._site.get_nodes()]
def get_available_resource(self, nodename):
return self._site.get_node(nodename).get_available_resource()
def get_num_instances(self):
return self._site.get_num_instances()
def spawn(self, context, instance, image_meta, injected_files,
admin_password, network_info=None, block_device_info=None):
pass
def get_info(self, instance):
# TODO(saggi) will be redirected to cascade service
return InstanceInfo(
state=power_state.RUNNING,
max_mem_kb=500,
mem_kb=500,
num_cpu=1,
cpu_time_ns=100,
id=instance.id,
)

+ 1
- 1
tricircle/db/client.py View File

@ -26,7 +26,7 @@ from keystoneclient.v3 import client as keystone_client
from oslo_config import cfg
from oslo_log import log as logging
import tricircle.context as tricircle_context
import tricircle.common.context as tricircle_context
from tricircle.db import exception
from tricircle.db import models
from tricircle.db import resource_handle


+ 1
- 0
tricircle/db/core.py View File

@ -30,6 +30,7 @@ ModelBase = declarative.declarative_base()
def _filter_query(model, query, filters):
"""Apply filter to query
:param model:
:param query:
:param filters: list of filter dict with key 'key', 'comparator', 'value'


+ 9
- 9
tricircle/dispatcher/compute.py View File

@ -14,12 +14,12 @@
# limitations under the License.
from nova.compute.manager import ComputeManager
from nova.virt.fake import FakeDriver
import nova.rpc as nova_rpc
from nova.service import Service
import nova.version as nova_version
import nova.rpc as nova_rpc
from tricircle.compute_tricircle.driver import TricircleComputeDriver
from tricircle.common.utils import get_import_path
_REPORT_INTERVAL = 30
@ -27,7 +27,7 @@ _REPORT_INTERVAL_MAX = 60
def _patch_nova_service():
if (nova_version.loaded):
if nova_version.loaded:
return
nova_version.NOVA_PACKAGE = "tricircle"
@ -67,8 +67,7 @@ class NovaService(Service):
def _fix_compute_service_exchange(service):
"""Fix service exchange value for nova
"""
"""Fix service exchange value for nova"""
manager = service.manager
for client in (
@ -83,7 +82,6 @@ def _fix_compute_service_exchange(service):
class ComputeHostManager(object):
def __init__(self, site_manager):
self._compute_nodes = []
TricircleComputeDriver.site_manager = site_manager
def _create_compute_node_service(self, host):
service = NovaService(
@ -95,7 +93,10 @@ class ComputeHostManager(object):
report_interval=_REPORT_INTERVAL,
periodic_interval_max=_REPORT_INTERVAL_MAX,
manager=get_import_path(ComputeManager),
compute_driver=get_import_path(TricircleComputeDriver),
# temporally use FakeDriver, new compute manager doesn't require
# compute driver so this can be removed after new compute manager
# is finished
compute_driver=get_import_path(FakeDriver)
)
_fix_compute_service_exchange(service)
@ -103,8 +104,7 @@ class ComputeHostManager(object):
return service
def create_host_adapter(self, host):
"""Creates an adapter between the nova compute API and Site object
"""
"""Creates an adapter between the nova compute API and Site object"""
service = self._create_compute_node_service(host)
service.start()
self._compute_nodes.append(service)

+ 1
- 1
tricircle/dispatcher/service.py View File

@ -20,8 +20,8 @@ from oslo_config import cfg
from oslo_log import log as logging
import oslo_messaging
from tricircle.common import topics
from tricircle.common.serializer import CascadeSerializer as Serializer
from tricircle.common import topics
from tricircle.dispatcher import site_manager
# import endpoints here


+ 4
- 5
tricircle/dispatcher/site_manager.py View File

@ -15,12 +15,12 @@
# TODO(saggi) change to oslo before release
from oslo_serialization import jsonutils as json
import tricircle.common.context as t_context
from tricircle.common.singleton import Singleton
from tricircle.common import utils
import tricircle.context as t_context
from tricircle.dispatcher.compute import ComputeHostManager
from tricircle.db import client
from tricircle.db import models
from tricircle.dispatcher.compute import ComputeHostManager
class Node(object):
@ -113,9 +113,8 @@ class _SiteManager(object):
self.create_site(t_context.get_admin_context(), site['site_name'])
def create_site(self, context, site_name):
"""creates a fake site, in reality the information about available
sites should be pulled from the DAL and not created at will.
"""
"""creates a fake node as nova-compute and add it to az"""
# TODO(saggi): thread safety
if site_name in self._sites:
raise RuntimeError("Site already exists in site map")


tricircle/compute_tricircle/__init__.py → tricircle/networking/__init__.py View File


tricircle/networking_tricircle/plugin.py → tricircle/networking/plugin.py View File


tricircle/networking_tricircle/rpc.py → tricircle/networking/rpc.py View File


+ 1
- 1
tricircle/tests/unit/api/controllers/test_root.py View File

@ -20,7 +20,7 @@ import unittest
import pecan
import tricircle.api.controllers.root as root_controller
from tricircle import context
from tricircle.common import context
from tricircle.db import client
from tricircle.db import core
from tricircle.db import models


+ 1
- 1
tricircle/tests/unit/db/test_client.py View File

@ -20,7 +20,7 @@ import uuid
import mock
from oslo_config import cfg
from tricircle import context
from tricircle.common import context
from tricircle.db import client
from tricircle.db import core
from tricircle.db import exception


+ 1
- 1
tricircle/tests/unit/db/test_models.py View File

@ -16,7 +16,7 @@
import unittest
from tricircle import context
from tricircle.common import context
from tricircle.db import core
from tricircle.db import exception
from tricircle.db import models


tricircle/networking_tricircle/__init__.py → tricircle/tests/unit/networking/__init__.py View File


tricircle/tests/unit/networking_tricircle/test_plugin.py → tricircle/tests/unit/networking/test_plugin.py View File


tricircle/tests/unit/networking_tricircle/test_rpc.py → tricircle/tests/unit/networking/test_rpc.py View File


+ 0
- 0
tricircle/tests/unit/networking_tricircle/__init__.py View File


Loading…
Cancel
Save