Implementation of NAPALM method discard_config.
961599
def discard_config(self):
        """"""
        if self.config_session is not None:
            commands = []
            commands.append('configure session {}'.format(self.config_session))
            commands.append('abort')
            self.device.run_commands(commands)
            self.config_session = None
1174882
function clearConfig() {
    var conf = J$.Config;
    conf.INSTR_READ = null;
    conf.INSTR_WRITE = null;
    conf.INSTR_GETFIELD = null;
    conf.INSTR_PUTFIELD = null;
    conf.INSTR_BINARY = null;
    conf.INSTR_PROPERTY_BINARY_ASSIGNMENT = null;
    conf.INSTR_UNARY = null;
    conf.INSTR_LITERAL = null;
    conf.INSTR_CONDITIONAL = null;
}
397718
def unapply(self):
        """"""
        for key, value in self._old_config.items():
            _config[key] = value
535401
def discard(self, value):
        ''''''
        return self.cache.remove((self.value_pickler.dumps(value),))
142454
def discard_config(self):
        """"""
        self.device.cu.rollback(rb_id=0)
        if not self.lock_disable and not self.session_config_lock:
            self._unlock()
957663
def remove(name, conf_file=default_conf):
    '''
    
    '''
    command = "logadm -f {0} -r {1}".format(conf_file, name)
    result = __salt__['cmd.run_all'](command, python_shell=False)
    if result['retcode'] != 0:
        return dict(
            Error='Failure in removing log. Possibly already removed?',
            Output=result['stderr']
        )
    return dict(Result='Success')
218883
def clean(self, config=True, catalog=False, check=False):
        

        try:
            if (config):
                os.unlink(self.config['FILTER_NAME'])
                os.unlink(self.config['PARAMETERS_NAME'])
                os.unlink(self.config['STARNNW_NAME'])
                os.unlink(self.config['CONFIG_FILE'])
            if (catalog):
                os.unlink(self.config['CATALOG_NAME'])
            if (check):
                os.unlink(self.config['CHECKIMAGE_NAME'])

        except OSError:
            pass
802045
function handleRemovedConfigItems(_a) {
    var fileInitialState = _a.fileInitialState, memoryInitialState = _a.memoryInitialState;
    var removedItems = memoryInitialState.filter(function (bsItem) {
        var removedItem = !fileInitialState.find(function (fileItem) { return bsItem.key === fileItem.key; });
        return removedItem;
    });
    if (removedItems.length > 0) {
        console.log('REMOVED CONFIG: ', removedItems);
    }
    removedItems.forEach(function (removedItem) {
        removeItemFromBrowserStorage(removedItem);
    });
}
506319
def terminate(self):
        """"""
        try:
            self.id2sims.terminate()
        except:
            pass
        import glob
        for fname in glob.glob(self.fname + '*'):
            try:
                os.remove(fname)
                logger.info("deleted %s" % fname)
            except Exception, e:
                logger.warning("failed to delete %s: %s" % (fname, e))
        for val in self.__dict__.keys():
            try:
                delattr(self, val)
            except:
                pass
582852
def discard_config(self):
        """"""
        discard_candidate = 'copy running-config {}'.format(self._gen_full_path(self.candidate_cfg))
        discard_merge = 'copy null: {}'.format(self._gen_full_path(self.merge_cfg))
        self._disable_confirm()
        self.device.send_command_expect(discard_candidate)
        self.device.send_command_expect(discard_merge)
        self._enable_confirm()
1303605
def _cleanup(self, domains):
        """"""
        for option in domains.values():
            try:
                os.remove(option['pot'])
            except (IOError, OSError):
                # It is not a problem if we can't actually remove the temporary file
                pass
1212802
def reset_config_files():
    """"""
    print("*** Reset Spyder settings to defaults ***", file=STDERR)
    for fname in SAVED_CONFIG_FILES:
        cfg_fname = get_conf_path(fname)
        if osp.isfile(cfg_fname) or osp.islink(cfg_fname):
            os.remove(cfg_fname)
        elif osp.isdir(cfg_fname):
            shutil.rmtree(cfg_fname)
        else:
            continue
        print("removing:", cfg_fname, file=STDERR)
1302077
def _config_logic(napalm_device,
                  loaded_result,
                  test=False,
                  debug=False,
                  replace=False,
                  commit_config=True,
                  loaded_config=None,
                  commit_in=None,
                  commit_at=None,
                  revert_in=None,
                  revert_at=None,
                  commit_jid=None,
                  **kwargs):
    '''
    
    '''
    # As the Salt logic is built around independent events
    # when it comes to configuration changes in the
    # candidate DB on the network devices, we need to
    # make sure we're using the same session.
    # Hence, we need to pass the same object around.
    # the napalm_device object is inherited from
    # the load_config or load_template functions
    # and forwarded to compare, discard, commit etc.
    # then the decorator will make sure that
    # if not proxy (when the connection is always alive)
    # and the `inherit_napalm_device` is set,
    # `napalm_device` will be overridden.
    # See `salt.utils.napalm.proxy_napalm_wrap` decorator.

    current_jid = kwargs.get('__pub_jid')
    if not current_jid:
        current_jid = '{0:%Y%m%d%H%M%S%f}'.format(datetime.datetime.now())

    loaded_result['already_configured'] = False

    loaded_result['loaded_config'] = ''
    if debug:
        loaded_result['loaded_config'] = loaded_config

    _compare = compare_config(inherit_napalm_device=napalm_device)
    if _compare.get('result', False):
        loaded_result['diff'] = _compare.get('out')
        loaded_result.pop('out', '')  # not needed
    else:
        loaded_result['diff'] = None
        loaded_result['result'] = False
        loaded_result['comment'] = _compare.get('comment')
        __context__['retcode'] = 1
        return loaded_result

    _loaded_res = loaded_result.get('result', False)
    if not _loaded_res or test:
        # if unable to load the config (errors / warnings)
        # or in testing mode,
        # will discard the config
        if loaded_result['comment']:
            loaded_result['comment'] += '\n'
        if not loaded_result.get('diff', ''):
            loaded_result['already_configured'] = True
        discarded = _safe_dicard_config(loaded_result, napalm_device)
        if not discarded['result']:
            return loaded_result
        loaded_result['comment'] += 'Configuration discarded.'
        # loaded_result['result'] = False not necessary
        # as the result can be true when test=True
        _explicit_close(napalm_device)
        if not loaded_result['result']:
            __context__['retcode'] = 1
        return loaded_result

    if not test and commit_config:
        # if not in testing mode and trying to commit
        if commit_jid:
            log.info('Committing the JID: %s', str(commit_jid))
            removed = cancel_commit(commit_jid)
            log.debug('Cleaned up the commit from the schedule')
            log.debug(removed['comment'])
        if loaded_result.get('diff', ''):
            # if not testing mode
            # and also the user wants to commit (default)
            # and there are changes to commit
            if commit_in or commit_at:
                commit_time = __utils__['timeutil.get_time_at'](time_in=commit_in,
                                                                time_at=commit_in)
                # schedule job
                scheduled_job_name = '__napalm_commit_{}'.format(current_jid)
                temp_file = salt.utils.files.mkstemp()
                with salt.utils.files.fopen(temp_file, 'w') as fp_:
                    fp_.write(loaded_config)
                scheduled = __salt__['schedule.add'](scheduled_job_name,
                                                     function='net.load_config',
                                                     job_kwargs={
                                                         'filename': temp_file,
                                                         'commit_jid': current_jid,
                                                         'replace': replace
                                                     },
                                                     once=commit_time)
                log.debug('Scheduling job')
                log.debug(scheduled)
                saved = __salt__['schedule.save']()  # ensure the schedule is
                # persistent cross Minion restart
                discarded = _safe_dicard_config(loaded_result, napalm_device)
                # discard the changes
                if not discarded['result']:
                    discarded['comment'] += ('Scheduled the job to be executed at {schedule_ts}, '
                        'but was unable to discard the config: \n').format(schedule_ts=commit_time)
                    return discarded
                loaded_result['comment'] = ('Changes discarded for now, and scheduled commit at: {schedule_ts}.\n'
                    'The commit ID is: {current_jid}.\n'
                    'To discard this commit, you can execute: \n\n'
                    'salt {min_id} net.cancel_commit {current_jid}').format(schedule_ts=commit_time,
                                                                             min_id=__opts__['id'],
                                                                             current_jid=current_jid)
                loaded_result['commit_id'] = current_jid
                return loaded_result
            log.debug('About to commit:')
            log.debug(loaded_result['diff'])
            if revert_in or revert_at:
                revert_time = __utils__['timeutil.get_time_at'](time_in=revert_in,
                                                                time_at=revert_at)
                if __grains__['os'] == 'junos':
                    if not HAS_JXMLEASE:
                        loaded_result['comment'] = ('This feature requires the library jxmlease to be installed.\n'
                                'To install, please execute: ``pip install jxmlease``.')
                        loaded_result['result'] = False
                        return loaded_result
                    timestamp_at = __utils__['timeutil.get_timestamp_at'](time_in=revert_in,
                                                                          time_at=revert_at)
                    minutes = int((timestamp_at - time.time())/60)
                    _comm = __salt__['napalm.junos_commit'](confirm=minutes)
                    if not _comm['out']:
                        # If unable to commit confirm, should try to bail out
                        loaded_result['comment'] = 'Unable to commit confirm: {}'.format(_comm['message'])
                        loaded_result['result'] = False
                        # But before exiting, we must gracefully discard the config
                        discarded = _safe_dicard_config(loaded_result, napalm_device)
                        if not discarded['result']:
                            return loaded_result
                else:
                    temp_file = salt.utils.files.mkstemp()
                    running_config = __salt__['net.config'](source='running')['out']['running']
                    with salt.utils.files.fopen(temp_file, 'w') as fp_:
                        fp_.write(running_config)
                    committed = _safe_commit_config(loaded_result, napalm_device)
                    if not committed['result']:
                        # If unable to commit, dicard the config (which is
                        # already done by the _safe_commit_config function), and
                        # return with the command and other details.
                        return loaded_result
                    scheduled_job_name = '__napalm_commit_{}'.format(current_jid)
                    scheduled = __salt__['schedule.add'](scheduled_job_name,
                                                         function='net.load_config',
                                                         job_kwargs={
                                                             'filename': temp_file,
                                                             'commit_jid': current_jid,
                                                             'replace': True
                                                         },
                                                         once=revert_time)
                    log.debug('Scheduling commit confirmed')
                    log.debug(scheduled)
                    saved = __salt__['schedule.save']()
                loaded_result['comment'] = ('The commit ID is: {current_jid}.\n'
                        'This commit will be reverted at: {schedule_ts}, unless confirmed.\n'
                        'To confirm the commit and avoid reverting, you can execute:\n\n'
                        'salt {min_id} net.confirm_commit {current_jid}').format(schedule_ts=revert_time,
                                                                                 min_id=__opts__['id'],
                                                                                 current_jid=current_jid)
                loaded_result['commit_id'] = current_jid
                return loaded_result
            committed = _safe_commit_config(loaded_result, napalm_device)
            if not committed['result']:
                return loaded_result
        else:
            # would like to commit, but there's no change
            # need to call discard_config() to release the config DB
            discarded = _safe_dicard_config(loaded_result, napalm_device)
            if not discarded['result']:
                return loaded_result
            loaded_result['already_configured'] = True
            loaded_result['comment'] = 'Already configured.'
    _explicit_close(napalm_device)
    if not loaded_result['result']:
        __context__['retcode'] = 1
    return loaded_result
843280
def cleanup(self):
        """"""
        try:
            self.exit_config_mode()
        except Exception:
            # Always try to send 'exit' regardless of whether exit_config_mode works or not.
            pass
        self._session_log_fin = True
        self.write_channel("exit" + self.RETURN)
104378
def _trim_config(self, b_config, mod, key):
        '''
        
        '''
        if isinstance(b_config[mod], list):
            self._remove_list_item(b_config[mod], key)
        elif isinstance(b_config[mod], dict):
            b_config[mod].pop(key)
        return b_config
1110932
def _cleanup(self):
        """"""
        current_time = time.time()
        timeout = self._config.timeout
        if current_time - self._last_cleanup_time > timeout:
            self.store.cleanup(timeout)
            self._last_cleanup_time = current_time
735541
function cleanUpPreviousConfig(location, app, callback) {
  var confRegex = new RegExp(app + ".*\\.conf");
  var removeConfig = function(fileName, rmCallback) {
    if (confRegex.test(fileName)) {
      return fs.unlink(location + '/' + fileName, rmCallback);
    } else {
      return rmCallback(null);
    }
  };

  fs.readdir(location, function(err, files) {
    async.forEach(files, removeConfig, callback);
  });
}