Esempio n. 1
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. 2
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. 3
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. 4
0
 def test_modern_bases(self):
     if not os.uname()[4] == 's390x':
         for distro, version in modern_version_bases[_get_arch()].items():
             entry = lookup(distro, version)
             self.assertEqual(entry['disk_bus'],
                              get_template_default('modern', 'disk_bus'))
             self.assertEqual(entry['nic_model'],
                              get_template_default('modern', 'nic_model'))
Esempio n. 5
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. 6
0
 def test_lookup_unknown_distro_version_returns_old_distro(self):
     distro = 'unknown_distro'
     version = 'unknown_version'
     entry = lookup(distro, version)
     self.assertEqual(entry['disk_bus'],
                      get_template_default('old', 'disk_bus'))
     self.assertEqual(entry['nic_model'],
                      get_template_default('old', 'nic_model'))
Esempio n. 7
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'],
                           get_template_default('old', 'disk_bus'))
         self.assertEquals(entry['nic_model'],
                           get_template_default('old', 'nic_model'))
Esempio n. 8
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. 9
0
 def test_modern_bases(self):
     if not os.uname()[4] == 's390x':
         for distro, version in modern_version_bases[_get_arch()].items():
             entry = lookup(distro, version)
             self.assertEqual(
                 entry['disk_bus'], get_template_default(
                     'modern', 'disk_bus')
             )
             self.assertEqual(
                 entry['nic_model'], get_template_default(
                     'modern', 'nic_model')
             )
Esempio n. 10
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'],
                           get_template_default('old', 'disk_bus'))
         self.assertEquals(entry['nic_model'],
                           get_template_default('old', 'nic_model'))
Esempio n. 11
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. 12
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. 13
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. 14
0
def get_iface_network_xml(params, arch=None, os_distro=None, os_version=None):
    """
    <interface type='network' name='ethX'>
      <start mode='onboot'/>
      <source network='default'/>
      <model type='virtio'/>
    </interface>
    """
    name = params.get('name', None)
    if name:
        interface = E.interface(type=params.get('type', 'network'), name=name)
    else:
        interface = E.interface(type=params.get('type', 'network'))

    stmode = params.get('startmode', None)
    if stmode:
        interface.append(E.start(mode=stmode))

    nw = params.get('network', None)
    if nw:
        interface.append(E.source(network=nw))

    model = params.get('model', None)

    # 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))

    return ET.tostring(interface, encoding='utf-8',
                       pretty_print=True).decode('utf-8')
Esempio n. 15
0
def get_iface_xml(params, arch=None, os_distro=None, os_version=None):
    """
    <interface type='network' name='ethX'>
      <start mode='onboot'/>
      <source network='default'/>
      <model type='virtio'/>
    </interface>
    """
    name = params.get('name', None)
    if name:
        interface = E.interface(type=params.get('type', 'network'), name=name)
    else:
        interface = E.interface(type=params.get('type', 'network'))

    stmode = params.get('startmode', None)
    if stmode:
        interface.append(E.start(mode=stmode))

    nw = params.get('network', None)
    if nw:
        interface.append(E.source(network=nw))

    model = params.get('model', None)

    # 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))

    return ET.tostring(interface, encoding='utf-8', pretty_print=True)
Esempio n. 16
0
 def test_default_lookup(self):
     entry = lookup(None, None)
     self.assertEqual('unknown', entry['os_distro'])
     self.assertEqual('unknown', entry['os_version'])
     if not os.uname()[4] == 's390x':
         self.assertEqual(['default'], entry['networks'])
Esempio n. 17
0
 def test_default_lookup(self):
     entry = lookup(None, None)
     self.assertEquals('unknown', entry['os_distro'])
     self.assertEquals('unknown', entry['os_version'])
     if not os.uname()[4] == "s390x":
         self.assertEquals(['default'], entry['networks'])
Esempio n. 18
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. 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 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

        default_disk = self.info['disks'][0]

        # Complete memory args, because dict method update is not recursive
        if 'memory' in args:
            if 'current' not in args['memory']:
                args['memory']['current'] = self.info['memory']['current']
            if 'maxmemory' not in args['memory']:
                args['memory']['maxmemory'] = self.info['memory']['maxmemory']

        # Override template values according to 'args'
        self.info.update(args)
        disks = self.info.get('disks')

        basic_disk = ['index', 'format', 'pool', 'size']
        ro_disk = ['index', 'format', 'pool', 'volume']
        base_disk = ['index', 'base', 'pool', 'size', 'format']

        for index, disk in enumerate(disks):
            disk_info = dict(default_disk)

            pool = disk.get('pool', default_disk['pool'])
            pool_type = self._get_storage_type(pool['name'])

            if pool_type in ['iscsi', 'scsi']:
                disk_info = {'index': 0, 'format': 'raw', 'volume': None}

            disk_info.update(disk)
            pool_name = disk_info.get('pool', {}).get('name')
            if pool_name is None:
                raise MissingParameter('KCHTMPL0028E')

            keys = sorted(disk_info.keys())
            if ((keys != sorted(basic_disk)) and (keys != sorted(ro_disk))
                    and (keys != sorted(base_disk))):
                raise MissingParameter('KCHTMPL0028E')

            if pool_type in ['logical', 'iscsi', 'scsi']:
                if disk_info['format'] != 'raw':
                    raise InvalidParameter('KCHTMPL0029E')

            disk_info['pool']['type'] = pool_type
            disk_info['index'] = disk_info.get('index', index)
            self.info['disks'][index] = disk_info
Esempio n. 20
0
    def __init__(self, args, scan=False, netboot=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.
        If netboot is True, no cdrom or base img will be used to boot the VM.
        """
        self.info = {}
        self.fc_host_support = args.get('fc_host_support')

        # Fetch defaults based on the os distro and version
        if netboot:
            distro = version = 'unknown'
        else:
            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

        default_disk = self.info['disks'][0]

        # Complete memory args, because dict method update is not recursive
        if 'memory' in args:
            if 'current' not in args['memory']:
                args['memory']['current'] = self.info['memory']['current']
            if 'maxmemory' not in args['memory']:
                args['memory']['maxmemory'] = self.info['memory']['maxmemory']

        # Override template values according to 'args'
        self.info.update(args)
        disks = self.info.get('disks')

        basic_disk = ['index', 'format', 'pool', 'size']
        ro_disk = ['index', 'format', 'pool', 'volume']
        base_disk = ['index', 'base', 'pool', 'size', 'format']

        for index, disk in enumerate(disks):
            disk_info = dict(default_disk)

            pool = disk.get('pool', default_disk['pool'])
            pool_type = self._get_storage_type(pool['name'])

            if pool_type in ['iscsi', 'scsi']:
                disk_info = {'index': 0, 'format': 'raw', 'volume': None}

            disk_info.update(disk)
            pool_name = disk_info.get('pool', {}).get('name')
            if pool_name is None:
                raise MissingParameter('KCHTMPL0028E')

            keys = sorted(disk_info.keys())
            if ((keys != sorted(basic_disk)) and (keys != sorted(ro_disk)) and
                    (keys != sorted(base_disk))):
                raise MissingParameter('KCHTMPL0028E')

            if pool_type in ['logical', 'iscsi', 'scsi']:
                if disk_info['format'] != 'raw':
                    raise InvalidParameter('KCHTMPL0029E')

            disk_info['pool']['type'] = pool_type
            disk_info['index'] = disk_info.get('index', index)
            self.info['disks'][index] = disk_info
Esempio n. 21
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. 22
0
    def __init__(self, args, scan=False, netboot=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.
        If netboot is True, no cdrom or base img will be used to boot the VM.
        """
        self.info = {}
        self.fc_host_support = args.get('fc_host_support')

        # Fetch defaults based on the os distro and version
        if netboot:
            distro = version = 'unknown'
        else:
            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

        default_disk = self.info['disks'][0]

        # Complete memory args, because dict method update is not recursive
        if 'memory' in args:
            if 'current' not in args['memory']:
                args['memory']['current'] = self.info['memory']['current']
            if 'maxmemory' not in args['memory']:
                args['memory']['maxmemory'] = self.info['memory']['maxmemory']

        # Override template values according to 'args'
        self.info.update(args)
        disks = self.info.get('disks')

        basic_disk = ['index', 'format', 'pool', 'size']
        basic_path_disk = ['index', 'format', 'path', 'size']
        ro_disk = ['index', 'format', 'pool', 'volume']
        base_disk = ['index', 'base', 'pool', 'size', 'format']
        base_path_disk = ['index', 'base', 'path', 'size', 'format']

        for index, disk in enumerate(disks):
            disk_info = dict(default_disk)

            if is_s390x():
                # Default disk should have either pool or path.
                if 'pool' not in default_disk and 'path' not in default_disk:
                    raise InvalidParameter('KCHTMPL0040E')

                # Each disk should have either pool or path.
                # if not then use "default_disk" configuration.
                pool = disk.get('pool')
                path = disk.get('path')
                if not path and not pool:
                    # If default disk is path then set disk with default path
                    if default_disk.get('path'):
                        path = default_disk.get('path')
                    # If default disk is pool then set disk with default pool
                    elif default_disk.get('pool'):
                        pool = default_disk.get('pool')
            else:
                pool = disk.get('pool', default_disk.get('pool'))

            if pool:
                pool_type = self._get_storage_type(pool['name'])
                if pool_type in ['iscsi', 'scsi']:
                    disk_info = {'index': 0, 'format': 'raw', 'volume': None}

                # This check is required where 'pool' disk
                # has to be added and hence default path
                # has to be removed during template update.
                if 'path' in disk_info:
                    del disk_info['path']

                disk_info.update(disk)
                pool_name = disk_info.get('pool', {}).get('name')
                if pool_name is None:
                    raise MissingParameter('KCHTMPL0028E')

                keys = sorted(disk_info.keys())

                if ((keys != sorted(basic_disk)) and (keys != sorted(ro_disk))
                        and (keys != sorted(base_disk))):
                    # Addition check required only on s390x
                    if not is_s390x() or (keys != sorted(basic_path_disk)):
                        raise MissingParameter('KCHTMPL0028E')

                if pool_type in ['logical', 'iscsi', 'scsi']:
                    if disk_info['format'] != 'raw':
                        raise InvalidParameter('KCHTMPL0029E')

                disk_info['pool']['type'] = pool_type
                disk_info['index'] = disk_info.get('index', index)
                self.info['disks'][index] = disk_info
            elif is_s390x():
                # This check is required where 'path' disk
                # has to be added and hence default pool
                # has to be removed during template update.
                if 'pool' in disk_info:
                    del disk_info['pool']

                disk_info.update(disk)
                keys = sorted(disk_info.keys())
                if ((keys != sorted(basic_path_disk))
                        and (keys != sorted(base_path_disk))):
                    raise MissingParameter('KCHTMPL0042E')

                disk_info['path'] = path
                disk_info['index'] = disk_info.get('index', index)
                self.info['disks'][index] = disk_info
Esempio n. 23
0
    def __init__(self, args, scan=False, netboot=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.
        If netboot is True, no cdrom or base img will be used to boot the VM.
        """
        self.info = {}
        self.fc_host_support = args.get("fc_host_support")

        # Fetch defaults based on the os distro and version
        if netboot:
            distro = version = "unknown"
        else:
            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

        default_disk = self.info["disks"][0]

        # Complete memory args, because dict method update is not recursive
        if "memory" in args:
            if "current" not in args["memory"]:
                args["memory"]["current"] = self.info["memory"]["current"]
            if "maxmemory" not in args["memory"]:
                args["memory"]["maxmemory"] = self.info["memory"]["maxmemory"]

        # Override template values according to 'args'
        self.info.update(args)
        disks = self.info.get("disks")

        basic_disk = ["index", "format", "pool", "size"]
        basic_path_disk = ["index", "format", "path", "size"]
        ro_disk = ["index", "format", "pool", "volume"]
        base_disk = ["index", "base", "pool", "size", "format"]
        base_path_disk = ["index", "base", "path", "size", "format"]

        for index, disk in enumerate(disks):
            disk_info = dict(default_disk)

            if is_s390x():
                # Default disk should have either pool or path.
                if "pool" not in default_disk and "path" not in default_disk:
                    raise InvalidParameter("KCHTMPL0040E")

                # Each disk should have either pool or path.
                # if not then use "default_disk" configuration.
                pool = disk.get("pool")
                path = disk.get("path")
                if not path and not pool:
                    # If default disk is path then set disk with default path
                    if default_disk.get("path"):
                        path = default_disk.get("path")
                    # If default disk is pool then set disk with default pool
                    elif default_disk.get("pool"):
                        pool = default_disk.get("pool")
            else:
                pool = disk.get("pool", default_disk.get("pool"))

            if pool:
                pool_type = self._get_storage_type(pool["name"])
                if pool_type in ["iscsi", "scsi"]:
                    disk_info = {"index": 0, "format": "raw", "volume": None}

                # This check is required where 'pool' disk
                # has to be added and hence default path
                # has to be removed during template update.
                if "path" in disk_info:
                    del disk_info["path"]

                disk_info.update(disk)
                pool_name = disk_info.get("pool", {}).get("name")
                if pool_name is None:
                    raise MissingParameter("KCHTMPL0028E")

                keys = sorted(disk_info.keys())

                if (keys != sorted(basic_disk)) and (keys != sorted(ro_disk)) and (keys != sorted(base_disk)):
                    # Addition check required only on s390x
                    if not is_s390x() or (keys != sorted(basic_path_disk)):
                        raise MissingParameter("KCHTMPL0028E")

                if pool_type in ["logical", "iscsi", "scsi"]:
                    if disk_info["format"] != "raw":
                        raise InvalidParameter("KCHTMPL0029E")

                disk_info["pool"]["type"] = pool_type
                disk_info["index"] = disk_info.get("index", index)
                self.info["disks"][index] = disk_info
            elif is_s390x():
                # This check is required where 'path' disk
                # has to be added and hence default pool
                # has to be removed during template update.
                if "pool" in disk_info:
                    del disk_info["pool"]

                disk_info.update(disk)
                keys = sorted(disk_info.keys())
                if (keys != sorted(basic_path_disk)) and (keys != sorted(base_path_disk)):
                    raise MissingParameter("KCHTMPL0042E")

                disk_info["path"] = path
                disk_info["index"] = disk_info.get("index", index)
                self.info["disks"][index] = disk_info
Esempio n. 24
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. 25
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'])