[Kimchi-devel] [PATCH 1/2] add two moethod to get/set vm iface model in metadata

shaohef at linux.vnet.ibm.com shaohef at linux.vnet.ibm.com
Tue Apr 22 12:48:53 UTC 2014


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

We store the model in metadata.
We can get it from metadata when we create a vm iface.

Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
---
 src/kimchi/model/vmifaces.py | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/kimchi/model/vmifaces.py b/src/kimchi/model/vmifaces.py
index 9bf110e..30e5373 100644
--- a/src/kimchi/model/vmifaces.py
+++ b/src/kimchi/model/vmifaces.py
@@ -24,6 +24,8 @@ from lxml import etree, objectify
 from lxml.builder import E
 
 from kimchi.exception import InvalidOperation, InvalidParameter, NotFoundError
+from kimchi.model.utils import get_vm_metadata_element
+from kimchi.model.utils import set_vm_metadata_element
 from kimchi.model.vms import DOM_STATE_MAP, VMModel
 
 
@@ -37,6 +39,12 @@ class VMIfacesModel(object):
             macs.append(iface.mac.get('address'))
         return macs
 
+    def _vm_get_iface_metadata(self, dom):
+        iface_xml = (get_vm_metadata_element(dom, "vmiface") or
+                     """<vmiface></vmiface>""")
+        vmiface = objectify.fromstring(iface_xml)
+        return vmiface.attrib.get("model")
+
     def create(self, vm, params):
         def randomMAC():
             mac = [0x52, 0x54, 0x00,
@@ -99,6 +107,14 @@ class VMIfaceModel(object):
                 return iface
         return None
 
+    @staticmethod
+    def vm_updata_iface_metadata(dom, params):
+        model = params.get("model")
+        if model is None:
+            return
+        iface = E.vmiface({"model": model})
+        set_vm_metadata_element(dom, etree.tostring(iface))
+
     def lookup(self, vm, mac):
         info = {}
 
-- 
1.9.0




More information about the Kimchi-devel mailing list