On 12/26/2013 02:55 PM, Shu Ming wrote:
2013/12/24 2:41, Aline Manera:
From: Aline Manera <alinefm@br.ibm.com>

The current implemenation put all resources implementation into controller.py
file. That way this file tends to increase to infinity as more resources are
added to Kimchi.

This patch splits controller module (controller.py) into small modules.
So each resource will have its own controller implementation under /control
It will make maintenance easier and anyone can easily identify where any resource
is implemented.
I would argue that most the resources defined are pretty trival and splitting these definitions into different files will add many small files which cause unnecessary maintenance.  From  another point of view,  the real logical is in model.py,  do you have plan to split the model.py file?
Maybe we can refactor the controller-model structure, make it more better.
such some mechanism to register different collections.

For src/kimchi/control/tasks.py

@expose("tasks", "auth")
+class Tasks(Collection):
+    def __init__(self, model):
+        super(Tasks, self).__init__(model)
+        self.resource = Task


"expose" means Tasks will be added as an exposed attribute  "tasks" of root.
src/kimchi/control/__init__.py  can do the register.
Then we will no need to assign Tasks to Root.tasks manually.
And these code in root.py can be removed.

--- a/src/kimchi/root.py
+++ b/src/kimchi/root.py

src/kimchi/root.py

+from kimchi.control.tasks import Tasks 
+class Root(Resource):
     def __init__(self, model, dev_env):
+        self.tasks = Tasks(model)





This patch set does not change any logic - just move classes from controller
to a new module.

Aline Manera (16):
   Move generate_action_handler() function to Resource() class
   Move common functions for Resource and Collection to control/utils.py
   Move login() and logout() functions from controller.py to root.py
   Move basic controller resources to control/base.py
   Move all resources related to vms to control/vms.py
   Move all resources related to templates to control/templates.py
   Move all resources related to debug reports to
     control/debugreports.py
   Move all resources related to storage pools to
     control/storagepools.py
   Move all resources related to storage volume to
     control/storagevolumes.py
   Move all resources related to interfaces to control/interfaces.py
   Move all resources related to networks to control/networks.py
   Move all resources related to config to control/config.py
   Move all resources related to host to control/host.py
   Move all resources related to plugins to control/plugins.py
   Move all resources related to tasks to control/tasks.py
   Use new control modules in root.py

  Makefile.am                          |   13 +
  src/kimchi/control/__init__.py       |   21 +
  src/kimchi/control/base.py           |  290 +++++++++++++
  src/kimchi/control/config.py         |   65 +++
  src/kimchi/control/debugreports.py   |   52 +++
  src/kimchi/control/host.py           |   61 +++
  src/kimchi/control/interfaces.py     |   44 ++
  src/kimchi/control/networks.py       |   48 +++
  src/kimchi/control/plugins.py        |   44 ++
  src/kimchi/control/storagepools.py   |  125 ++++++
  src/kimchi/control/storagevolumes.py |   79 ++++
  src/kimchi/control/tasks.py          |   41 ++
  src/kimchi/control/templates.py      |   51 +++
  src/kimchi/control/utils.py          |  103 +++++
  src/kimchi/control/vms.py            |   64 +++
  src/kimchi/controller.py             |  755 ----------------------------------
  src/kimchi/root.py                   |   61 ++-
  17 files changed, 1147 insertions(+), 770 deletions(-)
  create mode 100644 src/kimchi/control/__init__.py
  create mode 100644 src/kimchi/control/base.py
  create mode 100644 src/kimchi/control/config.py
  create mode 100644 src/kimchi/control/debugreports.py
  create mode 100644 src/kimchi/control/host.py
  create mode 100644 src/kimchi/control/interfaces.py
  create mode 100644 src/kimchi/control/networks.py
  create mode 100644 src/kimchi/control/plugins.py
  create mode 100644 src/kimchi/control/storagepools.py
  create mode 100644 src/kimchi/control/storagevolumes.py
  create mode 100644 src/kimchi/control/tasks.py
  create mode 100644 src/kimchi/control/templates.py
  create mode 100644 src/kimchi/control/utils.py
  create mode 100644 src/kimchi/control/vms.py
  delete mode 100644 src/kimchi/controller.py


_______________________________________________
Kimchi-devel mailing list
Kimchi-devel@ovirt.org
http://lists.ovirt.org/mailman/listinfo/kimchi-devel





-- 
Sheldon Feng(冯少合)<shaohef@linux.vnet.ibm.com>
IBM Linux Technology Center