[Kimchi-devel] [PATCH V1 5/6] VM supports interfaces: update mockmodel
shaohef at linux.vnet.ibm.com
shaohef at linux.vnet.ibm.com
Tue Jan 21 14:42:01 UTC 2014
From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
Support vm ifaces collection GET method
$ curl -u user -H 'Accept: application/json' -H 'Content-type:
application/json' http://localhost:800/vms/vm-name/ifaces/
Support vm iface resource GET method
$ curl -u user -H 'Accept: application/json' -H 'Content-type:
application/json' http://localhost:800/vms/vm-name/ifaces/mac
Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
---
src/kimchi/mockmodel.py | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
index 4ef3fa6..20cc0a7 100644
--- a/src/kimchi/mockmodel.py
+++ b/src/kimchi/mockmodel.py
@@ -488,6 +488,16 @@ class MockModel(object):
def networks_get_list(self):
return sorted(self._mock_networks.keys())
+ def vmifaces_get_list(self, vm):
+ dom = self._get_vm(vm)
+ macs = dom.ifaces.keys()
+ return macs
+
+ def vmiface_lookup(self, vm, mac):
+ dom = self._get_vm(vm)
+ info = dom.ifaces[mac].info
+ return info
+
def tasks_get_list(self):
with self.objstore as session:
return session.get_list('task')
@@ -626,12 +636,32 @@ class MockVMTemplate(VMTemplate):
return disk_paths
+class MockVMIface(object):
+ counter = 0
+
+ def __init__(self, network=None):
+ self.__class__.counter += 1
+ self.info = {'type': 'network',
+ 'model': 'virtio',
+ 'network': network if network else "net-%s" % self.counter,
+ 'mac': self.get_mac()
+ }
+
+ @classmethod
+ def get_mac(cls):
+ mac = ":".join(["52", "54"] + ["%02x" % (cls.counter/(256**i) % 256)
+ for i in range(3, -1, -1)])
+ return mac
+
+
class MockVM(object):
def __init__(self, uuid, name, template_info):
self.uuid = uuid
self.name = name
self.disk_paths = []
self.networks = template_info['networks']
+ ifaces = [MockVMIface(net) for net in self.networks]
+ self.ifaces = dict([(iface.info['mac'], iface) for iface in ifaces])
self.info = {'state': 'shutoff',
'stats': "{'cpu_utilization': 20, 'net_throughput' : 35, \
'net_throughput_peak': 100, 'io_throughput': 45, \
--
1.8.4.2
More information about the Kimchi-devel
mailing list