def test_new(self):
		self.domain = d = Data_Domain()
		# d.domain_type = 'kvm'
		d.name = 'ucs401'
		# d.os_type = 'hvm'
		# d.arch = 'x86_64'
		# d.boot = ['cdrom', 'hd']
		# d.maxMem = 1048576 << 10  # KiB
		d.vcpus = 1
		# d.rtc_offset = 'utc'

		disk = Disk()
		disk.type = Disk.TYPE_FILE
		disk.device = Disk.DEVICE_DISK
		# disk.driver = 'qemu'
		# disk.driver_type = 'qcow2'
		# disk.driver_cache = 'none'
		disk.source = "/var/lib/libvirt/images/ucs401-0.qcow2"
		# disk.target_dev = 'vda'
		# disk.target_bus = 'virtio'
		d.disks.append(disk)

		disk = Disk()
		disk.type = Disk.TYPE_FILE
		disk.device = Disk.DEVICE_CDROM
		# disk.driver = 'qemu'
		# disk.driver_type = 'raw'
		disk.source = "/var/univention/buildsystem2/isotests/ucs_4.0-1-latest-amd64.iso"
		disk.readonly = True
		# disk.target_dev = 'hda'
		# disk.target_bus = 'ide'
		d.disks.append(disk)

		interface = Interface()
		interface.type = Interface.TYPE_BRIDGE
		# interface.source = 'br0'
		# interface.model = 'virtio'
		d.interfaces.append(interface)

		graphic = Graphic()
		graphic.type = Graphic.TYPE_VNC
		# graphic.listen = '0.0.0.0'
		d.graphics.append(graphic)

		xml, update_xml = _domain_edit(self, d, xml=None)
		self.assertXmlEqual(self.xml, xml)
Пример #2
0
    def _create_disk(self, node_uri, disk, domain_info, profile=None):
        """
		Convert single disk from JSON to Python UVMM Disk object.
		"""
        uri = urlsplit(node_uri)

        driver_pv = disk.get('paravirtual',
                             False)  # by default no paravirtual devices

        drive = Disk()
        drive.device = disk['device']
        drive.driver_type = disk['driver_type']
        drive.driver_cache = disk.get('driver_cache', 'default')
        drive.driver = disk.get('driver', None)
        drive.target_bus = disk.get('target_bus', 'ide')
        drive.target_dev = disk.get('target_dev', None)

        pool_name = disk.get('pool')
        if pool_name:
            pool = self.get_pool(node_uri, pool_name)
        else:
            pool = {}

        if disk.get('source', None) is None:
            # new drive
            drive.size = disk['size']
            if not pool:
                raise ValueError('Pool "%s" not found' % (pool_name, ))
            drive.source = os.path.join(pool['path'], disk['volumeFilename'])

            if profile:
                if drive.device == Disk.DEVICE_DISK:
                    driver_pv = getattr(profile, 'pvdisk', False)
                elif drive.device == Disk.DEVICE_CDROM:
                    driver_pv = getattr(profile, 'pvcdrom', False)
        else:
            # old drive
            drive.source = disk['source']

        MODULE.info('Creating a %s drive' %
                    ('paravirtual' if driver_pv else 'emulated', ))

        try:
            pool_type = pool['type']
            drive.type = POOLS_TYPE[pool_type]
        except LookupError:
            if drive.source.startswith('/dev/'):
                drive.type = Disk.TYPE_BLOCK
            elif not drive.source:
                # empty CDROM or floppy device
                drive.type = Disk.TYPE_BLOCK
            else:
                drive.type = Disk.TYPE_FILE

        if drive.device == Disk.DEVICE_DISK:
            drive.readonly = disk.get('readonly', False)
        elif drive.device == Disk.DEVICE_CDROM:
            drive.driver_type = 'raw'  # ISOs need driver/@type='raw'
            drive.readonly = disk.get('readonly', True)
        elif drive.device == Disk.DEVICE_FLOPPY:
            drive.readonly = disk.get('readonly', True)
        else:
            raise ValueError('Invalid drive-type "%s"' % drive.device)

        if uri.scheme.startswith('qemu'):
            drive.driver = 'qemu'
            if drive.device == Disk.DEVICE_FLOPPY:
                drive.target_bus = 'fdc'
            elif driver_pv:
                drive.target_bus = 'virtio'
            elif disk.get('paravirtual', None) is False:
                drive.target_bus = 'ide'
            else:
                pass  # keep
        else:
            raise ValueError('Unknown virt-tech "%s"' % (node_uri, ))

        return drive
	def test_edit(self):
		self.domain = d = Data_Domain()
		d.domain_type = 'kvm'
		d.uuid = 'da33829a-4c56-4626-8d33-beec0580fc10'
		d.name = 'ucs401'
		d.annotations = {'description': 'https://forge.univention.org/bugzilla/show_bug.cgi?id=36640'}
		d.os_type = 'hvm'
		d.arch = 'x86_64'
		d.boot = ['cdrom', 'hd']
		d.maxMem = 1048576 << 10  # KiB
		d.vcpus = 1
		d.rtc_offset = 'utc'

		disk = Disk()
		disk.type = Disk.TYPE_FILE
		disk.device = Disk.DEVICE_DISK
		disk.driver = 'qemu'
		disk.driver_type = 'qcow2'
		disk.driver_cache = 'none'
		disk.source = "/var/lib/libvirt/images/ucs401-0.qcow2"
		disk.target_dev = 'vda'
		disk.target_bus = 'virtio'
		d.disks.append(disk)

		disk = Disk()
		disk.type = Disk.TYPE_FILE
		disk.device = Disk.DEVICE_CDROM
		disk.driver = 'qemu'
		disk.driver_type = 'raw'
		disk.source = "/var/univention/buildsystem2/isotests/ucs_4.0-1-latest-amd64.iso"
		disk.readonly = True
		disk.target_dev = 'hda'
		disk.target_bus = 'ide'
		d.disks.append(disk)

		interface = Interface()
		interface.type = Interface.TYPE_BRIDGE
		interface.mac_address = "52:54:00:71:90:4b"
		interface.source = 'br0'
		interface.model = 'virtio'
		d.interfaces.append(interface)

		graphic = Graphic()
		graphic.type = Graphic.TYPE_VNC
		graphic.listen = '0.0.0.0'
		d.graphics.append(graphic)

		xml, update_xml = _domain_edit(self, d, xml=None)
		self.assertXmlEqual(self.xml, xml)
Пример #4
0
	def _create_disks( self, node_uri, disks, domain_info, profile = None ):
		drives = []

		uri = urlparse.urlsplit( node_uri )
		for disk in disks:
			drive = Disk()
			# do we create a new disk or just copy data from an already defined drive
			create_new = disk.get( 'source', None ) is None

			drive.device = disk[ 'device' ]
			drive.driver_type = disk[ 'driver_type' ]
			drive.driver_cache = disk.get('driver_cache', 'default')

			# set old values of existing drive
			if not create_new:
				drive.source = disk[ 'source' ]
				drive.driver = disk[ 'driver' ]
				drive.target_bus = disk[ 'target_bus' ]
				drive.target_dev = disk[ 'target_dev' ]
				if disk[ 'size' ] is not None:
					drive.size = MemorySize.str2num( disk[ 'size' ], unit = 'MB' )
			else: # when changing the medium of a CDROM we must keep the target
				drive.target_bus = disk.get( 'target_bus', None )
				drive.target_dev = disk.get( 'target_dev', None )

			# creating new drive
			pool_path = self.get_pool_path( node_uri, disk.get( 'pool' ) )
			file_pool = self.is_file_pool( node_uri, disk.get( 'pool' ) )

			if pool_path:
				drive.source = os.path.join( pool_path, disk[ 'volumeFilename' ] )
			elif not file_pool and disk.get( 'volumeType', Disk.TYPE_BLOCK ) and disk[ 'volumeFilename' ]:
				drive.source = disk[ 'volumeFilename' ]
			elif drive.source is None:
				raise ValueError( _( 'No valid source for disk "%s" found' ) % drive.device )

			if file_pool:
				drive.type = Disk.TYPE_FILE
			else:
				drive.type = Disk.TYPE_BLOCK
				drive.target_bus = 'ide'
				drive.source = disk[ 'volumeFilename' ]

			# get default for paravirtual
			if create_new:
				if profile is not None:
					if drive.device == Disk.DEVICE_DISK:
						driver_pv = getattr( profile, 'pvdisk', False )
					elif drive.device == Disk.DEVICE_CDROM:
						driver_pv = getattr( profile, 'pvcdrom', False )
				else:
					driver_pv = disk.get( 'paravirtual', False ) # by default no paravirtual devices
			else:
				driver_pv = disk.get( 'paravirtual', False ) # by default no paravirtual devices

			MODULE.info( 'Creating a %s drive' % ( driver_pv and 'paravirtual' or 'non-paravirtual' ) )

			if drive.device in ( Disk.DEVICE_DISK, Disk.DEVICE_CDROM ):
				if drive.device == Disk.DEVICE_CDROM:
					drive.driver_type = 'raw' # ISOs need driver/@type='raw'
			elif drive.device == Disk.DEVICE_FLOPPY:
				drive.target_bus = 'fdc'
			else:
				raise ValueError('Invalid drive-type "%s"' % drive.device)

			if uri.scheme.startswith( 'qemu' ):
				drive.driver = 'qemu'
				if driver_pv and drive.device != Disk.DEVICE_FLOPPY and drive.type != Disk.TYPE_BLOCK:
					drive.target_bus = 'virtio'
				elif disk.get( 'paravirtual', None ) == False and not drive.target_bus:
					drive.target_bus = 'ide'
			elif uri.scheme.startswith( 'xen' ):
				pv_domain = domain_info.os_type == 'xen'
				if driver_pv and drive.device != Disk.DEVICE_FLOPPY and drive.type != Disk.TYPE_BLOCK:
					drive.target_bus = 'xen'
				elif pv_domain and not driver_pv:
					# explicitly set ide bus
					drive.target_bus = 'ide'
				# block devices of para-virtual xen instances must use bus xen
				if pv_domain and drive.type == Disk.TYPE_BLOCK:
					drive.target_bus = 'xen'
				# Since UCS 2.4-2 Xen 3.4.3 contains the blktab2 driver
				# from Xen 4.0.1
				if file_pool:
					# Use tapdisk2 by default, but not for empty CDROM drives
					if drive.source is not None and ucr.is_true( 'uvmm/xen/images/tap2', True ):
						drive.driver = 'tap2'
						drive.driver_type = 'aio'
						# if drive.type == 'raw':
						# 	drive.driver_type = 'aio'
					else:
						drive.driver = 'file'
						drive.driver_type = None # only raw support
				else:
					drive.driver = 'phy'
			else:
				raise ValueError( 'Unknown virt-tech "%s"' % node_uri )
			if disk[ 'size' ]:
				drive.size = MemorySize.str2num( disk[ 'size' ], unit = 'MB' )

			drives.append( drive )

		return drives