Skip to content

Instantly share code, notes, and snippets.

@torhve
Created March 4, 2013 11:54
Show Gist options
  • Select an option

  • Save torhve/5081801 to your computer and use it in GitHub Desktop.

Select an option

Save torhve/5081801 to your computer and use it in GitHub Desktop.
socat and wsproxy modules
#!/usr/bin/env python
'''
Support for socat
'''
# Import python libs
import os
import glob
# Import salt libs
import salt.utils
from salt.exceptions import SaltException
def __virtual__():
'''
Only load the module if socat is installed
'''
if salt.utils.which('socat'):
return 'socat'
return False
def start(source, target):
'''
Start a socat proxy for a given source to a given target
CLI Example::
salt '*' socat.start TCP4-LISTEN:5900 TCP4:remote:5900
'''
cmd = 'socat -t 30 -T 30 %s %s' %(source, target)
out = __salt__['cmd.run'](cmd)
return 'Started sockat daemon'
#!/usr/bin/env python
'''
Support for websockify
'''
# Import python libs
import os
import glob
# Import salt libs
import salt.utils
from salt.exceptions import SaltException
def __virtual__():
'''
Only load the module if websockify is installed
'''
if salt.utils.which('websockify'):
return 'wsproxy'
return False
def start(ws_port, target):
'''
Start a websocket proxy for a given port to a given target port
CLI Example::
salt '*' wsproxy.start 6080 localhost:5900
'''
cmd = 'websockify --run-once -D --cert /etc/ssl/salt.crt --key /etc/ssl/salt.key --timeout 30 --idle-timeout 30 %s %s' %(ws_port, target)
out = __salt__['cmd.run'](cmd)
return 'Started websockify daemon'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment