rdudyala | 996d70b | 2016-10-13 17:40:55 +0000 | [diff] [blame] | 1 | from xosresource import XOSResource |
| 2 | from core.models import Tenant, Service |
| 3 | from services.monitoring.models import ONOSServiceMonitoringPublisher, CeilometerService, InfraMonitoringAgentInfo, MonitoringCollectorPluginInfo |
| 4 | |
| 5 | class XOSONOSMonitoringPublisher(XOSResource): |
| 6 | provides = "tosca.nodes.ONOSMonitoringPublisher" |
| 7 | xos_model = ONOSServiceMonitoringPublisher |
| 8 | name_field = None |
| 9 | |
| 10 | def get_xos_args(self, throw_exception=True): |
| 11 | args = super(XOSONOSMonitoringPublisher, self).get_xos_args() |
| 12 | |
| 13 | # PublisherTenant must always have a provider_service |
| 14 | provider_name = self.get_requirement("tosca.relationships.TenantOfService", throw_exception=True) |
| 15 | if provider_name: |
| 16 | args["provider_service"] = self.get_xos_object(Service, throw_exception=True, name=provider_name) |
| 17 | |
| 18 | return args |
| 19 | |
| 20 | def get_existing_objs(self): |
| 21 | args = self.get_xos_args(throw_exception=False) |
| 22 | return ONOSServiceMonitoringPublisher.get_tenant_objects().filter(provider_service=args["provider_service"]) |
| 23 | |
| 24 | def postprocess(self, obj): |
| 25 | for ma_name in self.get_requirements("tosca.relationships.ProvidesInfraMonitoringAgentInfo"): |
| 26 | ma = self.get_xos_object(InfraMonitoringAgentInfo, name=ma_name) |
| 27 | ma.monitoring_publisher = obj |
| 28 | ma.save() |
| 29 | for mcp_name in self.get_requirements("tosca.relationships.ProvidesMonitoringCollectorPluginInfo"): |
| 30 | mcp = self.get_xos_object(MonitoringCollectorPluginInfo, name=mcp_name) |
| 31 | mcp.monitoring_publisher = obj |
| 32 | mcp.save() |
| 33 | |
| 34 | def can_delete(self, obj): |
| 35 | return super(XOSONOSMonitoringPublisher, self).can_delete(obj) |
| 36 | |