Skip to content

Commit 3156cba

Browse files
committed
Add optional property "cloud_info" for VMIs
This commit introduces a new optional property for all VMIPushItems named `VMICloudInformation` which stores the cloud's provider name and account alias into it. The goal of this change is to be able to parse the patched `clouds.json` with this new property, which was instroduced in pubtools-marketplacesvm#71, allowing the DeleteTask to have a more reliable way to retrieve the provider/account information. Refers to SPSTRAT-363
1 parent 10e5e0a commit 3156cba

File tree

16 files changed

+80
-2
lines changed

16 files changed

+80
-2
lines changed

docs/model/vmi.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@ Push items: VMI
77
.. autoclass:: pushsource.VMIRelease()
88
:members:
99

10+
.. autoclass:: pushsource.VMICloudInformation()
11+
:members:
12+
1013
.. autoclass:: pushsource.BootMode()
1114
:members:

src/pushsource/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
AmiBillingCodes,
2727
AmiSecurityGroup,
2828
VHDPushItem,
29+
VMICloudInformation,
2930
BootMode,
3031
ErratumPushItem,
3132
ErratumReference,

src/pushsource/_impl/model/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@
3030
AmiSecurityGroup,
3131
)
3232
from .azure import VHDPushItem
33-
from .vms import BootMode, VMIPushItem, VMIRelease
33+
from .vms import BootMode, VMICloudInformation, VMIPushItem, VMIRelease

src/pushsource/_impl/model/ami.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from .. import compat_attr as attr
44
from .conv import instance_of_str, instance_of, optional_str, optional
5-
from .vms import VMIRelease, VMIPushItem, BootMode
5+
from .vms import VMICloudInformation, VMIRelease, VMIPushItem, BootMode
66

77

88
class AmiRelease(VMIRelease):
@@ -219,6 +219,11 @@ def _from_data(cls, data):
219219
# base push item fields
220220
"name": data["name"],
221221
"build": data.get("build") or None,
222+
"cloud_info": (
223+
VMICloudInformation(**data.get("cloud_info"))
224+
if data.get("cloud_info")
225+
else None
226+
),
222227
"state": "PENDING",
223228
"src": data.get("src") or None,
224229
"dest": data.get("dest") or [],

src/pushsource/_impl/model/vms.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ def __repr__(self):
2424
return f"{cls_name}.{self.name}"
2525

2626

27+
@attr.s()
28+
class VMICloudInformation(object):
29+
"""Inform the cloud provider's name and account alias of a given push item."""
30+
31+
provider = attr.ib(type=str, validator=instance_of_str)
32+
"""The cloud provider's name, e.g.: "aws"."""
33+
34+
account = attr.ib(type=str, validator=instance_of_str)
35+
"""The cloud provider's account alias, e.g.: "aws-na"."""
36+
37+
2738
@attr.s()
2839
class VMIRelease(object):
2940
"""Release metadata associated with a VM image."""
@@ -79,6 +90,13 @@ class VMIPushItem(PushItem):
7990
boot_mode = attr.ib(type=BootMode, default=None, validator=optional(in_(BootMode)))
8091
"""Boot mode supported by the image (if known): uefi, legacy, or hybrid (uefi + legacy)."""
8192

93+
cloud_info = attr.ib(
94+
type=VMICloudInformation,
95+
default=None,
96+
validator=optional((instance_of(VMICloudInformation))),
97+
)
98+
"""Cloud provider information of its short name and account alias."""
99+
82100
marketplace_title_template = attr.ib(type=str, default=None, validator=optional_str)
83101
"""The template is of the form used by ``str.format``, with available keywords being all of
84102
the documented fields on ``VMIRelease`` and ``AMIRelease`` classes.

tests/baseline/cases/staged-simple-ami-bc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ items:
1818
boot_mode: null
1919
build: null
2020
build_info: null
21+
cloud_info: null
2122
description: A sample image for testing
2223
dest:
2324
- dest1

tests/baseline/cases/staged-simple-ami-bootmode.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ items:
1414
boot_mode: uefi
1515
build: null
1616
build_info: null
17+
cloud_info: null
1718
description: A sample image for testing
1819
dest:
1920
- dest1

tests/baseline/cases/staged-simple-ami-uefi.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ items:
1414
boot_mode: null
1515
build: null
1616
build_info: null
17+
cloud_info: null
1718
description: A sample image for testing
1819
dest:
1920
- dest1

tests/baseline/cases/staged-simple-ami.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ items:
1414
boot_mode: null
1515
build: null
1616
build_info: null
17+
cloud_info: null
1718
description: A sample image for testing
1819
dest:
1920
- dest1

tests/baseline/cases/staged-simple-cloud.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ items:
1818
name: rhel
1919
release: '1'
2020
version: '9.4'
21+
cloud_info: null
2122
description: build2 sample
2223
dest:
2324
- starmap
@@ -68,6 +69,7 @@ items:
6869
name: rhel
6970
release: '1'
7071
version: '9.4'
72+
cloud_info: null
7173
description: build2 sample
7274
dest:
7375
- starmap
@@ -118,6 +120,7 @@ items:
118120
name: rhel-ec2
119121
release: '1'
120122
version: '9.4'
123+
cloud_info: null
121124
description: build3 sample
122125
dest:
123126
- starmap
@@ -166,6 +169,7 @@ items:
166169
name: rhel-ec2
167170
release: '1'
168171
version: '9.4'
172+
cloud_info: null
169173
description: build1 sample
170174
dest:
171175
- starmap
@@ -203,6 +207,7 @@ items:
203207
name: rhel-ec2
204208
release: '1'
205209
version: '9.4'
210+
cloud_info: null
206211
description: build1 sample
207212
dest:
208213
- starmap

0 commit comments

Comments
 (0)