[Kimchi-devel] [PATCH V1 4/6] VM supports interfaces: update controller

shaohef at linux.vnet.ibm.com shaohef at linux.vnet.ibm.com
Tue Jan 21 14:42:00 UTC 2014


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

add VmIfaces collection and VmIface resource

Update VM resource.

Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
---
 src/kimchi/control/vm/ifaces.py | 48 +++++++++++++++++++++++++++++++++++++++++
 src/kimchi/control/vms.py       |  3 +++
 2 files changed, 51 insertions(+)
 create mode 100644 src/kimchi/control/vm/ifaces.py

diff --git a/src/kimchi/control/vm/ifaces.py b/src/kimchi/control/vm/ifaces.py
new file mode 100644
index 0000000..a333616
--- /dev/null
+++ b/src/kimchi/control/vm/ifaces.py
@@ -0,0 +1,48 @@
+#
+# Project Kimchi
+#
+# Copyright IBM, Corp. 2013
+#
+# Authors:
+#  ShaoHe Feng <shaohef at 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.utils import urlSubNode
+
+
+ at urlSubNode("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, ]
+
+
+class VMIface(Resource):
+    def __init__(self, model, vm, ident):
+        super(VMIface, self).__init__(model, ident)
+        self.vm = vm
+        self.ident = ident
+        self.info = {}
+        self.model_args = [self.vm, self.ident]
+        self.uri_fmt = '/vms/%s/iface/%s'
+
+    @property
+    def data(self):
+        return self.info
diff --git a/src/kimchi/control/vms.py b/src/kimchi/control/vms.py
index 25474fc..70ab826 100644
--- a/src/kimchi/control/vms.py
+++ b/src/kimchi/control/vms.py
@@ -24,6 +24,7 @@
 
 from kimchi.control.base import Collection, Resource
 from kimchi.control.utils import internal_redirect
+from kimchi.control.vm import sub_nodes
 from kimchi.utils import urlSubNode
 
 
@@ -40,6 +41,8 @@ class VM(Resource):
         self.update_params = ["name"]
         self.screenshot = VMScreenShot(model, ident)
         self.uri_fmt = '/vms/%s'
+        for ident, node in sub_nodes.items():
+            setattr(self, ident, node(model, self.ident.decode("utf-8")))
         self.start = self.generate_action_handler('start')
         self.stop = self.generate_action_handler('stop')
         self.connect = self.generate_action_handler('connect')
-- 
1.8.4.2




More information about the Kimchi-devel mailing list