def __init__(self, factory_id, create_function, start_function, stop_function, status_function, configure_function, preconfigure_function, prestart_function, help=None, category=None): super(Factory, self).__init__() self._factory_id = factory_id self._create_function = create_function self._start_function = start_function self._stop_function = stop_function self._status_function = status_function self._configure_function = configure_function self._preconfigure_function = preconfigure_function self._prestart_function = prestart_function self._help = help self._category = category self._connector_types = dict() self._traces = dict() self._box_attributes = AttributesMap() self._factory = None
def __init__(self, factory_id, create_function, start_function, stop_function, status_function, configure_function, preconfigure_function, prestart_function, help = None, category = None): super(Factory, self).__init__() self._factory_id = factory_id self._create_function = create_function self._start_function = start_function self._stop_function = stop_function self._status_function = status_function self._configure_function = configure_function self._preconfigure_function = preconfigure_function self._prestart_function = prestart_function self._help = help self._category = category self._connector_types = dict() self._traces = dict() self._box_attributes = AttributesMap() self._factory = None
class Factory(AttributesMap, Taggable): _box_class_cache = {} def __init__(self, factory_id, create_function, start_function, stop_function, status_function, configure_function, preconfigure_function, prestart_function, help = None, category = None): super(Factory, self).__init__() self._factory_id = factory_id self._create_function = create_function self._start_function = start_function self._stop_function = stop_function self._status_function = status_function self._configure_function = configure_function self._preconfigure_function = preconfigure_function self._prestart_function = prestart_function self._help = help self._category = category self._connector_types = dict() self._traces = dict() self._box_attributes = AttributesMap() self._factory = None @property def factory(self): if self._factory: return self._factory from nepi.core.design import Box if not self.has_addresses and not self.has_routes: self._factory = Box else: addresses = 'w' if self.allow_addresses else ('r' if self.has_addresses else '-') routes = 'w' if self.allow_routes else ('r' if self.has_routes else '-') key = addresses+routes if key in self._box_class_cache: self._factory = self._box_class_cache[key] else: # Create base class class _factory(Box): def __init__(self, guid, factory, testbed_guid, container = None): super(_factory, self).__init__(guid, factory, testbed_guid, container) # Add mixins, one by one if self.allow_addresses: MixIn(_factory, UserAddressableMixin) elif self.has_addresses: MixIn(_factory, AddressableMixin) if self.allow_routes: MixIn(_factory, UserRoutableMixin) elif self.has_routes: MixIn(_factory, RoutableMixin) # Put into cache self._box_class_cache[key] = self._factory = _factory return self._factory @property def factory_id(self): return self._factory_id @property def allow_addresses(self): return self.has_tag(tags.ALLOW_ADDRESSES) @property def allow_routes(self): return self.has_tag(tags.ALLOW_ROUTES) @property def has_addresses(self): return self.has_tag(tags.HAS_ADDRESSES) or \ self.allow_addresses @property def has_routes(self): return self.has_tag(tags.HAS_ROUTES) or \ self.allow_routes @property def help(self): return self._help @property def category(self): return self._category @property def connector_types(self): return self._connector_types.values() @property def traces(self): return self._traces.values() @property def traces_list(self): return self._traces.keys() @property def box_attributes(self): return self._box_attributes @property def create_function(self): return self._create_function @property def prestart_function(self): return self._prestart_function @property def start_function(self): return self._start_function @property def stop_function(self): return self._stop_function @property def status_function(self): return self._status_function @property def configure_function(self): return self._configure_function @property def preconfigure_function(self): return self._preconfigure_function def connector_type(self, name): return self._connector_types[name] def add_connector_type(self, connector_type): self._connector_types[connector_type.name] = connector_type def add_trace(self, name, help, enabled = False): self._traces[name] = (name, help, enabled) def add_box_attribute(self, name, help, type, value = None, range = None, allowed = None, flags = Attribute.NoFlags, validation_function = None, category = None): self._box_attributes.add_attribute(name, help, type, value, range, allowed, flags, validation_function, category) def create(self, guid, testbed_description): return self.factory(guid, self, testbed_description.guid) def destroy(self): super(Factory, self).destroy() self._connector_types = None
def testbed_attributes(self): attributes = AttributesMap() testbed_attributes = self._testbed_attributes() self._add_attributes(attributes.add_attribute, testbed_attributes) return attributes
class Factory(AttributesMap, Taggable): _box_class_cache = {} def __init__(self, factory_id, create_function, start_function, stop_function, status_function, configure_function, preconfigure_function, prestart_function, help=None, category=None): super(Factory, self).__init__() self._factory_id = factory_id self._create_function = create_function self._start_function = start_function self._stop_function = stop_function self._status_function = status_function self._configure_function = configure_function self._preconfigure_function = preconfigure_function self._prestart_function = prestart_function self._help = help self._category = category self._connector_types = dict() self._traces = dict() self._box_attributes = AttributesMap() self._factory = None @property def factory(self): if self._factory: return self._factory from nepi.core.design import Box if not self.has_addresses and not self.has_routes: self._factory = Box else: addresses = 'w' if self.allow_addresses else ( 'r' if self.has_addresses else '-') routes = 'w' if self.allow_routes else ( 'r' if self.has_routes else '-') key = addresses + routes if key in self._box_class_cache: self._factory = self._box_class_cache[key] else: # Create base class class _factory(Box): def __init__(self, guid, factory, testbed_guid, container=None): super(_factory, self).__init__(guid, factory, testbed_guid, container) # Add mixins, one by one if self.allow_addresses: MixIn(_factory, UserAddressableMixin) elif self.has_addresses: MixIn(_factory, AddressableMixin) if self.allow_routes: MixIn(_factory, UserRoutableMixin) elif self.has_routes: MixIn(_factory, RoutableMixin) # Put into cache self._box_class_cache[key] = self._factory = _factory return self._factory @property def factory_id(self): return self._factory_id @property def allow_addresses(self): return self.has_tag(tags.ALLOW_ADDRESSES) @property def allow_routes(self): return self.has_tag(tags.ALLOW_ROUTES) @property def has_addresses(self): return self.has_tag(tags.HAS_ADDRESSES) or \ self.allow_addresses @property def has_routes(self): return self.has_tag(tags.HAS_ROUTES) or \ self.allow_routes @property def help(self): return self._help @property def category(self): return self._category @property def connector_types(self): return self._connector_types.values() @property def traces(self): return self._traces.values() @property def traces_list(self): return self._traces.keys() @property def box_attributes(self): return self._box_attributes @property def create_function(self): return self._create_function @property def prestart_function(self): return self._prestart_function @property def start_function(self): return self._start_function @property def stop_function(self): return self._stop_function @property def status_function(self): return self._status_function @property def configure_function(self): return self._configure_function @property def preconfigure_function(self): return self._preconfigure_function def connector_type(self, name): return self._connector_types[name] def add_connector_type(self, connector_type): self._connector_types[connector_type.name] = connector_type def add_trace(self, name, help, enabled=False): self._traces[name] = (name, help, enabled) def add_box_attribute(self, name, help, type, value=None, range=None, allowed=None, flags=Attribute.NoFlags, validation_function=None, category=None): self._box_attributes.add_attribute(name, help, type, value, range, allowed, flags, validation_function, category) def create(self, guid, testbed_description): return self.factory(guid, self, testbed_description.guid) def destroy(self): super(Factory, self).destroy() self._connector_types = None