|
1 | 1 | #!/usr/bin/env python |
2 | 2 | """Module with k8s nodegroup.""" |
| 3 | +import gzip |
3 | 4 | import json |
4 | 5 | import os |
5 | 6 | from typing import Any |
|
20 | 21 |
|
21 | 22 |
|
22 | 23 | def get_valid_instance_types() -> Any: |
23 | | - """Return list of instance types.""" |
24 | | - ec2_service_file = os.path.join( |
25 | | - os.path.dirname(botocore.__file__), |
26 | | - "data", |
27 | | - "ec2", |
28 | | - "2016-11-15", |
29 | | - "service-2.json", |
| 24 | + """Return list of instance types from either a JSON or gzipped JSON file.""" |
| 25 | + base_path = os.path.join( |
| 26 | + os.path.dirname(botocore.__file__), "data", "ec2", "2016-11-15" |
30 | 27 | ) |
31 | | - # This encoding needs to be explicitly called out as utf-8 on Windows |
32 | | - # (or it will try cp1252 instead) |
33 | | - with open(ec2_service_file, "r", encoding="utf-8") as stream: |
34 | | - return json.load(stream)["shapes"]["InstanceType"]["enum"] |
| 28 | + |
| 29 | + json_path = os.path.join(base_path, "service-2.json") |
| 30 | + gzip_path = os.path.join(base_path, "service-2.json.gz") |
| 31 | + |
| 32 | + if os.path.exists(gzip_path): |
| 33 | + with gzip.open(gzip_path, "rt", encoding="utf-8") as stream: |
| 34 | + data = json.load(stream) |
| 35 | + elif os.path.exists(json_path): |
| 36 | + with open(json_path, "r", encoding="utf-8") as stream: |
| 37 | + data = json.load(stream) |
| 38 | + else: |
| 39 | + raise FileNotFoundError("Neither JSON nor gzipped JSON file found.") |
| 40 | + |
| 41 | + return data["shapes"]["InstanceType"]["enum"] |
35 | 42 |
|
36 | 43 |
|
37 | 44 | class NodeGroup(Blueprint): |
|
0 commit comments