def do_ovirt_reposetup( prefix, rpm_repo, reposync_yum_config, skip_sync, custom_sources, **kwargs ): if kwargs['engine_dir']: warnings.warn('Deprecated option --engine-dir ignored') if kwargs['vdsm_dir']: warnings.warn('Deprecated option --vdsm-dir ignored') if kwargs['ioprocess_dir']: warnings.warn('Deprecated option --ioprocess-dir ignored') rpm_repo = ( rpm_repo or lago_config.get('reposync_dir', CONF_DEFAULTS['reposync_dir']) ) reposync_config = ( reposync_yum_config or lago_config.get( 'reposync_config', CONF_DEFAULTS['reposync_config'], ) ) prefix.prepare_repo( rpm_repo=rpm_repo, reposync_yum_config=reposync_config, skip_sync=skip_sync, custom_sources=custom_sources, )
def do_ovirt_reposetup( prefix, rpm_repo, reposync_yum_config, skip_sync, custom_sources, **kwargs ): if kwargs['engine_dir']: warnings.warn('Deprecated option --engine-dir ignored') if kwargs['vdsm_dir']: warnings.warn('Deprecated option --vdsm-dir ignored') if kwargs['ioprocess_dir']: warnings.warn('Deprecated option --ioprocess-dir ignored') rpm_repo = ( rpm_repo or lago_config.get('reposync_dir', CONF_DEFAULTS['reposync_dir']) ) reposync_config = ( reposync_yum_config or lago_config.get( 'reposync_config', CONF_DEFAULTS['reposync_config'], ) ) prefix.prepare_repo( rpm_repo=rpm_repo, reposync_yum_config=reposync_config, skip_sync=skip_sync, custom_sources=custom_sources, )
def auth_callback(credentials, user_data): for credential in credentials: if credential[0] == libvirt.VIR_CRED_AUTHNAME: credential[4] = config.get('libvirt_username') elif credential[0] == libvirt.VIR_CRED_PASSPHRASE: credential[4] = config.get('libvirt_password') return 0
def auth_callback(credentials, user_data): for credential in credentials: if credential[0] == libvirt.VIR_CRED_AUTHNAME: credential[4] = config.get('libvirt_username') elif credential[0] == libvirt.VIR_CRED_PASSPHRASE: credential[4] = config.get('libvirt_password') return 0
def _normalize_spec(cls, spec): spec['snapshots'] = spec.get('snapshots', {}) spec['metadata'] = spec.get('metadata', {}) if 'root-password' not in spec: root_password = config.get('root_password') if root_password: spec['ssh-password'] = root_password else: spec['ssh-password'] = config.get('ssh_password') if 'ssh-user' not in spec: spec['ssh-user'] = config.get('ssh_user') return spec
def _normalize_spec(cls, spec): spec['snapshots'] = spec.get('snapshots', {}) spec['metadata'] = spec.get('metadata', {}) if 'root-password' not in spec: root_password = config.get('root_password') if root_password: spec['ssh-password'] = root_password else: spec['ssh-password'] = config.get('ssh_password') if 'ssh-user' not in spec: spec['ssh-user'] = config.get('ssh_user') return spec
def _create_vm(self, vm_spec): metadata = vm_spec.get('metadata', {}) role = metadata.get('ovirt-role', None) if role: warnings.warn( 'ovirt-role metadata entry will be soon deprecated, instead ' 'you should use the vm-provider entry in the domain ' 'definition and set it no one of: ovirt-node, ovirt-engine, ' 'ovirt-host') provider_name = 'ovirt-' + role else: provider_name = vm_spec.get( 'vm-type', lago_config.get('default_vm_provider', 'default'), ) if provider_name == 'ovirt-engine': if self._engine_vm is not None: raise RuntimeError('Engine VM already exists') vm_spec['vm-type'] = provider_name self._engine_vm = super(OvirtVirtEnv, self)._create_vm(vm_spec) return self._engine_vm elif provider_name in ('ovirt-host', 'ovirt-node'): vm_spec['vm-type'] = provider_name self._host_vms.append( super(OvirtVirtEnv, self)._create_vm(vm_spec)) return self._host_vms[-1] else: return super(OvirtVirtEnv, self)._create_vm(vm_spec)
def get_libvirt_connection(name): auth = [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_PASSPHRASE], auth_callback, None] libvirt_url = config.get('libvirt_url', 'qemu:///system') libvirt.registerErrorHandler(f=libvirt_callback, ctx=None) return libvirt.openAuth(libvirt_url, auth)
def __init__(self, env, spec): self._env = env libvirt_url = config.get('libvirt_url') self.libvirt_con = libvirt_utils.get_libvirt_connection( name=env.uuid + libvirt_url, libvirt_url=libvirt_url, ) self._spec = spec
def _create_vm(self, vm_spec): default_vm_type = config.get('default_vm_type') vm_type_name = vm_spec.get('vm-type', default_vm_type) try: vm_type = self.vm_types[vm_type_name] except KeyError: raise RuntimeError( 'Unknown VM type: {0}, available types: {1}'.format( vm_type_name, ','.join(self.vm_types.keys()))) vm_spec['vm-type'] = vm_type_name return vm_type(self, vm_spec)
def do_add(args): ret, _, _ = utils.run_command( [ 'git', 'clone', args.url, ], cwd=config.get('template_repos'), ) if ret: raise RuntimeError('Failed to clone the repository')
def do_add(args): ret, _, _ = utils.run_command( [ 'git', 'clone', args.url, ], cwd=config.get('template_repos'), ) if ret: raise RuntimeError('Failed to clone the repository')
def get_libvirt_connection(name): if name not in LIBVIRT_CONNECTIONS: auth = [ [libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_PASSPHRASE], auth_callback, None ] libvirt_url = config.get('libvirt_url', 'qemu:///system') libvirt.registerErrorHandler(f=libvirt_callback, ctx=None) LIBVIRT_CONNECTIONS[name] = libvirt.openAuth(libvirt_url, auth) return LIBVIRT_CONNECTIONS[name]
def interactive_console(self): """ Opens an interactive console Returns: lago.utils.CommandStatus: result of the virsh command execution """ virsh_command = [ "virsh", "-c", config.get('libvirt_url'), "console", self._libvirt_name(), ] return utils.run_interactive_command(command=virsh_command, )
def interactive_console(self): """ Opens an interactive console Returns: lago.utils.CommandStatus: result of the virsh command execution """ if not self.running(): raise RuntimeError('VM %s is not running' % self._libvirt_.name) virsh_command = [ "virsh", "-c", config.get('libvirt_url'), "console", self._libvirt_name(), ] return utils.run_interactive_command(command=virsh_command, )
def interactive_console(self): """ Opens an interactive console Returns: lago.utils.CommandStatus: result of the virsh command execution """ if not self.running(): raise RuntimeError('VM %s is not running' % self._libvirt_.name) virsh_command = [ "virsh", "-c", config.get('libvirt_url'), "console", self._libvirt_name(), ] return utils.run_interactive_command(command=virsh_command, )
def do_update(args): repos_dir = config.get('template_repos') ret, out, _ = utils.run_command( ['find', repos_dir, '-type', 'd', '-name', '.git'], ) for line in [l.strip() for l in out.split('\n') if len(l)]: repo_path = os.path.dirname(line) print 'Updating %s' % repo_path for command in [ ['git', 'fetch'], ['git', 'reset', '--hard'], ['git', 'checkout', 'origin/master'], ]: ret, _, _ = utils.run_command(command, cwd=repo_path) if ret: raise RuntimeError('Error running: %s' % (' '.join(command)))
def __init__(self, vm): super(LocalLibvirtVMProvider, self).__init__(vm) libvirt_url = config.get('libvirt_url') self.libvirt_con = libvirt_utils.get_libvirt_connection( name=self.vm.virt_env.uuid + libvirt_url, libvirt_url=libvirt_url, ) caps_raw_xml = self.libvirt_con.getCapabilities() self._caps = ET.fromstring(caps_raw_xml) host_cpu = self._caps.xpath('host/cpu')[0] self._cpu = cpu.CPU(spec=self.vm._spec, host_cpu=host_cpu) # TO-DO: found a nicer way to expose these attributes to the VM self.vm.cpu_model = self.cpu_model self.vm.cpu_vendor = self.cpu_vendor
def __init__(self, prefix, vm_specs, net_specs): self.vm_types = plugins.load_plugins( plugins.PLUGIN_ENTRY_POINTS['vm'], instantiate=False, ) self.prefix = prefix with open(self.prefix.paths.uuid(), 'r') as uuid_fd: self.uuid = uuid_fd.read().strip() self._nets = {} compat = self.get_compat() for name, spec in net_specs.items(): self._nets[name] = self._create_net(spec, compat) self._vms = {} self._default_vm_type = config.get('default_vm_type') for name, spec in vm_specs.items(): self._vms[name] = self._create_vm(spec)
def __init__(self, vm): super().__init__(vm) self._has_guestfs = 'lago.guestfs_tools' in sys.modules libvirt_url = config.get('libvirt_url') self.libvirt_con = libvirt_utils.get_libvirt_connection( name=self.vm.virt_env.uuid + libvirt_url, libvirt_url=libvirt_url, ) self._libvirt_ver = self.libvirt_con.getLibVersion() caps_raw_xml = self.libvirt_con.getCapabilities() self._caps = ET.fromstring(caps_raw_xml) host_cpu = self._caps.xpath('host/cpu')[0] self._cpu = cpu.CPU(spec=self.vm._spec, host_cpu=host_cpu) # TO-DO: found a nicer way to expose these attributes to the VM self.vm.cpu_model = self.cpu_model self.vm.cpu_vendor = self.cpu_vendor
def __init__(self, prefix, vm_specs, net_specs): self.vm_types = plugins.load_plugins( plugins.PLUGIN_ENTRY_POINTS['vm'], instantiate=False, ) self.prefix = prefix with open(self.prefix.paths.uuid(), 'r') as uuid_fd: self.uuid = uuid_fd.read().strip() self._nets = {} compat = self.get_compat() for name, spec in net_specs.items(): self._nets[name] = self._create_net(spec, compat) self._vms = {} self._default_vm_type = config.get('default_vm_type') for name, spec in vm_specs.items(): self._vms[name] = self._create_vm(spec)
def do_update(args): repos_dir = config.get('template_repos') ret, out, _ = utils.run_command( [ 'find', repos_dir, '-type', 'd', '-name', '.git' ], ) for line in [l.strip() for l in out.split('\n') if len(l)]: repo_path = os.path.dirname(line) print 'Updating %s' % repo_path for command in [ ['git', 'fetch'], ['git', 'reset', '--hard'], ['git', 'checkout', 'origin/master'], ]: ret, _, _ = utils.run_command(command, cwd=repo_path) if ret: raise RuntimeError('Error running: %s' % (' '.join(command)))
def __init__(self, prefix, vm_specs, net_specs): self.vm_types = plugins.load_plugins( plugins.PLUGIN_ENTRY_POINTS['vm'], instantiate=False, ) self.prefix = prefix with open(self.prefix.paths.uuid(), 'r') as uuid_fd: self.uuid = uuid_fd.read().strip() libvirt_url = config.get('libvirt_url') self.libvirt_con = libvirt_utils.get_libvirt_connection( name=self.uuid + libvirt_url, libvirt_url=libvirt_url, ) self._nets = {} for name, spec in net_specs.items(): self._nets[name] = self._create_net(spec) self._vms = {} for name, spec in vm_specs.items(): self._vms[name] = self._create_vm(spec)
def do_deploy(vm, custom_sources, release, workdir, **kwargs): release = OvirtRelease(release) release_script = release.get_install_script() dist = None domains = {} for v in vm: m = get_definition_from_settings(v) if m is None: raise RuntimeError('Invalid VM definition: %s' % v) if dist is None: dist = m.distro.split('.')[0] elif dist != m.distro.split('.')[0]: raise RuntimeError('All the VMs must use the same distro') domains[m.name] = m.to_dict() domains[m.name]['metadata']['deploy-scripts'].insert(0, release_script) if dist is None: raise RuntimeError('Failed to detect distro') conf = { 'domains': domains, 'nets': { 'ovirt-patch-verifier': { 'type': 'nat', 'dhcp': { 'start': 100, 'end': 254, }, 'management': True, 'dns_domain_name': 'lago.local', }, }, } prefix_name = 'ovirt-patch-verifier' if workdir is None: workdir = os.path.abspath('deployment_ovirt-patch-verifier') LOGGER.debug('Using workdir %s', workdir) workdir = Workdir(workdir) if not os.path.exists(workdir.path): LOGGER.debug( 'Initializing workdir %s with prefix %s', workdir.path, prefix_name, ) prefix = workdir.initialize(prefix_name) else: raise RuntimeError('Prefix already initialized. Please cleanup.') setup_prefix_logging(prefix.paths.logs()) try: repo = TemplateRepository.from_url( 'http://templates.ovirt.org/repo/repo.metadata') template_store_path = config.get('template_store', '/var/lib/lago/store') store = TemplateStore(template_store_path) prefix.virt_conf(conf, repo, store, do_bootstrap=True) workdir.set_current(new_current=prefix_name) except: shutil.rmtree(prefix.paths.prefixed(''), ignore_errors=True) raise rpm_repo = config.get('reposync_dir', '/var/lib/lago/reposync') prefix = OvirtPrefix(os.path.join(workdir.path, prefix_name)) prefix.prepare_repo( rpm_repo=rpm_repo, skip_sync=False, custom_sources=custom_sources or [], ) prefix.start() prefix.deploy()
def _get_vm_provider(self): default_provider = config.get('default_vm_provider') provider_name = self._spec.get('vm-provider', default_provider) provider = self.vm_providers.get(provider_name) self._spec['vm-provider'] = provider_name return provider(vm=self)
def _get_vm_provider(self): default_provider = config.get('default_vm_provider') provider_name = self._spec.get('vm-provider', default_provider) provider = self.vm_providers.get(provider_name) self._spec['vm-provider'] = provider_name return provider(vm=self)