diff --git a/cmd/api.py b/cmd/api.py index 8ba3078..1c18119 100755 --- a/cmd/api.py +++ b/cmd/api.py @@ -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 diff --git a/devstack/plugin.sh b/devstack/plugin.sh index 118e677..63de91e 100644 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -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 diff --git a/requirements.txt b/requirements.txt old mode 100755 new mode 100644 diff --git a/tricircle/api/controllers/root.py b/tricircle/api/controllers/root.py index bb8e4d7..7fadb34 100755 --- a/tricircle/api/controllers/root.py +++ b/tricircle/api/controllers/root.py @@ -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 diff --git a/tricircle/common/cascading_networking_api.py b/tricircle/common/cascading_networking_api.py index 498d2fb..1999111 100644 --- a/tricircle/common/cascading_networking_api.py +++ b/tricircle/common/cascading_networking_api.py @@ -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__) diff --git a/tricircle/common/config.py b/tricircle/common/config.py index fb70b18..bac37ce 100755 --- a/tricircle/common/config.py +++ b/tricircle/common/config.py @@ -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() diff --git a/tricircle/context.py b/tricircle/common/context.py similarity index 100% rename from tricircle/context.py rename to tricircle/common/context.py diff --git a/tricircle/common/exceptions.py b/tricircle/common/exceptions.py index 57f41ad..927ba9b 100755 --- a/tricircle/common/exceptions.py +++ b/tricircle/common/exceptions.py @@ -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): diff --git a/tricircle/i18n.py b/tricircle/common/i18n.py old mode 100755 new mode 100644 similarity index 100% rename from tricircle/i18n.py rename to tricircle/common/i18n.py diff --git a/tricircle/common/rpc.py b/tricircle/common/rpc.py index 2300a3b..d80390d 100644 --- a/tricircle/common/rpc.py +++ b/tricircle/common/rpc.py @@ -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 diff --git a/tricircle/common/serializer.py b/tricircle/common/serializer.py index b231ce6..ada58a6 100644 --- a/tricircle/common/serializer.py +++ b/tricircle/common/serializer.py @@ -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): diff --git a/tricircle/version.py b/tricircle/common/version.py old mode 100755 new mode 100644 similarity index 100% rename from tricircle/version.py rename to tricircle/common/version.py diff --git a/tricircle/compute_tricircle/driver.py b/tricircle/compute_tricircle/driver.py deleted file mode 100644 index 6b9767a..0000000 --- a/tricircle/compute_tricircle/driver.py +++ /dev/null @@ -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, - ) diff --git a/tricircle/db/client.py b/tricircle/db/client.py index 80e2a22..efc3714 100644 --- a/tricircle/db/client.py +++ b/tricircle/db/client.py @@ -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 diff --git a/tricircle/db/core.py b/tricircle/db/core.py index 23a5f44..bce7f62 100644 --- a/tricircle/db/core.py +++ b/tricircle/db/core.py @@ -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' diff --git a/tricircle/dispatcher/compute.py b/tricircle/dispatcher/compute.py index 03e89b9..14dc5e4 100644 --- a/tricircle/dispatcher/compute.py +++ b/tricircle/dispatcher/compute.py @@ -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) diff --git a/tricircle/dispatcher/service.py b/tricircle/dispatcher/service.py index 91ffe5b..bd7f579 100644 --- a/tricircle/dispatcher/service.py +++ b/tricircle/dispatcher/service.py @@ -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 diff --git a/tricircle/dispatcher/site_manager.py b/tricircle/dispatcher/site_manager.py index 7a94b35..8c24f71 100644 --- a/tricircle/dispatcher/site_manager.py +++ b/tricircle/dispatcher/site_manager.py @@ -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") diff --git a/tricircle/compute_tricircle/__init__.py b/tricircle/networking/__init__.py similarity index 100% rename from tricircle/compute_tricircle/__init__.py rename to tricircle/networking/__init__.py diff --git a/tricircle/networking_tricircle/plugin.py b/tricircle/networking/plugin.py similarity index 99% rename from tricircle/networking_tricircle/plugin.py rename to tricircle/networking/plugin.py index 44d0706..b9d8733 100644 --- a/tricircle/networking_tricircle/plugin.py +++ b/tricircle/networking/plugin.py @@ -31,7 +31,7 @@ from neutron.db import portbindings_db from neutron.db import securitygroups_db from neutron.i18n import _LI from tricircle.common import cascading_networking_api as c_net_api -from tricircle.networking_tricircle import rpc as c_net_rpc +from tricircle.networking import rpc as c_net_rpc LOG = log.getLogger(__name__) diff --git a/tricircle/networking_tricircle/rpc.py b/tricircle/networking/rpc.py similarity index 100% rename from tricircle/networking_tricircle/rpc.py rename to tricircle/networking/rpc.py diff --git a/tricircle/tests/unit/api/controllers/test_root.py b/tricircle/tests/unit/api/controllers/test_root.py index d231211..0185dd7 100644 --- a/tricircle/tests/unit/api/controllers/test_root.py +++ b/tricircle/tests/unit/api/controllers/test_root.py @@ -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 diff --git a/tricircle/tests/unit/db/test_client.py b/tricircle/tests/unit/db/test_client.py index cf320e0..eb07c1e 100644 --- a/tricircle/tests/unit/db/test_client.py +++ b/tricircle/tests/unit/db/test_client.py @@ -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 diff --git a/tricircle/tests/unit/db/test_models.py b/tricircle/tests/unit/db/test_models.py index c5c9fa4..9a41989 100644 --- a/tricircle/tests/unit/db/test_models.py +++ b/tricircle/tests/unit/db/test_models.py @@ -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 diff --git a/tricircle/networking_tricircle/__init__.py b/tricircle/tests/unit/networking/__init__.py similarity index 100% rename from tricircle/networking_tricircle/__init__.py rename to tricircle/tests/unit/networking/__init__.py diff --git a/tricircle/tests/unit/networking_tricircle/test_plugin.py b/tricircle/tests/unit/networking/test_plugin.py similarity index 96% rename from tricircle/tests/unit/networking_tricircle/test_plugin.py rename to tricircle/tests/unit/networking/test_plugin.py index 67668ef..01eff12 100644 --- a/tricircle/tests/unit/networking_tricircle/test_plugin.py +++ b/tricircle/tests/unit/networking/test_plugin.py @@ -22,8 +22,8 @@ from neutron.common import exceptions as neutron_exceptions from neutron.common import rpc as neutron_rpc from neutron.db import db_base_plugin_v2 -from tricircle import context -from tricircle.networking_tricircle.plugin import TricirclePlugin +from tricircle.common import context +from tricircle.networking.plugin import TricirclePlugin FAKE_PORT_ID = 'fake_port_uuid' diff --git a/tricircle/tests/unit/networking_tricircle/test_rpc.py b/tricircle/tests/unit/networking/test_rpc.py similarity index 96% rename from tricircle/tests/unit/networking_tricircle/test_rpc.py rename to tricircle/tests/unit/networking/test_rpc.py index dcff762..70fc8cc 100644 --- a/tricircle/tests/unit/networking_tricircle/test_rpc.py +++ b/tricircle/tests/unit/networking/test_rpc.py @@ -21,8 +21,8 @@ from neutron.common import constants as neutron_const from neutron.common import rpc as neutron_rpc from neutron import manager -from tricircle.networking_tricircle import plugin -from tricircle.networking_tricircle import rpc +from tricircle.networking import plugin +from tricircle.networking import rpc FAKE_PORT_ID = 'fake_port_uuid' diff --git a/tricircle/tests/unit/networking_tricircle/__init__.py b/tricircle/tests/unit/networking_tricircle/__init__.py deleted file mode 100644 index e69de29..0000000