Skip to content

Commit 5f0cf31

Browse files
sri-srikanthaesteve-rh
authored andcommitted
Option for custom disk description implemented
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>
1 parent 866e3e6 commit 5f0cf31

4 files changed

Lines changed: 19 additions & 2 deletions

File tree

ovirt_imageio/client/_options.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,14 @@ class Parser:
178178
default="warning",
179179
help=(f"Log level (choices: {log_level}, default: warning)."),
180180
),
181+
Option(
182+
name="description",
183+
args=["-d", "--description"],
184+
config=True,
185+
required=False,
186+
type=str,
187+
default="Uploaded by ovirt-img",
188+
),
181189
]
182190

183191
def __init__(self):

ovirt_imageio/client/_ovirt.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ def find_disk(con, disk_id):
5959

6060
def add_disk(con, name, provisioned_size, sd_name, id=None,
6161
initial_size=None, sparse=True, enable_backup=True,
62-
content_type=DATA, format=COW, timeout=ADD_DISK_TIMEOUT):
62+
content_type=DATA, description="Uploaded by ovirt-img",
63+
format=COW, timeout=ADD_DISK_TIMEOUT):
6364
"""
6465
Add a new disk to the storage domain, based on the source image
6566
information provided.
@@ -76,6 +77,7 @@ def add_disk(con, name, provisioned_size, sd_name, id=None,
7677
enable_backup (bool): Disk can be used for incremental backups.
7778
content_type (ovirtsdk4.types.DiskContentType): Content type for the
7879
new disk.
80+
description (str, optional): description for the new disk.
7981
format (ovirtsdk4.types.DiskFormat): Format of the new disk.
8082
timeout (int, optional): number of seconds to wait for
8183
disk to be created.
@@ -95,7 +97,7 @@ def add_disk(con, name, provisioned_size, sd_name, id=None,
9597
id=id,
9698
name=name,
9799
content_type=content_type,
98-
description='Uploaded by ovirt-img',
100+
description=description,
99101
format=format,
100102
initial_size=initial_size,
101103
provisioned_size=provisioned_size,

ovirt_imageio/client/_upload.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def upload_disk(args):
8484
sparse=disk_info.sparse,
8585
enable_backup=disk_info.format == _ovirt.COW,
8686
content_type=disk_info.content_type,
87+
description=args.description,
8788
format=disk_info.format,
8889
timeout=args.disk_timeout)
8990

test/client_options_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def config(tmpdir, monkeypatch):
122122
disk_timeout = 200
123123
log_file = /var/log/ovirt-img/engine.log
124124
log_level = info
125+
description = Uploaded by ovirt-img config
125126
126127
[required]
127128
engine_url = https://engine.com
@@ -168,6 +169,7 @@ def test_config_all(config):
168169
assert args.log_level == "info"
169170
assert args.max_workers == 4
170171
assert args.buffer_size == 4 * MiB
172+
assert args.description == "Uploaded by ovirt-img config"
171173

172174
# Use password from config.
173175
assert args.password_file is None
@@ -189,6 +191,7 @@ def test_config_all_override(config, tmpdir):
189191
"--cafile", "/engine2.pem",
190192
"--log-file", "test.log",
191193
"--log-level", "debug",
194+
"--description", "Uploaded by ovirt-img command line"
192195
])
193196
assert args.engine_url == "https://engine2.com"
194197
assert args.username == "username2"
@@ -200,6 +203,7 @@ def test_config_all_override(config, tmpdir):
200203
assert args.log_level == "debug"
201204
assert args.max_workers == 4
202205
assert args.buffer_size == 4 * MiB
206+
assert args.description == "Uploaded by ovirt-img command line"
203207

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

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

257263
# Read password from --password-file.
258264
assert args.password_file == password_file

0 commit comments

Comments
 (0)