Murat Parlakisik | 638c65f | 2017-05-31 11:10:24 +0300 | [diff] [blame^] | 1 | def __init__(self, *args, **kwargs): |
| 2 | super(ONOSServiceMonitoringPublisher, self).__init__(*args, **kwargs) |
| 3 | |
| 4 | def can_update(self, user): |
| 5 | #Don't allow creation of this model instances for non-admin users also |
| 6 | return False |
| 7 | |
| 8 | def save(self, *args, **kwargs): |
| 9 | if not self.creator: |
| 10 | if not getattr(self, "caller", None): |
| 11 | # caller must be set when creating a monitoring channel since it creates a slice |
| 12 | raise XOSProgrammingError("ONOSServiceMonitoringPublisher's self.caller was not set") |
| 13 | self.creator = self.caller |
| 14 | if not self.creator: |
| 15 | raise XOSProgrammingError("ONOSServiceMonitoringPublisher's self.creator was not set") |
| 16 | |
| 17 | if self.pk is None: |
| 18 | #Allow only one openstack monitoring publisher per admin user |
| 19 | publisher_count = sum ( [1 for onospublisher in ONOSServiceMonitoringPublisher.get_tenant_objects().all() if (onospublisher.creator == self.creator)] ) |
| 20 | if publisher_count > 0: |
| 21 | raise XOSValidationError("Already %s openstack publishers exist for user Can only create max 1 ONOSServiceMonitoringPublisher instance per user" % str(publisher_count)) |
| 22 | |
| 23 | super(ONOSServiceMonitoringPublisher, self).save(*args, **kwargs) |