def highstate(activate_transaction=False, queue=False, **kwargs): """Retrieve the state data from the salt master for this minion and execute it inside a transaction. For a formal description of the possible parameters accepted in this function, check `state.highstate` documentation. activate_transaction If at the end of the transaction there is a pending activation (i.e there is a new snaphot in the system), a new reboot will be scheduled (default False) queue Instead of failing immediately when another state run is in progress, queue the new state run to begin running once the other has finished. This option starts a new thread for each queued state run, so use this option sparingly. (Default: False) CLI Example: .. code-block:: bash salt microos transactional_update.highstate salt microos transactional_update.highstate pillar='{"foo": "bar"}' salt microos transactional_update.highstate activate_transaction=True """ conflict = _check_queue(queue, kwargs) if conflict is not None: return conflict # Get a copy of the pillar data, to avoid overwriting the current # pillar, instead the one delegated pillar = copy.deepcopy(__pillar__.value()) pillar.update(kwargs.get("pillar", {})) # Clone the options data and apply some default values. May not be # needed, as this module just delegate opts = salt.utils.state.get_sls_opts(__opts__, **kwargs) st_ = TransactionalUpdateHighstate( opts, pillar, __salt__, salt.fileclient.get_file_client(__opts__)) # Compile and verify the raw chunks chunks = st_.compile_low_chunks() file_refs = salt.client.ssh.state.lowstate_file_refs( chunks, salt.client.ssh.wrapper.state._merge_extra_filerefs( kwargs.get("extra_filerefs", ""), opts.get("extra_filerefs", "")), ) # Check for errors for chunk in chunks: if not isinstance(chunk, dict): __context__["retcode"] = 1 return chunks test = kwargs.pop("test", False) hash_type = opts["hash_type"] return _create_and_execute_salt_state(chunks, file_refs, test, hash_type, activate_transaction)
def sls(mods, activate_transaction=False, queue=False, **kwargs): """Execute the states in one or more SLS files inside a transaction. saltenv Specify a salt fileserver environment to be used when applying states mods List of states to execute test Run states in test-only (dry-run) mode exclude Exclude specific states from execution. Accepts a list of sls names, a comma-separated string of sls names, or a list of dictionaries containing ``sls`` or ``id`` keys. Glob-patterns may be used to match multiple states. activate_transaction If at the end of the transaction there is a pending activation (i.e there is a new snaphot in the system), a new reboot will be scheduled (default False) queue Instead of failing immediately when another state run is in progress, queue the new state run to begin running once the other has finished. This option starts a new thread for each queued state run, so use this option sparingly. (Default: False) For a formal description of the possible parameters accepted in this function, check `state.sls` documentation. CLI Example: .. code-block:: bash salt microos transactional_update.sls stuff pillar='{"foo": "bar"}' salt microos transactional_update.sls stuff activate_transaction=True """ conflict = _check_queue(queue, kwargs) if conflict is not None: return conflict concurrent = kwargs.pop("concurrent", True) return call("state.sls", mods, activate_transaction=activate_transaction, concurrent=concurrent, **kwargs)
def single(fun, name, activate_transaction=False, queue=False, **kwargs): """Execute a single state function with the named kwargs, returns False if insufficient data is sent to the command By default, the values of the kwargs will be parsed as YAML. So, you can specify lists values, or lists of single entry key-value maps, as you would in a YAML salt file. Alternatively, JSON format of keyword values is also supported. activate_transaction If at the end of the transaction there is a pending activation (i.e there is a new snaphot in the system), a new reboot will be scheduled (default False) queue Instead of failing immediately when another state run is in progress, queue the new state run to begin running once the other has finished. This option starts a new thread for each queued state run, so use this option sparingly. (Default: False) CLI Example: .. code-block:: bash salt microos transactional_update.single pkg.installed name=emacs salt microos transactional_update.single pkg.installed name=emacs activate_transaction=True """ conflict = _check_queue(queue, kwargs) if conflict is not None: return conflict return call("state.single", fun=fun, name=name, activate_transaction=activate_transaction, concurrent=True, **kwargs)
def highstate(activate_transaction=False, queue=False, **kwargs): """Retrieve the state data from the salt master for this minion and execute it inside a transaction. For a formal description of the possible parameters accepted in this function, check `state.highstate` documentation. activate_transaction If at the end of the transaction there is a pending activation (i.e there is a new snaphot in the system), a new reboot will be scheduled (default False) queue Instead of failing immediately when another state run is in progress, queue the new state run to begin running once the other has finished. This option starts a new thread for each queued state run, so use this option sparingly. (Default: False) CLI Example: .. code-block:: bash salt microos transactional_update.highstate salt microos transactional_update.highstate pillar='{"foo": "bar"}' salt microos transactional_update.highstate activate_transaction=True """ conflict = _check_queue(queue, kwargs) if conflict is not None: return conflict return call("state.highstate", activate_transaction=activate_transaction, concurrent=True, **kwargs)
def single(fun, name, test=None, activate_transaction=False, queue=False, **kwargs): """Execute a single state function with the named kwargs, returns False if insufficient data is sent to the command By default, the values of the kwargs will be parsed as YAML. So, you can specify lists values, or lists of single entry key-value maps, as you would in a YAML salt file. Alternatively, JSON format of keyword values is also supported. activate_transaction If at the end of the transaction there is a pending activation (i.e there is a new snaphot in the system), a new reboot will be scheduled (default False) queue Instead of failing immediately when another state run is in progress, queue the new state run to begin running once the other has finished. This option starts a new thread for each queued state run, so use this option sparingly. (Default: False) CLI Example: .. code-block:: bash salt microos transactional_update.single pkg.installed name=emacs salt microos transactional_update.single pkg.installed name=emacs activate_transaction=True """ conflict = _check_queue(queue, kwargs) if conflict is not None: return conflict # Get a copy of the pillar data, to avoid overwriting the current # pillar, instead the one delegated pillar = copy.deepcopy(__pillar__) pillar.update(kwargs.get("pillar", {})) # Clone the options data and apply some default values. May not be # needed, as this module just delegate opts = salt.utils.state.get_sls_opts(__opts__, **kwargs) st_ = salt.client.ssh.state.SSHState(opts, pillar) # state.fun -> [state, fun] comps = fun.split(".") if len(comps) < 2: __context__["retcode"] = 1 return "Invalid function passed" # Create the low chunk, using kwargs as a base kwargs.update({"state": comps[0], "fun": comps[1], "__id__": name, "name": name}) # Verify the low chunk err = st_.verify_data(kwargs) if err: __context__["retcode"] = 1 return err # Must be a list of low-chunks chunks = [kwargs] # Retrieve file refs for the state run, so we can copy relevant # files down to the minion before executing the state file_refs = salt.client.ssh.state.lowstate_file_refs( chunks, salt.client.ssh.wrapper.state._merge_extra_filerefs( kwargs.get("extra_filerefs", ""), opts.get("extra_filerefs", "") ), ) hash_type = opts["hash_type"] return _create_and_execute_salt_state( chunks, file_refs, test, hash_type, activate_transaction )
def sls( mods, saltenv="base", test=None, exclude=None, activate_transaction=False, queue=False, **kwargs ): """Execute the states in one or more SLS files inside a transaction. saltenv Specify a salt fileserver environment to be used when applying states mods List of states to execute test Run states in test-only (dry-run) mode exclude Exclude specific states from execution. Accepts a list of sls names, a comma-separated string of sls names, or a list of dictionaries containing ``sls`` or ``id`` keys. Glob-patterns may be used to match multiple states. activate_transaction If at the end of the transaction there is a pending activation (i.e there is a new snaphot in the system), a new reboot will be scheduled (default False) queue Instead of failing immediately when another state run is in progress, queue the new state run to begin running once the other has finished. This option starts a new thread for each queued state run, so use this option sparingly. (Default: False) For a formal description of the possible parameters accepted in this function, check `state.sls` documentation. CLI Example: .. code-block:: bash salt microos transactional_update.sls stuff pillar='{"foo": "bar"}' salt microos transactional_update.sls stuff activate_transaction=True """ conflict = _check_queue(queue, kwargs) if conflict is not None: return conflict # Get a copy of the pillar data, to avoid overwriting the current # pillar, instead the one delegated pillar = copy.deepcopy(__pillar__) pillar.update(kwargs.get("pillar", {})) # Clone the options data and apply some default values. May not be # needed, as this module just delegate opts = salt.utils.state.get_sls_opts(__opts__, **kwargs) st_ = TransactionalUpdateHighstate( opts, pillar, __salt__, salt.fileclient.get_file_client(__opts__) ) if isinstance(mods, str): mods = mods.split(",") high_data, errors = st_.render_highstate({saltenv: mods}) if exclude: if isinstance(exclude, str): exclude = exclude.split(",") if "__exclude__" in high_data: high_data["__exclude__"].extend(exclude) else: high_data["__exclude__"] = exclude high_data, ext_errors = st_.state.reconcile_extend(high_data) errors += ext_errors errors += st_.state.verify_high(high_data) if errors: return errors high_data, req_in_errors = st_.state.requisite_in(high_data) errors += req_in_errors if errors: return errors high_data = st_.state.apply_exclude(high_data) # Compile and verify the raw chunks chunks = st_.state.compile_high_data(high_data) file_refs = salt.client.ssh.state.lowstate_file_refs( chunks, salt.client.ssh.wrapper.state._merge_extra_filerefs( kwargs.get("extra_filerefs", ""), opts.get("extra_filerefs", "") ), ) hash_type = opts["hash_type"] return _create_and_execute_salt_state( chunks, file_refs, test, hash_type, activate_transaction )