[Kimchi-devel] [PATCH v2] [Kimchi] Feature request (#860): Support Guest Autostart

Aline Manera alinefm at linux.vnet.ibm.com
Mon Aug 29 19:01:00 UTC 2016


Hi Bianca,

The patch looks good IMO but I'd ask you to add tests using the REST 
API. You can add those tests in test_rest.py file.

Something like:

1. Verify the 'autostart' parameter is correctly returned by the API GET 
/vms/*name*
2. Update the autostart parameter by the API PUT /vms/*name* {autostart: 
true/false} and confirm the changes were really made through GET 
/vms/*name* API
3. Do the test 2. for running and powered guests

Regards,
Aline Manera


On 08/26/2016 11:58 AM, bianca at linux.vnet.ibm.com wrote:
> From: Bianca Carvalho <bianca at linux.vnet.ibm.com>
>
> Include 'autostart' option in API.json and vms.py (lookup and update)
> using libvirt dom.setAutostart to set as true or false. Also edit
> test_model.py to include those changes and updated API.md file.
>
> Signed-off-by: Bianca Carvalho <bianca at linux.vnet.ibm.com>
> ---
>   API.json            |  4 ++++
>   docs/API.md         |  2 ++
>   model/vms.py        | 12 +++++++++---
>   tests/test_model.py |  6 ++++++
>   4 files changed, 21 insertions(+), 3 deletions(-)
>
> diff --git a/API.json b/API.json
> index 4fdd522..4946069 100644
> --- a/API.json
> +++ b/API.json
> @@ -322,6 +322,10 @@
>                       "error": "KCHVM0053E",
>                       "type": "boolean"
>                   },
> +                "autostart": {
> +                  "description": "Enable/Disable guest autostart",
> +                  "type": "boolean"
> +                },
>                   "users": {
>                       "description": "Array of users who have permission to the VM",
>                       "type": "array",
> diff --git a/docs/API.md b/docs/API.md
> index b07bf16..9f30666 100644
> --- a/docs/API.md
> +++ b/docs/API.md
> @@ -147,6 +147,7 @@ server.
>       * groups: A list of system groups whose users have permission to access
>         the VM. Default is: empty (i.e. no groups given access).
>       * bootorder: list of devices in boot order
> +    * autostart: show if autostart is enabled.
>   * **DELETE**: Remove the Virtual Machine
>   * **PUT**: update the parameters of existing VM
>       * name: New name for this VM (only applied for shutoff VM)
> @@ -177,6 +178,7 @@ server.
>               * threads - The number of threads per core.
>       * bootorder: guest bootorder, types accepted: hd, cdrom, network or fd
>       * bootmenu: prompts guest bootmenu. Bool type.
> +    * autostart: enable/disable guest autostart (true or false params).
>
>   * **POST**: *See Virtual Machine Actions*
>
> diff --git a/model/vms.py b/model/vms.py
> index 433770a..cfe4c97 100644
> --- a/model/vms.py
> +++ b/model/vms.py
> @@ -79,11 +79,13 @@ DOM_STATE_MAP = {0: 'nostate',
>                    7: 'pmsuspended'}
>
>   # update parameters which are updatable when the VM is online
> -VM_ONLINE_UPDATE_PARAMS = ['graphics', 'groups', 'memory', 'users']
> +VM_ONLINE_UPDATE_PARAMS = ['graphics', 'groups', 'memory', 'users',
> +                           'autostart']
>
>   # update parameters which are updatable when the VM is offline
>   VM_OFFLINE_UPDATE_PARAMS = ['cpu_info', 'graphics', 'groups', 'memory',
> -                            'name', 'users', 'bootorder', 'bootmenu']
> +                            'name', 'users', 'bootorder', 'bootmenu',
> +                            'autostart']
>
>   XPATH_DOMAIN_DISK = "/domain/devices/disk[@device='disk']/source/@file"
>   XPATH_DOMAIN_DISK_BY_FILE = "./devices/disk[@device='disk']/source[@file='%s']"
> @@ -261,6 +263,9 @@ class VMModel(object):
>
>           with lock:
>               dom = self.get_vm(name, self.conn)
> +            if "autostart" in params:
> +                dom.setAutostart(1 if params['autostart'] == True else 0)
> +
>               # You can only change <maxMemory> offline, updating guest XML
>               if ("memory" in params) and ('maxmemory' in params['memory']) and\
>                  (DOM_STATE_MAP[dom.info()[0]] != 'shutoff'):
> @@ -1285,7 +1290,8 @@ class VMModel(object):
>                   'access': 'full',
>                   'persistent': True if dom.isPersistent() else False,
>                   'bootorder': boot,
> -                'bootmenu': bootmenu
> +                'bootmenu': bootmenu,
> +                'autostart': dom.autostart()
>                   }
>
>       def _vm_get_disk_paths(self, dom):
> diff --git a/tests/test_model.py b/tests/test_model.py
> index 27225f8..7b1fbfe 100644
> --- a/tests/test_model.py
> +++ b/tests/test_model.py
> @@ -1369,6 +1369,12 @@ class ModelTests(unittest.TestCase):
>               inst.vm_update(u'пeω-∨м', {"bootmenu": False})
>               self.assertEquals("no", inst.vm_lookup(u'пeω-∨м')['bootmenu'])
>
> +            # enable/disable autostart
> +            inst.vm_update(u'пeω-∨м', {"autostart": True})
> +            self.assertEquals("yes", inst.vm_lookup(u'пeω-∨м')['autostart'])
> +            inst.vm_update(u'пeω-∨м', {"autostart": False})
> +            self.assertEquals("no", inst.vm_lookup(u'пeω-∨м')['autostart'])
> +
>       def test_get_interfaces(self):
>           inst = model.Model('test:///default',
>                              objstore_loc=self.tmp_store)




More information about the Kimchi-devel mailing list