Left: | ||
Right: |
OLD | NEW |
---|---|
1 from collections import namedtuple | 1 from collections import namedtuple |
2 import csv | 2 import csv |
3 import logging | 3 import logging |
4 import operator | 4 import operator |
5 import os | |
5 from string import ascii_lowercase | 6 from string import ascii_lowercase |
6 import StringIO | 7 import StringIO |
7 | 8 |
8 from twisted.internet.defer import inlineCallbacks, returnValue | 9 from twisted.internet.defer import inlineCallbacks, returnValue |
9 from twisted.web.client import getPage | 10 from twisted.web.client import getPage |
10 from twisted.web.error import Error | 11 from twisted.web.error import Error |
11 | 12 |
12 from juju.errors import ProviderError | 13 from juju.errors import ProviderError |
13 | 14 |
14 # We don't actually know what's available in any given region | 15 # We don't actually know what's available in any given region |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 from txaws.client import ssl | 52 from txaws.client import ssl |
52 from txaws.client.ssl import VerifyingContextFactory | 53 from txaws.client.ssl import VerifyingContextFactory |
53 except ImportError: | 54 except ImportError: |
54 ssl = None | 55 ssl = None |
55 VerifyingContextFactory = None | 56 VerifyingContextFactory = None |
56 | 57 |
57 _CURRENT_IMAGE_HOST = 'cloud-images.ubuntu.com' | 58 _CURRENT_IMAGE_HOST = 'cloud-images.ubuntu.com' |
58 _CURRENT_IMAGE_URI_TEMPLATE = ( | 59 _CURRENT_IMAGE_URI_TEMPLATE = ( |
59 "https://%s/query/%s/server/released.current.txt") | 60 "https://%s/query/%s/server/released.current.txt") |
60 | 61 |
62 _STREAM_IMAGE_URI_TEMPLATE = ( | |
63 "https://%s/query/%s/server/daily.current.txt") | |
teknico
2013/01/22 12:02:19
Thanks for not using an ugly continuation backslas
| |
64 | |
61 MachineSpec = namedtuple("MachineSpec", "instance_type image_id") | 65 MachineSpec = namedtuple("MachineSpec", "instance_type image_id") |
62 | 66 |
63 | 67 |
64 def convert_zone(s): | 68 def convert_zone(s): |
65 s = s.lower() | 69 s = s.lower() |
66 if len(s) == 1: | 70 if len(s) == 1: |
67 if s in _PLAUSIBLE_ZONES: | 71 if s in _PLAUSIBLE_ZONES: |
68 return s | 72 return s |
69 raise ValueError("expected single ascii letter") | 73 raise ValueError("expected single ascii letter") |
70 | 74 |
(...skipping 19 matching lines...) Expand all Loading... | |
90 continue | 94 continue |
91 if len(tokens) > 10: | 95 if len(tokens) > 10: |
92 if tokens[10] != required_kind: | 96 if tokens[10] != required_kind: |
93 continue | 97 continue |
94 elif hvm: | 98 elif hvm: |
95 raise LookupError("HVM images not available for %s" % series) | 99 raise LookupError("HVM images not available for %s" % series) |
96 if tokens[5] == arch and tokens[6] == region: | 100 if tokens[5] == arch and tokens[6] == region: |
97 return tokens[7] | 101 return tokens[7] |
98 raise LookupError((series, arch, region)) | 102 raise LookupError((series, arch, region)) |
99 | 103 |
100 uri = _CURRENT_IMAGE_URI_TEMPLATE % (_CURRENT_IMAGE_HOST, series) | 104 if bool(os.environ.get("JUJU_TESTING")): |
105 uri = _STREAM_IMAGE_URI_TEMPLATE % (_CURRENT_IMAGE_HOST, series) | |
106 else: | |
107 uri = _CURRENT_IMAGE_URI_TEMPLATE % (_CURRENT_IMAGE_HOST, series) | |
teknico
2013/01/22 12:02:19
Is this two-liner an improvement?
uri = (_STR
| |
108 | |
101 if ssl and ssl_verify: | 109 if ssl and ssl_verify: |
102 contextFactory = VerifyingContextFactory(_CURRENT_IMAGE_HOST) | 110 contextFactory = VerifyingContextFactory(_CURRENT_IMAGE_HOST) |
103 else: | 111 else: |
104 contextFactory = None | 112 contextFactory = None |
teknico
2013/01/22 12:02:19
Similarly:
contextFactory = VerifyingContextF
| |
105 d = getPage(uri, contextFactory=contextFactory) | 113 d = getPage(uri, contextFactory=contextFactory) |
106 d.addErrback(handle_404) | 114 d.addErrback(handle_404) |
107 d.addCallback(extract_ami) | 115 d.addCallback(extract_ami) |
108 return d | 116 return d |
109 | 117 |
110 | 118 |
111 def _arch_match(actual, desired): | 119 def _arch_match(actual, desired): |
112 if actual == desired: | 120 if actual == desired: |
113 return True | 121 return True |
114 if actual == _EITHER_ARCH: | 122 if actual == _EITHER_ARCH: |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 instance_type = get_instance_type(config, constraints) | 170 instance_type = get_instance_type(config, constraints) |
163 image_id = config.get("default-image-id") | 171 image_id = config.get("default-image-id") |
164 if image_id is None: | 172 if image_id is None: |
165 series = constraints["ubuntu-series"] or config["default-series"] | 173 series = constraints["ubuntu-series"] or config["default-series"] |
166 arch = constraints["arch"] or "amd64" | 174 arch = constraints["arch"] or "amd64" |
167 region = config.get("region", DEFAULT_REGION) | 175 region = config.get("region", DEFAULT_REGION) |
168 hvm = INSTANCE_TYPES[instance_type].hvm | 176 hvm = INSTANCE_TYPES[instance_type].hvm |
169 ssl_verify = config.get("ssl-hostname-verification", False) | 177 ssl_verify = config.get("ssl-hostname-verification", False) |
170 image_id = yield get_current_ami(series, arch, region, hvm, ssl_verify) | 178 image_id = yield get_current_ami(series, arch, region, hvm, ssl_verify) |
171 returnValue(MachineSpec(instance_type, image_id)) | 179 returnValue(MachineSpec(instance_type, image_id)) |
OLD | NEW |