Scott Baker | 8e6647a | 2016-06-20 17:16:20 -0700 | [diff] [blame] | 1 | import os |
| 2 | import pdb |
| 3 | import sys |
| 4 | import tempfile |
| 5 | sys.path.append("/opt/tosca") |
| 6 | from translator.toscalib.tosca_template import ToscaTemplate |
| 7 | import pdb |
| 8 | |
| 9 | from core.models import User |
| 10 | from services.volt.models import VOLTTenant, VOLTService, CordSubscriberRoot, VOLT_KIND |
| 11 | |
| 12 | from xosresource import XOSResource |
| 13 | |
| 14 | class XOSVOLTTenant(XOSResource): |
| 15 | provides = "tosca.nodes.VOLTTenant" |
| 16 | xos_model = VOLTTenant |
| 17 | copyin_props = ["service_specific_id", "s_tag", "c_tag"] |
| 18 | name_field = None |
| 19 | |
| 20 | def get_xos_args(self, throw_exception=True): |
| 21 | args = super(XOSVOLTTenant, self).get_xos_args() |
| 22 | |
| 23 | provider_name = self.get_requirement("tosca.relationships.MemberOfService", throw_exception=throw_exception) |
| 24 | if provider_name: |
| 25 | args["provider_service"] = self.get_xos_object(VOLTService, throw_exception=throw_exception, name=provider_name) |
| 26 | |
| 27 | subscriber_name = self.get_requirement("tosca.relationships.BelongsToSubscriber") |
| 28 | if subscriber_name: |
| 29 | args["subscriber_root"] = self.get_xos_object(CordSubscriberRoot, throw_exception=throw_exception, name=subscriber_name) |
| 30 | |
| 31 | return args |
| 32 | |
| 33 | def get_existing_objs(self): |
| 34 | args = self.get_xos_args(throw_exception=False) |
| 35 | provider_service = args.get("provider_service", None) |
| 36 | service_specific_id = args.get("service_specific_id", None) |
| 37 | if (provider_service) and (service_specific_id): |
| 38 | existing_obj = self.get_xos_object(VOLTTenant, kind=VOLT_KIND, provider_service=provider_service, service_specific_id=service_specific_id, throw_exception=False) |
| 39 | if existing_obj: |
| 40 | return [ existing_obj ] |
| 41 | return [] |
| 42 | |
| 43 | def postprocess(self, obj): |
| 44 | pass |
| 45 | |
| 46 | def can_delete(self, obj): |
| 47 | return super(XOSVOLTTenant, self).can_delete(obj) |
| 48 | |