Matteo Scandolo | eb0d11c | 2017-08-08 13:05:26 -0700 | [diff] [blame] | 1 | |
| 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 | |
rdudyala | 996d70b | 2016-10-13 17:40:55 +0000 | [diff] [blame] | 17 | from xosresource import XOSResource |
| 18 | from core.models import Tenant, Service |
| 19 | from services.monitoring.models import UserServiceMonitoringPublisher, CeilometerService, InfraMonitoringAgentInfo, MonitoringCollectorPluginInfo |
| 20 | |
| 21 | class XOSUserServiceMonitoringPublisher(XOSResource): |
| 22 | provides = "tosca.nodes.UserServiceMonitoringPublisher" |
| 23 | xos_model = UserServiceMonitoringPublisher |
| 24 | name_field = None |
| 25 | |
| 26 | def get_xos_args(self, throw_exception=True): |
| 27 | args = super(XOSUserServiceMonitoringPublisher, 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 | target_service_name = self.get_requirement("tosca.relationships.PublishesMonitoringData", throw_exception=True) |
| 35 | if target_service_name: |
| 36 | args["target_service"] = self.get_xos_object(Service, throw_exception=True, name=target_service_name) |
| 37 | |
| 38 | return args |
| 39 | |
| 40 | def get_existing_objs(self): |
| 41 | args = self.get_xos_args(throw_exception=False) |
| 42 | return [publisher for publisher in UserServiceMonitoringPublisher.get_tenant_objects().all() if (publisher.target_service.id == args["target_service"].id)] |
| 43 | |
| 44 | def postprocess(self, obj): |
| 45 | #for ma_name in self.get_requirements("tosca.relationships.ProvidesMonitoringAgentInfo"): |
| 46 | # ma = self.get_xos_object(MonitoringAgentInfo, name=ma_name) |
| 47 | # ma.monitoring_publisher = obj |
| 48 | # ma.save() |
| 49 | for mcp_name in self.get_requirements("tosca.relationships.ProvidesMonitoringCollectorPluginInfo"): |
| 50 | mcp = self.get_xos_object(MonitoringCollectorPluginInfo, name=mcp_name) |
| 51 | mcp.monitoring_publisher = obj |
| 52 | mcp.save() |
| 53 | |
| 54 | def can_delete(self, obj): |
| 55 | return super(XOSUserServiceMonitoringPublisher, self).can_delete(obj) |
| 56 | |