Skip to content

Commit 8435246

Browse files
committed
finish up #38 & #39
1 parent f6a2308 commit 8435246

File tree

3 files changed

+38
-36
lines changed

3 files changed

+38
-36
lines changed

README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ upvm might not be for you if:
1515
- you already have all the images you need in a RHEV environment
1616
- you want to spin up new machines in an OpenStack cloud
1717

18+
#### I don't like image files! LVM is the best!
19+
I used to use LVM for all my VMs too ... so upvm can use `virt-builder` to generate an image and then write that image out to a block device you specify with the `--primary-blockdev` option. This optional feature of course requires some sudo access (to run [dd-helper.py](https://github.com/ryran/upvm/blob/master/dd-helper.py) as root) which upvm will walk you through the first time you do it.
20+
1821
## Install
1922

2023
#### yum/dnf (RPM) install in RHEL 7.2+ or Fedora 22+:
@@ -51,20 +54,20 @@ Are you annoyed with always having to open the `virt-manager` GUI to do stuff wi
5154
## Help page
5255

5356
```
54-
$ upvm --help
5557
usage: upvm [--loglevel {debug,info,error}] [--build-image-only] [--nocolor]
5658
[--noconsole] [--cachedir VBCACHEDIR] [-h] [--help] [-l]
5759
[--arch {x86_64,i386,i686,ia64,armv71,ppc,ppc64,ppc64le,aarch64,sparc64,s390,s390x}]
5860
[--info] [-n VMNAME] [--os-variant OS] [--root-password SELECTOR]
5961
[--dnsdomain DOMAIN] [--hostname HOSTNAME | --hostname-prompt]
6062
[--no-dhcphostname] [--img-dir DIR] [--img-size SIZE]
6163
[--img-format {auto,raw,qcow2}] [--timezone TIMEZONE]
62-
[--rhsm-key ORGID:KEY] [--ssh-pubkey FILE] [--upload FILE:DEST]
63-
[--run SCRIPT] [--run-command CMD+ARGS] [--firstboot SCRIPT]
64+
[--ssh-pubkey FILE] [--upload FILE:DEST] [--run SCRIPT]
65+
[--run-command CMD+ARGS] [--firstboot SCRIPT]
6466
[--firstboot-command CMD+ARGS] [--install PKG,PKG,@GROUP...]
6567
[--firstboot-install PKG,PKG,@GROUP...] [--selinux-relabel]
66-
[--vbuilder-arg ARG] [-m OPTIONS] [-c OPTIONS] [-d OPTIONS]
67-
[-w OPTIONS] [--boot OPTIONS | --uefi] [--vinstall-arg ARG]
68+
[--vbuilder-arg ARG] [--primary-blockdev BLOCKDEV] [-m OPTIONS]
69+
[-c OPTIONS] [-d OPTIONS] [-w OPTIONS] [--boot OPTIONS | --uefi]
70+
[--vinstall-arg ARG]
6871
[TEMPLATE]
6972
7073
Leverage virt-builder & virt-install to spin up new VMs with ease
@@ -149,17 +152,6 @@ TOTALLY OPTIONAL OS-LEVEL OPTIONS:
149152
syntax, i.e., paths rooted in /usr/share/zoneinfo,
150153
e.g.: 'Europe/London' or 'America/Los_Angeles' or
151154
'Asia/Calcutta')
152-
--rhsm-key ORGID:KEY With or without this option, upvm creates a
153-
/root/register script inside the guest which can be
154-
used to interactively register to RHN Classic or RHSM;
155-
this option edits that script to include an RHSM
156-
activation key created by you at
157-
access.redhat.com/management/activation_keys -- i.e.,
158-
so the script can be run without requiring a
159-
user/password (to use this option, specify both the
160-
organization ID and the activation key, e.g.,
161-
'0123456789:my_activation_key'); IMPORTANT NOTE: this
162-
does not run the /root/register script for you
163155
--ssh-pubkey FILE Inject specific ssh pubkeys (option may be used more
164156
than once) into the /root/.ssh/authorized_keys file of
165157
the guest (default: contents of local
@@ -201,10 +193,18 @@ TOTALLY OPTIONAL OS-LEVEL OPTIONS:
201193
in=/localpath:/mnt/remote')
202194
203195
TOTALLY OPTIONAL HARDWARE-LEVEL (VM) OPTIONS:
204-
Guest hardware configured by virt-install (after image is built). Each option
205-
corresponds with virt-install option of same name. More configurability is
196+
Guest hardware configured by virt-install (after image is built). Most options
197+
correspond with virt-install options of same name. More configurability is
206198
possible than described. See virt-install man page.
207199
200+
--primary-blockdev BLOCKDEV
201+
To use this option, specify a BLOCKDEV like
202+
'/dev/sdb2' or '/dev/vg/logvol' and then in that case,
203+
the image generated by virt-builder [using the above
204+
options] will be written to BLOCKDEV and then deleted;
205+
the first time you try this as a non-root user, upvm
206+
will exit with a warning explaining how to add the
207+
appropriate sudo access to the dd helper-wrapper
208208
-m, --memory OPTIONS If this option is omitted, the guest will be defined
209209
with a RAM allocation of 1024 MiB; in its simplest
210210
form OPTIONS can be the amount of RAM in MiB; more
@@ -262,6 +262,6 @@ ABOUT CONFIG FILES:
262262
override config file values which override defaults.
263263
264264
VERSION:
265-
upvm v0.10.5 last mod 2016/02/14
265+
upvm v0.10.6 last mod 2016/02/16
266266
See <http://github.com/ryran/upvm> to report bugs or RFEs
267267
```

dd-helper.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,20 @@
1616
# limitations under the License.
1717
#-------------------------------------------------------------------------------
1818

19-
# Modules from standard library
20-
from subprocess import call
19+
import subprocess
2120
from sys import argv, exit
22-
if len(argv) != 3:
23-
print("Improper arguments")
21+
from os import devnull
22+
outfile, infile = argv[1], argv[2]
23+
null = open(devnull, 'w')
24+
rc = subprocess.call(['findmnt', '-no', 'target', outfile], stdout=null, stderr=null)
25+
if rc == 0:
26+
# If findmnt reports outfile is mounted
2427
exit(2)
25-
cmd = [
26-
'nice', '-n', '19',
27-
'dd',
28-
'of={}'.format(argv[1]),
29-
'if={}'.format(argv[2]),
30-
'bs=1M',
31-
]
32-
rc = call(cmd)
33-
exit(rc)
28+
lsof = subprocess.Popen(['nice', 'lsof', '-tlS', outfile], stdout=subprocess.PIPE, stderr=null)
29+
output = lsof.communicate()[0]
30+
if output:
31+
# If lsof reports anything using our outfile
32+
exit(3)
33+
null.close()
34+
dd = ['nice', 'dd', 'of={}'.format(outfile), 'if={}'.format(infile), 'bs=1M']
35+
exit(subprocess.call(dd))

modules/argparser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ def parse():
190190
grpAA.add_argument(
191191
'--timezone',
192192
help="Set system timezone inside the OS (use traditional syntax, i.e., paths rooted in /usr/share/zoneinfo, e.g.: 'Europe/London' or 'America/Los_Angeles' or 'Asia/Calcutta')")
193-
grpAA.add_argument(
194-
'--rhsm-key', metavar='ORGID:KEY',
195-
help="With or without this option, {} creates a /root/register script inside the guest which can be used to interactively register to RHN Classic or RHSM; this option edits that script to include an RHSM activation key created by you at access.redhat.com/management/activation_keys -- i.e., so the script can be run without requiring a user/password (to use this option, specify both the organization ID and the activation key, e.g., '0123456789:my_activation_key'); IMPORTANT NOTE: this does not run the /root/register script for you".format(cfg.prog))
193+
# grpAA.add_argument(
194+
# '--rhsm-key', metavar='ORGID:KEY',
195+
# help="With or without this option, {} creates a /root/register script inside the guest which can be used to interactively register to RHN Classic or RHSM; this option edits that script to include an RHSM activation key created by you at access.redhat.com/management/activation_keys -- i.e., so the script can be run without requiring a user/password (to use this option, specify both the organization ID and the activation key, e.g., '0123456789:my_activation_key'); IMPORTANT NOTE: this does not run the /root/register script for you".format(cfg.prog))
196196
grpAA.add_argument(
197197
'--ssh-pubkey', metavar='FILE', action='append',
198198
default=['~/.ssh/authorized_keys', '~/.ssh/id_[dr]sa.pub', '~/.ssh/id_ecdsa.pub', '~/.ssh/id_ed25519.pub'],
@@ -230,7 +230,7 @@ def parse():
230230
description="Guest hardware configured by virt-install (after image is built). Most options\ncorrespond with virt-install options of same name. More configurability is\npossible than described. See virt-install man page.")
231231
grpBB.add_argument(
232232
'--primary-blockdev', metavar='BLOCKDEV',
233-
help="To use this option, specify a BLOCKDEV like '/dev/sdb2' or '/dev/vg/logvol' and then in that case, the image generated by virt-builder [using the above options] will be written to BLOCKDEV and then deleted; the first time you try this as a non-root user, {} will exit with a warning explaining how to add the appropriate sudo access".format(cfg.prog))
233+
help="To use this option, specify a BLOCKDEV like '/dev/sdb2' or '/dev/vg/logvol' and then in that case, the image generated by virt-builder [using the above options] will be written to BLOCKDEV and then deleted; the first time you try this as a non-root user, {} will exit with a warning explaining how to add the appropriate sudo access to the dd helper-wrapper".format(cfg.prog))
234234
grpBB.add_argument(
235235
'-m', '--memory', metavar='OPTIONS', default=1024,
236236
help="If this option is omitted, the guest will be defined with a RAM allocation of 1024 MiB; in its simplest form OPTIONS can be the amount of RAM in MiB; more complicated example: '-m 512,maxmemory=4096' (which would set the default to 512 MiB but allow raising up to 4 GiB without powering off)")

0 commit comments

Comments
 (0)