def create_image (_qemu_img_path, _image, _t = _tracer, _e = _enforcer) : _outcome = None if _outcome is None : if _qemu_img_path is None : _qemu_img_path = default_qemu_img_path _outcome = check_qemu_img_path (_qemu_img_path, _t = _t, _e = _e) if _outcome : _outcome = None if _outcome is None : _outcome = validate_image_definition (_image, null_uuid_allowed = True, _t = _t, _e = _e) if _outcome : _outcome = None if _outcome is None : if os_path.exists (_image.path) : _outcome = _failed ('image file already exists', format = _image.format, size = _image.size, path = _image.path, __log = _t.e) if _outcome is None : if not os_path.exists (os_path.dirname (_image.path)) : _outcome = _failed ('image directory does not exist', format = _image.format, size = _image.size, path = _image.path, __log = _t.e) if _outcome is None : if not os_path.isdir (os_path.dirname (_image.path)) : _outcome = _failed ('image directory is not a directory', format = _image.format, size = _image.size, path = _image.path, __log = _t.e) if _outcome is None : _qemu_img_arguments = build_qemu_img_create_arguments (_qemu_img_path, _image, _t = _t, _e = _e) if _outcome is None : _t.d and _t.d ('creating image', format = _image.format, size = _image.size, path = _image.path, qemu_img_path = _qemu_img_path, qemu_img_arguments = _qemu_img_arguments) _outcome = processes.execute_and_wait (_qemu_img_path, _qemu_img_arguments, _t = _t, _e = _e) if not _outcome : _outcome = _failed ('error encountered while executing `qemu-img`', format = _image.format, size = _image.size, path = _image.path, qemu_img_path = _qemu_img_path, qemu_img_arguments = _qemu_img_arguments, __log = _t.e) elif _outcome.exit != 0 : _outcome = _failed ('error encountered while creating image file', format = _image.format, size = _image.size, path = _image.path, qemu_img_path = _qemu_img_path, qemu_img_arguments = _qemu_img_arguments, exit = _outcome.exit, stdout = _outcome.stdout, stderr = _outcome.stderr, __log = _t.e) else : _outcome = None if _outcome is None : _outcome = _succeeded (__log = _t.d) return _outcome
def inspect_image (_qemu_img_path, _image_path, _t = _tracer, _e = _enforcer) : _e and _e.enforce_string (_image_path) _outcome = None if _outcome is None : if _qemu_img_path is None : _qemu_img_path = default_qemu_img_path _outcome = check_qemu_img_path (_qemu_img_path, _t = _t, _e = _e) if _outcome : _outcome = None if _outcome is None : if not os_path.exists (_image_path) : _outcome = _failed ('image file does not exist', path = _image_path, __log = _t.e) if _outcome is None : if not os_path.isfile (_image_path) : _outcome = _failed ('image file is not a file', path = _image_path, __log = _t.e) if _outcome is None : _qemu_img_arguments = build_qemu_img_info_arguments (_qemu_img_path, _image_path, _t = _t, _e = _e) if _outcome is None : _t.d and _t.d ('inspecting image', path = _image_path, qemu_img_path = _qemu_img_path, qemu_img_arguments = _qemu_img_arguments) _outcome = processes.execute_and_wait (_qemu_img_path, _qemu_img_arguments, _t = _t, _e = _e) if not _outcome : _outcome = _failed ('error encountered while executing `qemu-img`', path = _image_path, qemu_img_path = _qemu_img_path, qemu_img_arguments = _qemu_img_arguments, __log = _t.e) elif _outcome.exit != 0 : _outcome = _failed ('error encountered while inspecting image file', path = _image_path, qemu_img_path = _qemu_img_path, qemu_img_arguments = _qemu_img_arguments, exit = _outcome.exit, stdout = _outcome.stdout, stderr = _outcome.stderr, __log = _t.e) else : _qemu_img_output = _outcome.stdout _outcome = None if _outcome is None : _outcome = parse_qemu_img_info_output (_image_path, _qemu_img_output, _t = _t, _e = _e) if _outcome is None : _outcome = _succeeded (__log = _t.d) return _outcome