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

Aline Manera alinefm at linux.vnet.ibm.com
Tue Mar 3 19:28:14 UTC 2015


Christy, just to make everyone aware about what we discussed offline.

Instead of using a new parameter, we could append the operation name to 
the target uri.
For example:

/vms/<name>/clone

So GET /vms?target_uri=^/vms/.*/clone will return all the VMs being cloned.

On 27/02/2015 12:41, Christy Perez wrote:
> Currently, you can only filter tasks by their state (running) or
> their URL. If you want to see cloning tasks, you query all running
> vm-related tasks.
>
> It also adds descriptions for non-vm-related tasks.
>
> Signed-off-by: Christy Perez <christy at linux.vnet.ibm.com>
> ---
>   docs/API.md                        | 14 ++++++++++++++
>   src/kimchi/asynctask.py            |  6 ++++--
>   src/kimchi/model/debugreports.py   |  4 ++--
>   src/kimchi/model/host.py           |  4 ++--
>   src/kimchi/model/storagepools.py   |  2 +-
>   src/kimchi/model/storagevolumes.py |  7 ++++---
>   src/kimchi/model/tasks.py          |  1 -
>   src/kimchi/model/vms.py            |  5 ++---
>   src/kimchi/model/vmsnapshots.py    |  3 ++-
>   src/kimchi/utils.py                |  4 ++--
>   10 files changed, 33 insertions(+), 17 deletions(-)
>
> diff --git a/docs/API.md b/docs/API.md
> index 3f7925f..bc68f06 100644
> --- a/docs/API.md
> +++ b/docs/API.md
> @@ -651,6 +651,20 @@ server.
>           * failed: The task failed
>       * message: Human-readable details about the Task status
>       * target_uri: Resource URI related to the Task
> +    * description: A more-detailed identifier for a task.
> +            * VM task descriptions:
> +                * clone
> +                * create
> +            * Storage descriptions:
> +                * create
> +                * clone
> +            * Pool descriptions:
> +                * create
> +                * scan
> +            * Debugreport descriptions:
> +                * create
> +            * Host SW Update descriptions:
> +                * update
>   * **POST**: *See Task Actions*
>
>   **Actions (POST):**
> diff --git a/src/kimchi/asynctask.py b/src/kimchi/asynctask.py
> index b5673b2..4944d7c 100644
> --- a/src/kimchi/asynctask.py
> +++ b/src/kimchi/asynctask.py
> @@ -26,12 +26,14 @@
>
>
>   class AsyncTask(object):
> -    def __init__(self, id, target_uri, fn, objstore, opaque=None):
> +    def __init__(self, id, target_uri, descr, fn, objstore,
> +                 opaque=None):
>           if objstore is None:
>               raise OperationFailed("KCHASYNC0001E")
>
>           self.id = str(id)
>           self.target_uri = target_uri
> +        self.description = descr
>           self.fn = fn
>           self.objstore = objstore
>           self.status = 'running'
> @@ -56,7 +58,7 @@ def _status_cb(self, message, success=None):
>
>       def _save_helper(self):
>           obj = {}
> -        for attr in ('id', 'target_uri', 'message', 'status'):
> +        for attr in ('id', 'target_uri', 'message', 'status', 'description'):
>               obj[attr] = getattr(self, attr)
>           try:
>               with self.objstore as session:
> diff --git a/src/kimchi/model/debugreports.py b/src/kimchi/model/debugreports.py
> index 5f74da8..c657181 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' % name, 'create', gen_cmd,
> +                            self.objstore, name)
>
>           raise OperationFailed("KCHDR0002E")
>
> diff --git a/src/kimchi/model/host.py b/src/kimchi/model/host.py
> index 4419bb3..26211d6 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..e7a005b 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' % ISO_POOL_NAME, 'scan',
>                              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..e44f7db 100644
> --- a/src/kimchi/model/storagevolumes.py
> +++ b/src/kimchi/model/storagevolumes.py
> @@ -117,7 +117,8 @@ def create(self, pool_name, params):
>
>           params['pool'] = pool_name
>           targeturi = '/storagepools/%s/storagevolumes/%s' % (pool_name, name)
> -        taskid = add_task(targeturi, create_func, self.objstore, params)
> +        taskid = add_task(targeturi, 'create', create_func, self.objstore,
> +                          params)
>           return self.task.lookup(taskid)
>
>       def _create_volume_with_file(self, cb, params):
> @@ -414,8 +415,8 @@ def clone(self, pool, name, new_pool=None, new_name=None):
>                     '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)
> +                          (pool, new_name), 'clone', self._clone_task,
> +                          self.objstore, params)
>           return self.task.lookup(taskid)
>
>       def _clone_task(self, cb, params):
> diff --git a/src/kimchi/model/tasks.py b/src/kimchi/model/tasks.py
> index 61bc2f3..5520cfd 100644
> --- a/src/kimchi/model/tasks.py
> +++ b/src/kimchi/model/tasks.py
> @@ -17,7 +17,6 @@
>   # License along with this library; if not, write to the Free Software
>   # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
>
> -
>   import time
>
>   from kimchi.exception import TimeoutExpired
> diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py
> index 379c850..078e63e 100644
> --- a/src/kimchi/model/vms.py
> +++ b/src/kimchi/model/vms.py
> @@ -330,9 +330,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' % new_name, 'clone', 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..c899d2e 100644
> --- a/src/kimchi/model/vmsnapshots.py
> +++ b/src/kimchi/model/vmsnapshots.py
> @@ -73,7 +73,8 @@ def create(self, vm_name, params={}):
>
>           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)
> +                          'create', self._create_task, self.objstore,
> +                          task_params)
>           return self.task.lookup(taskid)
>
>       def _create_task(self, cb, params):
> diff --git a/src/kimchi/utils.py b/src/kimchi/utils.py
> index fc5245f..32ec6b1 100644
> --- a/src/kimchi/utils.py
> +++ b/src/kimchi/utils.py
> @@ -66,9 +66,9 @@ def get_next_task_id():
>       return task_id
>
>
> -def add_task(target_uri, fn, objstore, opaque=None):
> +def add_task(target_uri, description, fn, objstore, opaque=None):
>       id = get_next_task_id()
> -    AsyncTask(id, target_uri, fn, objstore, opaque)
> +    AsyncTask(id, target_uri, description, fn, objstore, opaque)
>       return id
>
>




More information about the Kimchi-devel mailing list