blob: efac81d51ff38f3ef19360b8d8bb81dd939bb60d [file] [log] [blame]
rdudyala996d70b2016-10-13 17:40:55 +00001from xosresource import XOSResource
2from core.models import Tenant, Service
3from services.monitoring.models import UserServiceMonitoringPublisher, CeilometerService, InfraMonitoringAgentInfo, MonitoringCollectorPluginInfo
4
5class XOSUserServiceMonitoringPublisher(XOSResource):
6 provides = "tosca.nodes.UserServiceMonitoringPublisher"
7 xos_model = UserServiceMonitoringPublisher
8 name_field = None
9
10 def get_xos_args(self, throw_exception=True):
11 args = super(XOSUserServiceMonitoringPublisher, 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 target_service_name = self.get_requirement("tosca.relationships.PublishesMonitoringData", throw_exception=True)
19 if target_service_name:
20 args["target_service"] = self.get_xos_object(Service, throw_exception=True, name=target_service_name)
21
22 return args
23
24 def get_existing_objs(self):
25 args = self.get_xos_args(throw_exception=False)
26 return [publisher for publisher in UserServiceMonitoringPublisher.get_tenant_objects().all() if (publisher.target_service.id == args["target_service"].id)]
27
28 def postprocess(self, obj):
29 #for ma_name in self.get_requirements("tosca.relationships.ProvidesMonitoringAgentInfo"):
30 # ma = self.get_xos_object(MonitoringAgentInfo, name=ma_name)
31 # ma.monitoring_publisher = obj
32 # ma.save()
33 for mcp_name in self.get_requirements("tosca.relationships.ProvidesMonitoringCollectorPluginInfo"):
34 mcp = self.get_xos_object(MonitoringCollectorPluginInfo, name=mcp_name)
35 mcp.monitoring_publisher = obj
36 mcp.save()
37
38 def can_delete(self, obj):
39 return super(XOSUserServiceMonitoringPublisher, self).can_delete(obj)
40