Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option for custom disk description implemented #207

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ovirt_imageio/client/_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ class Parser:
default="warning",
help=(f"Log level (choices: {log_level}, default: warning)."),
),
Option(
name="description",
args=["-d", "--description"],
config=True,
required=False,
type=str,
default="Uploaded by ovirt-img",
aesteve-rh marked this conversation as resolved.
Show resolved Hide resolved
),
]

def __init__(self):
Expand Down
6 changes: 4 additions & 2 deletions ovirt_imageio/client/_ovirt.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def find_disk(con, disk_id):

def add_disk(con, name, provisioned_size, sd_name, id=None,
initial_size=None, sparse=True, enable_backup=True,
content_type=DATA, format=COW, timeout=ADD_DISK_TIMEOUT):
content_type=DATA, description="Uploaded by ovirt-img",
format=COW, timeout=ADD_DISK_TIMEOUT):
"""
Add a new disk to the storage domain, based on the source image
information provided.
Expand All @@ -76,6 +77,7 @@ def add_disk(con, name, provisioned_size, sd_name, id=None,
enable_backup (bool): Disk can be used for incremental backups.
content_type (ovirtsdk4.types.DiskContentType): Content type for the
new disk.
description (str, optional): description for the new disk.
format (ovirtsdk4.types.DiskFormat): Format of the new disk.
timeout (int, optional): number of seconds to wait for
disk to be created.
Expand All @@ -95,7 +97,7 @@ def add_disk(con, name, provisioned_size, sd_name, id=None,
id=id,
name=name,
content_type=content_type,
description='Uploaded by ovirt-img',
description=description,
format=format,
initial_size=initial_size,
provisioned_size=provisioned_size,
Expand Down
1 change: 1 addition & 0 deletions ovirt_imageio/client/_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def upload_disk(args):
sparse=disk_info.sparse,
enable_backup=disk_info.format == _ovirt.COW,
content_type=disk_info.content_type,
description=args.description,
format=disk_info.format,
timeout=args.disk_timeout)

Expand Down
6 changes: 6 additions & 0 deletions test/client_options_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def config(tmpdir, monkeypatch):
disk_timeout = 200
log_file = /var/log/ovirt-img/engine.log
log_level = info
description = Uploaded by ovirt-img config

[required]
engine_url = https://engine.com
Expand Down Expand Up @@ -168,6 +169,7 @@ def test_config_all(config):
assert args.log_level == "info"
assert args.max_workers == 4
assert args.buffer_size == 4 * MiB
assert args.description == "Uploaded by ovirt-img config"

# Use password from config.
assert args.password_file is None
Expand All @@ -189,6 +191,7 @@ def test_config_all_override(config, tmpdir):
"--cafile", "/engine2.pem",
"--log-file", "test.log",
"--log-level", "debug",
"--description", "Uploaded by ovirt-img command line"
])
assert args.engine_url == "https://engine2.com"
assert args.username == "username2"
Expand All @@ -200,6 +203,7 @@ def test_config_all_override(config, tmpdir):
assert args.log_level == "debug"
assert args.max_workers == 4
assert args.buffer_size == 4 * MiB
assert args.description == "Uploaded by ovirt-img command line"

# --password-file overrides password from config.
assert args.password_file == str(password_file)
Expand All @@ -222,6 +226,7 @@ def test_config_required(config, monkeypatch):
assert args.log_level == "warning"
assert args.max_workers == 4
assert args.buffer_size == 4 * MiB
assert args.description == "Uploaded by ovirt-img"

# No --password-file or config password: use getpass.getpass().
assert args.password_file is None
Expand Down Expand Up @@ -253,6 +258,7 @@ def test_config_required_override(config, tmpdir):
assert args.log_level == "debug"
assert args.max_workers == 4
assert args.buffer_size == 4 * MiB
assert args.description == "Uploaded by ovirt-img"

# Read password from --password-file.
assert args.password_file == password_file
Expand Down
Loading