blob: 57e10a4ed0fa9c91097459675b0bf76f4d940738 [file] [log] [blame]
Matteo Scandolo62dab882018-04-24 12:58:12 +02001
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
17import json
18from xosapi.orm import ORMWrapper, register_convenience_wrapper
19
Matteo Scandolod1707b32018-05-04 12:42:53 -070020class ORMWrapperRCORDSubscriber(ORMWrapper):
Matteo Scandolo62dab882018-04-24 12:58:12 +020021 @property
22 def volt(self):
23 links = self.subscribed_links.all()
24 for link in links:
Matteo Scandolod1707b32018-05-04 12:42:53 -070025 # FIXME: hardcoded service dependency
Matteo Scandolo62dab882018-04-24 12:58:12 +020026 # cast from ServiceInstance to VOLTServiceInstance
27 volts = self.stub.VOLTServiceInstance.objects.filter(id = link.provider_service_instance.id)
28 if volts:
29 return volts[0]
30 return None
31
32 sync_attributes = ("firewall_enable",
33 "firewall_rules",
34 "url_filter_enable",
35 "url_filter_rules",
36 "cdn_enable",
37 "uplink_speed",
38 "downlink_speed",
39 "enable_uverse",
40 "status")
41
42 # figure out what to do about "devices"... is it still needed?
43
44 def get_attribute(self, name, default=None):
45 if self.service_specific_attribute:
46 attributes = json.loads(self.service_specific_attribute)
47 else:
48 attributes = {}
49 return attributes.get(name, default)
50
51 @property
52 def devices(self):
53 return self.get_attribute("devices", [])
54
Matteo Scandolod1707b32018-05-04 12:42:53 -070055register_convenience_wrapper("RCORDSubscriber", ORMWrapperRCORDSubscriber)