[Kimchi-devel] [PATCHv3 1/2] utils: Add nfs prevalication

Zhou Zheng Sheng zhshzhou at linux.vnet.ibm.com
Tue Jan 14 05:02:29 UTC 2014


on 2014/01/13 18:40, lvroyce at linux.vnet.ibm.com wrote:
> From: Royce Lv <lvroyce at linux.vnet.ibm.com>
> 
> Abstract a helper function to parse cmd result.
> Usage:
>     (1)get cmd result with subprocess.call or subprocess.Popen
>     (2) call pass_cmd_output to get formated outputs
> Example:
>     blkid = subprocess.Popen(["cat", "/proc/mounts"],
>                 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>     outs = blkid.communicate()[0]
>     output_items= ['path', 'mnt_point', 'type', 'option']
>         utils.parse_cmd_output(outs, output_items)
> Sample output:
>     [{'path': '/dev/sda8', 'type': 'ext4',
>       'option': 'rw,relatime,data=ordered', 'mnt_point': '/home'},
>      {'path': 'localhost:/home/royce/isorepo', 'type': 'nfs4',
>       'option': 'rw...addr=127.0.0.1', 'mnt_point': '/mnt'}]
> 
>     To prevent future mount of nfs path will hang,
>     we will try nfs path with a quick mount,
>     if this check fails, report warning to user.
> 
> Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
> ---
>  src/kimchi/utils.py | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/src/kimchi/utils.py b/src/kimchi/utils.py
> index af245c6..781525b 100644
> --- a/src/kimchi/utils.py
> +++ b/src/kimchi/utils.py
> @@ -96,3 +96,11 @@ def check_url_path(path):
>          return False
> 
>      return True
> +
> +
> +def parse_cmd_output(output, output_items):
> +    res = []
> +    for line in output.split("\n"):
> +        res.append(dict(zip(output_items, line.split())))
> +
> +    return res
> 

This function looks useful. I think it deserves a better name. May I
suggest def parse_table_text(output, keys): ... ?
-- 
Thanks and best regards!

Zhou Zheng Sheng / 周征晟
E-mail: zhshzhou at linux.vnet.ibm.com
Telephone: 86-10-82454397




More information about the Kimchi-devel mailing list