9 # Decorator to invoke class initialization method
11 class Resource(object):
17 def _register_filter(cls, attr):
18 """ Resource subclasses will invoke this method to add a
20 cls._filters[attr.name] = attr
23 def _register_attribute(cls, attr):
24 """ Resource subclasses will invoke this method to add a
26 cls._attributes[attr.name] = attr
29 def _register_filters(cls):
30 """ Resource subclasses will invoke this method to add a
35 def _register_attributes(cls):
36 """ Resource subclasses will invoke this method to add a
42 # static template for resource filters
44 cls._register_filters()
46 # static template for resource attributes
47 cls._attributes = dict()
48 cls._register_attributes()
56 return copy.deepcopy(cls._filters.values())
59 def get_attributes(cls):
60 return copy.deepcopy(cls._attributes.values())
62 def __init__(self, ec, guid):
64 self._ec = weakref.ref(ec)
65 self._connections = set()
66 # the resource instance gets a copy of all attributes
68 self._attrs = copy.deepcopy(self._attributes)
72 self._logger = logging.getLogger("neco.execution.resource.Resource.%s" %
74 self._logger.setLevel(getattr(logging, loglevel.upper()))
84 def connect(self, guid):
85 if (self._validate_connection(guid)):
86 self._connections.add(guid)
88 def discover(self, filters):
91 def provision(self, filters):
94 def set(self, name, value):
95 attr = self._attrs[name]
99 attr = self._attrs[name]
102 def start_after(self, time, after_status, guid):
105 def stop_after(self, time, after_status, guid):
108 def set_after(self, name, value, time, after_status, guid):
117 def _validate_connection(self, guid):
121 class ResourceFactory(object):
122 _resource_types = dict()
125 def resource_types(cls):
126 return cls._resource_types
129 def register_type(cls, rclass):
130 cls._resource_types[rclass.rtype()] = rclass
133 def create(cls, rtype, ec, guid):
134 rclass = cls._resource[rtype]
135 return rclass(ec, guid)