|
17 | 17 | import email_report
|
18 | 18 |
|
19 | 19 | from utils import daemonize, randpass, enum, LinodeCommand, AWSCommand
|
| 20 | +from botocore.exceptions import ClientError |
20 | 21 |
|
21 | 22 | # Rotation Policies
|
22 | 23 | Policy = enum('ROTATION_RANDOM',
|
@@ -475,27 +476,39 @@ def provision(self, count=8, add=False):
|
475 | 476 | start = 0
|
476 | 477 |
|
477 | 478 | for i in range(start, start + count):
|
478 |
| - # region = self.pick_region() |
479 |
| - # Do a round-robin on regions |
480 |
| - region = self.config.region_ids[idx % len(self.config.region_ids) ] |
481 |
| - try: |
482 |
| - ip, lid = self.make_new_linode(region) |
483 |
| - self.linode_cmd.linode_update(int(lid), |
484 |
| - self.config.proxy_prefix + str(i+1), |
485 |
| - self.config.group) |
486 |
| - num += 1 |
487 |
| - except Exception, e: |
488 |
| - print 'Error creating linode',e |
| 479 | + |
| 480 | + if self.config.vps_provider == 'linode': |
| 481 | + # region = self.pick_region() |
| 482 | + # Do a round-robin on regions |
| 483 | + region = self.config.region_ids[idx % len(self.config.region_ids) ] |
| 484 | + try: |
| 485 | + ip, lid = self.make_new_linode(region) |
| 486 | + self.linode_cmd.linode_update(int(lid), |
| 487 | + self.config.proxy_prefix + str(i+1), |
| 488 | + self.config.group) |
| 489 | + num += 1 |
| 490 | + except Exception, e: |
| 491 | + print 'Error creating linode',e |
| 492 | + |
| 493 | + elif self.config.vps_provider == 'aws': |
| 494 | + try: |
| 495 | + ip, instance_id = self.make_new_ec2() |
| 496 | + num += 1 |
| 497 | + except ClientError as e: |
| 498 | + print 'Error creating aws ec2 instance ',e |
489 | 499 |
|
490 | 500 | idx += 1
|
491 | 501 |
|
492 |
| - print 'Provisioned',num,'linodes.' |
493 |
| - linodes_list = rotator.linode_cmd.linode_list_proxies().strip().split('\n') |
| 502 | + print 'Provisioned',num,' proxies.' |
| 503 | + if self.config.vps_provider == 'linode': |
| 504 | + proxies_list = rotator.linode_cmd.linode_list_proxies().strip().split('\n') |
| 505 | + elif self.config.vps_provider == 'aws': |
| 506 | + proxies_list = rotator.aws_command.list_proxies() |
494 | 507 | # Randomize it
|
495 | 508 | for i in range(5):
|
496 |
| - random.shuffle(linodes_list) |
497 |
| - |
498 |
| - print >> open('proxies.list', 'w'), '\n'.join(linodes_list) |
| 509 | + random.shuffle(proxies_list) |
| 510 | + |
| 511 | + print >> open('proxies.list', 'w'), '\n'.join(proxies_list) |
499 | 512 | print 'Saved current proxy configuration to proxies.list'
|
500 | 513 |
|
501 | 514 | def test(self):
|
|
0 commit comments