1 # Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs")
2 # and others. All rights reserved.
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:
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 class Consumer(enum.Enum):
20 QoS Specification consumer types
22 front_end = 'front-end'
27 class QoSConfig(object):
28 def __init__(self, **kwargs):
31 :param name: the qos's name (required)
32 :param consumer: the qos's consumer type of the enum type Consumer
34 :param specs: dict of key/values
37 self.name = kwargs.get('name')
39 if kwargs.get('consumer'):
40 self.consumer = map_consumer(kwargs['consumer'])
44 self.specs = kwargs.get('specs')
48 if not self.name or not self.consumer:
50 "The attributes name and consumer are required")
53 def map_consumer(consumer):
55 Takes a the protocol value maps it to the Consumer enum. When None return
57 :param consumer: the value to map to the Enum
58 :return: the Protocol enum object
59 :raise: Exception if value is invalid
63 elif isinstance(consumer, Consumer):
65 elif isinstance(consumer, str):
66 proto_str = str(consumer)
67 if proto_str == 'front-end':
68 return Consumer.front_end
69 elif proto_str == 'back-end':
70 return Consumer.back_end
71 elif proto_str == 'both':
74 raise QoSConfigError('Invalid Consumer - ' + proto_str)
76 if consumer.value == 'front-end':
77 return Consumer.front_end
78 elif consumer.value == 'back-end':
79 return Consumer.back_end
80 elif consumer.value == 'both':
83 raise QoSConfigError('Invalid Consumer - ' + consumer.value)
86 class QoSConfigError(Exception):
88 Exception to be thrown when an qos settings are incorrect
91 def __init__(self, message):
92 Exception.__init__(self, message)