blob: d4e46836eaf54afb3c9c7363d0218aab0e31c3c0 [file] [log] [blame]
Zack Williams1ce6c382016-10-05 18:02:09 -07001from xosresource import XOSResource
Scott Baker619de672016-06-20 12:49:38 -07002from core.models import Tenant, Service
3from 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:
17 args["provider_service"] = self.get_xos_object(Service, throw_exception=True, name=provider_name)
18
19 return args
20
21 def get_existing_objs(self):
22 args = self.get_xos_args(throw_exception=False)
23 return ExampleTenant.get_tenant_objects().filter(provider_service=args["provider_service"], service_specific_id=args["service_specific_id"])
24 return []
25
26 def can_delete(self, obj):
27 return super(XOSExampleTenant, self).can_delete(obj)
28