2 # -*- coding: utf-8 -*-
5 Common connector base classes
10 class ConnectorTypeBase(object):
11 def __init__(self, testbed_id, factory_id, name, max = -1, min = 0):
12 super(ConnectorTypeBase, self).__init__()
16 raise RuntimeError, "The maximum number of connections allowed need to be more than 0"
18 raise RuntimeError, "The minimum number of connections allowed needs to be at least 0"
19 # connector_type_id -- univoquely identifies a connector type
21 self._connector_type_id = self.make_connector_type_id(
22 testbed_id, factory_id, name)
23 # name -- display name for the connector type
25 # max -- maximum amount of connections that this type support,
28 # min -- minimum amount of connections required by this type of connector
32 def connector_type_id(self):
33 return self._connector_type_id
48 def make_connector_type_id(testbed_id, factory_id, name):
49 testbed_id = testbed_id.lower() if testbed_id else None
50 factory_id = factory_id.lower() if factory_id else None
51 name = name.lower() if name else None
52 return (testbed_id, factory_id, name)
55 def _type_resolution_order(connector_type_id):
56 testbed_id, factory_id, name = connector_type_id
58 # the key is always a candidate
59 yield connector_type_id
61 # Try wildcard combinations
62 if (testbed_id, None, name) != connector_type_id:
63 yield (testbed_id, None, name)
64 if (None, factory_id, name) != connector_type_id:
65 yield (None, factory_id, name)
66 if (None, None, name) != connector_type_id:
67 yield (None, None, name)