blob: 5b37edea5505ddf99d708955cbec272694ef4c93 [file] [log] [blame]
Matteo Scandoloeb0d11c2017-08-08 13:05:26 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
rdudyala996d70b2016-10-13 17:40:55 +000017from xosresource import XOSResource
18from core.models import Tenant, Service
19from services.monitoring.models import ONOSServiceMonitoringPublisher, CeilometerService, InfraMonitoringAgentInfo, MonitoringCollectorPluginInfo
20
21class XOSONOSMonitoringPublisher(XOSResource):
22 provides = "tosca.nodes.ONOSMonitoringPublisher"
23 xos_model = ONOSServiceMonitoringPublisher
24 name_field = None
25
26 def get_xos_args(self, throw_exception=True):
27 args = super(XOSONOSMonitoringPublisher, self).get_xos_args()
28
29 # PublisherTenant must always have a provider_service
30 provider_name = self.get_requirement("tosca.relationships.TenantOfService", throw_exception=True)
31 if provider_name:
32 args["provider_service"] = self.get_xos_object(Service, throw_exception=True, name=provider_name)
33
34 return args
35
36 def get_existing_objs(self):
37 args = self.get_xos_args(throw_exception=False)
38 return ONOSServiceMonitoringPublisher.get_tenant_objects().filter(provider_service=args["provider_service"])
39
40 def postprocess(self, obj):
41 for ma_name in self.get_requirements("tosca.relationships.ProvidesInfraMonitoringAgentInfo"):
42 ma = self.get_xos_object(InfraMonitoringAgentInfo, name=ma_name)
43 ma.monitoring_publisher = obj
44 ma.save()
45 for mcp_name in self.get_requirements("tosca.relationships.ProvidesMonitoringCollectorPluginInfo"):
46 mcp = self.get_xos_object(MonitoringCollectorPluginInfo, name=mcp_name)
47 mcp.monitoring_publisher = obj
48 mcp.save()
49
50 def can_delete(self, obj):
51 return super(XOSONOSMonitoringPublisher, self).can_delete(obj)
52