예제 #1
0
def provision_system(fqdn):
    system = _get_system_by_FQDN(fqdn)
    if not system.can_configure_netboot(identity.current.user):
        raise Forbidden403('Cannot provision system')
    data = read_json_request(request)
    with convert_internal_errors():
        if not data['distro_tree'] or 'id' not in data['distro_tree']:
            raise ValueError('No distro tree specified')
        distro_tree = DistroTree.by_id(data['distro_tree']['id'])
        user = identity.current.user
        if user.rootpw_expired:
            raise ValueError('Your root password has expired, you must '
                    'change or clear it in order to provision.')
            redirect(u"/view/%s" % system.fqdn)
        install_options = system.manual_provision_install_options(distro_tree)\
                .combined_with(InstallOptions.from_strings(data.get('ks_meta'),
                    data.get('koptions'), data.get('koptions_post')))
        if 'ks' not in install_options.kernel_options:
            kickstart = generate_kickstart(install_options,
                    distro_tree=distro_tree, system=system, user=user)
            install_options.kernel_options['ks'] = kickstart.link
        system.configure_netboot(distro_tree,
                install_options.kernel_options_str, service=u'HTTP')
        system.record_activity(user=identity.current.user, service=u'HTTP',
                action=u'Provision', field=u'Distro Tree',
                new=unicode(distro_tree))
        if data.get('reboot'):
            system.action_power(action=u'reboot', service=u'HTTP')
    # in future "installations" will be a real thing in our model,
    # but for now we have nothing to return
    return 'Provisioned', 201
예제 #2
0
def provision_system(fqdn):
    system = _get_system_by_FQDN(fqdn)
    if not system.can_configure_netboot(identity.current.user):
        raise Forbidden403('Cannot provision system')
    data = read_json_request(request)
    with convert_internal_errors():
        if not data['distro_tree'] or 'id' not in data['distro_tree']:
            raise ValueError('No distro tree specified')
        distro_tree = DistroTree.by_id(data['distro_tree']['id'])
        user = identity.current.user
        if user.rootpw_expired:
            raise ValueError('Your root password has expired, you must '
                             'change or clear it in order to provision.')
            redirect(u"/view/%s" % system.fqdn)
        install_options = system.manual_provision_install_options(distro_tree)\
                .combined_with(InstallOptions.from_strings(data.get('ks_meta'),
                    data.get('koptions'), data.get('koptions_post')))
        if 'ks' not in install_options.kernel_options:
            kickstart = generate_kickstart(install_options,
                                           distro_tree=distro_tree,
                                           system=system,
                                           user=user)
            install_options.kernel_options['ks'] = kickstart.link
        system.configure_netboot(distro_tree,
                                 install_options.kernel_options_str,
                                 service=u'HTTP')
        system.record_activity(user=identity.current.user,
                               service=u'HTTP',
                               action=u'Provision',
                               field=u'Distro Tree',
                               new=unicode(distro_tree))
        if data.get('reboot'):
            system.action_power(action=u'reboot', service=u'HTTP')
    # in future "installations" will be a real thing in our model,
    # but for now we have nothing to return
    return 'Provisioned', 201
예제 #3
0
def main(*args):
    parser = optparse.OptionParser('usage: %prog [options]',
        description=__description__,
        version=__version__)
    parser.add_option('-u', '--user', metavar='USERNAME',
        help='The user we are creating a kickstart for', default='admin')
    parser.add_option('-r', '--recipe-id', metavar='ID',
        help='Recreate kickstart based on recipe ID')
    parser.add_option('-d', '--distro-tree-id', metavar='ID',
        help='Recreate kickstart based on distro ID')
    parser.add_option('-t', '--template-dir', metavar='DIR',
        help='Retrieve templates from DIR')
    parser.add_option('-f', '--system', metavar='FQDN',
        help='Generate kickstart for system identified by FQDN')
    parser.add_option('-m', '--ks-meta', metavar='OPTIONS',
        help='Kickstart meta data')
    parser.add_option('-p', '--kernel-options-post', metavar='OPTIONS',
        help='Kernel options post')
    options, args = parser.parse_args(*args)
    ks_meta = options.ks_meta
    koptions_post = options.kernel_options_post
    template_dir = options.template_dir
    if template_dir:
        add_to_template_searchpath(template_dir)

    if not options.recipe_id:
        if not options.distro_tree_id and not options.system:
            parser.error('Must specify either a recipe or a distro tree and system')
        elif not options.distro_tree_id:
            parser.error('Must specify a distro tree id when passing in a system')
        elif not options.system:
            parser.error('Must specify a system when not specifying a recipe')

    load_config_or_exit()
    with session.begin():
        user = User.by_user_name(options.user)
        ks_appends = None
        recipe = None
        distro_tree = None
        system = None
        install_options = None

        if options.distro_tree_id:
            try:
                distro_tree = DistroTree.by_id(options.distro_tree_id)
            except NoResultFound:
                raise RuntimeError("Distro tree id '%s' does not exist" % options.distro_tree_id)
        if options.system:
            fqdn = options.system
            try:
                system = System.by_fqdn(fqdn, user)
            except NoResultFound:
                raise RuntimeError("System '%s' does not exist" % fqdn)

            if distro_tree and not options.recipe_id:
                install_options = system.manual_provision_install_options(distro_tree)\
                    .combined_with(InstallOptions.from_strings(ks_meta, None, koptions_post))

        if options.recipe_id:
            try:
                recipe = Recipe.by_id(options.recipe_id)
            except NoResultFound:
                raise RuntimeError("Recipe id '%s' does not exist" % options.recipe_id)
            if not recipe.resource and not options.system:
                raise RuntimeError('Recipe must have (or had) a resource'
                                   ' assigned to it')
            if not system:
                system = getattr(recipe.resource, 'system', None)
            if not distro_tree:
                distro_tree = recipe.distro_tree

            install_options = InstallOptions.reduce(chain(
                    [global_install_options()],
                    distro_tree.install_options(),
                    system.install_options(distro_tree),
                    [recipe.generated_install_options(),
                     InstallOptions.from_strings(recipe.ks_meta,
                        recipe.kernel_options, recipe.kernel_options_post),
                     InstallOptions.from_strings(ks_meta, None, koptions_post)]))

            ks_appends = [ks_append.ks_append for ks_append \
                          in recipe.ks_appends]
            user = recipe.recipeset.job.owner

        # Render the kickstart
        rendered_kickstart = generate_kickstart(install_options,
                                                distro_tree=distro_tree,
                                                system=system,
                                                user=user,
                                                recipe=recipe,
                                                ks_appends=ks_appends)
        kickstart = rendered_kickstart.kickstart

    print kickstart
예제 #4
0
def main(*args):
    parser = optparse.OptionParser('usage: %prog [options]',
                                   description=__description__,
                                   version=__version__)
    parser.add_option('-u',
                      '--user',
                      metavar='USERNAME',
                      help='The user we are creating a kickstart for',
                      default='admin')
    parser.add_option('-r',
                      '--recipe-id',
                      metavar='ID',
                      help='Recreate kickstart based on recipe ID')
    parser.add_option('-d',
                      '--distro-tree-id',
                      metavar='ID',
                      help='Recreate kickstart based on distro ID')
    parser.add_option('-t',
                      '--template-dir',
                      metavar='DIR',
                      help='Retrieve templates from DIR')
    parser.add_option('-f',
                      '--system',
                      metavar='FQDN',
                      help='Generate kickstart for system identified by FQDN')
    parser.add_option('-m',
                      '--ks-meta',
                      metavar='OPTIONS',
                      help='Kickstart meta data')
    parser.add_option('-p',
                      '--kernel-options-post',
                      metavar='OPTIONS',
                      help='Kernel options post')
    options, args = parser.parse_args(*args)
    ks_meta = options.ks_meta
    koptions_post = options.kernel_options_post
    template_dir = options.template_dir
    if template_dir:
        add_to_template_searchpath(template_dir)

    if not options.recipe_id:
        if not options.distro_tree_id and not options.system:
            parser.error(
                'Must specify either a recipe or a distro tree and system')
        elif not options.distro_tree_id:
            parser.error(
                'Must specify a distro tree id when passing in a system')
        elif not options.system:
            parser.error('Must specify a system when not specifying a recipe')

    load_config_or_exit()
    with session.begin():
        user = User.by_user_name(options.user)
        ks_appends = None
        recipe = None
        distro_tree = None
        system = None
        install_options = None

        if options.distro_tree_id:
            try:
                distro_tree = DistroTree.by_id(options.distro_tree_id)
            except NoResultFound:
                raise RuntimeError("Distro tree id '%s' does not exist" %
                                   options.distro_tree_id)
        if options.system:
            fqdn = options.system
            try:
                system = System.by_fqdn(fqdn, user)
            except NoResultFound:
                raise RuntimeError("System '%s' does not exist" % fqdn)

            if distro_tree and not options.recipe_id:
                install_options = system.manual_provision_install_options(distro_tree)\
                    .combined_with(InstallOptions.from_strings(ks_meta, None, koptions_post))

        if options.recipe_id:
            try:
                recipe = Recipe.by_id(options.recipe_id)
            except NoResultFound:
                raise RuntimeError("Recipe id '%s' does not exist" %
                                   options.recipe_id)
            if not recipe.resource and not options.system:
                raise RuntimeError('Recipe must have (or had) a resource'
                                   ' assigned to it')
            if not system:
                system = getattr(recipe.resource, 'system', None)
            if not distro_tree:
                distro_tree = recipe.distro_tree

            install_options = InstallOptions.reduce(
                chain([global_install_options()],
                      distro_tree.install_options(),
                      system.install_options(distro_tree), [
                          recipe.generated_install_options(),
                          InstallOptions.from_strings(
                              recipe.ks_meta, recipe.kernel_options,
                              recipe.kernel_options_post),
                          InstallOptions.from_strings(ks_meta, None,
                                                      koptions_post)
                      ]))

            ks_appends = [ks_append.ks_append for ks_append \
                          in recipe.ks_appends]
            user = recipe.recipeset.job.owner

        # Render the kickstart
        rendered_kickstart = generate_kickstart(install_options,
                                                distro_tree=distro_tree,
                                                system=system,
                                                user=user,
                                                recipe=recipe,
                                                ks_appends=ks_appends)
        kickstart = rendered_kickstart.kickstart

    print kickstart
예제 #5
0
    def provision(self,
                  fqdn,
                  distro_tree_id,
                  ks_meta=None,
                  kernel_options=None,
                  kernel_options_post=None,
                  kickstart=None,
                  reboot=True):
        """
        Provisions a system with the given distro tree and options.

        The *ks_meta*, *kernel_options*, and *kernel_options_post* arguments 
        override the default values configured for the system. For example, if 
        the default kernel options for the system/distro are
        'console=ttyS0 ksdevice=eth0', and the caller passes 'ksdevice=eth1' 
        for *kernel_options*, the kernel options used will be
        'console=ttyS0 ksdevice=eth1'.

        :param distro_tree_id: numeric id of distro tree to be provisioned
        :type distro_tree_id: int
        :param ks_meta: kickstart options
        :type ks_meta: str
        :param kernel_options: kernel options for installation
        :type kernel_options: str
        :param kernel_options_post: kernel options for after installation
        :type kernel_options_post: str
        :param kickstart: complete kickstart
        :type kickstart: str
        :param reboot: whether to reboot the system after applying Cobbler changes
        :type reboot: bool

        .. versionadded:: 0.6

        .. versionchanged:: 0.6.10
           System-specific kickstart/kernel options are now obeyed.

        .. versionchanged:: 0.9
           *distro_install_name* parameter is replaced with *distro_tree_id*. 
           See :meth:`distrotrees.filter`.
        """
        system = System.by_fqdn(fqdn, identity.current.user)
        if not system.user == identity.current.user:
            raise BX(_(u'Reserve a system before provisioning'))
        distro_tree = DistroTree.by_id(distro_tree_id)

        # sanity check: does the distro tree apply to this system?
        if not system.compatible_with_distro_tree(distro_tree):
            raise BX(
                _(u'Distro tree %s cannot be provisioned on %s') %
                (distro_tree, system.fqdn))
        if not system.lab_controller:
            raise BX(_(u'System is not attached to a lab controller'))
        if not distro_tree.url_in_lab(system.lab_controller):
            raise BX(
                _(u'Distro tree %s is not available in lab %s') %
                (distro_tree, system.lab_controller))

        if identity.current.user.rootpw_expired:
            raise BX(
                _('Your root password has expired, please change or clear it in order to submit jobs.'
                  ))

        # ensure system-specific defaults are used
        # (overriden by this method's arguments)
        options = system.manual_provision_install_options(distro_tree)\
            .combined_with(InstallOptions.from_strings(
                    ks_meta or '',
                    kernel_options or '',
                    kernel_options_post or ''))
        if 'ks' not in options.kernel_options:
            rendered_kickstart = generate_kickstart(options,
                                                    distro_tree=distro_tree,
                                                    system=system,
                                                    user=identity.current.user,
                                                    kickstart=kickstart)
            options.kernel_options['ks'] = rendered_kickstart.link
        system.configure_netboot(distro_tree,
                                 options.kernel_options_str,
                                 service=u'XMLRPC')
        system.record_activity(user=identity.current.user,
                               service=u'XMLRPC',
                               action=u'Provision',
                               field=u'Distro Tree',
                               old=u'',
                               new=u'Success: %s' % distro_tree)

        if reboot:
            system.action_power(action='reboot', service=u'XMLRPC')

        return system.fqdn  # because turbogears makes us return something
예제 #6
0
def main(*args):
    parser = optparse.OptionParser('usage: %prog [options]',
        description=__description__,
        version=__version__)
    parser.add_option('-u', '--user', metavar='USERNAME',
        help='The user we are creating a kickstart for', default='admin')
    parser.add_option('-r', '--recipe-id', metavar='ID',
        help='Recreate kickstart based on recipe ID')
    parser.add_option('-d', '--distro-tree-id', metavar='ID',
        help='Recreate kickstart based on distro ID')
    parser.add_option('-t', '--template-dir', metavar='DIR',
        help='Retrieve templates from DIR')
    parser.add_option('-f', '--system', metavar='FQDN',
        help='Generate kickstart for system identified by FQDN')
    parser.add_option('-m', '--ks-meta', metavar='OPTIONS', default='',
        help='Kickstart meta data')
    parser.add_option('-p', '--kernel-options-post', metavar='OPTIONS', default='',
        help='Kernel options post')
    options, args = parser.parse_args(*args)
    ks_meta = options.ks_meta.decode(sys.getfilesystemencoding())
    koptions_post = options.kernel_options_post.decode(sys.getfilesystemencoding())
    template_dir = options.template_dir
    if template_dir:
        add_to_template_searchpath(template_dir)

    if not options.recipe_id:
        if not options.distro_tree_id and not options.system:
            parser.error('Must specify either a recipe or a distro tree and system')
        elif not options.distro_tree_id:
            parser.error('Must specify a distro tree id when passing in a system')
        elif not options.system:
            parser.error('Must specify a system when not specifying a recipe')

    load_config_or_exit()
    with session.begin():
        user = User.by_user_name(options.user.decode(sys.getfilesystemencoding()))
        ks_appends = None
        recipe = None
        distro_tree = None
        system = None
        install_options = None

        if options.distro_tree_id:
            try:
                distro_tree = DistroTree.by_id(options.distro_tree_id)
            except NoResultFound:
                raise RuntimeError("Distro tree id '%s' does not exist" % options.distro_tree_id)
        if options.system:
            fqdn = options.system.decode(sys.getfilesystemencoding())
            try:
                system = System.by_fqdn(fqdn, user)
            except DatabaseLookupError:
                raise RuntimeError("System '%s' does not exist" % fqdn)

            if distro_tree and not options.recipe_id:
                install_options = system.manual_provision_install_options(distro_tree)\
                    .combined_with(InstallOptions.from_strings(ks_meta, None, koptions_post))

        if options.recipe_id:
            try:
                recipe = Recipe.by_id(options.recipe_id)
            except NoResultFound:
                raise RuntimeError("Recipe id '%s' does not exist" % options.recipe_id)
            if not recipe.resource and not options.system:
                raise RuntimeError('Recipe must have (or had) a resource'
                                   ' assigned to it')
            if not system:
                system = getattr(recipe.resource, 'system', None)
            if not distro_tree:
                distro_tree = recipe.distro_tree

            sources = []
            # if distro_tree is specified, distro_tree overrides recipe
            osmajor = distro_tree.distro.osversion.osmajor.osmajor if distro_tree else recipe.installation.osmajor
            osminor = distro_tree.distro.osversion.osminor if distro_tree else recipe.installation.osminor
            variant = distro_tree.variant if distro_tree else recipe.installation.variant
            arch = distro_tree.arch if distro_tree else recipe.installation.arch

            sources.append(install_options_for_distro(osmajor, osminor, variant, arch))
            if distro_tree:
                sources.append(distro_tree.install_options())
            sources.extend(system.install_options(arch, osmajor, osminor))
            sources.append(recipe.generated_install_options())
            sources.append(InstallOptions.from_strings(recipe.ks_meta,
                                                       recipe.kernel_options, recipe.kernel_options_post))
            sources.append(InstallOptions.from_strings(ks_meta, None, koptions_post))

            install_options = InstallOptions.reduce(sources)

            ks_appends = [ks_append.ks_append for ks_append \
                          in recipe.ks_appends]
            user = recipe.recipeset.job.owner

        # Render the kickstart
        installation = recipe.installation if recipe and recipe.installation else \
            FakeInstallation(distro_tree.distro.osversion.osmajor.osmajor,
                             distro_tree.distro.osversion.osminor,
                             distro_tree.distro.name,
                             distro_tree.variant,
                             distro_tree.arch,
                             distro_tree.url_in_lab(lab_controller=system.lab_controller))
        rendered_kickstart = generate_kickstart(install_options=install_options,
                                                distro_tree=distro_tree,
                                                installation=installation,
                                                system=system,
                                                user=user,
                                                recipe=recipe,
                                                ks_appends=ks_appends)
        kickstart = rendered_kickstart.kickstart

    print kickstart
예제 #7
0
파일: systems.py 프로젝트: sibiaoluo/beaker
    def provision(self, fqdn, distro_tree_id, ks_meta=None,
            kernel_options=None, kernel_options_post=None, kickstart=None,
            reboot=True):
        """
        Provisions a system with the given distro tree and options.

        The *ks_meta*, *kernel_options*, and *kernel_options_post* arguments 
        override the default values configured for the system. For example, if 
        the default kernel options for the system/distro are
        'console=ttyS0 ksdevice=eth0', and the caller passes 'ksdevice=eth1' 
        for *kernel_options*, the kernel options used will be
        'console=ttyS0 ksdevice=eth1'.

        :param distro_tree_id: numeric id of distro tree to be provisioned
        :type distro_tree_id: int
        :param ks_meta: kickstart options
        :type ks_meta: str
        :param kernel_options: kernel options for installation
        :type kernel_options: str
        :param kernel_options_post: kernel options for after installation
        :type kernel_options_post: str
        :param kickstart: complete kickstart
        :type kickstart: str
        :param reboot: whether to reboot the system after applying Cobbler changes
        :type reboot: bool

        .. versionadded:: 0.6

        .. versionchanged:: 0.6.10
           System-specific kickstart/kernel options are now obeyed.

        .. versionchanged:: 0.9
           *distro_install_name* parameter is replaced with *distro_tree_id*. 
           See :meth:`distrotrees.filter`.
        """
        system = System.by_fqdn(fqdn, identity.current.user)
        if not system.can_provision_now(identity.current.user):
            raise BX(_(u'User %s has insufficient permissions to provision %s')
                    % (identity.current.user.user_name, system.fqdn))
        if not system.user == identity.current.user:
            raise BX(_(u'Reserve a system before provisioning'))
        distro_tree = DistroTree.by_id(distro_tree_id)

        # sanity check: does the distro tree apply to this system?
        if distro_tree.systems().filter(System.id == system.id).count() < 1:
            raise BX(_(u'Distro tree %s cannot be provisioned on %s')
                    % (distro_tree, system.fqdn))

        if identity.current.user.rootpw_expired:
            raise BX(_('Your root password has expired, please change or clear it in order to submit jobs.'))

        # ensure system-specific defaults are used
        # (overriden by this method's arguments)
        options = system.install_options(distro_tree).combined_with(
                InstallOptions.from_strings(ks_meta or '',
                    kernel_options or '',
                    kernel_options_post or ''))
        if 'ks' not in options.kernel_options:
            rendered_kickstart = generate_kickstart(options,
                    distro_tree=distro_tree,
                    system=system, user=identity.current.user, kickstart=kickstart)
            options.kernel_options['ks'] = rendered_kickstart.link
        system.configure_netboot(distro_tree, options.kernel_options_str,
                service=u'XMLRPC')
        system.activity.append(SystemActivity(user=identity.current.user,
                service=u'XMLRPC', action=u'Provision',
                field_name=u'Distro Tree', old_value=u'',
                new_value=u'Success: %s' % distro_tree))

        if reboot:
            system.action_power(action='reboot', service=u'XMLRPC')

        return system.fqdn # because turbogears makes us return something