Skip to content

Commit 0fc2b7c

Browse files
committed
Adds support for clouds.json to Pub Source
1 parent e157d2f commit 0fc2b7c

File tree

6 files changed

+692
-19
lines changed

6 files changed

+692
-19
lines changed

src/pushsource/_impl/backend/pub_source/pub_client.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,25 @@ def _session(self):
4343
self._tls.session = requests.Session()
4444
return self._tls.session
4545

46-
def _do_request(self, **kwargs):
47-
return self._session.request(**kwargs)
46+
def _do_request(self, url, **kwargs):
47+
kwargs["url"] = url.format(filename="images.json")
48+
resp = self._session.request(**kwargs)
49+
# if 404 lets try clouds.json
50+
if resp.status_code == 404:
51+
kwargs["url"] = url.format(filename="clouds.json")
52+
resp = self._session.request(**kwargs)
53+
return resp
4854

4955
def get_ami_json_f(self, task_id):
5056
"""
5157
Returns Future[dict|list] holding json obj with AMI push items returned from Pub for given task id.
5258
"""
5359
endpoint = "pub/task"
54-
url_ending = "log/images.json"
60+
url_ending = "log/{filename}"
5561
params = {"format": "raw"}
5662
url = os.path.join(self._url, endpoint, str(task_id), url_ending)
5763

58-
LOG.info("Requesting Pub service for %s of task: %s", url_ending, str(task_id))
64+
LOG.info("Fetching AMI details from Pub task: %s", str(task_id))
5965
ft = self._executor.submit(
6066
self._do_request, method="GET", url=url, params=params
6167
)

src/pushsource/_impl/model/ami.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ def _from_data(cls, data):
224224
"origin": data.get("origin") or None,
225225
# ami push item fields
226226
"release": AmiRelease._from_data(data.get("release") or {}),
227-
"type": data["type"],
228-
"region": data["region"],
227+
"type": data.get("type") or None,
228+
"region": data.get("region") or None,
229229
"virtualization": data["virtualization"],
230230
"volume": data["volume"],
231231
"root_device": data["root_device"],
@@ -236,8 +236,10 @@ def _from_data(cls, data):
236236
"boot_mode": (
237237
BootMode(data.get("boot_mode")) if data.get("boot_mode") else None
238238
),
239-
"billing_codes": AmiBillingCodes._from_data(
240-
data.get("billing_codes") or {}
239+
"billing_codes": (
240+
AmiBillingCodes._from_data(data.get("billing_codes"))
241+
if data.get("billing_codes")
242+
else None
241243
),
242244
"image_id": data.get("ami") or None,
243245
"public_image": data.get("public_image"),

tests/pub/data/123456/clouds.json

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
[
2+
{
3+
"boot_mode": null,
4+
"build": "rhel-sap-ec2-8.8-2116",
5+
"build_info": {
6+
"id": 3176889,
7+
"name": "rhel-sap-ec2",
8+
"release": "2116",
9+
"version": "8.8"
10+
},
11+
"description": "Provided by Red Hat, Inc.",
12+
"dest": [
13+
"test-dest"
14+
],
15+
"ena_support": true,
16+
"image_id": "ami-test",
17+
"marketplace_entity_type": "AmiProduct",
18+
"md5sum": "0ef2038e599967f7074b6c52e5b2afae",
19+
"name": "rhel-sap-ec2-8.8-2116.x86_64.raw.xz",
20+
"recommended_instance_type": "t2.micro",
21+
"release": {
22+
"arch": "x86_64",
23+
"base_product": null,
24+
"base_version": null,
25+
"date": "20240717",
26+
"product": "RHEL-SAP",
27+
"respin": 2116,
28+
"type": null,
29+
"variant": null,
30+
"version": "8.8"
31+
},
32+
"release_notes": "Fake release notes",
33+
"root_device": "/dev/sda1",
34+
"scanning_port": 22,
35+
"security_groups": [
36+
{
37+
"from_port": 22,
38+
"ip_protocol": "tcp",
39+
"ip_ranges": [
40+
"0.0.0.0/0"
41+
],
42+
"to_port": 22
43+
}
44+
],
45+
"src": "/test/path/packages/rhel-sap-ec2/8.8/2116/images/rhel-sap-ec2-8.8-2116.x86_64.raw.xz",
46+
"sriov_net_support": "simple",
47+
"starmap_query": {
48+
"clouds": {
49+
"aws-emea": [
50+
{
51+
"architecture": "x86_64",
52+
"destination": "test-dest",
53+
"id": null,
54+
"meta": {
55+
"description": "Provided by Red Hat Limited.",
56+
"ena_support": true,
57+
"marketplace_entity_type": "AmiProduct",
58+
"recommended_instance_type": "t2.micro",
59+
"release_notes": "Fake release notes",
60+
"root_device": "/dev/sda1",
61+
"scanning_port": 22,
62+
"security_groups": [
63+
{
64+
"from_port": 22,
65+
"ip_protocol": "tcp",
66+
"ip_ranges": [
67+
"0.0.0.0/0"
68+
],
69+
"to_port": 22
70+
}
71+
],
72+
"sharing_accounts": [
73+
"tester"
74+
],
75+
"sriov_net_support": "simple",
76+
"usage_instructions": "Fake use instructions",
77+
"user_name": "Fake-Username",
78+
"virtualization": "hvm",
79+
"volume": "gp2"
80+
},
81+
"overwrite": false,
82+
"provider": null,
83+
"restrict_major": null,
84+
"restrict_minor": null,
85+
"restrict_version": true,
86+
"tags": {}
87+
}
88+
],
89+
"aws-na": [
90+
{
91+
"architecture": "x86_64",
92+
"destination": "test-dest2",
93+
"id": null,
94+
"meta": {
95+
"description": "Provided by Red Hat, Inc.",
96+
"ena_support": true,
97+
"marketplace_entity_type": "AmiProduct",
98+
"recommended_instance_type": "t2.micro",
99+
"release_notes": "Fake release notes",
100+
"root_device": "/dev/sda1",
101+
"scanning_port": 22,
102+
"security_groups": [
103+
{
104+
"from_port": 22,
105+
"ip_protocol": "tcp",
106+
"ip_ranges": [
107+
"0.0.0.0/0"
108+
],
109+
"to_port": 22
110+
}
111+
],
112+
"sharing_accounts": [
113+
"tester"
114+
],
115+
"sriov_net_support": "simple",
116+
"usage_instructions": "Fake use instructions",
117+
"user_name": "Fake-Username",
118+
"virtualization": "hvm",
119+
"volume": "gp2"
120+
},
121+
"overwrite": false,
122+
"provider": null,
123+
"restrict_major": null,
124+
"restrict_minor": null,
125+
"restrict_version": true,
126+
"tags": {}
127+
}
128+
]
129+
},
130+
"name": "rhel-sap-ec2",
131+
"workflow": "stratosphere"
132+
},
133+
"state": "PUSHED",
134+
"usage_instructions": "Fake use instructions",
135+
"user_name": "Fake-Username",
136+
"virtualization": "hvm",
137+
"volume": "gp2"
138+
}
139+
]

0 commit comments

Comments
 (0)