Save the load to the specified jid
197743
def save_load(jid, load, minions=None):
    '''
    
    '''
    log.debug('sqlite3 returner <save_load> called jid: %s load: %s', jid, load)
    conn = _get_conn(ret=None)
    cur = conn.cursor()
    sql = '''INSERT INTO jids (jid, load) VALUES (:jid, :load)'''
    cur.execute(sql,
                {'jid': jid,
                 'load': salt.utils.json.dumps(load)})
    _close_conn(conn)
1281490
def get_load(jid):
    '''
    
    '''
    log.debug('sdstack_etcd returner <get_load> called jid: %s', jid)
    read_profile = __opts__.get('etcd.returner_read_profile')
    client, path = _get_conn(__opts__, read_profile)
    return salt.utils.json.loads(client.get('/'.join((path, 'jobs', jid, '.load.p'))).value)
1354356
def save(self):
        """"""

        with open(self.store_file_path, 'w') as fh:
            fh.write(json.dumps(self.store, indent=4))
493351
def save(self):
        """"""
        logger.debug("Save the GUI state to `%s`.", self.path)
        _save_json(self.path, {k: v for k, v in self.items()
                               if k not in ('config_dir', 'name')})
353927
def save_cache(data, filename):
    """"""
    with open(filename, 'wb') as handle:
        pickle.dump(data, handle)
1365134
def save(self, cachedir=None, cfgstr=None, verbose=VERBOSE, quiet=QUIET,
             ignore_keys=None):
        
        fpath = self.get_fpath(cachedir, cfgstr=cfgstr)
        if verbose:
            print('[Cachable] cache save: %r' % (basename(fpath),))

        if hasattr(self, '__getstate__'):
            statedict = self.__getstate__()
        else:
            statedict = self.__dict__

        if ignore_keys is None:
            save_dict = statedict
        else:
            save_dict = {key: val
                         for (key, val) in six.iteritems(statedict)
                         if key not in ignore_keys}

        util_io.save_data(fpath, save_dict)
        return fpath
734850
def save_load(jid, load, minions=None):
    '''
    
    '''
    serv = _get_serv(ret=None)

    # create legacy request in case an InfluxDB 0.8.x version is used
    if "influxdb08" in serv.__module__:
        req = [
            {
                'name': 'jids',
                'columns': ['jid', 'load'],
                'points': [
                    [jid, salt.utils.json.dumps(load)]
                ],
            }
        ]
    # create InfluxDB 0.9+ version request
    else:
        req = [
            {
                'measurement': 'jids',
                'tags': {
                    'jid': jid
                },
                'fields': {
                    'load': salt.utils.json.dumps(load)
                }
            }
        ]

    try:
        serv.write_points(req)
    except Exception as ex:
        log.critical('Failed to store load with InfluxDB returner: %s', ex)
150651
def save_load(jid, clear_load, minions=None):
    '''
    
    '''
    jid = _escape_jid(jid)
    conn = _get_conn()
    if conn is None:
        return None
    cur = conn.cursor()
    sql = '''INSERT INTO jids ''' \
          '''(jid, started, tgt_type, cmd, tgt, kwargs, ret, username, arg,''' \
          ''' fun) ''' \
          '''VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)'''

    cur.execute(
        sql, (
            jid,
            salt.utils.jid.jid_to_time(jid),
            six.text_type(clear_load.get("tgt_type")),
            six.text_type(clear_load.get("cmd")),
            six.text_type(clear_load.get("tgt")),
            six.text_type(clear_load.get("kwargs")),
            six.text_type(clear_load.get("ret")),
            six.text_type(clear_load.get("user")),
            six.text_type(salt.utils.json.dumps(clear_load.get("arg"))),
            six.text_type(clear_load.get("fun")),
        )
    )
    # TODO: Add Metadata support when it is merged from develop
    _close_conn(conn)
1294627
def get_load(jid):
    '''
    
    '''
    options = _get_options(ret=None)
    _response = _request("GET", options['url'] + options['db'] + '/' + jid)
    if 'error' in _response:
        log.error('Unable to get JID "%s" : "%s"', jid, _response)
        return {}
    return {_response['id']: _response}
283402
def prep_jid(nocache=False, passed_jid=None):
    '''
    
    '''
    conn = _get_conn()
    if conn is None:
        return None
    cur = conn.cursor()
    if passed_jid is None:
        jid = _gen_jid(cur)
    else:
        jid = passed_jid
    while not jid:
        log.info("jid clash, generating a new one")
        jid = _gen_jid(cur)

    cur.close()
    conn.close()
    return jid
895644
def save_state(self):
        """"""
        set_setting('lastSourceDir', self.source_directory.text())
        set_setting('lastOutputDir', self.output_directory.text())
        set_setting(
            'useDefaultOutputDir', self.scenario_directory_radio.isChecked())
396451
def Save(self):
        """"""
        # This method is intercepted to allow ui_sync
        if self._file_to_save_on_Save:
            self._iopticalsystem.SaveAs(self._file_to_save_on_Save)
        else:
            self._iopticalsystem.Save()
198308
def do_save(self, arg):
        """"""
        #We need to save the full paths to the staging directories for the tests that are loaded
        #so far; then when the session is restored, we can reparse the results.
        from os import path
        import json
        fullpath = path.expanduser(arg)

        data = {
            "tests": [path.abspath(a.stagedir) for a in list(self.tests.values())],
            "args": self.args
        }

        with open(fullpath, 'w') as f:
            json.dump(data, f)
        msg.okay("Saved current session to {}".format(fullpath))
272124
def store_job(opts, load, event=None, mminion=None):
    '''
    
    '''
    # Generate EndTime
    endtime = salt.utils.jid.jid_to_time(salt.utils.jid.gen_jid(opts))
    # If the return data is invalid, just ignore it
    if any(key not in load for key in ('return', 'jid', 'id')):
        return False
    if not salt.utils.verify.valid_id(opts, load['id']):
        return False
    if mminion is None:
        mminion = salt.minion.MasterMinion(opts, states=False, rend=False)

    job_cache = opts['master_job_cache']
    if load['jid'] == 'req':
        # The minion is returning a standalone job, request a jobid
        load['arg'] = load.get('arg', load.get('fun_args', []))
        load['tgt_type'] = 'glob'
        load['tgt'] = load['id']

        prep_fstr = '{0}.prep_jid'.format(opts['master_job_cache'])
        try:
            load['jid'] = mminion.returners[prep_fstr](nocache=load.get('nocache', False))
        except KeyError:
            emsg = "Returner '{0}' does not support function prep_jid".format(job_cache)
            log.error(emsg)
            raise KeyError(emsg)

        # save the load, since we don't have it
        saveload_fstr = '{0}.save_load'.format(job_cache)
        try:
            mminion.returners[saveload_fstr](load['jid'], load)
        except KeyError:
            emsg = "Returner '{0}' does not support function save_load".format(job_cache)
            log.error(emsg)
            raise KeyError(emsg)
    elif salt.utils.jid.is_jid(load['jid']):
        # Store the jid
        jidstore_fstr = '{0}.prep_jid'.format(job_cache)
        try:
            mminion.returners[jidstore_fstr](False, passed_jid=load['jid'])
        except KeyError:
            emsg = "Returner '{0}' does not support function prep_jid".format(job_cache)
            log.error(emsg)
            raise KeyError(emsg)

    if event:
        # If the return data is invalid, just ignore it
        log.info('Got return from %s for job %s', load['id'], load['jid'])
        event.fire_event(load,
                         salt.utils.event.tagify([load['jid'], 'ret', load['id']], 'job'))
        event.fire_ret_load(load)

    # if you have a job_cache, or an ext_job_cache, don't write to
    # the regular master cache
    if not opts['job_cache'] or opts.get('ext_job_cache'):
        return

    # do not cache job results if explicitly requested
    if load.get('jid') == 'nocache':
        log.debug('Ignoring job return with jid for caching %s from %s',
                  load['jid'], load['id'])
        return

    # otherwise, write to the master cache
    savefstr = '{0}.save_load'.format(job_cache)
    getfstr = '{0}.get_load'.format(job_cache)
    fstr = '{0}.returner'.format(job_cache)
    updateetfstr = '{0}.update_endtime'.format(job_cache)
    if 'fun' not in load and load.get('return', {}):
        ret_ = load.get('return', {})
        if 'fun' in ret_:
            load.update({'fun': ret_['fun']})
        if 'user' in ret_:
            load.update({'user': ret_['user']})

    # Try to reach returner methods
    try:
        savefstr_func = mminion.returners[savefstr]
        getfstr_func = mminion.returners[getfstr]
        fstr_func = mminion.returners[fstr]
    except KeyError as error:
        emsg = "Returner '{0}' does not support function {1}".format(job_cache, error)
        log.error(emsg)
        raise KeyError(emsg)

    if job_cache != 'local_cache':
        try:
            mminion.returners[savefstr](load['jid'], load)
        except KeyError as e:
            log.error("Load does not contain 'jid': %s", e)

    mminion.returners[fstr](load)

    if (opts.get('job_cache_store_endtime')
            and updateetfstr in mminion.returners):
        mminion.returners[updateetfstr](load['jid'], endtime)
1049224
def save_object(fname, obj):
    """"""

    fd = gzip.open(fname, "wb")
    six.moves.cPickle.dump(obj, fd)
    fd.close()
984927
def format_jid_instance(jid, job):
    '''
    
    '''
    ret = format_job_instance(job)
    ret.update({'StartTime': jid_to_time(jid)})
    return ret
1003806
def get_jid(returner, jid):
    '''
    
    '''
    returners = salt.loader.returners(__opts__, __salt__)
    return returners['{0}.get_jid'.format(returner)](jid)