Esempio n. 1
0
 def test_old_distros(self):
     old_versions = {'debian': '5.0', 'ubuntu': '7.04', 'opensuse': '10.1',
                     'centos': '5.1', 'rhel': '5.1', 'fedora': '15'}
     for distro, version in old_versions.iteritems():
         entry = lookup(distro, version)
         self.assertEquals(entry['disk_bus'], 'ide')
         self.assertEquals(entry['nic_model'], 'e1000')
Esempio n. 2
0
 def test_fedora_lookup(self):
     cd = ('http://fedora.mirrors.tds.net/pub/fedora/releases/17/Live/'
           'x86_64/Fedora-17-x86_64-Live-Desktop.iso')
     entry = lookup('fedora', '17')
     self.assertEquals(10, entry['disks'][0]['size'])
     self.assertEquals(cd, entry['cdrom'])
     self.assertEquals('/storagepools/default', entry['storagepool'])
Esempio n. 3
0
 def test_fedora_lookup(self):
     cd = ('http://fedora.mirrors.tds.net/pub/fedora/releases/17/Live/'
           'x86_64/Fedora-17-x86_64-Live-Desktop.iso')
     entry = lookup('fedora', '17')
     self.assertEquals(10, entry['disks'][0]['size'])
     self.assertEquals(cd, entry['cdrom'])
     self.assertEquals('/storagepools/default', entry['storagepool'])
Esempio n. 4
0
 def test_modern_bases(self):
     for distro, version in modern_version_bases[_get_arch()].iteritems():
         entry = lookup(distro, version)
         self.assertEquals(entry['disk_bus'],
                           get_template_default('modern', 'disk_bus'))
         self.assertEquals(entry['nic_model'],
                           get_template_default('modern', 'nic_model'))
Esempio n. 5
0
    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 and no one is passed
        if 'name' not in args or args['name'] == '':
            args['name'] = self._gen_name(distro, version)
        self.name = args['name']

        # Override with the passed in parameters
        graph_args = args.get('graphics')
        if graph_args:
            graphics = dict(self.info['graphics'])
            graphics.update(graph_args)
            args['graphics'] = graphics
        self.info.update(args)
Esempio n. 6
0
    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 = {}
        self.fc_host_support = args.get('fc_host_support')

        # Identify the cdrom if present
        iso_distro = iso_version = 'unknown'
        iso = args.get('cdrom', '')

        if scan and len(iso) > 0:
            iso_distro, iso_version = self.get_iso_info(iso)
            if not iso.startswith('/'):
                self.info.update({'iso_stream': True})

        # 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)
        entry = osinfo.lookup(os_distro, os_version)
        self.info.update(entry)

        # Override with the passed in parameters
        graph_args = args.get('graphics')
        if graph_args:
            graphics = dict(self.info['graphics'])
            graphics.update(graph_args)
            args['graphics'] = graphics
        self.info.update(args)
Esempio n. 7
0
def get_iface_xml(params, arch=None, os_distro=None, os_version=None):
    """
    <interface type='network'>
      <source network='default'/>
      <model type='virtio'/>
    </interface>
    """
    interface = E.interface(type=params['type'])
    interface.append(E.source(network=params['network']))

    model = params.get('model')

    # no model specified; let's try querying osinfo
    if model is None:
        # if os_distro and os_version are invalid, nic_model will also be None
        model = osinfo.lookup(os_distro, os_version).get('nic_model')

    # only append 'model' to the XML if it's been specified as a parameter or
    # returned by osinfo.lookup; otherwise let libvirt use its default value
    if model is not None:
        interface.append(E.model(type=model))

    mac = params.get('mac', None)
    if mac is not None:
        interface.append(E.mac(address=mac))

    # Hack to disable vhost feature in Ubuntu LE and SLES LE (PPC)
    if arch == 'ppc64' and \
       ((os_distro == 'ubuntu' and
         LooseVersion(os_version) >= LooseVersion('14.04')) or
        (os_distro == 'sles' and
         LooseVersion(os_version) >= LooseVersion('12'))):
        interface.append(E.driver(name='qemu'))

    return ET.tostring(interface, encoding='utf-8', pretty_print=True)
Esempio n. 8
0
 def test_modern_bases(self):
     for distro, version in modern_version_bases[_get_arch()].iteritems():
         entry = lookup(distro, version)
         self.assertEquals(entry['disk_bus'],
                           get_template_default('modern', 'disk_bus'))
         self.assertEquals(entry['nic_model'],
                           get_template_default('modern', 'nic_model'))
Esempio n. 9
0
    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
        distro, version = self._get_os_info(args, scan)
        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 and no one is passed
        if 'name' not in args or args['name'] == '':
            args['name'] = self._gen_name(distro, version)
        self.name = args['name']

        # Override with the passed in parameters
        graph_args = args.get('graphics')
        if graph_args:
            graphics = dict(self.info['graphics'])
            graphics.update(graph_args)
            args['graphics'] = graphics
        self.info.update(args)
Esempio n. 10
0
    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 = {}
        self.fc_host_support = args.get('fc_host_support')

        # Identify the cdrom if present
        iso_distro = iso_version = 'unknown'
        iso = args.get('cdrom', '')

        if scan and len(iso) > 0:
            iso_distro, iso_version = self.get_iso_info(iso)
            if not iso.startswith('/'):
                self.info.update({'iso_stream': True})

        # 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)
        entry = osinfo.lookup(os_distro, os_version)
        self.info.update(entry)

        # Override with the passed in parameters
        graph_args = args.get('graphics')
        if graph_args:
            graphics = dict(self.info['graphics'])
            graphics.update(graph_args)
            args['graphics'] = graphics
        self.info.update(args)
Esempio n. 11
0
 def test_lookup_unknown_distro_version_returns_old_distro(self):
     distro = 'unknown_distro'
     version = 'unknown_version'
     entry = lookup(distro, version)
     self.assertEquals(entry['disk_bus'],
                       get_template_default('old', 'disk_bus'))
     self.assertEquals(entry['nic_model'],
                       get_template_default('old', 'nic_model'))
Esempio n. 12
0
 def test_modern_distros(self):
     modern_versions = {'debian': '7.0', 'ubuntu': '12.04',
                        'opensuse': '12.3', 'centos': '6.4', 'rhel': '6.3',
                        'fedora': '18', 'gentoo': '12.1'}
     for distro, version in modern_versions.iteritems():
         entry = lookup(distro, version)
         self.assertEquals(entry['disk_bus'], 'virtio')
         self.assertEquals(entry['nic_model'], 'virtio')
Esempio n. 13
0
 def test_lookup_unknown_distro_version_returns_old_distro(self):
     distro = 'unknown_distro'
     version = 'unknown_version'
     entry = lookup(distro, version)
     self.assertEquals(entry['disk_bus'],
                       get_template_default('old', 'disk_bus'))
     self.assertEquals(entry['nic_model'],
                       get_template_default('old', 'nic_model'))
Esempio n. 14
0
 def test_modern_distros(self):
     # versions based on ppc64 modern distros
     modern_versions = {'ubuntu': '14.04', 'opensuse': '13.1',
                        'rhel': '6.5', 'fedora': '19', 'sles': '11sp3'}
     for distro, version in modern_versions.iteritems():
         entry = lookup(distro, version)
         self.assertEquals(entry['disk_bus'],
                           get_template_default('modern', 'disk_bus'))
         self.assertEquals(entry['nic_model'],
                           get_template_default('modern', 'nic_model'))
Esempio n. 15
0
 def test_old_distros(self):
     old_versions = {
         'debian': '5.0',
         'ubuntu': '7.04',
         'opensuse': '10.1',
         'centos': '5.1',
         'rhel': '5.1',
         'fedora': '15'
     }
     for distro, version in old_versions.iteritems():
         entry = lookup(distro, version)
         self.assertEquals(entry['disk_bus'], 'ide')
         self.assertEquals(entry['nic_model'], 'e1000')
Esempio n. 16
0
 def test_modern_distros(self):
     modern_versions = {
         'debian': '7.0',
         'ubuntu': '12.04',
         'opensuse': '12.3',
         'centos': '6.4',
         'rhel': '6.3',
         'fedora': '18',
         'gentoo': '12.1'
     }
     for distro, version in modern_versions.iteritems():
         entry = lookup(distro, version)
         self.assertEquals(entry['disk_bus'], 'virtio')
         self.assertEquals(entry['nic_model'], 'virtio')
Esempio n. 17
0
 def test_modern_distros(self):
     # versions based on ppc64 modern distros
     modern_versions = {
         'ubuntu': '14.04',
         'opensuse': '13.1',
         'rhel': '6.5',
         'fedora': '19',
         'sles': '11sp3'
     }
     for distro, version in modern_versions.iteritems():
         entry = lookup(distro, version)
         self.assertEquals(entry['disk_bus'],
                           get_template_default('modern', 'disk_bus'))
         self.assertEquals(entry['nic_model'],
                           get_template_default('modern', 'nic_model'))
Esempio n. 18
0
    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)
Esempio n. 19
0
    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 = 'unknown'
        iso = args.get('cdrom', '')

        if scan and len(iso) > 0:

            iso_prefixes = ['/', 'http', 'https', 'ftp', 'ftps', 'tftp']
            if len(filter(iso.startswith, iso_prefixes)) == 0:
                raise InvalidParameter("KCHTMPL0006E", {'param': iso})

            if not iso.startswith('/'):
                self.info.update({'iso_stream': True})

            try:
                iso_img = IsoImage(iso)
                iso_distro, iso_version = iso_img.probe()
            except IsoFormatError:
                raise InvalidParameter("KCHISO0001E", {'filename': 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)
        entry = osinfo.lookup(os_distro, os_version)
        self.info.update(entry)

        # Override with the passed in parameters
        graph_args = args.get('graphics')
        if graph_args:
            graphics = dict(self.info['graphics'])
            graphics.update(graph_args)
            args['graphics'] = graphics
        self.info.update(args)
Esempio n. 20
0
    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 and no one is passed
        if 'name' not in args or args['name'] == '':
            args['name'] = self._gen_name(distro, version)
        self.name = args['name']

        # Override with the passed in parameters
        graph_args = args.get('graphics')
        if graph_args:
            graphics = dict(self.info['graphics'])
            graphics.update(graph_args)
            args['graphics'] = graphics
        self.info.update(args)

        # Assign right disk format to logical and [i]scsi storagepools
        if self._get_storage_type() in ['logical', 'iscsi', 'scsi']:
            for i, disk in enumerate(self.info['disks']):
                self.info['disks'][i]['format'] = 'raw'
Esempio n. 21
0
def _get_device_bus(dev_type, dom, metadata_support):
    try:
        version, distro = VMModel.vm_get_os_metadata(dom, metadata_support)
    except:
        version, distro = ('unknown', 'unknown')
    return lookup(distro, version)[dev_type + '_bus']
Esempio n. 22
0
 def test_default_lookup(self):
     entry = lookup(None, None)
     self.assertEquals('unknown', entry['os_distro'])
     self.assertEquals('unknown', entry['os_version'])
     self.assertEquals(['default'], entry['networks'])
Esempio n. 23
0
 def test_default_lookup(self):
     entry = lookup(None, None)
     self.assertEquals('unknown', entry['os_distro'])
     self.assertEquals('unknown', entry['os_version'])
     self.assertEquals(['default'], entry['networks'])
Esempio n. 24
0
 def test_modern_bases(self):
     for distro, version in modern_version_bases[_get_arch()].iteritems():
         entry = lookup(distro, version)
         self.assertEquals(entry['disk_bus'], 'virtio')
         self.assertEquals(entry['nic_model'], 'virtio')
Esempio n. 25
0
def _get_device_bus(dev_type, dom):
    try:
        version, distro = VMModel.vm_get_os_metadata(dom)
    except:
        version, distro = ('unknown', 'unknown')
    return lookup(distro, version)[dev_type+'_bus']
Esempio n. 26
0
 def test_modern_bases(self):
     for distro, version in modern_version_bases[_get_arch()].iteritems():
         entry = lookup(distro, version)
         self.assertEquals(entry['disk_bus'], 'virtio')
         self.assertEquals(entry['nic_model'], 'virtio')