Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 04597f9

Browse files
committed
virt-install: --disk: make path= optional
1 parent 33b976a commit 04597f9

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

man/en/virt-install.pod.in

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,11 @@ general format of a disk string is
377377

378378
--disk opt1=val1,opt2=val2,...
379379

380-
To specify media, one of the following options is required:
380+
To specify media, the command can either be:
381+
382+
--disk /some/storage/path,opt1=val1
383+
384+
or explicitly specify one of the following arguments:
381385

382386
=over 4
383387

@@ -726,7 +730,7 @@ the rest of the options.
726730
# virt-install \
727731
--name demo
728732
--ram 512
729-
--disk path=/home/user/VMs/mydisk.img
733+
--disk /home/user/VMs/mydisk.img
730734
--import
731735

732736
=head1 AUTHORS

tests/clitest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@
146146
"--disk path=%(ROIMG)s,perms=ro",
147147
# Using RO path with cdrom dev
148148
"--disk path=%(ROIMG)s,device=cdrom",
149+
# Not specifying path=
150+
"--disk %(EXISTIMG1)s",
151+
# Not specifying path= but creating storage
152+
"--disk %(NEWIMG1)s,format=raw,size=.0000001",
149153
],
150154

151155
"invalid": [
@@ -175,6 +179,8 @@
175179
"--disk path=%(MANAGEDNEW1)s,format=frob,size=.0000001",
176180
# Managed disk using any format
177181
"--disk path=%(MANAGEDDISKNEW1)s,format=raw,size=.0000001",
182+
# Not specifying path= and non existent storage w/ no size
183+
"--disk %(NEWIMG1)s",
178184
]
179185
}, # category "storage"
180186

virt-install

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,19 @@ def parse_disk_option(guest, path, size):
161161

162162
# Strip media type
163163
path, ignore, optstr = partition(path, ",")
164+
path_type = None
164165
if path.startswith("path="):
165166
path_type = "path="
166167
elif path.startswith("vol="):
167168
path_type = "vol="
168169
elif path.startswith("pool="):
169170
path_type = "pool="
171+
172+
if path_type:
173+
path = path[len(path_type):]
170174
else:
171-
fail(_("--disk path must start with path=, pool=, or vol=."))
172-
path = path[len(path_type):]
175+
# Allow a default fallback mode --disk /some/path,foo,rah
176+
path_type = "path="
173177

174178
# Parse out comma separated options
175179
opts = cli.parse_optstr(optstr)
@@ -209,6 +213,7 @@ def parse_disk_option(guest, path, size):
209213
abspath = os.path.abspath(path)
210214
if os.path.dirname(abspath) == DEFAULT_POOL_PATH:
211215
build_default_pool(guest)
216+
212217
elif path_type == "pool=":
213218
if not size:
214219
raise ValueError(_("Size must be specified with all 'pool='"))

0 commit comments

Comments
 (0)