<commit_before>#!/usr/bin/env python

"""
Brings up a DNS server with container (skydns + skydock) that allow
different dockers to see each other by hostnames.
Run the script with -h flag to learn about script's running options.
"""

from __future__ import print_function

import argparse
import collections
import common
import docker
import json


parser = argparse.ArgumentParser(
    formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    description='Bring up skydns.')

parser.add_argument(
    '--create-service', '-c',
    action='store',
    default='{0}/createService.js'.format(common.get_script_dir()),
    help='path to createService.js plugin',
    dest='create_service')

parser.add_argument(
    '--uid', '-u',
    action='store',
    default=common.generate_uid(),
    help='uid that will be concatenated to docker name',
    dest='uid')

args = parser.parse_args()
uid = args.uid

skydns = docker.run(
    image='crosbymichael/skydns',
    detach=True,
    name='skydns_{0}'.format(uid),
    command=['-nameserver', '8.8.8.8:53', '-domain', 'docker'])

skydock = docker.run(
    image='crosbymichael/skydock',
    detach=True,
    name='skydock_{0}'.format(uid),
    reflect=[('/var/run/docker.sock', 'rw')],
    volumes=[(args.create_service, '/createService.js', 'ro')],
    command=['-ttl', '30', '-environment', 'dev', '-s', '/var/run/docker.sock',
             '-domain', 'docker', '-name', 'skydns_{0}'.format(uid), '-plugins',
             '/createService.js'])

skydns_config = docker.inspect(skydns)
dns = skydns_config['NetworkSettings']['IPAddress']

output = collections.defaultdict(list)
output['dns'] = dns
output['docker_ids'] = [skydns, skydock]

# Print JSON to output so it can be parsed by other scripts
print(json.dumps(output))<commit_msg>VFS-1000, use common.py where possible<commit_after>#!/usr/bin/env python

"""
Brings up a DNS server with container (skydns + skydock) that allow
different dockers to see each other by hostnames.
Run the script with -h flag to learn about script's running options.
"""

from __future__ import print_function

import argparse
import collections
import common
import docker
import json


parser = argparse.ArgumentParser(
    formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    description='Bring up skydns.')

parser.add_argument(
    '--create-service', '-c',
    action='store',
    default='{0}/createService.js'.format(common.get_script_dir()),
    help='path to createService.js plugin',
    dest='create_service')

parser.add_argument(
    '--uid', '-u',
    action='store',
    default=common.generate_uid(),
    help='uid that will be concatenated to docker name',
    dest='uid')

args = parser.parse_args()
uid = args.uid

skydns = docker.run(
    image='crosbymichael/skydns',
    detach=True,
    name=common.format_dockername('skydns', uid),
    command=['-nameserver', '8.8.8.8:53', '-domain', 'docker'])

skydock = docker.run(
    image='crosbymichael/skydock',
    detach=True,
    name=common.format_dockername('skydock', uid),
    reflect=[('/var/run/docker.sock', 'rw')],
    volumes=[(args.create_service, '/createService.js', 'ro')],
    command=['-ttl', '30', '-environment', 'dev', '-s', '/var/run/docker.sock',
             '-domain', 'docker', '-name', 'skydns_{0}'.format(uid), '-plugins',
             '/createService.js'])

skydns_config = docker.inspect(skydns)
dns = skydns_config['NetworkSettings']['IPAddress']

output = {
    'dns': dns,
    'docker_ids': [skydns, skydock]
}

# Print JSON to output so it can be parsed by other scripts
print(json.dumps(output))
{'fraction_non_alphanumeric': 0.15867261572783045, 'fraction_numerical': 0.007250418293363078, 'mean_word_length': 4.2212518195050945, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3591551', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1170, 'n_words': 276}