[Kimchi-devel] [PATCH 2/7] Host's software update: Update REST API

Sheldon shaohef at linux.vnet.ibm.com
Mon Feb 17 07:53:42 UTC 2014


On 02/13/2014 10:07 PM, Aline Manera wrote:
> From: Paulo Vital <pvital at linux.vnet.ibm.com>
>
> Define PackageUpdate resource features according to API.md
> Activate auth support to new resource
>
> Signed-off-by: Paulo Vital <pvital at linux.vnet.ibm.com>
> Signed-off-by: Ramon Medeiros <ramonn at linux.vnet.ibm.com>
> Signed-off-by: Aline Manera <alinefm at br.ibm.com>
> ---
>   src/kimchi/control/host.py |   29 +++++++++++++++++++++++++++++
>   1 file changed, 29 insertions(+)
>
> diff --git a/src/kimchi/control/host.py b/src/kimchi/control/host.py
> index 053c822..b4dd544 100644
> --- a/src/kimchi/control/host.py
> +++ b/src/kimchi/control/host.py
> @@ -23,8 +23,12 @@
>   # 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 cherrypy
> +
>   from kimchi.control.base import Collection, Resource
>   from kimchi.control.utils import UrlSubNode
> +from kimchi.exception import OperationFailed
> +from kimchi.template import render
>
>
>   @UrlSubNode("host", True)
> @@ -36,6 +40,7 @@ class Host(Resource):
>           self.shutdown = self.generate_action_handler('shutdown')
>           self.stats = HostStats(self.model)
>           self.partitions = Partitions(self.model)
> +        self.packagesupdate = PackagesUpdate(self.model)
>
>       @property
>       def data(self):
> @@ -61,3 +66,27 @@ class Partition(Resource):
>       @property
>       def data(self):
>           return self.info
> +
> +
> +class PackagesUpdate(Collection):
> +    def __init__(self, model):
> +        super(PackagesUpdate, self).__init__(model)
> +        self.resource = PackageUpdate
> +
> +    @cherrypy.expose
Oh, from your document,
+**Actions (POST):**
+
+* update: Start the update of packages in background and return a Task 
resource
+ * task resource. * See Resource: Task *

This should be a POST method.
Now it support all method: DELETE,POST,PUT,GET.

you can have a try
# curl -u <user> -H 'Content-type: application/json' -H 'Accept: 
application/json' http://localhost:8000/host/packagesupdate/update -x DELETE

> +    def update(self):
> +        try:
> +            task = self.model.packagesupdate_update()
> +            cherrypy.response.status = 202
> +            return render("Task", task)
> +        except OperationFailed, e:
> +            raise cherrypy.HTTPError(500, e.message)
> +
> +
> +class PackageUpdate(Resource):
> +    def __init__(self, model, id=None):
> +        super(PackageUpdate, self).__init__(model, id)
> +
> +    @property
> +    def data(self):
> +        return self.info


-- 
Thanks and best regards!

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




More information about the Kimchi-devel mailing list