[Kimchi-devel] [PATCH 1/7] Granular Task Queries: Backend

Aline Manera alinefm at linux.vnet.ibm.com
Fri Apr 17 17:51:30 UTC 2015



On 17/04/2015 12:24, Christy Perez wrote:
> You can filter tasks by their state (running) and/or a target_uri.
> If you want to see all cloning VM tasks, you can only query for
> running tasks with /vm in the target_uri. This patch adds an action
> keyword to the target_uris for existing tasks. This will make it
> possible to query other types of tasks for the same resource.
>
> Signed-off-by: Christy Perez <christy at linux.vnet.ibm.com>
> ---
>   docs/API.md                        | 16 ++++++++++++++++
>   src/kimchi/mockmodel.py            |  7 ++++---
>   src/kimchi/model/debugreports.py   |  4 ++--
>   src/kimchi/model/host.py           |  4 ++--
>   src/kimchi/model/storagepools.py   |  2 +-
>   src/kimchi/model/storagevolumes.py | 12 +++++++-----
>   src/kimchi/model/vms.py            |  5 ++---
>   src/kimchi/model/vmsnapshots.py    |  5 +++--
>   8 files changed, 37 insertions(+), 18 deletions(-)
>
> diff --git a/docs/API.md b/docs/API.md
> index 3f7925f..1f8e769 100644
> --- a/docs/API.md
> +++ b/docs/API.md
> @@ -651,6 +651,22 @@ server.
>           * failed: The task failed
>       * message: Human-readable details about the Task status
>       * target_uri: Resource URI related to the Task
> +      The target uri may end with an action descriptor:
> +        * VM task descriptions:
> +            * clone
> +            * create
> +        * VM Snapshot description
> +           * create
> +        * Storage descriptions:
> +            * create
> +            * clone
> +        * Pool descriptions:
> +            * create
> +            * scan

Is there a scan action? Something like /storagepools/<name>/scan ?

> +        * Debugreport descriptions:
> +            * create
> +        * Host SW Update descriptions:
> +            * update

I don't think we need to change the main POST action. Just those actions 
to a specific resource.
Example,

# to create the VM
POST /vms
Target URI: /vms/<name>

# to clone the VM
POST /vms/<name>/clone
Target URI: /vms/<name>/clone

# to create a snapshot
POST /vms/<name>/snapshot
Target URI: /vms/<name>/snapshot/<snap>

Does that make sense?






>   * **POST**: *See Task Actions*
>
>   **Actions (POST):**
> diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
> index 413ac5d..2b1b214 100644
> --- a/src/kimchi/mockmodel.py
> +++ b/src/kimchi/mockmodel.py
> @@ -244,7 +244,7 @@ def _get_volume_path(self, pool, vol):
>           return MockModel._libvirt_get_vol_path(pool, vol)
>
>       def _gen_debugreport_file(self, name):
> -        return add_task('/debugreports/%s' % name, self._create_log,
> +        return add_task('/debugreports/%s/create' % name, self._create_log,
>                           self.objstore, name)
>
>       def _create_log(self, cb, name):
> @@ -333,7 +333,8 @@ def _mock_packageupdate_lookup(self, pkg_name):
>           return self._mock_swupdate.pkgs[pkg_name]
>
>       def _mock_host_swupdate(self, args=None):
> -        task_id = add_task('/host/swupdate', self._mock_swupdate.doUpdate,
> +        task_id = add_task('/host/swupdate/update',
> +                           self._mock_swupdate.doUpdate,
>                              self.objstore)
>           return self.task_lookup(task_id)
>
> @@ -385,7 +386,7 @@ def _mock_vm_clone(self, name):
>       def _mock_vmsnapshots_create(self, vm_name, params):
>           name = params.get('name', unicode(int(time.time())))
>           params = {'vm_name': vm_name, 'name': name}
> -        taskid = add_task(u'/vms/%s/snapshots/%s' % (vm_name, name),
> +        taskid = add_task(u'/vms/%s/snapshots/%s/create' % (vm_name, name),
>                             self._vmsnapshots_create_task, self.objstore, params)
>           return self.task_lookup(taskid)
>
> diff --git a/src/kimchi/model/debugreports.py b/src/kimchi/model/debugreports.py
> index 5f74da8..19b4de5 100644
> --- a/src/kimchi/model/debugreports.py
> +++ b/src/kimchi/model/debugreports.py
> @@ -62,8 +62,8 @@ def _gen_debugreport_file(self, name):
>           gen_cmd = self.get_system_report_tool()
>
>           if gen_cmd is not None:
> -            return add_task('/debugreports/%s' % name, gen_cmd, self.objstore,
> -                            name)
> +            return add_task('/debugreports/%s/create' % name, gen_cmd,
> +                            self.objstore, name)
>
>           raise OperationFailed("KCHDR0002E")
>
> diff --git a/src/kimchi/model/host.py b/src/kimchi/model/host.py
> index 4419bb3..f429415 100644
> --- a/src/kimchi/model/host.py
> +++ b/src/kimchi/model/host.py
> @@ -115,8 +115,8 @@ def swupdate(self, *name):
>               raise OperationFailed('KCHPKGUPD0001E')
>
>           kimchi_log.debug('Host is going to be updated.')
> -        taskid = add_task('/host/swupdate', swupdate.doUpdate, self.objstore,
> -                          None)
> +        taskid = add_task('/host/swupdate/update', swupdate.doUpdate,
> +                          self.objstore, None)
>           return self.task.lookup(taskid)
>
>       def shutdown(self, args=None):
> diff --git a/src/kimchi/model/storagepools.py b/src/kimchi/model/storagepools.py
> index b85f3b4..094c841 100644
> --- a/src/kimchi/model/storagepools.py
> +++ b/src/kimchi/model/storagepools.py
> @@ -167,7 +167,7 @@ def _do_deep_scan(self, params):
>
>           params['path'] = self.scanner.scan_dir_prepare(params['name'])
>           scan_params['pool_path'] = params['path']
> -        task_id = add_task('/storagepools/%s' % ISO_POOL_NAME,
> +        task_id = add_task('/storagepools/%s/scan' % ISO_POOL_NAME,
>                              self.scanner.start_scan, self.objstore, scan_params)
>           # Record scanning-task/storagepool mapping for future querying
>           try:
> diff --git a/src/kimchi/model/storagevolumes.py b/src/kimchi/model/storagevolumes.py
> index 0480496..9f93f10 100644
> --- a/src/kimchi/model/storagevolumes.py
> +++ b/src/kimchi/model/storagevolumes.py
> @@ -116,8 +116,10 @@ def create(self, pool_name, params):
>               raise InvalidParameter('KCHVOL0001E', {'name': name})
>
>           params['pool'] = pool_name
> -        targeturi = '/storagepools/%s/storagevolumes/%s' % (pool_name, name)
> -        taskid = add_task(targeturi, create_func, self.objstore, params)
> +        targeturi = '/storagepools/%s/storagevolumes/%s/create' \
> +                    % (pool_name, name)
> +        taskid = add_task(targeturi, create_func, self.objstore,
> +                          params)
>           return self.task.lookup(taskid)
>
>       def _create_volume_with_file(self, cb, params):
> @@ -413,9 +415,9 @@ def clone(self, pool, name, new_pool=None, new_name=None):
>                     'name': name,
>                     'new_pool': new_pool,
>                     'new_name': new_name}
> -        taskid = add_task(u'/storagepools/%s/storagevolumes/%s' %
> -                          (pool, new_name), self._clone_task, self.objstore,
> -                          params)
> +        taskid = add_task(u'/storagepools/%s/storagevolumes/%s/clone' %
> +                          (pool, new_name), self._clone_task,
> +                          self.objstore, params)
>           return self.task.lookup(taskid)
>
>       def _clone_task(self, cb, params):
> diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py
> index 4c5f443..1ae841d 100644
> --- a/src/kimchi/model/vms.py
> +++ b/src/kimchi/model/vms.py
> @@ -332,9 +332,8 @@ def clone(self, name):
>           new_name = get_next_clone_name(current_vm_names, name)
>
>           # create a task with the actual clone function
> -        taskid = add_task(u'/vms/%s' % new_name, self._clone_task,
> -                          self.objstore,
> -                          {'name': name, 'new_name': new_name})
> +        taskid = add_task(u'/vms/%s/clone' % new_name, self._clone_task,
> +                          self.objstore, {'name': name, 'new_name': new_name})
>
>           return self.task.lookup(taskid)
>
> diff --git a/src/kimchi/model/vmsnapshots.py b/src/kimchi/model/vmsnapshots.py
> index 3a92cdc..c4cc663 100644
> --- a/src/kimchi/model/vmsnapshots.py
> +++ b/src/kimchi/model/vmsnapshots.py
> @@ -72,8 +72,9 @@ def create(self, vm_name, params={}):
>           name = params.get('name', unicode(int(time.time())))
>
>           task_params = {'vm_name': vm_name, 'name': name}
> -        taskid = add_task(u'/vms/%s/snapshots/%s' % (vm_name, name),
> -                          self._create_task, self.objstore, task_params)
> +        taskid = add_task(u'/vms/%s/snapshots/%s/create' % (vm_name, name),
> +                          self._create_task, self.objstore,
> +                          task_params)
>           return self.task.lookup(taskid)
>
>       def _create_task(self, cb, params):




More information about the Kimchi-devel mailing list