-
Notifications
You must be signed in to change notification settings - Fork 29
/
juju-pdb
executable file
·54 lines (34 loc) · 1.35 KB
/
juju-pdb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This plugin handles a connection to a remote python
# debugger already started on a juju unit.
# For more information about the python debugger, please
# refer to 'charmhelpers/contrib/python/debug'
from __future__ import print_function
__author__ = 'Jorge Niedbalski R. <[email protected]>'
import sys
import subprocess
from utils import get_units
from optparse import OptionParser
def warning(message):
print("WARNING: ", message, file=sys.stderr)
sys.exit(-1)
def main(options):
unit = filter(lambda u: u.name == options.unit, get_units())
if not len(unit):
warning("Not found unit with name: %s" % options.unit)
unit = unit[0]
if not "{}/tcp".format(options.port) in unit.open_ports:
warning("Port:%s not opened on unit:%s" % (options.port, options.unit))
subprocess.check_output(["telnet", unit.public_address, options.port])
def parse_options():
parser = OptionParser()
parser.add_option("-u", "--unit", dest="unit",
help="Unit name to debug", metavar="unit")
parser.add_option("-p", "--port",
dest="port", default="4444",
help="Port on unit where Pdb is binded")
(options, args) = parser.parse_args()
return options
if __name__ == "__main__":
main(parse_options())