[Kimchi-devel] [PATCH v2 2/4] Implement the package manager monitor backend
Aline Manera
alinefm at linux.vnet.ibm.com
Mon Oct 5 21:34:59 UTC 2015
On 04/10/2015 17:44, Jose Ricardo Ziviani wrote:
> - The client will be able to know if there is a package manager instance
> running and to follow the package manager logfiles to know what is
> happening within.
>
> Signed-off-by: Jose Ricardo Ziviani <joserz at linux.vnet.ibm.com>
> ---
> src/wok/plugins/kimchi/control/host.py | 1 +
> src/wok/plugins/kimchi/model/host.py | 10 +++++++
> src/wok/plugins/kimchi/swupdate.py | 53 ++++++++++++++++++++++++++++++++++
> 3 files changed, 64 insertions(+)
>
> diff --git a/src/wok/plugins/kimchi/control/host.py b/src/wok/plugins/kimchi/control/host.py
> index 0a40f1b..6c2ed43 100644
> --- a/src/wok/plugins/kimchi/control/host.py
> +++ b/src/wok/plugins/kimchi/control/host.py
> @@ -39,6 +39,7 @@ class Host(Resource):
> self.packagesupdate = PackagesUpdate(self.model)
> self.repositories = Repositories(self.model)
> self.swupdate = self.generate_action_handler_task('swupdate')
> + self.taillogs = self.generate_action_handler_task('taillogs')
That way we will create a POST API which is not the case here.
The POST method is to change a resource in some way. And this operation
is to return the logs from a started operation. So it looks more like a
GET request.
Also it is related to software update, so I'd say the API should be
something like: GET /host/swupdateprogress
So we'd have the following APIs:
POST /host/swupdate (to update all packages)
GET /host/swupdateprogress (to
return the update progress)
> self.cpuinfo = CPUInfo(self.model)
>
> @property
> diff --git a/src/wok/plugins/kimchi/model/host.py b/src/wok/plugins/kimchi/model/host.py
> index ddfbf0f..c850669 100644
> --- a/src/wok/plugins/kimchi/model/host.py
> +++ b/src/wok/plugins/kimchi/model/host.py
> @@ -128,6 +128,16 @@ class HostModel(object):
> self.host_info['memory'] = psutil.virtual_memory().total
> return self.host_info
>
> + def taillogs(self, *name):
> + try:
> + swupdate = SoftwareUpdate()
> + except:
> + raise OperationFailed('KCHPKGUPD0004E')
> +
> + taskid = add_task('/plugins/kimchi/host/taillogs',
> + swupdate.tailUpdateLogs, self.objstore, None)
> + return self.task.lookup(taskid)
> +
> def swupdate(self, *name):
> try:
> swupdate = SoftwareUpdate()
> diff --git a/src/wok/plugins/kimchi/swupdate.py b/src/wok/plugins/kimchi/swupdate.py
> index f86c12e..687d3f5 100644
> --- a/src/wok/plugins/kimchi/swupdate.py
> +++ b/src/wok/plugins/kimchi/swupdate.py
> @@ -122,6 +122,59 @@ class SoftwareUpdate(object):
> os.setsid()
> signal.signal(signal.SIGTERM, signal.SIG_IGN)
>
> + def tailUpdateLogs(self, cb, params):
> + """
> + When the package manager is already running (started outside kimchi or
> + if wokd is restarted) we can only know what's happening by reading the
> + logfiles. This method acts like a 'tail -f' on the default package
> + manager logfile. If the logfile is not found, a simple '*' is
> + displayed to track progress. This will be until the process finishes.
> + """
> + if not self._pkg_mnger.isRunning():
> + return
> +
> + fd = None
> + try:
> + fd = os.open(self._pkg_mnger.logfile, os.O_RDONLY)
> +
> + # cannot open logfile, print something to let users know that the
> + # system is being upgrading until the package manager finishes its
> + # job
> + except (TypeError, OSError):
> + msgs = []
> + while self._pkg_mnger.isRunning():
> + msgs.append('*')
> + cb(''.join(msgs))
> + time.sleep(1)
> + msgs.append('\n')
> + cb(''.join(msgs), True)
> + return
> +
> + # go to the end of logfile and starts reading, if nothing is read or
> + # a pattern is not found in the message just wait and retry until
> + # the package manager finishes
> + os.lseek(fd, 0, os.SEEK_END)
> + msgs = []
> + progress = []
> + while True:
> + read = os.read(fd, 1024)
> + if not read:
> + if not self._pkg_mnger.isRunning():
> + break
> +
> + if not msgs:
> + progress.append('*')
> + cb(''.join(progress))
> +
> + time.sleep(1)
> + continue
> +
> + msgs.append(read)
> + cb(''.join(msgs))
> +
> + os.close(fd)
> + return cb(''.join(msgs), True)
> +
> def doUpdate(self, cb, params):
> """
> Execute the update
More information about the Kimchi-devel
mailing list