class VMTemplate(object): _bus_to_dev = {'ide': 'hd', 'virtio': 'vd', 'scsi': 'sd'} def __init__(self, args, scan=False): """ Construct a VM Template from a widely variable amount of information. The only required parameter is a name for the VMTemplate. If present, the os_distro and os_version fields are used to lookup recommended settings. Any parameters provided by the caller will override the defaults. If scan is True and a cdrom is present, the operating system will be detected by probing the installation media. """ self.name = args['name'] self.info = {} # Identify the cdrom if present iso_distro = iso_version = None if scan: iso = args.get('cdrom') if iso is not None and iso.startswith('/'): try: iso_distro, iso_version = isoinfo.probe_one(iso) except isoinfo.IsoFormatError, e: raise InvalidParameter(e) # Fetch defaults based on the os distro and version os_distro = args.get('os_distro', iso_distro) os_version = args.get('os_version', iso_version) name, entry = osinfo.lookup(os_distro, os_version) self.info.update(entry) # Override with the passed in parameters self.info.update(args)
def __init__(self, args, scan=False): """ Construct a VM Template from a widely variable amount of information. The only required parameter is a name for the VMTemplate. If present, the os_distro and os_version fields are used to lookup recommended settings. Any parameters provided by the caller will override the defaults. If scan is True and a cdrom is present, the operating system will be detected by probing the installation media. """ self.name = args['name'] self.info = {} # Identify the cdrom if present iso_distro = iso_version = None if scan: iso = args.get('cdrom') if iso is not None and iso.startswith('/'): iso_distro, iso_version = isoinfo.probe_one(iso) # Fetch defaults based on the os distro and version os_distro = args.get('os_distro', iso_distro) os_version = args.get('os_version', iso_version) name, entry = osinfo.lookup(os_distro, os_version) self.info.update(entry) # Override with the passed in parameters self.info.update(args)
def __init__(self, args, scan=False): """ Construct a VM Template from a widely variable amount of information. The only required parameter is a name for the VMTemplate. If present, the os_distro and os_version fields are used to lookup recommended settings. Any parameters provided by the caller will override the defaults. If scan is True and a cdrom or a base img is present, the operating system will be detected by probing the installation media. """ self.info = {} self.fc_host_support = args.get('fc_host_support') # Fetch defaults based on the os distro and version try: distro, version = self._get_os_info(args, scan) except ImageFormatError as e: raise OperationFailed('KCHTMPL0020E', {'err': e.message}) os_distro = args.get('os_distro', distro) os_version = args.get('os_version', version) entry = osinfo.lookup(os_distro, os_version) self.info.update(entry) # Auto-generate a template name if no one is passed if 'name' not in args or args['name'] == '': args['name'] = self._gen_name(distro, version) self.name = args['name'] # Merge graphics settings graph_args = args.get('graphics') if graph_args: graphics = dict(self.info['graphics']) graphics.update(graph_args) args['graphics'] = graphics # Merge disks dict default_disk = self.info['disks'][0] for i, d in enumerate(args.get('disks', [])): disk = dict(default_disk) disk.update(d) # Assign right disk format to logical and [i]scsi storagepools if self._get_storage_type() in ['logical', 'iscsi', 'scsi']: disk['format'] = 'raw' args['disks'][i] = disk # Override template values according to 'args' self.info.update(args)