
17 Jan
2014
17 Jan
'14
11:35 a.m.
On 01/16/2014 11:56 PM, shaohef@linux.vnet.ibm.com wrote: > From: ShaoHe Feng <shaohef@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@linux.vnet.ibm.com> > --- > src/kimchi/mockmodel.py | 31 +++++++++++++++++++++++++++++++ > 1 file changed, 31 insertions(+) > > diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py > index 4ef3fa6..4027526 100644 > --- a/src/kimchi/mockmodel.py > +++ b/src/kimchi/mockmodel.py > @@ -488,6 +488,17 @@ 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, name): > + dom = self._get_vm(vm) > + info = dom.ifaces[name].info > + info['name'] = info['mac'] > + return info > + > def tasks_get_list(self): > with self.objstore as session: > return session.get_list('task') > @@ -626,12 +637,32 @@ class MockVMTemplate(VMTemplate): > return disk_paths > > > +class MockVMIface(object): > + counter = 0 > + > + def __init__(self, network=None): add: + self.__class__.count += 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)]) > + cls.counter = cls.counter + 1 remove: + cls.counter = cls.counter + 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, \ -- Thanks and best regards! Sheldon Feng(冯少合)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center