Scott Baker | 619de67 | 2016-06-20 12:49:38 -0700 | [diff] [blame] | 1 | import importlib |
| 2 | import os |
| 3 | import pdb |
| 4 | import sys |
| 5 | import tempfile |
| 6 | sys.path.append("/opt/tosca") |
| 7 | from translator.toscalib.tosca_template import ToscaTemplate |
| 8 | from core.models import Tenant, Service |
| 9 | from services.exampleservice.models import ExampleTenant, SERVICE_NAME as EXAMPLETENANT_KIND |
| 10 | |
| 11 | from xosresource import XOSResource |
| 12 | |
| 13 | class XOSExampleTenant(XOSResource): |
| 14 | provides = "tosca.nodes.ExampleTenant" |
| 15 | xos_model = ExampleTenant |
| 16 | name_field = "service_specific_id" |
| 17 | copyin_props = ("tenant_message",) |
| 18 | |
| 19 | def get_xos_args(self, throw_exception=True): |
| 20 | args = super(XOSExampleTenant, self).get_xos_args() |
| 21 | |
| 22 | # ExampleTenant must always have a provider_service |
| 23 | provider_name = self.get_requirement("tosca.relationships.TenantOfService", throw_exception=True) |
| 24 | if provider_name: |
| 25 | args["provider_service"] = self.get_xos_object(Service, throw_exception=True, name=provider_name) |
| 26 | |
| 27 | return args |
| 28 | |
| 29 | def get_existing_objs(self): |
| 30 | args = self.get_xos_args(throw_exception=False) |
| 31 | return ExampleTenant.get_tenant_objects().filter(provider_service=args["provider_service"], service_specific_id=args["service_specific_id"]) |
| 32 | return [] |
| 33 | |
| 34 | def can_delete(self, obj): |
| 35 | return super(XOSExampleTenant, self).can_delete(obj) |
| 36 | |