Esempio n. 1
0
    def installKits(self, dbm):
        self._logger.info('Installing kits')

        self.out('\n' + _('Installing kits') + '...\n')

        kitApi = KitApi()

        # Iterate over the glob of 'kits-*.tar.bz2'
        kitFileGlob = '%s/kits/kit-*.tar.bz2' % (self._cm.getRoot())

        # Split comma-separated list of kits to skip installing. Sorry, you
        # cannot skip installing the base kit.
        val = self._settings['skip_kits'] \
            if 'skip_kits' in self._settings else ''

        skip_kits = set([
            item for item in val.split(',') if item != 'base']) \
            if val else set()

        for kitPackage in glob.glob(kitFileGlob):
            try:
                kit = get_metadata_from_archive(kitPackage)
            except KitNotFound:
                msg = 'Kit [%s] is malformed/invalid. Skipping.' % (
                    os.path.basename(kitPackage))

                self._logger.error(msg)

                self.out('   %s\n' % (msg))

                continue

            if kit['name'] in skip_kits:
                msg = 'Kit [%s] installation skipped.' % (kit['name'])

                self.out('   %s\n' % (msg))

                self._logger.info(msg)

                continue

            try:
                kitApi.installKitPackage(dbm, kitPackage)
            except EulaAcceptanceRequired:
                msg = 'Kit [%s] requires EULA acceptance. Skipping.' % (
                    kitPackage)

                self.out('   %s\n' % (msg))

                self._logger.info(msg)

                continue

            self.out('   - %s installed.\n' % (kit['name']))

            self._logger.info('Kit [%s] installed' % (kit['name']))

        self._logger.info('Done installing kits')

        load_kits()
Esempio n. 2
0
    def _enable_kit_component(self, kit, comp_name, comp_version,
                              software_profile):
        """
        Enables a regular kit component on a specific software profile.

        :param kit:              the Kit instance, whose component is being
                                 enabled
        :param comp_name:        the name of the component to enable
        :param comp_version:     the version of the component to enable
        :param software_profile: the software profile on which the component
                                 will be enabled

        :return:                 the Component instance that was enabled

        """
        kit_spec = (kit.getName(), kit.getVersion(), kit.getIteration())

        load_kits()
        installer = get_kit_installer(kit_spec)()
        comp_installer = installer.get_component_installer(comp_name)
        if not comp_installer.is_enableable(software_profile):
            self.getLogger().warning('Component cannot be enabled: {}'.format(
                comp_installer.spec))
            return None
        comp_installer.run_action('pre_enable', software_profile.getName())

        best_match_component = self._add_component_to_software_profile(
            kit, comp_name, comp_version, software_profile)

        comp_installer.run_action('enable', software_profile.getName())
        comp_installer.run_action('post_enable', software_profile.getName())

        return best_match_component
Esempio n. 3
0
    def _disable_kit_component(self, kit, comp_name, comp_version,
                               software_profile):
        """
        Disables a regular kit component on a specific software profile.

        :param kit:              the Kit instance, whose component is being
                                 disabled
        :param comp_name:        the name of the component to disable
        :param comp_version:     the version of the component to disable
        :param software_profile: the software profile on which the component
                                 will be disable

        :return:                 the Component instance that was disabled

        """
        kit_spec = (kit.getName(), kit.getVersion(), kit.getIteration())

        load_kits()
        installer = get_kit_installer(kit_spec)()
        comp_installer = installer.get_component_installer(comp_name)
        comp_installer.run_action('pre_disable', software_profile.getName())
        comp_installer.run_action('disable', software_profile.getName())

        best_match_component = \
            self._remove_component_from_software_profile(
                kit, comp_name, comp_version, software_profile)

        comp_installer.run_action('post_disable', software_profile.getName())

        return best_match_component
Esempio n. 4
0
    def runCommand(self):
        self.parseArgs(
            _("""
Lists all software to hardware profile mappings in the system.
"""))
        load_kits()

        softwareUsesHardwareDbApi = SoftwareUsesHardwareDbApi()

        hwApi = HardwareProfileApi()
        swApi = SoftwareProfileApi()

        with DbManager().session() as session:
            hwPList = hwApi.getHardwareProfileList(session)
            swPList = swApi.getSoftwareProfileList(session)

            mappingList = softwareUsesHardwareDbApi.getSoftwareUsesHardwareList(
                session)

        print('Current mappings:')
        print('Software Profile               Hardware Profile')
        for mapping in mappingList:
            outputString = ''
            for sp in swPList:
                if sp.getId() == mapping[0]:
                    outputString += ' %s' % sp.getName()
                    outputString = outputString.ljust(32)
            for hp in hwPList:
                if hp.getId() == mapping[1]:
                    outputString += hp.getName()

            print(outputString)
Esempio n. 5
0
def run_server(daemonize: bool = False, pidfile: str = None,
               debug: bool = False):
    logger.debug('Starting service')

    #
    # Load kits
    #
    load_kits()

    #
    # Initialize plugins
    #
    if daemonize:
        plugins.Daemonizer(cherrypy.engine).subscribe()

    if pidfile:
        plugins.PIDFile(cherrypy.engine, pidfile).subscribe()

    DatabasePlugin(cherrypy.engine).subscribe()

    WebsocketPlugin(
        app.cm.getWebsocketScheme(),
        app.cm.getWebsocketPort(),
        cherrypy.engine,
        debug=debug
    ).subscribe()

    #
    # Setup the signal handler to stop the application while running.
    #
    cherrypy.engine.signals.subscribe()

    #
    # Initialize tools
    #
    cherrypy.tools.db = DatabaseTool()
    authentication_methods = [
        auth_methods.HttpBasicAuthenticationMethod(),
        auth_methods.HttpBasicAuthenticationVaultMethod(),
        auth_methods.HttpSessionAuthenticationMethod(),
        auth_methods.HttpJwtAuthenticationMethod()
    ]
    cherrypy.tools.auth = cherrypy.Tool(
        'before_handler',
        CherryPyAuthenticator(authentication_methods)
    )

    #
    # Start the engine.
    #
    cherrypy.engine.start()
    cherrypy.engine.block()

    return 0
Esempio n. 6
0
def main():
    if len(sys.argv) != 2:
        sys.exit(1)

    # ensure all available kits are loaded
    load_kits()

    nodeName = sys.argv[1].lower()

    # Load DNSZone from GlobalParameters
    session = dbm.openSession()

    try:
        get_puppet_node_yaml(session, nodeName)
    finally:
        dbm.closeSession()
Esempio n. 7
0
 def _map_db_tables(self):
     #
     # Make sure all kit table mappers have been registered
     #
     load_kits()
     for kit_installer_class in get_all_kit_installers():
         kit_installer = kit_installer_class()
         kit_installer.register_database_table_mappers()
     #
     # Map all tables that haven't yet been mapped
     #
     for table_mapper in get_all_table_mappers():
         key = table_mapper.__name__
         if key not in self._mapped_tables.keys():
             logger.debug('Mapping table: {}'.format(key))
             self._mapped_tables[key] = table_mapper()
             self._mapped_tables[key].map(self)
    def runCommand(self):
        self.parseArgs(
            _("""
Display list of nodes able to use the specified software profile,
ordered by cost.
"""))
        softwareProfileName = self.getArgs().softwareProfile

        nodeApi = NodeApi()
        softwareUsesHardwareDbApi = SoftwareUsesHardwareDbApi()
        hardwareProfileDbApi = HardwareProfileDbApi()

        load_kits()

        with DbManager().session() as session:
            hwPList = hardwareProfileDbApi.getHardwareProfileList(session)

            hardwareProfileIdList = softwareUsesHardwareDbApi.\
                getAllowedHardwareProfilesBySoftwareProfileName(
                    session, softwareProfileName)

            nodeList = nodeApi.getNodeList(session)
            usableNodes = []
            for node in nodeList:
                if (node.getHardwareProfile().getId() in hardwareProfileIdList) \
                        and node.getIsIdle():
                    usableNodes.append(node)

            costNameList = []
            for node in usableNodes:
                nodeHwP = node.getHardwareProfile().getId()
                for hwP in hwPList:
                    if hwP.getId() == nodeHwP:
                        costNameList.append(
                            [int(hwP.getCost()),
                             node.getName()])
                        break

            costNameList.sort()

            for node in costNameList:
                print('%s' % (node[1]))
Esempio n. 9
0
    def runCommand(self):
        self.parseArgs()

        load_kits()

        with DbManager().session() as session:
            kitmgr = KitActionsManager()
            kitmgr.session = session

            component = kitmgr.load_component(self.getArgs().cname)

            nodegroup = 'installer'

            if '_configure' not in dir(component):
                print(_('This component does not have configuration'),
                      file=sys.stderr)

                sys.exit(0)

            component._configure(nodegroup, sys.stdout)
Esempio n. 10
0
    def start(self):
        self.bus.log('[{0}] Initializing thread manager'.format(
            self.__class__.__name__))

        #
        # Ensure that all kit worker actions are loaded
        #
        load_kits()
        for kit_installer_class in get_all_kit_installers():
            kit_installer = kit_installer_class()
            kit_installer.register_web_service_worker_actions()

        # Create 8 worker threads
        num_worker_threads = 8

        self.bus.log('[{0}] Initializing {1} worker threads'.format(
            self.__class__.__name__, num_worker_threads))

        for thread_id in range(num_worker_threads):
            t = threading.Thread(target=worker_thread,
                                 args=(thread_id, threadManager))
            t.setDaemon(True)
            t.start()
Esempio n. 11
0
    def runCommand(self):
        self.parseArgs(
            _("""
Installs operating system media to Tortuga for the purpose of
package-based node provisioning.
"""))

        load_kits()

        api = getKitApi(self.getUsername(), self.getPassword())

        # Pre-process the media URL list
        os_media_urls: List[str] = self.getArgs().osMediaUrl.split(',')

        with DbManager().session() as session:
            api.installOsKit(session,
                             os_media_urls,
                             bUseSymlinks=self.getArgs().symlinksFlag,
                             bInteractive=True,
                             mirror=self.getArgs().mirror)

        if self.getArgs().sync:
            Puppet().agent()
Esempio n. 12
0
def setupRoutes():
    """
    Used to setup RESTFul resources.

    """
    #
    # Ensure all kits are loaded, and their web services are registered
    #
    load_kits()
    for kit_installer_class in get_all_kit_installers():
        kit_installer = kit_installer_class()
        kit_installer.register_web_service_controllers()

    dispatcher = cherrypy.dispatch.RoutesDispatcher()
    dispatcher.mapper.explicit = False
    for controller_class in get_all_ws_controllers():
        controller = controller_class()
        for action in controller.actions:
            dispatcher.connect(action['name'],
                               action['path'],
                               action=action['action'],
                               controller=controller,
                               conditions=dict(method=action['method']))
    return dispatcher
    def runCommand(self):
        self.parseArgs(
            _("""
Show the software to hardware profile mappings for the specified software
profile."""))

        load_kits()

        softwareUsesHardwareDbApi = SoftwareUsesHardwareDbApi()

        with DbManager().session() as session:
            api = HardwareProfileApi()

            hardwareProfileIdList = softwareUsesHardwareDbApi.\
                getAllowedHardwareProfilesBySoftwareProfileName(
                    session, self.getArgs().swprofile)

            print('Software Profile [%s] is allowed to use the following'
                  ' hardware profiles:' % (self.getArgs().swprofile))

            for hardwareProfileId in hardwareProfileIdList:
                for hp in api.getHardwareProfileList(session):
                    if hp.getId() == hardwareProfileId:
                        print(hp.getName())
Esempio n. 14
0
# the Celery app that does not depend on an external broker.
#
if 'TORTUGA_TEST' in os.environ:
    app = TestApp(include=[
        'tortuga.events.tasks',
        'tortuga.resourceAdapter.tasks',
    ])
    app.app = Application()
    app.dbm = DbManager()

#
# In regular mode, we also want to load the kits, and include any tasks
# they may have as well.
#
else:
    load_kits()
    kits_task_modules: List[str] = []
    for kit_installer_class in get_all_kit_installers():
        kit_installer = kit_installer_class()
        kit_installer.register_event_listeners()
        kits_task_modules += kit_installer.task_modules

    config_manager = ConfigManager()
    redis_password = config_manager.getRedisPassword()

    app = TortugaCeleryApp(
        'tortuga.tasks.queue',
        broker='redis://:{}@localhost:6379/0'.format(redis_password),
        backend='redis://:{}@localhost:6379/0'.format(redis_password),
        include=[
            'tortuga.events.tasks',
Esempio n. 15
0
 def __init__(self):
     super(KitActionsManager, self).__init__()
     load_kits()
Esempio n. 16
0
def main():
    cm = ConfigManager()

    p = argparse.ArgumentParser()

    p.add_argument('-f',
                   '--force',
                   dest='force',
                   action='store_true',
                   default=False)

    p.add_argument('name', help='Software profile name')
    p.add_argument('kit', help='Kit descriptor (NAME-VERSION-ITERATION)')
    p.add_argument('component', help='Component descriptor (NAME-VERSION)')

    args = p.parse_args()

    kitNameAndVersion, kitIteration = args.kit.rsplit('-', 1)
    kitName, kitVersion = kitNameAndVersion.split('-', 1)

    compName, _ = args.component.split('-', 2)

    flagFile = os.path.join(
        cm.getRoot(), 'var/run/actions/%s/component_%s_%s_post_install' %
        (args.name, args.kit, args.component))

    if os.path.exists(flagFile):
        if not args.force:
            sys.stderr.write(
                'post-install component action for [%s] already run\n' %
                (compName))
            sys.exit(0)

        # Remove the existing flag file, we're forcing a run
        os.unlink(flagFile)

    load_kits()
    kit_spec = (kitName, kitVersion, kitIteration)

    try:
        with DbManager().session() as session:
            kit_installer = get_kit_installer(kit_spec)()
            kit_installer.session = session
            c = kit_installer.get_component_installer(compName)
            if c is None:
                raise ComponentNotFound(
                    'Component [%s] not found in kit [%s]' %
                    (compName, kitName))

            c.run_action('post_install')

        logger.debug(
            'post_install component action run for [%s] from kit [%s]' %
            (args.component, args.kit))

        # Ensure destination directory exists
        if not os.path.exists(os.path.dirname(flagFile)):
            os.makedirs(os.path.dirname(flagFile))

        # touch flagFile
        open(flagFile, 'w').close()

    except Exception as exc:  # noqa pylint: disable=broad-except
        print('Error: {}'.format(exc), file=sys.stderr)
        sys.exit(0)