blob: e5bb5103954493c83c5ebeac3eae9eeb6b50f483 [file] [log] [blame]
Matteo Scandoloede125b2017-08-08 13:05:25 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
Scott Baker8f32cc82016-08-08 10:34:53 -070017from xosresource import XOSResource
Zack Williamsb7e97762016-10-05 16:12:36 -070018from services.hpc.models import OriginServer, ContentProvider
Scott Baker8f32cc82016-08-08 10:34:53 -070019
20class XOSOriginServer(XOSResource):
21 provides = "tosca.nodes.OriginServer"
22 xos_model = OriginServer
23 name_field = "url"
24 copyin_props = []
25
26 def obj_name_to_url(self):
27 url = self.obj_name
28 if url.startswith("http_"):
29 url = url[5:]
30 return url
31
32 def get_existing_objs(self):
33 url = self.obj_name_to_url()
34 return self.xos_model.objects.filter(**{self.name_field: url})
35
36 def get_xos_args(self):
37 url = self.obj_name_to_url()
38 cp_name = self.get_requirement("tosca.relationships.MemberOfContentProvider", throw_exception=True)
39 cp = self.get_xos_object(ContentProvider, name=cp_name)
40 return {"url": url,
41 "contentProvider": cp}
42
43 def can_delete(self, obj):
44 return super(XOSOriginServer, self).can_delete(obj)
45