[Kimchi-devel] [PATCH V3 0/4] support create/delete VMIface

Sheldon shaohef at linux.vnet.ibm.com
Fri Jan 24 17:30:20 UTC 2014


On 01/25/2014 12:23 AM, Aline Manera wrote:
>
> The result when I tried to attach a network:
>
> alinefm at alinefm:~/mail-patches$ curl -u <user:password> -H 
> 'Content-type: application/json' -H 'Accept: application/json 
> http://localhost:8000/vms/Fedora19/ifaces -X POST -d'{"type": 
> "network", "network": "for_test"}'
> {}
>
> And when I tried to get them:
>
> alinefm at alinefm:~/mail-patches$ curl -u <user:password> -H 
> 'Content-type: application/json' -H 'Accept: application/json' 
> http://localhost:8000/vms/Fedora19/ifaces -X GET -d'{}'
> [
> {
> "mac":"52:54:00:a9:74:9d",
> "type":"network",
> "model":"virtio",
> "network":"default"
> },
> {},
> {},
> {},
> {}
> ]
>
> But looking inside the VM xml, I noticed all the interfaces were added 
> successfully.
>
> <interface type='network'>
> <mac address='52:54:00:a9:74:9d'/>
> <source network='default'/>
> <model type='virtio'/>
> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' 
> function='0x0'/>
> </interface>
> <interface type='network'>
> <mac address='52:54:00:4a:50:fb'/>
> <source network='default'/>
> <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' 
> function='0x0'/>
> </interface>
> <interface type='network'>
> <mac address='52:54:00:3d:3e:9b'/>
> <source network='default'/>
> <address type='pci' domain='0x0000' bus='0x00' slot='0x0b' 
> function='0x0'/>
> </interface>
> <interface type='network'>
> <mac address='52:54:00:69:7d:48'/>
> <source network='default'/>
> <address type='pci' domain='0x0000' bus='0x00' slot='0x0c' 
> function='0x0'/>
> </interface>
> <interface type='network'>
> <mac address='52:54:00:67:18:12'/>
> <source network='for_test'/>
> <address type='pci' domain='0x0000' bus='0x00' slot='0x0d' 
> function='0x0'/>
> </interface>
>
> The problem is with the API
>
> Seems the problem is in vmiface_lookup()
>
> def vmiface_lookup(self, vm, mac):
> info = {}
>
> iface = self._get_vmiface(vm, mac)
> if iface is None:
> raise NotFoundError('iface: "%s"' % mac)
>
> info['type'] = iface.attrib['type']
> info['mac'] = iface.mac.get('address')
>
> info['model'] = iface.model.get('type')
>
> if info['type'] == 'network':
> info['network'] = iface.source.get('network')
> if info['type'] == 'bridge':
> info['bridge'] = iface.source.get('bridge')
>
> return info
>
> As the vm is powered off, there is no <model> tag on xml
> libvirt will get the default model type only when starting the vm
>
> So we need to do something like:
>
> # it is a mock code. I don't know how objectify works for that
> if iface.model:
> info['model'] = iface.model.get('type')
>
seems strangely, we have discuss this this problem.
I have try libvirt can create a model for vm automatically.
I try it on F20

>
> On 01/24/2014 12:24 AM, shaohef at linux.vnet.ibm.com wrote:
>> From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
>>
>> V2 -> V3
>> rebase
>>
>> V1 -> V2
>> do not support hot plugging attach/detach interface
>> we will support this feature after we implement events.
>>
>>
>> 1. get all vms:
>> $ curl -u <user> -H 'Accept: application/json' -H 'Content-type:
>> application/json' http://localhost:8000/vms
>>
>> 2. get all networks:
>> $ curl -u <user> -H 'Accept: application/json' -H 'Content-type:
>> application/json' http://localhost:8000/networks
>>
>> 3. get all ifaces of a vm
>> $ curl -u <user> -H 'Accept: application/json' -H 'Content-type:
>> application/json' http://localhost:8000/vms/test-vm-0/ifaces/
>> [
>> {
>> "mac":"52:54:00:00:00:01",
>> "model":"virtio",
>> "type":"network",
>> "network":"default"
>> }
>> ]
>>
>> 4. attach a new iface to vm
>> $ curl -u <user> -H 'Accept: application/json' -H 'Content-type:
>> application/json' http://localhost:8000/vms/test-vm-8/ifaces -X POST 
>> -d '
>> {
>> "type":"network",
>> "network":"test-network-0"
>> }
>> '
>>
>> {
>> "mac":"52:54:00:00:00:0d",
>> "model":"virtio",
>> "type":"network",
>> "network":"test-network-0"
>> }
>>
>> 5. detach a iface from vm
>> $ curl -u <user> -H 'Accept: application/json' -H 'Content-type:
>> application/json' 
>> http://localhost:8000/vms/test-vm-8/ifaces/52:54:00:00:00:0d -X DELETE
>>
>>
>> ShaoHe Feng (4):
>> support create/delete VMIface: update model
>> support create/delete VMIface: update mockmodel
>> support create/delete VMIface: update API.json
>> support create/delete VMIface: update testcase
>>
>> src/kimchi/API.json | 21 +++++++++++++++++++
>> src/kimchi/mockmodel.py | 21 +++++++++++++++++++
>> src/kimchi/model.py | 56 
>> ++++++++++++++++++++++++++++++++++++++++++++++++-
>> tests/test_model.py | 22 +++++++++++++++++++
>> tests/test_rest.py | 27 ++++++++++++++++++++++++
>> 5 files changed, 146 insertions(+), 1 deletion(-)
>>
>
>
>


-- 
Thanks and best regards!

Sheldon Feng(冯少合)<shaohef at linux.vnet.ibm.com>
IBM Linux Technology Center




More information about the Kimchi-devel mailing list