@@ -212,9 +212,8 @@ class ActivationKey(
212212
213213 def __init__ (self , server_config = None , ** kwargs ):
214214 self ._fields = {
215- 'content_view ' : entity_fields .OneToOneField ( ContentView ),
215+ 'content_view_environment_ids ' : entity_fields .ListField ( ),
216216 'description' : entity_fields .StringField (),
217- 'environment' : entity_fields .OneToOneField (LifecycleEnvironment ),
218217 'host_collection' : entity_fields .OneToManyField (HostCollection ),
219218 'max_hosts' : entity_fields .IntegerField (),
220219 'name' : entity_fields .StringField (
@@ -262,10 +261,42 @@ def path(self, which=None):
262261 return f'{ super ().path (which = "self" )} /{ which } '
263262 return super ().path (which )
264263
264+ def read (self , entity = None , attrs = None , ignore = None , params = None ):
265+ """Handle the content_view_environments response format."""
266+ if attrs is None :
267+ attrs = self .read_json (params = params )
268+ if ignore is None :
269+ ignore = set ()
270+ ignore .add ('content_view_environment_ids' )
271+ entity = super ().read (entity , attrs , ignore , params )
272+ entity .content_view_environments = attrs .get ('content_view_environments' , [])
273+ return entity
274+
275+ @property
276+ def content_view (self ):
277+ """Backward-compat: extract the first content view from content_view_environments."""
278+ cves = getattr (self , 'content_view_environments' , None )
279+ if not cves :
280+ return None
281+ cv_data = cves [0 ].get ('content_view' )
282+ if not cv_data :
283+ return None
284+ return ContentView (server_config = self ._server_config , id = cv_data ['id' ])
285+
286+ @property
287+ def environment (self ):
288+ """Backward-compat: extract the first lifecycle environment from content_view_environments."""
289+ cves = getattr (self , 'content_view_environments' , None )
290+ if not cves :
291+ return None
292+ lce_data = cves [0 ].get ('lifecycle_environment' )
293+ if not lce_data :
294+ return None
295+ return LifecycleEnvironment (server_config = self ._server_config , id = lce_data ['id' ])
296+
265297 def update_payload (self , fields = None ):
266298 """Include organization_id in all payloads."""
267299 payload = super ().update_payload (fields )
268- # organization is required for the AK update call
269300 payload ['organization_id' ] = self .organization .id
270301 return payload
271302
@@ -4043,6 +4074,7 @@ def __init__(self, server_config=None, **kwargs):
40434074 self ._fields .update (
40444075 {
40454076 'content_view' : entity_fields .OneToOneField (ContentView ),
4077+ 'content_view_environment_id' : entity_fields .IntegerField (),
40464078 'lifecycle_environment' : entity_fields .OneToOneField (LifecycleEnvironment ),
40474079 }
40484080 )
@@ -4062,13 +4094,12 @@ def create(self, create_missing=None):
40624094 ).read ()
40634095
40644096 def create_payload (self ):
4065- """Wrap submitted data within an extra dict.
4066-
4067- For more information, see `Bugzilla #1151220
4068- <https://bugzilla.redhat.com/show_bug.cgi?id=1151220>`_.
4069-
4070- """
4071- return {'hostgroup' : super ().create_payload ()}
4097+ """Wrap submitted data within an extra dict."""
4098+ payload = super ().create_payload ()
4099+ if 'content_view_environment_id' in payload :
4100+ payload .pop ('content_view_id' , None )
4101+ payload .pop ('lifecycle_environment_id' , None )
4102+ return {'hostgroup' : payload }
40724103
40734104 def read (self , entity = None , attrs = None , ignore = None , params = None ):
40744105 """Deal with several bugs.
@@ -4110,7 +4141,11 @@ def update(self, fields=None):
41104141
41114142 def update_payload (self , fields = None ):
41124143 """Wrap submitted data within an extra dict."""
4113- return {'hostgroup' : super ().update_payload (fields )}
4144+ payload = super ().update_payload (fields )
4145+ if 'content_view_environment_id' in payload :
4146+ payload .pop ('content_view_id' , None )
4147+ payload .pop ('lifecycle_environment_id' , None )
4148+ return {'hostgroup' : payload }
41144149
41154150 def path (self , which = None ):
41164151 """Extend ``nailgun.entity_mixins.Entity.path``.
0 commit comments