~abentley/juju-ci-tools/client-from-config-4

« back to all changes in this revision

Viewing changes to get_ami.py

  • Committer: Martin Packman
  • Date: 2015-11-17 14:19:06 UTC
  • mto: This revision was merged to the branch mainline in revision 1155.
  • Revision ID: martin.packman@canonical.com-20151117141906-a4zmuqre72s7fyf1
Sample script for generating image streams for rackspace

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 
10
10
 
11
11
STREAM_INDEX = "http://cloud-images.ubuntu.com/releases/streams/v1/index.json"
12
 
DAILY_INDEX = "http://cloud-images.ubuntu.com/daily/streams/v1/index.json"
13
12
ENDPOINT_TEMPLATE = "endpoint~ec2.{region}.amazonaws.com"
14
13
 
15
14
DEFAULT_PARAMS = {
19
18
}
20
19
 
21
20
 
22
 
def query_ami(series, arch, region=None, stream='released', **kwargs):
 
21
def query_ami(series, arch, region=None, **kwargs):
23
22
    """Lookup newest ami for given series and arch, plus optional params."""
24
23
    if region is None:
25
24
        region = "us-east-1"
26
 
    if stream == 'daily':
27
 
        index = DAILY_INDEX
28
 
    else:
29
 
        index = STREAM_INDEX
30
25
    sstream_params = ["arch=" + arch, "release=" + series]
31
26
    for k in sorted(DEFAULT_PARAMS):
32
27
        v = kwargs.pop(k, DEFAULT_PARAMS[k])
37
32
    if kwargs:
38
33
        raise ValueError("Unknown kwargs: {}".format(", ".join(kwargs)))
39
34
    endpoint_info = ENDPOINT_TEMPLATE.format(region=region)
40
 
    cmdline = ["sstream-query", index, endpoint_info]
 
35
    cmdline = ["sstream-query", STREAM_INDEX, endpoint_info]
41
36
    cmdline.extend(sstream_params)
42
37
    cmdline.extend(["--output-format", "%(id)s"])
43
38
    try:
57
52
    parser = ArgumentParser('Get an up to date ami.')
58
53
    parser.add_argument('series', help='Ubuntu series for image')
59
54
    parser.add_argument('arch', help='Architecture for image')
60
 
    parser.add_argument('--stream', choices=['released', 'daily'],
61
 
                        default='released',
62
 
                        help='The stream to select the image from')
63
55
    parser.add_argument('--region', help='Region to retrieve image for')
64
56
    parser.add_argument('--label')
65
57
    parser.add_argument('--root-store')
70
62
def main():
71
63
    args = parse_args()
72
64
    try:
73
 
        print(query_ami(args.series, args.arch, region=args.region,
74
 
                        stream=args.stream, label=args.label,
 
65
        print(query_ami(args.series, args.arch, args.region, label=args.label,
75
66
                        root_store=args.root_store, virt=args.virt))
76
67
    except ValueError as err:
77
68
        print(err, file=sys.stderr)