Przeglądaj źródła

Refactor endpoint_*_options module into single endpoint_options module

Daniel Vincze 5 lat temu
rodzic
commit
39125e67e2

+ 3 - 4
coriolis/api/v1/endpoint_destination_minion_pool_options.py

@@ -4,10 +4,9 @@
 from oslo_log import log as logging
 
 from coriolis import utils
-from coriolis.api.v1.views import (
-    endpoint_destination_minion_pool_options_view)
+from coriolis.api.v1.views import endpoint_options_view
 from coriolis.api import wsgi as api_wsgi
-from coriolis.endpoint_minion_pool_options import api
+from coriolis.endpoint_options import api
 from coriolis.policies import endpoints as endpoint_policies
 
 
@@ -36,7 +35,7 @@ class EndpointDestinationMinionPoolOptionsController(api_wsgi.Controller):
         else:
             options = {}
 
-        return endpoint_destination_minion_pool_options_view.collection(
+        return endpoint_options_view.destination_minion_pool_options_collection(
             req,
             self._minion_pool_options_api.get_endpoint_destination_minion_pool_options(
                 context, endpoint_id, env=env, option_names=options))

+ 3 - 3
coriolis/api/v1/endpoint_destination_options.py

@@ -4,9 +4,9 @@
 from oslo_log import log as logging
 
 from coriolis import utils
-from coriolis.api.v1.views import endpoint_destination_options_view
+from coriolis.api.v1.views import endpoint_options_view
 from coriolis.api import wsgi as api_wsgi
-from coriolis.endpoint_destination_options import api
+from coriolis.endpoint_options import api
 from coriolis.policies import endpoints as endpoint_policies
 
 
@@ -35,7 +35,7 @@ class EndpointDestinationOptionsController(api_wsgi.Controller):
         else:
             options = {}
 
-        return endpoint_destination_options_view.collection(
+        return endpoint_options_view.destination_options_collection(
             req,
             self._destination_options_api.get_endpoint_destination_options(
                 context, endpoint_id, env=env, option_names=options))

+ 3 - 4
coriolis/api/v1/endpoint_source_minion_pool_options.py

@@ -4,10 +4,9 @@
 from oslo_log import log as logging
 
 from coriolis import utils
-from coriolis.api.v1.views import (
-        endpoint_source_minion_pool_options_view)
+from coriolis.api.v1.views import endpoint_options_view
 from coriolis.api import wsgi as api_wsgi
-from coriolis.endpoint_minion_pool_options import api
+from coriolis.endpoint_options import api
 from coriolis.policies import endpoints as endpoint_policies
 
 
@@ -36,7 +35,7 @@ class EndpointSourceMinionPoolOptionsController(api_wsgi.Controller):
         else:
             options = {}
 
-        return endpoint_source_minion_pool_options_view.collection(
+        return endpoint_options_view.source_minion_pool_options_collection(
             req,
             self._minion_pool_options_api.get_endpoint_source_minion_pool_options(
                 context, endpoint_id, env=env, option_names=options))

+ 3 - 3
coriolis/api/v1/endpoint_source_options.py

@@ -4,9 +4,9 @@
 from oslo_log import log as logging
 
 from coriolis import utils
-from coriolis.api.v1.views import endpoint_source_options_view
+from coriolis.api.v1.views import endpoint_options_view
 from coriolis.api import wsgi as api_wsgi
-from coriolis.endpoint_source_options import api
+from coriolis.endpoint_options import api
 from coriolis.policies import endpoints as endpoint_policies
 
 
@@ -35,7 +35,7 @@ class EndpointSourceOptionsController(api_wsgi.Controller):
         else:
             options = {}
 
-        return endpoint_source_options_view.collection(
+        return endpoint_options_view.source_options_collection(
             req,
             self._source_options_api.get_endpoint_source_options(
                 context, endpoint_id, env=env, option_names=options))

+ 0 - 20
coriolis/api/v1/views/endpoint_destination_minion_pool_options_view.py

@@ -1,20 +0,0 @@
-# Copyright 2020 Cloudbase Solutions Srl
-# All Rights Reserved.
-
-import itertools
-
-
-def _format_dest_opt(req, destination_option, keys=None):
-    def transform(key, value):
-        if keys and key not in keys:
-            return
-        yield (key, value)
-
-    return dict(itertools.chain.from_iterable(
-        transform(k, v) for k, v in destination_option.items()))
-
-
-def collection(req, destination_pool_options):
-    formatted_opts = [
-        _format_dest_opt(req, opt) for opt in destination_pool_options]
-    return {'destination_minion_pool_options': formatted_opts}

+ 0 - 20
coriolis/api/v1/views/endpoint_destination_options_view.py

@@ -1,20 +0,0 @@
-# Copyright 2018 Cloudbase Solutions Srl
-# All Rights Reserved.
-
-import itertools
-
-
-def _format_dest_opt(req, destination_option, keys=None):
-    def transform(key, value):
-        if keys and key not in keys:
-            return
-        yield (key, value)
-
-    return dict(itertools.chain.from_iterable(
-        transform(k, v) for k, v in destination_option.items()))
-
-
-def collection(req, destination_options):
-    formatted_opts = [
-        _format_dest_opt(req, opt) for opt in destination_options]
-    return {'destination_options': formatted_opts}

+ 38 - 0
coriolis/api/v1/views/endpoint_options_view.py

@@ -0,0 +1,38 @@
+# Copyright 2020 Cloudbase Solutions Srl
+# All Rights Reserved.
+
+import itertools
+
+
+def _format_opt(req, option, keys=None):
+    def transform(key, value):
+        if keys and key not in keys:
+            return
+        yield (key, value)
+
+    return dict(itertools.chain.from_iterable(
+        transform(k, v) for k, v in option.items()))
+
+
+def destination_minion_pool_options_collection(req, destination_pool_options):
+    formatted_opts = [
+        _format_opt(req, opt) for opt in destination_pool_options]
+    return {'destination_minion_pool_options': formatted_opts}
+
+
+def destination_options_collection(req, destination_options):
+    formatted_opts = [
+        _format_opt(req, opt) for opt in destination_options]
+    return {'destination_options': formatted_opts}
+
+
+def source_minion_pool_options_collection(req, source_pool_options):
+    formatted_opts = [
+        _format_opt(req, opt) for opt in source_pool_options]
+    return {'source_minion_pool_options': formatted_opts}
+
+
+def source_options_collection(req, source_options):
+    formatted_opts = [
+        _format_opt(req, opt) for opt in source_options]
+    return {'source_options': formatted_opts}

+ 0 - 20
coriolis/api/v1/views/endpoint_source_minion_pool_options_view.py

@@ -1,20 +0,0 @@
-# Copyright 2020 Cloudbase Solutions Srl
-# All Rights Reserved.
-
-import itertools
-
-
-def _format_dest_opt(req, source_option, keys=None):
-    def transform(key, value):
-        if keys and key not in keys:
-            return
-        yield (key, value)
-
-    return dict(itertools.chain.from_iterable(
-        transform(k, v) for k, v in source_option.items()))
-
-
-def collection(req, source_pool_options):
-    formatted_opts = [
-        _format_dest_opt(req, opt) for opt in source_pool_options]
-    return {'source_minion_pool_options': formatted_opts}

+ 0 - 20
coriolis/api/v1/views/endpoint_source_options_view.py

@@ -1,20 +0,0 @@
-# Copyright 2019 Cloudbase Solutions Srl
-# All Rights Reserved.
-
-import itertools
-
-
-def _format_source_opt(req, source_option, keys=None):
-    def transform(key, value):
-        if keys and key not in keys:
-            return
-        yield (key, value)
-
-    return dict(itertools.chain.from_iterable(
-        transform(k, v) for k, v in source_option.items()))
-
-
-def collection(req, source_options):
-    formatted_opts = [
-        _format_source_opt(req, opt) for opt in source_options]
-    return {'source_options': formatted_opts}

+ 0 - 0
coriolis/endpoint_destination_options/__init__.py


+ 0 - 14
coriolis/endpoint_destination_options/api.py

@@ -1,14 +0,0 @@
-# Copyright 2016 Cloudbase Solutions Srl
-# All Rights Reserved.
-
-from coriolis.conductor.rpc import client as rpc_client
-
-
-class API(object):
-    def __init__(self):
-        self._rpc_client = rpc_client.ConductorClient()
-
-    def get_endpoint_destination_options(
-            self, ctxt, endpoint_id, env=None, option_names=None):
-        return self._rpc_client.get_endpoint_destination_options(
-            ctxt, endpoint_id, env, option_names)

+ 0 - 0
coriolis/endpoint_minion_pool_options/__init__.py


+ 2 - 0
coriolis/endpoint_options/__init__.py

@@ -0,0 +1,2 @@
+# Copyright 2020 Cloudbase Solutions Srl
+# All Rights Reserved.

+ 10 - 0
coriolis/endpoint_minion_pool_options/api.py → coriolis/endpoint_options/api.py

@@ -8,6 +8,11 @@ class API(object):
     def __init__(self):
         self._rpc_client = rpc_client.ConductorClient()
 
+    def get_endpoint_destination_options(
+            self, ctxt, endpoint_id, env=None, option_names=None):
+        return self._rpc_client.get_endpoint_destination_options(
+            ctxt, endpoint_id, env, option_names)
+
     def get_endpoint_source_minion_pool_options(
             self, ctxt, endpoint_id, env=None, option_names=None):
         return self._rpc_client.get_endpoint_source_minion_pool_options(
@@ -17,3 +22,8 @@ class API(object):
             self, ctxt, endpoint_id, env=None, option_names=None):
         return self._rpc_client.get_endpoint_destination_minion_pool_options(
             ctxt, endpoint_id, env, option_names)
+
+    def get_endpoint_source_options(
+            self, ctxt, endpoint_id, env=None, option_names=None):
+        return self._rpc_client.get_endpoint_source_options(
+            ctxt, endpoint_id, env, option_names)

+ 0 - 0
coriolis/endpoint_source_options/__init__.py


+ 0 - 14
coriolis/endpoint_source_options/api.py

@@ -1,14 +0,0 @@
-# Copyright 2019 Cloudbase Solutions Srl
-# All Rights Reserved.
-
-from coriolis.conductor.rpc import client as rpc_client
-
-
-class API(object):
-    def __init__(self):
-        self._rpc_client = rpc_client.ConductorClient()
-
-    def get_endpoint_source_options(
-            self, ctxt, endpoint_id, env=None, option_names=None):
-        return self._rpc_client.get_endpoint_source_options(
-            ctxt, endpoint_id, env, option_names)