From 6a3ffa1c6761485f332c84a06e0d1f820ec5c65a Mon Sep 17 00:00:00 2001 From: Frank Dai Date: Sat, 8 Feb 2020 17:51:15 -0800 Subject: [PATCH 1/5] Add ceph option to makevm --- staff/sys/makevm | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/staff/sys/makevm b/staff/sys/makevm index 9079675..9ef2ad9 100755 --- a/staff/sys/makevm +++ b/staff/sys/makevm @@ -60,7 +60,17 @@ def generate_mac_addr(): return ':'.join('{:02x}'.format(random_byte(i)) for i in range(MAC_BYTES)) -def create_vm(name, memory, vcpus, vg, os_type, os_variant, network, mac, skip_config): +def gen_ceph_disk_param(ceph_pool, size): + """Generates the --disk argument to virt-install for a Ceph VM in the given pool""" + return 'pool={},size={}'.format(ceph_pool, size) + + +def gen_lvm_disk_param(name, vg): + """Generates the --disk argument to virt-install for an LVM VM in the given VG""" + return '/dev/{}/{},cache=none'.format(vg, name) + + +def create_vm(name, memory, vcpus, disk_arg, os_type, os_variant, network, mac, skip_config): """Creates a new VM.""" # try to print info about the domain to see if it already exists @@ -77,9 +87,9 @@ def create_vm(name, memory, vcpus, vg, os_type, os_variant, network, mac, skip_c 'when the install is complete, or else the VM configuration cannot continue.') exec_cmd('virt-install', '-r', str(memory), '--pxe', '--os-type', os_type, - '--os-variant', os_variant, '--disk', '/dev/{}/{},cache=none'.format(vg, name), - '--vcpus', str(vcpus), '--network', network + ',mac=' + mac, '--graphics', 'vnc', - '--serial', 'pty', '--name', name, '--wait', '0' if skip_config else '-1') + '--os-variant', os_variant, '--disk', disk_arg, '--vcpus', str(vcpus), + '--network', network + ',mac=' + mac, '--graphics', 'vnc', '--serial', + 'pty', '--name', name, '--wait', '0' if skip_config else '-1') def get_running_vms(): @@ -201,6 +211,10 @@ def _main(args): help='amount of disk storage (in GB)') parser.add_argument('-V', '--vg', type=str, default='vg', help='LVM volume group to use for storage') + parser.add_argument('-C', '--ceph', action='store_true', default=False, + help='use Ceph storage instead of LVM') + parser.add_argument('-P', '--ceph-pool', type=str, default='vm', + help='Ceph Pool to use for storage') parser.add_argument('--os-type', type=str, default='linux', help='os type') parser.add_argument('--os-variant', type=str, default='debian9') @@ -262,7 +276,12 @@ def _main(args): print('\tOS Type: {}'.format(args.os_type)) print('\tOS Variant: {}'.format(args.os_variant)) print('\tDisk Space: {} GB'.format(args.storage)) - print('\tVolume Group: {}'.format(args.vg)) + if args.ceph: + print('\tBacking Storage: Ceph') + print('\tCeph Pool: {}'.format(args.ceph_pool)) + else: + print('\tBacking Storage: LVM') + print('\tVolume Group: {}'.format(args.vg)) print('\tMemory: {} MB'.format(args.memory)) print('\tvCPUs: {}'.format(args.vcpus)) print('\tNetwork: {}'.format(args.network)) @@ -273,8 +292,14 @@ def _main(args): mac = generate_mac_addr() - create_disk(args.vg, args.hostname, args.storage) - create_vm(args.hostname, args.memory, args.vcpus, args.vg, args.os_type, + disk_param = None + if not args.ceph: + create_disk(args.vg, args.hostname, args.storage) + disk_param = gen_lvm_disk_param(args.hostname, args.vg) + else: + disk_param = gen_ceph_disk_param(args.ceph_pool, args.storage) + + create_vm(args.hostname, args.memory, args.vcpus, disk_param, args.os_type, args.os_variant, args.network, mac, args.skip_config) if args.skip_config: From 0063654f75b9b6c80d640225fdaf7318fff164ef Mon Sep 17 00:00:00 2001 From: Frank Dai Date: Sat, 8 Feb 2020 17:53:35 -0800 Subject: [PATCH 2/5] Run update-symlinks --- sbin/add-to-group | 1 + 1 file changed, 1 insertion(+) create mode 120000 sbin/add-to-group diff --git a/sbin/add-to-group b/sbin/add-to-group new file mode 120000 index 0000000..f1a7efe --- /dev/null +++ b/sbin/add-to-group @@ -0,0 +1 @@ +../staff/acct/add-to-group \ No newline at end of file From b1d2f688472a5553b15cdbf6dcfbdb27e5c96928 Mon Sep 17 00:00:00 2001 From: Frank Dai Date: Sat, 8 Feb 2020 18:01:31 -0800 Subject: [PATCH 3/5] Change default makevm debian to 10 --- staff/sys/makevm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/staff/sys/makevm b/staff/sys/makevm index 9ef2ad9..4544a20 100755 --- a/staff/sys/makevm +++ b/staff/sys/makevm @@ -217,7 +217,7 @@ def _main(args): help='Ceph Pool to use for storage') parser.add_argument('--os-type', type=str, default='linux', help='os type') - parser.add_argument('--os-variant', type=str, default='debian9') + parser.add_argument('--os-variant', type=str, default='debian10') parser.add_argument('--network', type=str, default='bridge=br0', help='network configuration') parser.add_argument('--preseed-user', type=str, default='root', From fa1a64776c0b0f3934030c86f26371f81acc0c98 Mon Sep 17 00:00:00 2001 From: Frank Dai Date: Sat, 8 Feb 2020 22:14:02 -0500 Subject: [PATCH 4/5] Add more makevm checks --- staff/sys/makevm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/staff/sys/makevm b/staff/sys/makevm index 4544a20..9e78f19 100755 --- a/staff/sys/makevm +++ b/staff/sys/makevm @@ -256,6 +256,20 @@ def _main(args): print('Cancelled.') sys.exit(2) + if args.ceph and args.vg != 'vg': + print("Warning: You have Ceph backing storage, but specified a non-default VG") + + if not confirm(): + print('Cancelled.') + sys.exit(2) + + if not args.ceph and args.ceph_pool != 'vm': + print("Warning: You have LVM backing storage, but specified a Ceph pool") + + if not confirm(): + print('Cancelled.') + sys.exit(2) + # Check to make sure the IP address provided is an OCF IPv4 address ip_addr = ip_address(args.ip) if not is_ocf_ip(ip_addr) or not isinstance(ip_addr, IPv4Address): From 1b412d5e45790ded21db0941652c3793869df5b8 Mon Sep 17 00:00:00 2001 From: Frank Dai Date: Sat, 8 Feb 2020 22:21:08 -0500 Subject: [PATCH 5/5] Add more ceph sanity checks --- staff/sys/makevm | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/staff/sys/makevm b/staff/sys/makevm index 9e78f19..152b711 100755 --- a/staff/sys/makevm +++ b/staff/sys/makevm @@ -10,6 +10,7 @@ import os.path import random import re import shlex +import shutil import socket import subprocess import sys @@ -256,15 +257,22 @@ def _main(args): print('Cancelled.') sys.exit(2) + if args.ceph and not shutil.which('ceph'): + print("Warning: You are trying to use Ceph but I couldn't find the `ceph` executable.") + + if not confirm(): + print('Cancelled.') + sys.exit(2) + if args.ceph and args.vg != 'vg': - print("Warning: You have Ceph backing storage, but specified a non-default VG") + print('Warning: You have Ceph backing storage, but specified a non-default VG.') if not confirm(): print('Cancelled.') sys.exit(2) if not args.ceph and args.ceph_pool != 'vm': - print("Warning: You have LVM backing storage, but specified a Ceph pool") + print('Warning: You have LVM backing storage, but specified a Ceph pool.') if not confirm(): print('Cancelled.') @@ -307,11 +315,11 @@ def _main(args): mac = generate_mac_addr() disk_param = None - if not args.ceph: + if args.ceph: + disk_param = gen_ceph_disk_param(args.ceph_pool, args.storage) + else: create_disk(args.vg, args.hostname, args.storage) disk_param = gen_lvm_disk_param(args.hostname, args.vg) - else: - disk_param = gen_ceph_disk_param(args.ceph_pool, args.storage) create_vm(args.hostname, args.memory, args.vcpus, disk_param, args.os_type, args.os_variant, args.network, mac, args.skip_config)