Example #1
0
    def _get_disks_xml(self, vm_uuid):
        # Current implementation just allows to create disk in one single
        # storage pool, so we cannot mix the types (scsi volumes vs img file)
        storage_type = self._get_storage_type()
        storage_path = self._get_storage_path()

        base_disk_params = {'type': 'disk', 'disk': 'file',
                            'bus': self.info['disk_bus']}
        logical_disk_params = {'format': 'raw'}
        iscsi_disk_params = {'disk': 'block', 'format': 'raw'}

        scsi_disk = 'volume' if self.fc_host_support else 'block'
        scsi_disk_params = {'disk': scsi_disk, 'type': 'lun',
                            'format': 'raw', 'bus': 'scsi'}

        disks_xml = ''
        pool_name = pool_name_from_uri(self.info['storagepool'])
        for index, disk in enumerate(self.info['disks']):
            params = dict(base_disk_params)
            params['format'] = disk['format']
            params.update(locals().get('%s_disk_params' % storage_type, {}))
            params['index'] = index

            volume = disk.get('volume')
            if volume is not None:
                params['path'] = self._get_volume_path(pool_name, volume)
            else:
                volume = "%s-%s.img" % (vm_uuid, params['index'])
                params['path'] = os.path.join(storage_path, volume)

            disks_xml += get_disk_xml(params)[1]

        return unicode(disks_xml, 'utf-8')
Example #2
0
    def _get_cdrom_xml(self, libvirt_stream_protocols):
        if 'cdrom' not in self.info:
            return ''

        params = {}
        params['type'] = 'cdrom'
        params['format'] = 'raw'
        params['bus'] = self.info['cdrom_bus']
        params['index'] = self.info['cdrom_index']
        params['path'] = self.info['cdrom']

        if self.info.get('iso_stream', False):
            protocol = urlparse.urlparse(params['path']).scheme
            if protocol not in libvirt_stream_protocols:
                driveOpt = 'file=%(path)s,if=none,id=drive-%(bus)s0-1-0,'
                driveOpt += 'readonly=on,format=%(format)s'

                deviceOpt = '%(bus)s-cd,bus=%(bus)s.1,unit=0,'
                deviceOpt += 'drive=drive-%(bus)s0-1-0,id=%(bus)s0-1-0'

                args = {}
                args['-drive'] = driveOpt % params
                args['-device'] = deviceOpt % params
                # return qemucmdline XML
                return get_qemucmdline_xml(args)

        dev, xml = get_disk_xml(params)
        return xml
Example #3
0
    def _get_cdrom_xml(self, libvirt_stream_protocols):
        if 'cdrom' not in self.info:
            return ''

        params = {}
        params['type'] = 'cdrom'
        params['format'] = 'raw'
        params['bus'] = self.info['cdrom_bus']
        params['index'] = self.info['cdrom_index']
        params['path'] = self.info['cdrom']

        if self.info.get('iso_stream', False):
            protocol = urlparse.urlparse(params['path']).scheme
            if protocol not in libvirt_stream_protocols:
                driveOpt = 'file=%(path)s,if=none,id=drive-%(bus)s0-1-0,'
                driveOpt += 'readonly=on,format=%(format)s'

                deviceOpt = '%(bus)s-cd,bus=%(bus)s.1,unit=0,'
                deviceOpt += 'drive=drive-%(bus)s0-1-0,id=%(bus)s0-1-0'

                args = {}
                args['-drive'] = driveOpt % params
                args['-device'] = deviceOpt % params
                # return qemucmdline XML
                return get_qemucmdline_xml(args)

        dev, xml = get_disk_xml(params)
        return xml
Example #4
0
    def _get_disks_xml(self, vm_uuid):
        # Current implementation just allows to create disk in one single
        # storage pool, so we cannot mix the types (scsi volumes vs img file)
        storage_type = self._get_storage_type()
        storage_path = self._get_storage_path()

        base_disk_params = {
            'type': 'disk',
            'disk': 'file',
            'bus': self.info['disk_bus']
        }
        logical_disk_params = {'format': 'raw'}
        iscsi_disk_params = {'disk': 'block', 'format': 'raw'}

        scsi_disk = 'volume' if self.fc_host_support else 'block'
        scsi_disk_params = {
            'disk': scsi_disk,
            'type': 'lun',
            'format': 'raw',
            'bus': 'scsi'
        }

        disks_xml = ''
        pool_name = pool_name_from_uri(self.info['storagepool'])
        for index, disk in enumerate(self.info['disks']):
            params = dict(base_disk_params)
            params['format'] = disk['format']
            params.update(locals().get('%s_disk_params' % storage_type, {}))
            params['index'] = index

            volume = disk.get('volume')
            if volume is not None:
                params['path'] = self._get_volume_path(pool_name, volume)
            else:
                volume = "%s-%s.img" % (vm_uuid, params['index'])
                params['path'] = os.path.join(storage_path, volume)

            disks_xml += get_disk_xml(params)[1]

        return unicode(disks_xml, 'utf-8')