Added profile type checking for update actions
We only allow update to be performed using the same profile type.
This commit is contained in:
parent
da333cf5de
commit
2048447280
@ -193,16 +193,25 @@ class Cluster(object):
|
|||||||
def do_delete(self, context, **kwargs):
|
def do_delete(self, context, **kwargs):
|
||||||
self.status = self.DELETED
|
self.status = self.DELETED
|
||||||
|
|
||||||
def do_update(self, context, **kwargs):
|
def do_update(self, context, new_profile_id, **kwargs):
|
||||||
# Profile type checking is done here because the do_update logic can
|
# Profile type checking is done here because the do_update logic can
|
||||||
# be triggered from API or Webhook
|
# be triggered from API or Webhook
|
||||||
# TODO(Qiming): check if profile is of the same type
|
if self.profile_id == new_profile_id:
|
||||||
profile_id = kwargs.get('profile_id')
|
|
||||||
if self.profile_id == profile_id:
|
|
||||||
events.warning(_LW('Cluster refuses to update to the same profile'
|
events.warning(_LW('Cluster refuses to update to the same profile'
|
||||||
'(%s)' % (profile_id)))
|
'(%s)' % (new_profile_id)))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
# Check if profile types match
|
||||||
|
old_profile = db_api.get_profile(context, self.profile_id)
|
||||||
|
new_profile = db_api.get_profile(context, new_profile_id)
|
||||||
|
if old_profile.type != new_profile.type:
|
||||||
|
events.warning(_LW('Cluster cannot be updated to a different '
|
||||||
|
'profile type (%(oldt)s->%(newt)s)'),
|
||||||
|
{'oldt': old_profile.type,
|
||||||
|
'newt': new_profile.type})
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def get_next_index(self):
|
def get_next_index(self):
|
||||||
# TODO(Qiming): Get next_index from db and increment it in db
|
# TODO(Qiming): Get next_index from db and increment it in db
|
||||||
curr = self._next_index
|
curr = self._next_index
|
||||||
|
Loading…
Reference in New Issue
Block a user