9 # Decorator to invoke class initialization method
11 class ResourceManager(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)
71 self._logger = logging.getLogger("neco.execution.resource.Resource.%s" %
82 def connect(self, guid):
83 if (self._validate_connection(guid)):
84 self._connections.add(guid)
87 def connections(self):
88 return self._connections
90 def discover(self, filters):
93 def provision(self, filters):
96 def set(self, name, value):
97 attr = self._attrs[name]
101 attr = self._attrs[name]
104 def start_after(self, time, after_status, guid):
107 def stop_after(self, time, after_status, guid):
110 def set_after(self, name, value, time, after_status, guid):
119 def deploy(self, group = None):
125 def _validate_connection(self, guid):
129 class ResourceFactory(object):
130 _resource_types = dict()
133 def resource_types(cls):
134 return cls._resource_types
137 def register_type(cls, rclass):
138 cls._resource_types[rclass.rtype()] = rclass
141 def create(cls, rtype, ec, guid):
142 rclass = cls._resource_types[rtype]
143 return rclass(ec, guid)