|
13 | 13 |
|
14 | 14 | BASEDIR = '/usr/local/share/libvirt'
|
15 | 15 | IMAGE_DIR = '/var/lib/libvirt/images'
|
| 16 | +RAMDISK_DIR = '' |
16 | 17 |
|
17 | 18 | # bridge interface directly connected to the Internet (or your intranet)
|
18 | 19 | # It can be configured by the config file
|
@@ -89,12 +90,19 @@ def getImageFormat(image):
|
89 | 90 | return fmt.split(': ')[1]
|
90 | 91 |
|
91 | 92 |
|
92 |
| -def copyImage(base, image): |
| 93 | +def copyImage(base, image, use_ramdisk=False): |
93 | 94 | src_path = os.path.join(BASEIMAGE_DIR, base)
|
94 | 95 | dst_path = os.path.join(IMAGE_DIR, image)
|
| 96 | + if use_ramdisk and RAMDISK_DIR: |
| 97 | + ramdisk_dir = RAMDISK_DIR |
| 98 | + else: |
| 99 | + ramdisk_dir = '' |
95 | 100 | print 'Copying %s -> %s...' % (os.path.basename(base),
|
96 | 101 | os.path.basename(image))
|
97 |
| - callCmdAsRoot(CMD_COPY_IMAGE, src_path, dst_path, direct_stderr=True) |
| 102 | + if ramdisk_dir: |
| 103 | + print '(using ramdisk dir %s)' % ramdisk_dir |
| 104 | + callCmdAsRoot(CMD_COPY_IMAGE, src_path, dst_path, ramdisk_dir, |
| 105 | + direct_stderr=True) |
98 | 106 |
|
99 | 107 |
|
100 | 108 | def setHostnameToImage(image, name):
|
@@ -182,9 +190,12 @@ def parseArgs():
|
182 | 190 | parser.add_argument('-i', '--nic', action='append', default=[],
|
183 | 191 | help='NIC (bridge_name or "NAT").'
|
184 | 192 | ' Specify multiple times if you want multiple vNICs.')
|
185 |
| - parser.add_argument('--no-hostname', action='store_false', |
| 193 | + parser.add_argument('-H', '--no-hostname', action='store_false', |
186 | 194 | dest='set_hostname',
|
187 | 195 | help='Do not set hostname of VM.')
|
| 196 | + parser.add_argument('-r', '--use-ramdisk', action='store_true', |
| 197 | + dest='use_ramdisk', |
| 198 | + help='Place VM image to ramdisk (if ramdisk is configured).') |
188 | 199 | args = parser.parse_args()
|
189 | 200 |
|
190 | 201 | if args.BASEIMAGE == '?' or args.BASEIMAGE.upper() == 'LIST':
|
@@ -213,6 +224,9 @@ def loadConfig():
|
213 | 224 | if conf.has_option('default', 'public_bridge'):
|
214 | 225 | global PUBLIC_BRIDGE
|
215 | 226 | PUBLIC_BRIDGE = conf.get('default', 'public_bridge')
|
| 227 | + if conf.has_option('default', 'ramdisk_dir'): |
| 228 | + global RAMDISK_DIR |
| 229 | + RAMDISK_DIR = conf.get('default', 'ramdisk_dir') |
216 | 230 |
|
217 | 231 |
|
218 | 232 | def getAliasNames(name):
|
@@ -341,7 +355,7 @@ def main():
|
341 | 355 |
|
342 | 356 | generateLibvirtXML(args, libvirt_xml)
|
343 | 357 | defineDomain(libvirt_xml)
|
344 |
| - copyImage(base_abspath, dest_abspath) |
| 358 | + copyImage(base_abspath, dest_abspath, args.use_ramdisk) |
345 | 359 | if args.set_hostname and image_fmt != 'raw':
|
346 | 360 | setHostnameToImage(dest_abspath, args.NAME)
|
347 | 361 | deleteLibvirtXML(libvirt_xml)
|
|
0 commit comments