Gabe Black | 4c040b7 | 2016-11-17 22:35:04 +0000 | [diff] [blame^] | 1 | from core.models import Tenant, Service |
| 2 | from services.activetest.models import VtaTenant |
| 3 | |
| 4 | from xosresource import XOSResource |
| 5 | |
| 6 | class XOSVtaTenant(XOSResource): |
| 7 | name_field = "service_specific_id" |
| 8 | provides = "tosca.nodes.VtaTenant" |
| 9 | xos_model = VtaTenant |
| 10 | |
| 11 | def get_xos_args(self, throw_exception=True): |
| 12 | args = super(XOSVtaTenant, self).get_xos_args() |
| 13 | |
| 14 | # VtaTenant must always have a provider_service |
| 15 | provider_name = self.get_requirement("tosca.relationships.TenantOfService", throw_exception=True) |
| 16 | if provider_name: |
| 17 | args["provider_service"] = self.get_xos_object(Service, throw_exception=True, name=provider_name) |
| 18 | |
| 19 | return args |
| 20 | |
| 21 | def can_delete(self, obj): |
| 22 | return super(XOSVtaTenant, self).can_delete(obj) |
| 23 | |
| 24 | def get_existing_objs(self): |
| 25 | args = self.get_xos_args(throw_exception=False) |
| 26 | return VtaTenant.get_tenant_objects().filter(provider_service=args["provider_service"], service_specific_id=args["service_specific_id"]) |
| 27 | return [] |