Reviewed-by: Daniel Barboza <danielhb(a)linux.vnet.ibm.com>
On 12/26/2013 07:48 PM, Aline Manera wrote:
From: Aline Manera <alinefm(a)br.ibm.com>
VMs(Collection), VM(Resource) and VMScreenshot(Resource) were moved to a new -
control/vms.py
That way we can easily know where vm resource is implemented.
Signed-off-by: Aline Manera <alinefm(a)br.ibm.com>
---
src/kimchi/control/vms.py | 65 +++++++++++++++++++++++++++++++++++++++++++++
src/kimchi/controller.py | 38 --------------------------
src/kimchi/root.py | 3 ++-
3 files changed, 67 insertions(+), 39 deletions(-)
create mode 100644 src/kimchi/control/vms.py
diff --git a/src/kimchi/control/vms.py b/src/kimchi/control/vms.py
new file mode 100644
index 0000000..d722920
--- /dev/null
+++ b/src/kimchi/control/vms.py
@@ -0,0 +1,65 @@
+#
+# Project Kimchi
+#
+# Copyright IBM, Corp. 2013
+#
+# Authors:
+# Adam Litke <agl(a)linux.vnet.ibm.com>
+# Aline Manera <alinefm(a)linux.vnet.ibm.com>
+# Royce Lv <lvroyce(a)linux.vnet.ibm.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# 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
+
+from kimchi.control.base import Collection, Resource
+from kimchi.control.utils import internal_redirect
+
+
+class VMs(Collection):
+ def __init__(self, model):
+ super(VMs, self).__init__(model)
+ self.resource = VM
+
+
+class VM(Resource):
+ def __init__(self, model, ident):
+ super(VM, self).__init__(model, ident)
+ self.update_params = ["name"]
+ self.screenshot = VMScreenShot(model, ident)
+ self.uri_fmt = '/vms/%s'
+ self.start = self.generate_action_handler('start')
+ self.stop = self.generate_action_handler('stop')
+ self.connect = self.generate_action_handler('connect')
+
+ @property
+ def data(self):
+ return {'name': self.ident,
+ 'uuid': self.info['uuid'],
+ 'stats': self.info['stats'],
+ 'memory': self.info['memory'],
+ 'cpus': self.info['cpus'],
+ 'state': self.info['state'],
+ 'screenshot': self.info['screenshot'],
+ 'icon': self.info['icon'],
+ 'graphics': {'type':
self.info['graphics']['type'],
+ 'port':
self.info['graphics']['port']}}
+
+
+class VMScreenShot(Resource):
+ def __init__(self, model, ident):
+ super(VMScreenShot, self).__init__(model, ident)
+
+ def get(self):
+ self.lookup()
+ raise internal_redirect(self.info)
diff --git a/src/kimchi/controller.py b/src/kimchi/controller.py
index fade825..cca2b57 100644
--- a/src/kimchi/controller.py
+++ b/src/kimchi/controller.py
@@ -44,44 +44,6 @@ class DebugReportContent(Resource):
raise internal_redirect(self.info['file'])
-class VMs(Collection):
- def __init__(self, model):
- super(VMs, self).__init__(model)
- self.resource = VM
-
-
-class VM(Resource):
- def __init__(self, model, ident):
- super(VM, self).__init__(model, ident)
- self.update_params = ["name"]
- self.screenshot = VMScreenShot(model, ident)
- self.uri_fmt = '/vms/%s'
- self.start = self.generate_action_handler('start')
- self.stop = self.generate_action_handler('stop')
- self.connect = self.generate_action_handler('connect')
-
- @property
- def data(self):
- return {'name': self.ident,
- 'uuid': self.info['uuid'],
- 'stats': self.info['stats'],
- 'memory': self.info['memory'],
- 'cpus': self.info['cpus'],
- 'state': self.info['state'],
- 'screenshot': self.info['screenshot'],
- 'icon': self.info['icon'],
- 'graphics': {'type':
self.info['graphics']['type'],
- 'port':
self.info['graphics']['port']}}
-
-
-class VMScreenShot(Resource):
- def __init__(self, model, ident):
- super(VMScreenShot, self).__init__(model, ident)
-
- def get(self):
- self.lookup()
- raise internal_redirect(self.info)
-
class Templates(Collection):
def __init__(self, model):
super(Templates, self).__init__(model)
diff --git a/src/kimchi/root.py b/src/kimchi/root.py
index 2af2cf6..99185eb 100644
--- a/src/kimchi/root.py
+++ b/src/kimchi/root.py
@@ -31,6 +31,7 @@ from kimchi import template
from kimchi.config import get_api_schema_file
from kimchi.control.utils import parse_request
from kimchi.control.base import Resource
+from kimchi.control.vms import VMs
from kimchi.exception import OperationFailed
@@ -48,7 +49,7 @@ class Root(Resource):
for key in self._handled_error])
Resource.__init__(self, model)
- self.vms = controller.VMs(model)
+ self.vms = VMs(model)
self.templates = controller.Templates(model)
self.storagepools = controller.StoragePools(model)
self.interfaces = controller.Interfaces(model)