Created
March 19, 2015 08:25
-
-
Save mogi/e0d9a988b5f0ee64f3a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# | |
# Get uuid by blkid output. | |
# :param blkid: str | |
# :param target: str | |
# :rtype :str | |
# | |
import json | |
import sys | |
import shlex | |
def _get_args_data(): | |
args_file = sys.argv[1] | |
args_data = file(args_file).read() | |
return shlex.split(args_data) | |
def _get_args(key): | |
value = None | |
for arg in _get_args_data(): | |
if key in arg: | |
value = arg.split(key)[1] | |
return value | |
def _error(): | |
print json.dumps({ | |
"failed": True, | |
"msg": "search failed" | |
}) | |
sys.exit(1) | |
def _get_uuid(): | |
str_obj = _get_args('blkid') | |
for line in str_obj.split(' '): | |
if not 'UUID' in line: | |
continue | |
return line.split('=')[1].strip('"') | |
else: | |
_error() | |
def _output(dict_obj): | |
print json.dumps(dict_obj) | |
sys.exit(0) | |
def main(): | |
result = _get_uuid() | |
_output({ | |
"value": result, | |
"changed": True | |
}) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment