@@ -660,23 +660,7 @@ def _add_new_resources(self, command_generator, resources, resource_options):
660660 cfg_editors = []
661661 aaz_ref = {}
662662 for resource , options in zip (resources , resource_options ):
663- try :
664- command_group = command_generator .create_draft_command_group (
665- resource , instance_var = CMDBuildInVariants .Instance , ** options )
666- except InvalidSwaggerValueError as err :
667- raise exceptions .InvalidAPIUsage (
668- message = str (err )
669- ) from err
670- assert not command_group .command_groups , "The logic to support sub command groups is not supported"
671- if not isinstance (resource , CMDResource ):
672- # Typespec use CMDResource directly, but swagger use swagger Resource
673- resource = resource .to_cmd ()
674- cfg_editor = WorkspaceCfgEditor .new_cfg (
675- plane = self .ws .plane ,
676- resources = [resource ],
677- command_groups = [command_group ]
678- )
679-
663+ cfg_editor = self ._build_draft_cfg_editor (command_generator , resource , options )
680664 # inherit modification from cfg in aaz
681665 aaz_version = options .get ('aaz_version' , None )
682666 if aaz_version :
@@ -689,7 +673,14 @@ def _add_new_resources(self, command_generator, resources, resource_options):
689673 for cmd_names , _ in cfg_editor .iter_commands ():
690674 aaz_ref [' ' .join (cmd_names )] = aaz_version
691675
692- cfg_editor .build_identity_subresource (command_group )
676+ update_cmd_info = cfg_editor .get_update_cmd (resource .id )
677+ temp_generic_update_cmd = None
678+ if update_cmd_info and options .get ('update_by' , None ) == "PatchOnly" :
679+ temp_cfg_editor = self ._build_draft_cfg_editor (command_generator , resource , {"update_by" : "GenericOnly" })
680+ temp_update_cmd_info = temp_cfg_editor .get_update_cmd (resource .id )
681+ if temp_update_cmd_info :
682+ _ , temp_generic_update_cmd , _ = temp_update_cmd_info
683+ cfg_editor .build_identity_subresource (resource .id , temp_generic_update_cmd )
693684 cfg_editors .append (cfg_editor )
694685
695686 # add cfg_editors
@@ -824,23 +815,15 @@ def _reload_resources(self, command_generator, reload_resource_map):
824815 if update_cmd_info :
825816 _ , _ , update_by = update_cmd_info
826817 options ['update_by' ] = update_by
827- try :
828- command_group = command_generator .create_draft_command_group (
829- resource , instance_var = CMDBuildInVariants .Instance , ** options )
830- except InvalidSwaggerValueError as err :
831- raise exceptions .InvalidAPIUsage (
832- message = str (err )
833- ) from err
834- assert not command_group .command_groups , "The logic to support sub command groups is not supported"
835- if not isinstance (resource , CMDResource ):
836- # Typespec use CMDResource directly, but swagger use swagger Resource
837- resource = resource .to_cmd ()
838- new_cfg_editor = WorkspaceCfgEditor .new_cfg (
839- plane = self .ws .plane ,
840- resources = [resource ],
841- command_groups = [command_group ]
842- )
818+ new_cfg_editor = self ._build_draft_cfg_editor (command_generator , resource , options )
843819 new_cfg_editor .inherit_modification (cfg_editor )
820+ temp_generic_update_cmd = None
821+ if update_cmd_info and update_by == "PatchOnly" :
822+ temp_cfg_editor = self ._build_draft_cfg_editor (command_generator , resource , {"update_by" : "GenericOnly" })
823+ temp_update_cmd_info = temp_cfg_editor .get_update_cmd (resource_id )
824+ if temp_update_cmd_info :
825+ _ , temp_generic_update_cmd , _ = temp_update_cmd_info
826+ new_cfg_editor .build_identity_subresource (resource_id , temp_generic_update_cmd )
844827 new_cfg_editors .append (new_cfg_editor )
845828
846829 # remove old cfg editor
@@ -850,6 +833,24 @@ def _reload_resources(self, command_generator, reload_resource_map):
850833
851834 # add cfg_editors
852835 self ._add_cfg_editors (new_cfg_editors )
836+
837+ def _build_draft_cfg_editor (self , command_generator , resource , options ):
838+ try :
839+ command_group = command_generator .create_draft_command_group (
840+ resource , instance_var = CMDBuildInVariants .Instance , ** options )
841+ except InvalidSwaggerValueError as err :
842+ raise exceptions .InvalidAPIUsage (
843+ message = str (err )
844+ ) from err
845+ assert not command_group .command_groups , "The logic to support sub command groups is not supported"
846+ if not isinstance (resource , CMDResource ):
847+ # Typespec use CMDResource directly, but swagger use swagger Resource
848+ resource = resource .to_cmd ()
849+ return WorkspaceCfgEditor .new_cfg (
850+ plane = self .ws .plane ,
851+ resources = [resource ],
852+ command_groups = [command_group ]
853+ )
853854
854855 def add_new_command_by_aaz (self , * cmd_names , version ):
855856 # TODO: add support to load from aaz
0 commit comments