blob: 1b30555c2fb24e3c649e2a87191e9a8ec90eecf7 [file] [log] [blame]
rdudyala996d70b2016-10-13 17:40:55 +00001from xosresource import XOSResource
2from core.models import Tenant, Service
3from services.monitoring.models import OpenStackServiceMonitoringPublisher, CeilometerService, InfraMonitoringAgentInfo, MonitoringCollectorPluginInfo
4
5class XOSOpenStackMonitoringPublisher(XOSResource):
6 provides = "tosca.nodes.OpenStackMonitoringPublisher"
7 xos_model = OpenStackServiceMonitoringPublisher
8 name_field = None
9
10 def get_xos_args(self, throw_exception=True):
11 args = super(XOSOpenStackMonitoringPublisher, 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 postprocess(self, obj):
21 for ma_name in self.get_requirements("tosca.relationships.ProvidesInfraMonitoringAgentInfo"):
22 ma = self.get_xos_object(InfraMonitoringAgentInfo, name=ma_name)
23 ma.monitoring_publisher = obj
24 ma.save()
25 for mcp_name in self.get_requirements("tosca.relationships.ProvidesMonitoringCollectorPluginInfo"):
26 mcp = self.get_xos_object(MonitoringCollectorPluginInfo, name=mcp_name)
27 mcp.monitoring_publisher = obj
28 mcp.save()
29
30 def get_existing_objs(self):
31 args = self.get_xos_args(throw_exception=False)
32 return OpenStackServiceMonitoringPublisher.get_tenant_objects().filter(provider_service=args["provider_service"])
33
34 def can_delete(self, obj):
35 return super(XOSOpenStackMonitoringPublisher, self).can_delete(obj)
36