コード例 #1
0
ファイル: disco_route53.py プロジェクト: Angakkuit/asiaq-aws
    disco_route53 = DiscoRoute53()

    if args['list-zones']:
        for hosted_zone in disco_route53.list_zones():
            is_private_zone = hosted_zone.config['PrivateZone']
            print("{0:<20} {1:10} {2:5}".format(hosted_zone.name, hosted_zone.id, is_private_zone))
    elif args['list-records']:
        for hosted_zone in disco_route53.list_zones():
            # the Hosted Zone name is the domain name with a period appended to it
            # allow searching by either with or without the period
            if not args['--zone'] or hosted_zone.name in (args['--zone'], args['--zone'] + '.'):
                for record in disco_route53.list_records(hosted_zone.name):
                    values = ','.join(record.resource_records)
                    print("{0:<5} {1:20} {2:50}".format(record.type, record.name, values))
    elif args['create-record']:
        disco_route53.create_record(args['<zone-name>'],
                                    args['<record-name>'],
                                    args['<type>'],
                                    args['<value>'])
    elif args['delete-record']:
        record_name = args['<record-name>']
        # AWS appends a . to the end of the record name.
        # Add it here as a convenience if the argument is missing it
        if not record_name.endswith('.'):
            record_name += '.'
        disco_route53.delete_record(args['<zone-name>'], record_name, args['<type>'])


if __name__ == "__main__":
    run_gracefully(run)
コード例 #2
0
   https://gist.githubusercontent.com/shevron/6204349/raw/cw-monitor-memusage.py
"""

import time
import random

from docopt import docopt

from disco_aws_automation import DiscoMetrics
from disco_aws_automation.disco_aws_util import run_gracefully
from disco_aws_automation.disco_logging import configure_logging


def run():
    """Parses command line and dispatches the commands"""
    args = docopt(__doc__)

    configure_logging(args["--debug"])

    if args["upload"]:
        metrics = DiscoMetrics(dummy=args['--dummy'])
        metrics.collect()
        if args["--jitter"]:
            sleep_time = random.randrange(0, int(args.get("--jitter")))
            time.sleep(sleep_time)
        metrics.upload()


if __name__ == "__main__":
    run_gracefully(run)
コード例 #3
0
ファイル: disco_ssh.py プロジェクト: amplifylitco/asiaq
        jump_host_ip = self.aws().find_jump_address()
        if not jump_host_ip:
            raise EasyExit("No direct route to host and no jump host in {}".format(self.env))

        return [jump_host_ip, instance.private_ip_address]

    def build_ssh_cmd(self, ips):
        """
        Given a list of ip addresses, build an ssh command to tunnel through n-1 ips to reach the n-th ip
        """
        command = " ".join([
            "ssh -At {} {}".format(
                SSH_OPTIONS,
                "'%s@%s'" % (self.user, ip) if self.user else ip
            )
            for ip in ips])
        return command

    def run(self):
        """Parses command line and dispatches the commands"""
        host = self.args["<host>"]

        ips = self.detect_best_route(host)
        cmd = self.build_ssh_cmd(ips)
        logger.info("Now ssh-ing: %s", cmd)
        os.system(cmd)

if __name__ == "__main__":
    disco_ssh = DiscoSSH(docopt(__doc__))
    run_gracefully(disco_ssh.run)
コード例 #4
0
ファイル: disco_ssh.py プロジェクト: Angakkuit/asiaq
                return [interface.private_ip_address]

        logging.info("No direct route. Trying jump host.")
        jump_host_ip = self.aws().find_jump_address()
        if not jump_host_ip:
            raise EasyExit("No direct route to host and no jump host in {}".format(self.env))

        return [jump_host_ip, instance.private_ip_address]

    def build_ssh_cmd(self, ips):
        """
        Given a list of ip addresses, build an ssh command to tunnel through n-1 ips to reach the n-th ip
        """
        command = " ".join([
            "ssh -At {} {}".format(SSH_OPTIONS, ip)
            for ip in ips])
        return command

    def run(self):
        """Parses command line and dispatches the commands"""
        host = self.args["<host>"]

        ips = self.detect_best_route(host)
        cmd = self.build_ssh_cmd(ips)
        logging.info("Now ssh-ing: %s", cmd)
        os.system(cmd)

if __name__ == "__main__":
    disco_ssh = DiscoSSH(docopt(__doc__))
    run_gracefully(disco_ssh.run)