diff --git a/.deepsource.toml b/.deepsource.toml new file mode 100644 index 0000000..25bc3d7 --- /dev/null +++ b/.deepsource.toml @@ -0,0 +1,8 @@ +version = 1 + +[[analyzers]] +name = "python" +enabled = true + + [analyzers.meta] + runtime_version = "3.x.x" diff --git a/base.py b/base.py index 9f09fb8..97894d1 100644 --- a/base.py +++ b/base.py @@ -60,7 +60,7 @@ def rotate(self, region=None): else: print 'Using supplied region',region,'...' - # Switch in the new linode from this region + # Switch in the new proxy from this region new_proxy, proxy_id = self.make_new_instance(region) # Rotate another node @@ -99,7 +99,7 @@ def rotate(self, region=None): print 'Error - Did not switch out proxy as there was a problem in writing/restarting LB' if proxy_out_label != None: - # Get its label and assign it to the new linode + # Get its label and assign it to the new proxy print 'Assigning label',proxy_out_label,'to new instance',proxy_id time.sleep(5) self.update_instance(proxy_id, @@ -124,14 +124,14 @@ def post_process(self, ip): os.system(cmd) def provision(self, count=8, add=False): - """ Provision an entirely fresh set of linodes after dropping current set """ + """ Provision an entirely fresh set of proxies after dropping current set """ if not add: self.drop() num, idx = 0, 0 - # If we are adding Linodes without dropping, start from current count + # If we are adding without dropping, start from current count if add: start = len(self.config.get_active_proxies()) else: @@ -177,14 +177,14 @@ def test(self): region = self.pick_region() print 'Rotating proxy to new region',region,'...' # Make a test IP - new_proxy, proxy_id = self.make_new_linode(region, test=True) + new_proxy, proxy_id = self.make_new_instance(region, test=True) proxy_out = self.config.get_proxy_for_rotation(least_used=True, region_switch=True, input_region=region) if proxy_out != None: print 'Switched out proxy',proxy_out proxy_out_id = int(self.config.get_proxy_id(proxy_out)) - proxy_out_label = self.linode_cmd.get_label(proxy_out_id) + proxy_out_label = self.get_instance_label(proxy_out_id) # Switch in the new proxy self.config.switch_in_proxy(new_proxy, proxy_id, region) diff --git a/config.py b/config.py index 8291b7b..8b83b2e 100644 --- a/config.py +++ b/config.py @@ -36,7 +36,7 @@ Region: %(region)s --- Linode proxy daemon +-- Proxy Rotator Daemon """ @@ -54,7 +54,7 @@ def __init__(self, cfg='proxy.conf'): self.parse_config(cfg) # This is a file with each line of the form - # IPV4 address, datacenter code, linode-id, switch_in timestamp, switch_out timestamp + # IPV4 address, datacenter code, instance-id, switch_in timestamp, switch_out timestamp # E.g: 45.79.91.191, 3, 1446731065, 144673390 try: proxies = map(lambda x: x.strip().split(','), open(self.proxylist).readlines()) diff --git a/rotate_proxies.py b/rotate_proxies.py index 4cfb8ad..86af943 100644 --- a/rotate_proxies.py +++ b/rotate_proxies.py @@ -1,11 +1,13 @@ """ -Script to auto-rotate and configure Linodes as squid proxies. +Script to auto-rotate and configure squid proxy farms using multiple +VPS backends using their APIs. """ import argparse import os import sys +import signal def process_args(rotator, args): @@ -15,17 +17,17 @@ def process_args(rotator, args): sys.exit(0) if args.add != 0: - print 'Adding new set of',args.num,'linode proxies ...' + print 'Adding new set of',args.num,'proxies ...' rotator.provision(count = int(args.num), add=True) sys.exit(0) if args.provision != 0: - print 'Provisioning fresh set of',args.num,'linode proxies ...' + print 'Provisioning fresh set of',args.num,'proxies ...' rotator.provision(count = int(args.num)) sys.exit(0) if args.create: - print 'Creating new linode...' + print 'Creating new instance...' rotator.create(int(args.region)) sys.exit(0) @@ -70,21 +72,21 @@ def process_args(rotator, args): parser.add_argument('-C','--conf',help='Use the given configuration file', default='proxy.conf') parser.add_argument('-s','--stop',help='Stop the currently running daemon', action='store_true') parser.add_argument('-t','--test',help='Run the test function to test the daemon', action='store_true') - parser.add_argument('-c','--create',help='Create a proxy linode', action='store_true',default=False) - parser.add_argument('-r','--region',help='Specify a region when creating a linode', default=3, type=int) + parser.add_argument('-c','--create',help='Create a proxy instance', action='store_true',default=False) + parser.add_argument('-r','--region',help='Specify a region when creating an instance', default=3, type=int) parser.add_argument('-R','--rotate',help='Rotate a node immediately and go to sleep', default=False, action='store_true') parser.add_argument('-D','--drop',help='Drop the current configuration of proxies (except LB)', default=False,action='store_true') - parser.add_argument('-P','--provision',help='Provision a fresh set of proxy linodes',default=False, + parser.add_argument('-P','--provision',help='Provision a fresh set of proxy instances',default=False, action='store_true') - parser.add_argument('-A','--add',help='Add a new set of linodes to existing set',default=False, + parser.add_argument('-A','--add',help='Add a new set of instances to existing farm',default=False, action='store_true') - parser.add_argument('-N','--num',help='Number of new linodes to provision or add (use with -P or -A)',type=int, + parser.add_argument('-N','--num',help='Number of new instances to provision or add (use with -P or -A)',type=int, default=10) - parser.add_argument('-w','--writeconfig',help='Load current Linode proxies configuration and write a fresh proxies.list config file', action='store_true') - parser.add_argument('-W','--writelbconfig',help='Load current Linode proxies configuration and write a fresh HAProxy config to /etc/haproxy/haproxy.cfg', action='store_true') + parser.add_argument('-w','--writeconfig',help='Load current proxies configuration and write a fresh proxies.list config file', action='store_true') + parser.add_argument('-W','--writelbconfig',help='Load current proxies configuration and write a fresh HAProxy config to /etc/haproxy/haproxy.cfg', action='store_true') parser.add_argument('--restart',help='Restart the daemon',action='store_true') parser.add_argument('-T','--target',help='Target VPS platform (linode, aws)',default='linode') @@ -96,7 +98,7 @@ def process_args(rotator, args): rotator = linode.LinodeProxyRotator(cfg=args.conf, test_mode = args.test, rotate=args.rotate) - else: + elif args.target == 'aws': aws = __import__('aws') rotator = aws.AwsProxyRotator(cfg=args.conf, test_mode = args.test, diff --git a/send_gmail.py b/send_gmail.py index 5b06589..e4430a9 100644 --- a/send_gmail.py +++ b/send_gmail.py @@ -3,12 +3,7 @@ Send email via gmail SMTP """ - -import os -import sys -import optparse import smtplib -import time from email.MIMEMultipart import MIMEMultipart from email.MIMEText import MIMEText