27
27
28
28
from .common import (
29
29
AZURE_SHARED_RG_NAME ,
30
+ AzureNodeSchema ,
30
31
check_blob_exist ,
31
32
check_or_create_gallery ,
32
33
check_or_create_gallery_image ,
@@ -565,6 +566,10 @@ class SigTransformerSchema(schema.Transformer):
565
566
),
566
567
),
567
568
)
569
+ # Marketplace image to take features from.
570
+ # Will override gallery_image_architecture,
571
+ # gallery_image_hyperv_generation, and gallery_image_securitytype
572
+ marketplace_source : str = field (default = "" )
568
573
569
574
570
575
class SharedGalleryImageTransformer (Transformer ):
@@ -607,6 +612,18 @@ def _internal_run(self) -> Dict[str, Any]:
607
612
raise_error = True ,
608
613
)
609
614
615
+ # Get features from marketplace image if specified
616
+ features = self ._get_image_features (platform , runbook .marketplace_source )
617
+ if features :
618
+ runbook .gallery_image_hyperv_generation = features .pop (
619
+ "hyper_v_generation" , runbook .gallery_image_hyperv_generation
620
+ )
621
+ runbook .gallery_image_architecture = features .pop (
622
+ "architecture" , runbook .gallery_image_architecture
623
+ )
624
+ elif runbook .gallery_image_securitytype :
625
+ features = {"SecurityType" : runbook .gallery_image_securitytype }
626
+
610
627
(
611
628
gallery_image_publisher ,
612
629
gallery_image_offer ,
@@ -643,7 +660,7 @@ def _internal_run(self) -> Dict[str, Any]:
643
660
runbook .gallery_image_osstate ,
644
661
runbook .gallery_image_hyperv_generation ,
645
662
runbook .gallery_image_architecture ,
646
- runbook . gallery_image_securitytype ,
663
+ features ,
647
664
)
648
665
649
666
check_or_create_gallery_image_version (
@@ -670,3 +687,26 @@ def _internal_run(self) -> Dict[str, Any]:
670
687
671
688
self ._log .info (f"SIG Url: { sig_url } " )
672
689
return {self .__sig_name : sig_url }
690
+
691
+ def _get_image_features (
692
+ self , platform : AzurePlatform , marketplace : str
693
+ ) -> Dict [str , Any ]:
694
+ if not marketplace :
695
+ return {}
696
+ node_schema = AzureNodeSchema (marketplace_raw = marketplace )
697
+ if not node_schema .marketplace :
698
+ return {}
699
+ features = node_schema .marketplace ._get_info (platform )
700
+
701
+ # Convert hyper_v_generation to int from form "V1", "V2"
702
+ if (
703
+ features .get ("hyper_v_generation" , None )
704
+ and features ["hyper_v_generation" ].strip ("V" ).isdigit ()
705
+ ):
706
+ features ["hyper_v_generation" ] = int (
707
+ features ["hyper_v_generation" ].strip ("V" )
708
+ )
709
+ else :
710
+ features .pop ("hyper_v_generation" , None )
711
+
712
+ return features
0 commit comments