@@ -60,7 +60,17 @@ def generate_mac_addr():
6060 return ':' .join ('{:02x}' .format (random_byte (i )) for i in range (MAC_BYTES ))
6161
6262
63- def create_vm (name , memory , vcpus , vg , os_type , os_variant , network , mac , skip_config ):
63+ def gen_ceph_disk_param (ceph_pool , size ):
64+ """Generates the --disk argument to virt-install for a Ceph VM in the given pool"""
65+ return 'pool={},size={}' .format (ceph_pool , size )
66+
67+
68+ def gen_lvm_disk_param (name , vg ):
69+ """Generates the --disk argument to virt-install for an LVM VM in the given VG"""
70+ return '/dev/{}/{},cache=none' .format (vg , name )
71+
72+
73+ def create_vm (name , memory , vcpus , disk_arg , os_type , os_variant , network , mac , skip_config ):
6474 """Creates a new VM."""
6575
6676 # 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
7787 'when the install is complete, or else the VM configuration cannot continue.' )
7888
7989 exec_cmd ('virt-install' , '-r' , str (memory ), '--pxe' , '--os-type' , os_type ,
80- '--os-variant' , os_variant , '--disk' , '/dev/{}/{},cache=none' . format ( vg , name ),
81- '--vcpus' , str ( vcpus ), '-- network' , network + ',mac=' + mac , '--graphics' , 'vnc' ,
82- '--serial' , ' pty' , '--name' , name , '--wait' , '0' if skip_config else '-1' )
90+ '--os-variant' , os_variant , '--disk' , disk_arg , '--vcpus' , str ( vcpus ),
91+ '--network' , network + ',mac=' + mac , '--graphics' , 'vnc' , '--serial ' ,
92+ 'pty' , '--name' , name , '--wait' , '0' if skip_config else '-1' )
8393
8494
8595def get_running_vms ():
@@ -201,6 +211,10 @@ def _main(args):
201211 help = 'amount of disk storage (in GB)' )
202212 parser .add_argument ('-V' , '--vg' , type = str , default = 'vg' ,
203213 help = 'LVM volume group to use for storage' )
214+ parser .add_argument ('-C' , '--ceph' , action = 'store_true' , default = False ,
215+ help = 'use Ceph storage instead of LVM' )
216+ parser .add_argument ('-P' , '--ceph-pool' , type = str , default = 'vm' ,
217+ help = 'Ceph Pool to use for storage' )
204218 parser .add_argument ('--os-type' , type = str , default = 'linux' ,
205219 help = 'os type' )
206220 parser .add_argument ('--os-variant' , type = str , default = 'debian9' )
@@ -262,7 +276,12 @@ def _main(args):
262276 print ('\t OS Type: {}' .format (args .os_type ))
263277 print ('\t OS Variant: {}' .format (args .os_variant ))
264278 print ('\t Disk Space: {} GB' .format (args .storage ))
265- print ('\t Volume Group: {}' .format (args .vg ))
279+ if args .ceph :
280+ print ('\t Backing Storage: Ceph' )
281+ print ('\t Ceph Pool: {}' .format (args .ceph_pool ))
282+ else :
283+ print ('\t Backing Storage: LVM' )
284+ print ('\t Volume Group: {}' .format (args .vg ))
266285 print ('\t Memory: {} MB' .format (args .memory ))
267286 print ('\t vCPUs: {}' .format (args .vcpus ))
268287 print ('\t Network: {}' .format (args .network ))
@@ -273,8 +292,14 @@ def _main(args):
273292
274293 mac = generate_mac_addr ()
275294
276- create_disk (args .vg , args .hostname , args .storage )
277- create_vm (args .hostname , args .memory , args .vcpus , args .vg , args .os_type ,
295+ disk_param = None
296+ if not args .ceph :
297+ create_disk (args .vg , args .hostname , args .storage )
298+ disk_param = gen_lvm_disk_param (args .hostname , args .vg )
299+ else :
300+ disk_param = gen_ceph_disk_param (args .ceph_pool , args .storage )
301+
302+ create_vm (args .hostname , args .memory , args .vcpus , disk_param , args .os_type ,
278303 args .os_variant , args .network , mac , args .skip_config )
279304
280305 if args .skip_config :
0 commit comments