Skip to content

Instantly share code, notes, and snippets.

@tsaridas
Last active December 26, 2017 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsaridas/168f0178c67a2e0caa65497675209ddf to your computer and use it in GitHub Desktop.
Save tsaridas/168f0178c67a2e0caa65497675209ddf to your computer and use it in GitHub Desktop.
simple-salt-client
#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
import zmq
import msgpack
root_file = '/var/cache/salt/master/.root_key'
with open(root_file) as f:
root_key = f.read()
msg = {'load': {'tgt_type': 'list', 'jid': '', 'cmd': 'publish', 'tgt': ['salt-minion-01'], 'key': root_key, 'arg': [], 'fun': 'test.ping', 'kwargs': {'delimiter': ':', 'show_timeout': True, 'show_jid': False}, 'ret': '', 'user': 'root'}, 'enc': u'clear'}
context = zmq.Context()
message = msgpack.dumps(msg, encoding='utf-8')
# Socket to talk to server
print("Connecting to server… {0}".format(message))
socket = context.socket(zmq.REQ)
socket.connect("tcp://192.168.69.40:4506")
print("Sending request %s …" % msg)
socket.send(b'{0}'.format(message))
# Get the reply.
message = socket.recv()
message = msgpack.loads(message)
print("Received reply %s" % message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment