Skip to content

Instantly share code, notes, and snippets.

@pcn
pcn / smalltest.py
Created October 16, 2018 20:59
For some reason, this is not sending anything that I can see with
# I feel like I should be able to see this with
# $ sudo salt-run state.event swi/autoscale/highstate
# But I'm not seeing anything.
def success_message(minion_name):
import salt.client
import json
__opts__ = salt.config.minion_config('/etc/salt/minion')
caller = salt.client.Caller(mopts=__opts__)
caller.cmd('event.send', 'swi/autoscale/highstate', json.dumps({"success": minion_name}))
@pcn
pcn / callme.py
Created October 11, 2018 15:23
This seems to allow for running a salt client, ala salt-call, from within a python script
import salt.cli.call
call = salt.cli.call.SaltCall()
call.parse_args(args=['state.highstate'])
# It's initialized but it's going to try to parse the command line,
# so override those properties
if call.options.master:
call.config['master'] = call.options.master
# Setup file logging!
call.setup_logfile_logger()
@pcn
pcn / notsure
Last active October 10, 2018 12:40
Appending to a python list while iterating on it
# This seems like a bad idea, but it also seems to work
In [3]: baselist = range(20)
In [4]: baselist
Out[4]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
In [5]: for item in baselist:
...: if item % 2:
...: baselist.append(item + 1)
@pcn
pcn / BUILD
Created August 29, 2018 17:27
Doing a simple build with bazel and python
package(default_visibility = ["//visibility:public"])
load("@subpar//:subpar.bzl", "par_binary")
load(
"@io_bazel_rules_python//python:python.bzl",
"py_binary", "py_library", "py_test"
)
# Load the pip_install symbol for my_deps, and create the dependencies'
@pcn
pcn / try_orch_macros.md
Last active July 6, 2018 19:13
More jinja issues witih orching
{% for node in all_minions | sort %}
    {# generate unique state IDs per target+loop iteration. #}
    {%- macro gen_id(name) -%} {{ name }}_{{ node }}_{{ loop.index }} {%- endmacro -%}
    {# XXX: an abort macro that logs to slack #}
    {# XXX: a lock-checker that can also abort between steps #}
    {%- macro gen_state(name) -%}
    {{ name }}_{{ node }}_{{ loop.index }}:
      salt.state:
        - name: {{ name }}_{{ node }}_{{ loop.index }}
@pcn
pcn / why.sls
Created July 6, 2018 17:34
Not getting my pillar data
This is in the orch state:
```
{{ gen_id("artifact") }}:
salt.state:
- tgt: {{ node }}
- sls:
- deploy_{{ deploy.app_type }}.artifact
- pillar:
tier: {{ deploy['tier_name'] }}
@pcn
pcn / mycache.py
Last active July 2, 2018 22:35
Salt 2018.3.2 breaks the cache runner, maybe other things too?
# Putt his runner in your runners dir and you'll have the documented behavior back.
#
# -*- coding: utf-8 -*-
'''
Return cached data from minions
'''
from __future__ import absolute_import, print_function, unicode_literals
# Import python libs
import fnmatch
import logging
@pcn
pcn / master.log
Last active July 2, 2018 18:07
Why can't I see cached minion grains for this dummy?
2018-07-02 15:24:28,851 [salt.utils.event ][DEBUG ] Sending event: tag = salt/run/20180702152428092436/new; data = {u'fun': u'runner.cache.grains', u'fun_args': [{u'tgt': u'dummy1'}], u'jid': u'20180702152428092436', u'user': u'sudo_ubuntu', u'_stamp': '2018-07-02T15:24:28.851086'}
2018-07-02 15:24:28,852 [salt.utils.reactor][DEBUG ] Gathering reactors for tag salt/run/20180702152428092436/new
2018-07-02 15:24:28,853 [salt.utils.master][DEBUG ] New instance of MasterPillarUtil created.
2018-07-02 15:24:28,853 [salt.utils.master][DEBUG ] Init settings: tgt: 'dummy1', tgt_type: 'glob', saltenv: 'None', use_cached_grains: True, use_cached_pillar: True, grains_fallback: False, pillar_fallback: True
2018-07-02 15:24:28,853 [salt.utils.master][DEBUG ] No minions matched for tgt="dummy1" and tgt_type="glob"
2018-07-02 15:24:28,854 [salt.utils.lazy ][DEBUG ] LazyLoaded local_cache.prep_jid
2018-07-02 15:24:28,855 [salt.loaded.int.returner.local_cache][DEBUG ] Adding minions for job 20180702152428092436
@pcn
pcn / test.py
Created June 13, 2018 19:47
What canI do with these objects now that jmx has given them to me?
#!/usr/bin/env python
import sys
import socket
import logging
import docopt
import appoptics_metrics
import java.io.BufferedReader;
@pcn
pcn / exploring.md
Created June 8, 2018 05:28
jmxterm getting started
open st2kafka03.qa1:9999
domain java.lang
bean type=Memory
get HeapMemoryUsage
get NonHeapMemoryUsage