コード例 #1
0
ファイル: apichute.py プロジェクト: SejalChauhan/Paradrop
    def POST_stopChute(self, apiPkg):
        """
           Description:
           Arguments:
               POST request:
           Returns:
               On success: SUCCESS object
               On failure: FAILURE object
        """

        out.info('Stopping chute...')

        # For now fake out a create chute message
        update = dict(updateClass='CHUTE', updateType='stop', name=apiPkg.inputArgs.get('name'),
                      tok=timeint(), pkg=apiPkg, func=self.rest.complete)

        self.rest.configurer.updateList(**update)

        # Tell our system we aren't done yet (the configurer will deal with
        # closing the connection)
        apiPkg.setNotDoneYet()
コード例 #2
0
ファイル: restart.py プロジェクト: SejalChauhan/Paradrop
def reloadChutes():
    """
    This function is called to restart any chutes that were running prior to the system being restarted.
    It waits for pdconfd to come up and report whether or not it failed to bring up any of the interfaces
    that existed before the power cycle. If pdconfd indicates something failed we then force a stop update
    in order to bring down all interfaces associated with that chute and mark it with a warning. 
    If the stop fails we mark the chute with a warning manually and change its state to stopped and save to 
    storage this isn't great as it could mean our system still has interfaces up associated with that chute.
    If pdconfd doesn't report failure we attempt to start the chute and if this fails we trust the abort process
    to restore the system to a consistent state and we manually mark the chute as stopped and add a warning to it.
    :param None
    :returns: (list) A list of update dicts to be used to create updateObjects that should be run before accepting new updates.
    """
    if not settings.PDCONFD_ENABLED:
        return []
    chuteStore = chutestorage.ChuteStorage()
    chutes = [ ch for ch in chuteStore.getChuteList() if ch.state == 'running']

    # Part of restoring the chute to its previously running state is reclaiming
    # IP addresses, interface names, etc. that it had previously.
    for chute in chutes:
        reclaimNetworkResources(chute)

    #We need to make sure confd is up and all interfaces have been brought up properly
    confdup = False
    while not confdup:
        confdInfo = waitSystemUp()
        if confdInfo == None:
            time.sleep(1)
            continue
        confdup = True
        confdInfo = str2json(confdInfo)

    #Remove any chutes from the restart queue if confd failed to bring up the
    #proper interfaces
    #
    # At this point, we only care about the chute names, not the full objects.
    # We are using sets of chute names for their O(1) membership test and
    # element uniqueness.
    okChutes = set([ch.name for ch in chutes])
    failedChutes = set()
    for iface in confdInfo:
        if iface.get('success') is False:
            failedChuteName = iface.get('comment')
            if failedChuteName == settings.RESERVED_CHUTE:
                out.warn('Failed to load a system config section')
            elif failedChuteName in okChutes:
                # This was a chute that we are supposed to restart, but one of
                # its config sections failed to load.
                okChutes.remove(failedChuteName)
                failedChutes.add(failedChuteName)
            elif failedChuteName not in failedChutes:
                # In this case, the name in the comment was not something that
                # we recognize from the chute storage.  Maybe the chute storage
                # file was deleted but not the config files, or someone
                # manually modified the config files.  Anyway, we cannot
                # attempt to stop this chute because the object does not exist,
                # but we can give a warning message.
                out.warn('Failed to load config section for '
                         'unrecognized chute: {}'.format(failedChuteName))

    #First stop all chutes that failed to bring up interfaces according to
    #pdconfd then start successful ones #We do this because pdfcd needs to
    #handle cleaning up uci files and then tell pdconfd
    updates = []
    for ch in failedChutes:
        updates.append(dict(updateClass='CHUTE', updateType='stop', name=ch,
                       tok=timeint(), func=updateStatus,
                       warning=FAILURE_WARNING))

    for ch in okChutes:
        updates.append(dict(updateClass='CHUTE', updateType='restart', name=ch,
                       tok=timeint(), func=updateStatus))

    return updates