blob: 1cb7b1f4813578ffea99880036595c55d9bbe17e [file] [log] [blame]
Zack Williams1ce6c382016-10-05 18:02:09 -07001from xosresource import XOSResource
Scott Baker09820022017-07-18 11:29:59 -07002from core.models import Service
Scott Baker619de672016-06-20 12:49:38 -07003from services.exampleservice.models import ExampleTenant, SERVICE_NAME as EXAMPLETENANT_KIND
4
Scott Baker619de672016-06-20 12:49:38 -07005class XOSExampleTenant(XOSResource):
6 provides = "tosca.nodes.ExampleTenant"
7 xos_model = ExampleTenant
8 name_field = "service_specific_id"
9 copyin_props = ("tenant_message",)
10
11 def get_xos_args(self, throw_exception=True):
12 args = super(XOSExampleTenant, self).get_xos_args()
13
14 # ExampleTenant must always have a provider_service
15 provider_name = self.get_requirement("tosca.relationships.TenantOfService", throw_exception=True)
16 if provider_name:
Scott Baker09820022017-07-18 11:29:59 -070017 args["owner"] = self.get_xos_object(Service, throw_exception=True, name=provider_name)
Scott Baker619de672016-06-20 12:49:38 -070018
19 return args
20
21 def get_existing_objs(self):
22 args = self.get_xos_args(throw_exception=False)
Scott Baker09820022017-07-18 11:29:59 -070023 return ExampleTenant.objects.filter(owner=args["owner"], service_specific_id=args["service_specific_id"])
Scott Baker619de672016-06-20 12:49:38 -070024 return []
25
26 def can_delete(self, obj):
27 return super(XOSExampleTenant, self).can_delete(obj)
28