Skip to content

Commit 0f0d0c0

Browse files
JAVGanrohanpm
andauthored
Add optional property "cloud_info" for VMIs (#637)
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 introduced in release-engineering/pubtools-marketplacesvm#71 , allowing the DeleteTask to have a more reliable way to retrieve the provider/account information. Refers to SPSTRAT-363 --------- Co-authored-by: Rohan McGovern <[email protected]>
1 parent 2b702ce commit 0f0d0c0

File tree

16 files changed

+89
-2
lines changed

16 files changed

+89
-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.VMICloudInfo()
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+
VMICloudInfo,
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, VMICloudInfo, 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 VMICloudInfo, 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+
VMICloudInfo(**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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@ def __repr__(self):
2424
return f"{cls_name}.{self.name}"
2525

2626

27+
@attr.s()
28+
class VMICloudInfo(object):
29+
"""Information on the cloud provider associated with a given push item.
30+
31+
Cloud provider information is only available for VMIs which have previously
32+
been published to a cloud. It may be used to locate an existing VMI for
33+
manipulation, such as metadata updates or deletion.
34+
35+
This library doesn't define any specific cloud provider names or aliases.
36+
Generally, a user of this library is expected to use the information here
37+
to look up cloud access details from a configuration file or other source.
38+
"""
39+
40+
provider = attr.ib(type=str, validator=instance_of_str)
41+
"""The cloud provider's name, e.g.: "aws"."""
42+
43+
account = attr.ib(type=str, validator=instance_of_str)
44+
"""The cloud provider's account alias, e.g.: "aws-na"."""
45+
46+
2747
@attr.s()
2848
class VMIRelease(object):
2949
"""Release metadata associated with a VM image."""
@@ -79,6 +99,13 @@ class VMIPushItem(PushItem):
7999
boot_mode = attr.ib(type=BootMode, default=None, validator=optional(in_(BootMode)))
80100
"""Boot mode supported by the image (if known): uefi, legacy, or hybrid (uefi + legacy)."""
81101

102+
cloud_info = attr.ib(
103+
type=VMICloudInfo,
104+
default=None,
105+
validator=optional((instance_of(VMICloudInfo))),
106+
)
107+
"""Cloud provider information, such as the provider's short name and account alias."""
108+
82109
marketplace_title_template = attr.ib(type=str, default=None, validator=optional_str)
83110
"""The template is of the form used by ``str.format``, with available keywords being all of
84111
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)