Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Add Compute Gallery images support (#1450)
Browse files Browse the repository at this point in the history
  • Loading branch information
puhley authored Nov 18, 2021
1 parent dd03996 commit 58091c2
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/api-service/__app__/onefuzzlib/azure/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,27 @@
@cached(ttl=60)
def get_os(region: Region, image: str) -> Union[Error, OS]:
client = get_compute_client()
# The dict returned here may not have any defined keys.
#
# See: https://github.com/Azure/msrestazure-for-python/blob/v0.6.3/msrestazure/tools.py#L134 # noqa: E501
parsed = parse_resource_id(image)
if "resource_group" in parsed:
try:
name = client.images.get(
parsed["resource_group"], parsed["name"]
).storage_profile.os_disk.os_type.name
except (ResourceNotFoundError, CloudError) as err:
return Error(code=ErrorCode.INVALID_IMAGE, errors=[str(err)])
if parsed["type"] == "galleries":
try:
# See: https://docs.microsoft.com/en-us/rest/api/compute/gallery-images/get#galleryimage # noqa: E501
name = client.gallery_images.get(
parsed["resource_group"], parsed["name"], parsed["child_name_1"]
).os_type.lower()
except (ResourceNotFoundError, CloudError) as err:
return Error(code=ErrorCode.INVALID_IMAGE, errors=[str(err)])
else:
try:
# See: https://docs.microsoft.com/en-us/rest/api/compute/images/get
name = client.images.get(
parsed["resource_group"], parsed["name"]
).storage_profile.os_disk.os_type.lower()
except (ResourceNotFoundError, CloudError) as err:
return Error(code=ErrorCode.INVALID_IMAGE, errors=[str(err)])
else:
publisher, offer, sku, version = image.split(":")
try:
Expand Down

0 comments on commit 58091c2

Please sign in to comment.