Zack Williams | 1ce6c38 | 2016-10-05 18:02:09 -0700 | [diff] [blame] | 1 | from xosresource import XOSResource |
Scott Baker | 0982002 | 2017-07-18 11:29:59 -0700 | [diff] [blame] | 2 | from core.models import Service |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 3 | from services.exampleservice.models import ExampleTenant, SERVICE_NAME as EXAMPLETENANT_KIND |
| 4 | |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 5 | class 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 Baker | 0982002 | 2017-07-18 11:29:59 -0700 | [diff] [blame] | 17 | args["owner"] = self.get_xos_object(Service, throw_exception=True, name=provider_name) |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 18 | |
| 19 | return args |
| 20 | |
| 21 | def get_existing_objs(self): |
| 22 | args = self.get_xos_args(throw_exception=False) |
Scott Baker | 0982002 | 2017-07-18 11:29:59 -0700 | [diff] [blame] | 23 | return ExampleTenant.objects.filter(owner=args["owner"], service_specific_id=args["service_specific_id"]) |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 24 | return [] |
| 25 | |
| 26 | def can_delete(self, obj): |
| 27 | return super(XOSExampleTenant, self).can_delete(obj) |
| 28 | |