Skip to content

Commit

Permalink
Option for custom disk description implemented
Browse files Browse the repository at this point in the history
Option to add a custom disk description implemented.
Changes made in ovirt_imageio/client/_ovirt.py's
add_disk and ovirt_imageio/client/upload.py's
upload_disk to incorporate a description variable,
along with test/client_options_test.py to test
config and command line usage of the new custom
description option.

Fixes: #118
Signed-off-by: sri-srikanth <srivatsansrikanth2018@gmail.com>
  • Loading branch information
sri-srikanth authored and aesteve-rh committed Jan 17, 2024
1 parent 866e3e6 commit 5f0cf31
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
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",
),
]

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

0 comments on commit 5f0cf31

Please sign in to comment.