Zack Williams | 1ce6c38 | 2016-10-05 18:02:09 -0700 | [diff] [blame] | 1 | from xosresource import XOSResource |
Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 2 | from core.models import Tenant, Service |
| 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: |
| 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 | |