[Kimchi-devel] [PATCH V4 2/4] improve controller: tag the collections/resouces of root with @UrlSubNode

shaohef at linux.vnet.ibm.com shaohef at linux.vnet.ibm.com
Fri Jan 24 01:38:11 UTC 2014


From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>

we can difine a /host as follow:

@UrlSubNode("host", True)
 class Host(Resource):
     def __init__(self, model, id=None):
         super(Host, self).__init__(model, id)

@UrlSubNode("host", True) means:
the URL "/host" is root.Host, and it need authentication

Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
---
 src/kimchi/control/__init__.py     | 8 ++++++++
 src/kimchi/control/config.py       | 2 ++
 src/kimchi/control/debugreports.py | 2 ++
 src/kimchi/control/host.py         | 2 ++
 src/kimchi/control/interfaces.py   | 2 ++
 src/kimchi/control/networks.py     | 2 ++
 src/kimchi/control/plugins.py      | 2 ++
 src/kimchi/control/storagepools.py | 2 ++
 src/kimchi/control/tasks.py        | 2 ++
 src/kimchi/control/templates.py    | 2 ++
 src/kimchi/control/vms.py          | 3 ++-
 11 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/src/kimchi/control/__init__.py b/src/kimchi/control/__init__.py
index 8a37cc4..f24f9f3 100644
--- a/src/kimchi/control/__init__.py
+++ b/src/kimchi/control/__init__.py
@@ -19,3 +19,11 @@
 # You should have received a copy of the GNU Lesser General Public
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+
+import os
+
+
+from kimchi.control.utils import load_url_sub_node
+
+
+sub_nodes = load_url_sub_node(os.path.dirname(__file__), __name__)
diff --git a/src/kimchi/control/config.py b/src/kimchi/control/config.py
index 603f51d..cc41e8a 100644
--- a/src/kimchi/control/config.py
+++ b/src/kimchi/control/config.py
@@ -27,8 +27,10 @@ import cherrypy
 
 from kimchi.config import config
 from kimchi.control.base import Collection, Resource
+from kimchi.control.utils import UrlSubNode
 
 
+ at UrlSubNode("config")
 class Config(Resource):
     def __init__(self, model, id=None):
         super(Config, self).__init__(model, id)
diff --git a/src/kimchi/control/debugreports.py b/src/kimchi/control/debugreports.py
index a55ba38..324d826 100644
--- a/src/kimchi/control/debugreports.py
+++ b/src/kimchi/control/debugreports.py
@@ -23,8 +23,10 @@
 
 from kimchi.control.base import AsyncCollection, Resource
 from kimchi.control.utils import internal_redirect
+from kimchi.control.utils import UrlSubNode
 
 
+ at UrlSubNode("debugreports", True)
 class DebugReports(AsyncCollection):
     def __init__(self, model):
         super(DebugReports, self).__init__(model)
diff --git a/src/kimchi/control/host.py b/src/kimchi/control/host.py
index 9b19577..f041b35 100644
--- a/src/kimchi/control/host.py
+++ b/src/kimchi/control/host.py
@@ -24,8 +24,10 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 
 from kimchi.control.base import Collection, Resource
+from kimchi.control.utils import UrlSubNode
 
 
+ at UrlSubNode("host", True)
 class Host(Resource):
     def __init__(self, model, id=None):
         super(Host, self).__init__(model, id)
diff --git a/src/kimchi/control/interfaces.py b/src/kimchi/control/interfaces.py
index 28be26e..f93dd6a 100644
--- a/src/kimchi/control/interfaces.py
+++ b/src/kimchi/control/interfaces.py
@@ -23,8 +23,10 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 
 from kimchi.control.base import Collection, Resource
+from kimchi.control.utils import UrlSubNode
 
 
+ at UrlSubNode("interfaces")
 class Interfaces(Collection):
     def __init__(self, model):
         super(Interfaces, self).__init__(model)
diff --git a/src/kimchi/control/networks.py b/src/kimchi/control/networks.py
index f3f0b41..8510e49 100644
--- a/src/kimchi/control/networks.py
+++ b/src/kimchi/control/networks.py
@@ -22,8 +22,10 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 
 from kimchi.control.base import Collection, Resource
+from kimchi.control.utils import UrlSubNode
 
 
+ at UrlSubNode("networks", True)
 class Networks(Collection):
     def __init__(self, model):
         super(Networks, self).__init__(model)
diff --git a/src/kimchi/control/plugins.py b/src/kimchi/control/plugins.py
index af32709..5938085 100644
--- a/src/kimchi/control/plugins.py
+++ b/src/kimchi/control/plugins.py
@@ -25,8 +25,10 @@
 import kimchi.template
 from kimchi.control.base import Collection, Resource
 from kimchi.control.utils import get_class_name, model_fn
+from kimchi.control.utils import UrlSubNode
 
 
+ at UrlSubNode("plugins")
 class Plugins(Collection):
     def __init__(self, model):
         super(Plugins, self).__init__(model)
diff --git a/src/kimchi/control/storagepools.py b/src/kimchi/control/storagepools.py
index 35e7664..3b8ef79 100644
--- a/src/kimchi/control/storagepools.py
+++ b/src/kimchi/control/storagepools.py
@@ -31,8 +31,10 @@ from kimchi.control.storagevolumes import IsoVolumes, StorageVolumes
 from kimchi.control.utils import get_class_name, model_fn, parse_request
 from kimchi.control.utils import validate_params
 from kimchi.model import ISO_POOL_NAME
+from kimchi.control.utils import UrlSubNode
 
 
+ at UrlSubNode("storagepools", True)
 class StoragePools(Collection):
     def __init__(self, model):
         super(StoragePools, self).__init__(model)
diff --git a/src/kimchi/control/tasks.py b/src/kimchi/control/tasks.py
index b799422..f3dbfd9 100644
--- a/src/kimchi/control/tasks.py
+++ b/src/kimchi/control/tasks.py
@@ -22,8 +22,10 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 
 from kimchi.control.base import Collection, Resource
+from kimchi.control.utils import UrlSubNode
 
 
+ at UrlSubNode("tasks", True)
 class Tasks(Collection):
     def __init__(self, model):
         super(Tasks, self).__init__(model)
diff --git a/src/kimchi/control/templates.py b/src/kimchi/control/templates.py
index a77936e..ce1dda4 100644
--- a/src/kimchi/control/templates.py
+++ b/src/kimchi/control/templates.py
@@ -22,8 +22,10 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 
 from kimchi.control.base import Collection, Resource
+from kimchi.control.utils import UrlSubNode
 
 
+ at UrlSubNode("templates", True)
 class Templates(Collection):
     def __init__(self, model):
         super(Templates, self).__init__(model)
diff --git a/src/kimchi/control/vms.py b/src/kimchi/control/vms.py
index 7843be7..a7a0b3b 100644
--- a/src/kimchi/control/vms.py
+++ b/src/kimchi/control/vms.py
@@ -23,9 +23,10 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 
 from kimchi.control.base import Collection, Resource
-from kimchi.control.utils import internal_redirect
+from kimchi.control.utils import internal_redirect, UrlSubNode
 
 
+ at UrlSubNode("vms", True)
 class VMs(Collection):
     def __init__(self, model):
         super(VMs, self).__init__(model)
-- 
1.8.4.2




More information about the Kimchi-devel mailing list