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)
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)
def domain_add(self, request): """ Creates a new domain on nodeURI. options: { 'nodeURI': <node uri>, 'domain': {...}, } return: """ self.required_options(request, 'nodeURI', 'domain') domain = request.options.get('domain') domain_info = Data_Domain() # when we edit a domain there must be a UUID if 'domainURI' in domain: _node_uri, domain_uuid = urldefrag(domain['domainURI']) domain_info.uuid = domain_uuid # annotations & profile profile = None if not domain_info.uuid: profile_dn = domain.get('profile') for dn, pro in self.profiles: if dn == profile_dn: profile = pro break else: raise UMC_Error(_('Unknown profile given')) domain_info.annotations['profile'] = profile_dn MODULE.info('Creating new domain using profile %s' % (object2dict(profile), )) domain_info.annotations['os'] = getattr(profile, 'os') else: domain_info.annotations['os'] = domain.get('os', '') domain_info.annotations['contact'] = domain.get('contact', '') domain_info.annotations['description'] = domain.get('description', '') domain_info.name = domain['name'] if 'arch' in domain: domain_info.arch = domain['arch'] elif profile: domain_info.arch = profile.arch else: raise UMC_Error(_('Could not determine architecture for domain'), status=500) if domain_info.arch == 'automatic': success, node_list = self.uvmm.send( 'NODE_LIST', None, group='default', pattern=request.options['nodeURI']) if not success: raise UMC_Error( _('Failed to retrieve details for the server %(nodeURI)s') % request.options, status=500) if not node_list: raise UMC_Error(_('Unknown physical server %(nodeURI)s') % request.options, status=500) archs = set([t.arch for t in node_list[0].capabilities]) if 'x86_64' in archs: domain_info.arch = 'x86_64' else: domain_info.arch = 'i686' domain_info.domain_type = 'kvm' domain_info.os_type = 'hvm' domain_info.maxMem = domain['maxMem'] # CPUs try: domain_info.vcpus = int(domain['vcpus']) except ValueError: raise UMC_Error(_('vcpus must be a number')) domain_info.hyperv = domain.get('hyperv', True) # boot devices if 'boot' in domain: domain_info.boot = domain['boot'] elif profile: domain_info.boot = getattr(profile, 'bootdev', None) else: raise UMC_Error( _('Could not determine the list of boot devices for domain'), status=500) # VNC if domain['vnc']: gfx = Graphic() if domain.get('vnc_remote', False): gfx.listen = '0.0.0.0' else: gfx.listen = None if 'kblayout' in domain: gfx.keymap = domain['kblayout'] elif profile: gfx.keymap = profile.kblayout else: raise UMC_Error(_( 'Could not determine the keyboard layout for the VNC access' ), status=500) if domain.get('vnc_password', None): gfx.passwd = domain['vnc_password'] domain_info.graphics = [gfx] # RTC offset if 'rtc_offset' in domain: domain_info.rtc_offset = domain['rtc_offset'] elif profile and getattr(profile, 'rtcoffset'): domain_info.rtc_offset = profile.rtcoffset else: domain_info.rtc_offset = 'utc' # drives domain_info.disks = [ self._create_disk(request.options['nodeURI'], disk, domain_info, profile) for disk in domain['disks'] ] # network interface domain_info.interfaces = [] for interface in domain['interfaces']: iface = Interface() if interface.get('type', '').startswith('network:'): iface.type = 'network' iface.source = interface['type'].split(':', 1)[1] else: iface.type = interface.get('type', 'bridge') iface.source = interface['source'] iface.model = interface['model'] iface.mac_address = interface.get('mac_address', None) domain_info.interfaces.append(iface) def _finished(data): """ Process asynchronous UVMM DOMAIN_DEFINE answer. """ return object2dict(data) self.uvmm.send('DOMAIN_DEFINE', self.process_uvmm_response(request, _finished), uri=request.options['nodeURI'], domain=domain_info)
def domain_add( self, request ): """Creates a new domain on nodeURI. options: { 'nodeURI': <node uri>, 'domain' : {} } return: """ self.required_options( request, 'nodeURI', 'domain' ) domain = request.options.get( 'domain' ) domain_info = Data_Domain() # when we edit a domain there must be a UUID if 'domainURI' in domain: node_uri, domain_uuid = urlparse.urldefrag( domain[ 'domainURI' ] ) domain_info.uuid = domain_uuid # annotations & profile profile = None if not domain_info.uuid: profile_dn = domain.get( 'profile' ) for dn, pro in self.profiles: if dn == profile_dn: profile = pro break else: raise UMC_OptionTypeError( _( 'Unknown profile given' ) ) domain_info.annotations[ 'profile' ] = profile_dn MODULE.info( 'Creating new domain using profile %s' % str( object2dict( profile ) ) ) domain_info.annotations[ 'os' ] = getattr( profile, 'os' ) else: domain_info.annotations[ 'os' ] = domain.get( 'os', '' ) domain_info.annotations[ 'contact' ] = domain.get( 'contact', '' ) domain_info.annotations[ 'description' ] = domain.get( 'description', '' ) domain_info.name = domain[ 'name' ] if 'arch' in domain: domain_info.arch = domain[ 'arch' ] elif profile: domain_info.arch = profile.arch else: raise UMC_CommandError( 'Could not determine architecture for domain' ) if domain_info.arch == 'automatic': success, node_list = self.uvmm.send( 'NODE_LIST', None, group = 'default', pattern = request.options[ 'nodeURI' ] ) if not success: raise UMC_CommandError( _( 'Failed to retrieve details for the server %(nodeURI)s' ) % request.optiond ) if not node_list: raise UMC_CommandError( _( 'Unknown physical server %(nodeURI)s' ) % request.options ) archs = set( [ t.arch for t in node_list[ 0 ].capabilities ] ) if 'x86_64' in archs: domain_info.arch = 'x86_64' else: domain_info.arch = 'i686' if 'type' in domain: try: domain_info.domain_type, domain_info.os_type = domain['type'].split( '-' ) except ValueError: domain_info.domain_type, domain_info.os_type = ( None, None ) if domain_info.domain_type is None or domain_info.os_type is None: if profile: domain_info.domain_type, domain_info.os_type = profile.virttech.split( '-' ) else: raise UMC_CommandError( 'Could not determine virtualisation technology for domain' ) # check configuration for para-virtualized machines if domain_info.os_type == 'xen': if profile and getattr( profile, 'advkernelconf', None ) != True: # use pyGrub domain_info.bootloader = '/usr/bin/pygrub' domain_info.bootloader_args = '-q' # Bug #19249: PyGrub timeout else: domain_info.kernel = domain['kernel'] domain_info.cmdline = domain['cmdline'] domain_info.initrd = domain['initrd'] # memory domain_info.maxMem = MemorySize.str2num( domain['maxMem'], unit = 'MB' ) # CPUs try: domain_info.vcpus = int( domain[ 'vcpus' ] ) except ValueError: raise UMC_OptionTypeError( 'vcpus must be a number' ) # boot devices if 'boot' in domain: domain_info.boot = domain[ 'boot' ] elif profile: domain_info.boot = getattr( profile, 'bootdev', None ) else: raise UMC_CommandError( 'Could not determine the list of boot devices for domain' ) # VNC if domain[ 'vnc' ]: gfx = Graphic() if domain.get( 'vnc_remote', False ): gfx.listen = '0.0.0.0' else: gfx.listen = None if 'kblayout' in domain: gfx.keymap = domain[ 'kblayout' ] elif profile: gfx.keymap = profile.kblayout else: raise UMC_CommandError( 'Could not determine the keyboard layout for the VNC access' ) if domain.get( 'vnc_password', None ): gfx.passwd = domain[ 'vnc_password' ] domain_info.graphics = [gfx,] # RTC offset if 'rtc_offset' in domain: domain_info.rtc_offset = domain[ 'rtc_offset' ] elif profile and getattr( profile, 'rtcoffset' ): domain_info.rtc_offset = profile.rtcoffset else: domain_info.rtc_offset = 'utc' # drives domain_info.disks = self._create_disks( request.options[ 'nodeURI' ], domain[ 'disks' ], domain_info, profile ) verify_device_files( domain_info ) # on _new_ PV machines we should move the CDROM drive to first position if domain_info.uuid is None and domain_info.os_type == 'xen': non_disks, disks = [], [] for dev in domain_info.disks: if dev.device == Disk.DEVICE_DISK: disks.append( dev ) else: non_disks.append( dev ) domain_info.disks = non_disks + disks # network interface domain_info.interfaces = [] for interface in domain[ 'interfaces' ]: iface = Interface() if interface.get( 'type', '' ).startswith( 'network:' ): iface.type = 'network' iface.source = interface[ 'type' ].split( ':', 1 )[ 1 ] else: iface.type = interface.get( 'type', 'bridge' ) iface.source = interface[ 'source' ] iface.model = interface[ 'model' ] iface.mac_address = interface.get( 'mac_address', None ) # if domain_info.os_type == 'hvm': # if domain_info.domain_type == 'xen': # iface.model = 'netfront' # elif domain_info.domain_type in ( 'kvm', 'qemu' ): # iface.model = 'virtio' domain_info.interfaces.append( iface ) def _finished( thread, result, request ): if self._check_thread_error( thread, result, request ): return success, data = result json = object2dict( data ) MODULE.info( 'New domain: success: %s, data: %s' % ( success, json ) ) if success: self.finished( request.id, json ) else: self.finished( request.id, None, message = str( data ), status = MODULE_ERR_COMMAND_FAILED ) self.uvmm.send( 'DOMAIN_DEFINE', Callback( _finished, request ), uri = request.options[ 'nodeURI' ], domain = domain_info )