Exemplo n.º 1
0
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,
    )
Exemplo n.º 2
0
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,
    )
Exemplo n.º 3
0
Arquivo: utils.py Projeto: nirs/lago
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
Exemplo n.º 4
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
Exemplo n.º 5
0
Arquivo: vm.py Projeto: nirs/lago
    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
Exemplo n.º 6
0
Arquivo: vm.py Projeto: mz-pdm/lago
    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
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
Arquivo: utils.py Projeto: tinez/lago
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)
Exemplo n.º 9
0
 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
Exemplo n.º 10
0
 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)
Exemplo n.º 11
0
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')
Exemplo n.º 12
0
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')
Exemplo n.º 13
0
Arquivo: utils.py Projeto: nirs/lago
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]
Exemplo n.º 14
0
    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, )
Exemplo n.º 15
0
Arquivo: vm.py Projeto: bellle/lago
    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, )
Exemplo n.º 16
0
Arquivo: vm.py Projeto: nirs/lago
    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, )
Exemplo n.º 17
0
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)))
Exemplo n.º 18
0
    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
Exemplo n.º 19
0
    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)
Exemplo n.º 20
0
Arquivo: vm.py Projeto: Kryndex/lago
    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
Exemplo n.º 21
0
Arquivo: virt.py Projeto: nirs/lago
    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)
Exemplo n.º 22
0
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)))
Exemplo n.º 23
0
    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()
Exemplo n.º 25
0
Arquivo: vm.py Projeto: mz-pdm/lago
 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)
Exemplo n.º 26
0
Arquivo: vm.py Projeto: nirs/lago
 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)