[RFC]: a new mechanism to improve controller

as we all know we will use the follow URL for vm device. /vms/vm-name/devices/device-name we will create a new path "vm" for these devices in source tree. all device collections and resources will be in this path. |-- src | |-- distros.d | | `-- ubuntu.json | |-- kimchi | | |-- control | | | |-- base.py | | | |-- vm | | | | |-- ifaces.py | | | | `-- cdroms.py Now, I'd like to introduce a new mechanism to dispatch the vm devices(sub-collections). you can see this patch [PATCH 2/7] add a method to load vms sub collection automatically After this patch, we can dispatch the vm sub-collections more easily. For example, if we want to add a sub-collection ifaces, we can just define it as follow in iface.py +@SubCollection('ifaces') +class VmIfaces(Collection): + def __init__(self, model, vm): + super(VmIfaces, self).__init__(model) + self.resource = VmIface + self.vm = vm + self.resource_args = [self.vm, ] + self.model_args = [self.vm, ] We do not need to touch the vm.py any more. The tag @SubCollection('ifaces') means this is sub-collection of VM and the URL is /vms/vm-name/ifaces/iface-name discuss with Mark and Royce, they think we can improve the root also by this way. Such as we can define vms collection in vms.py as follow: +@SubCollection('vms', auth=True) +class VMs(Collection): + def __init__(self, model, vm): + super(Vms, self).__init__(model) + self.resource = vm For @SubCollection('vms', auth=True): the "vms" means the URL is /vms and "auth=True" means it will set tools.kimchiauth.on ad True. After we tag the Collection with the tag @SubCollection('vms', auth=True), We do not need to touch root.py and server.py any more when we add new Collections. And we can remove the follow codes. diff --git a/src/kimchi/root.py b/src/kimchi/root.py index 3cc6321..2bac4e1 100644 --- a/src/kimchi/root.py +++ b/src/kimchi/root.py @@ -27,19 +27,6 @@ import json from kimchi import auth from kimchi import template -from kimchi.config import get_api_schema_file -from kimchi.control.base import Resource -from kimchi.control.config import Config -from kimchi.control.debugreports import DebugReports -from kimchi.control.host import Host -from kimchi.control.interfaces import Interfaces -from kimchi.control.networks import Networks -from kimchi.control.plugins import Plugins -from kimchi.control.storagepools import StoragePools -from kimchi.control.tasks import Tasks -from kimchi.control.templates import Templates -from kimchi.control.utils import parse_request -from kimchi.control.vms import VMs from kimchi.exception import OperationFailed @@ -57,16 +44,6 @@ class Root(Resource): for key in self._handled_error]) Resource.__init__(self, model) - self.vms = VMs(model) - self.templates = Templates(model) - self.storagepools = StoragePools(model) - self.interfaces = Interfaces(model) - self.networks = Networks(model) - self.tasks = Tasks(model) - self.config = Config(model) - self.host = Host(model) - self.debugreports = DebugReports(model) - self.plugins = Plugins(model) self.api_schema = json.load(open(get_api_schema_file())) def error_production_handler(self, status, message, traceback, version): diff --git a/src/kimchi/server.py b/src/kimchi/server.py index b820263..08dfde2 100644 --- a/src/kimchi/server.py +++ b/src/kimchi/server.py @@ -74,13 +74,6 @@ class Server(object): 'tools.sessions.storage_type': 'file', 'tools.sessions.storage_path': config.get_session_path(), 'tools.kimchiauth.on': False}, - '/host': {'tools.kimchiauth.on': True}, - '/vms': {'tools.kimchiauth.on': True}, - '/templates': {'tools.kimchiauth.on': True}, - '/networks': {'tools.kimchiauth.on': True}, - '/storagepools': {'tools.kimchiauth.on': True}, - '/tasks': {'tools.kimchiauth.on': True}, - '/debugreports': {'tools.kimchiauth.on': True}, '/css': { 'tools.staticdir.on': True, 'tools.staticdir.dir': 'ui/css', -- Thanks and best regards! Sheldon Feng(冯少合)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center

I think this idea is brilliant, look forward to see the patches. On 2014年01月17日 18:33, Sheldon wrote:
as we all know we will use the follow URL for vm device. /vms/vm-name/devices/device-name
we will create a new path "vm" for these devices in source tree. all device collections and resources will be in this path.
|-- src | |-- distros.d | | `-- ubuntu.json | |-- kimchi | | |-- control | | | |-- base.py | | | |-- vm | | | | |-- ifaces.py | | | | `-- cdroms.py
Now, I'd like to introduce a new mechanism to dispatch the vm devices(sub-collections).
you can see this patch [PATCH 2/7] add a method to load vms sub collection automatically
After this patch, we can dispatch the vm sub-collections more easily.
For example, if we want to add a sub-collection ifaces, we can just define it as follow in iface.py
+@SubCollection('ifaces') +class VmIfaces(Collection): + def __init__(self, model, vm): + super(VmIfaces, self).__init__(model) + self.resource = VmIface + self.vm = vm + self.resource_args = [self.vm, ] + self.model_args = [self.vm, ]
We do not need to touch the vm.py any more. The tag @SubCollection('ifaces') means this is sub-collection of VM and the URL is /vms/vm-name/ifaces/iface-name
discuss with Mark and Royce, they think we can improve the root also by this way. Such as we can define vms collection in vms.py as follow:
+@SubCollection('vms', auth=True) +class VMs(Collection): + def __init__(self, model, vm): + super(Vms, self).__init__(model) + self.resource = vm
For @SubCollection('vms', auth=True): the "vms" means the URL is /vms and "auth=True" means it will set tools.kimchiauth.on ad True.
After we tag the Collection with the tag @SubCollection('vms', auth=True), We do not need to touch root.py and server.py any more when we add new Collections.
And we can remove the follow codes.
diff --git a/src/kimchi/root.py b/src/kimchi/root.py index 3cc6321..2bac4e1 100644 --- a/src/kimchi/root.py +++ b/src/kimchi/root.py @@ -27,19 +27,6 @@ import json
from kimchi import auth from kimchi import template -from kimchi.config import get_api_schema_file -from kimchi.control.base import Resource -from kimchi.control.config import Config -from kimchi.control.debugreports import DebugReports -from kimchi.control.host import Host -from kimchi.control.interfaces import Interfaces -from kimchi.control.networks import Networks -from kimchi.control.plugins import Plugins -from kimchi.control.storagepools import StoragePools -from kimchi.control.tasks import Tasks -from kimchi.control.templates import Templates -from kimchi.control.utils import parse_request -from kimchi.control.vms import VMs from kimchi.exception import OperationFailed
@@ -57,16 +44,6 @@ class Root(Resource): for key in self._handled_error])
Resource.__init__(self, model) - self.vms = VMs(model) - self.templates = Templates(model) - self.storagepools = StoragePools(model) - self.interfaces = Interfaces(model) - self.networks = Networks(model) - self.tasks = Tasks(model) - self.config = Config(model) - self.host = Host(model) - self.debugreports = DebugReports(model) - self.plugins = Plugins(model) self.api_schema = json.load(open(get_api_schema_file()))
def error_production_handler(self, status, message, traceback, version): diff --git a/src/kimchi/server.py b/src/kimchi/server.py index b820263..08dfde2 100644 --- a/src/kimchi/server.py +++ b/src/kimchi/server.py @@ -74,13 +74,6 @@ class Server(object): 'tools.sessions.storage_type': 'file', 'tools.sessions.storage_path': config.get_session_path(), 'tools.kimchiauth.on': False}, - '/host': {'tools.kimchiauth.on': True}, - '/vms': {'tools.kimchiauth.on': True}, - '/templates': {'tools.kimchiauth.on': True}, - '/networks': {'tools.kimchiauth.on': True}, - '/storagepools': {'tools.kimchiauth.on': True}, - '/tasks': {'tools.kimchiauth.on': True}, - '/debugreports': {'tools.kimchiauth.on': True}, '/css': { 'tools.staticdir.on': True, 'tools.staticdir.dir': 'ui/css',
participants (2)
-
Royce Lv
-
Sheldon