def __init__(self, *args, **kwargs): AttributeDict.__init__(self) self.env = Environment.getInstance() self.resourceType = self.__class__.__name__ self.isUpdated = False seen = set() if not hasattr(self, '_schema'): raise Fail("Resource failed to define a valid _schema") # union global schema with local schema schema = copy.deepcopy(self._schema) for key in self.s_globalSchema: if not key in schema: schema[key] = self.s_globalSchema[key] resolvedArgs = { } keys = schema.keys() keysLen = len(keys) index = 0 # resolve unnamed arguments with names corresponding to the order # they were passed to Resource's ctor and their relative definitions # in the subclass' ResourceArgumentSchema (which is an OrderedDict, # so as to retain this ordering information). for arg in args: if index < keysLen: key = keys[index] resolvedArgs[keys[index]] = arg else: raise InvalidArgument("Invalid unnamed argument %s provided to resource %s" % (arg, str(self))) index += 1 for arg in kwargs: if arg in resolvedArgs: raise InvalidArgument("Invalid mixture of named and unnamed arguments provided to resource %s, possibly around argument %s" % (str(self), arg)) else: resolvedArgs[arg] = kwargs[arg] utils.log("Initializing resource '%s' with args: %s" % (self.resourceType, resolvedArgs)) # validate resource arguments output = schema.validate(resolvedArgs) for key in output: self[key] = output[key] self.subscriptions = { 'immediate' : set(), 'delayed' : set() } for sub in self.subscribes: if len(sub) == 2: action, resource = sub immediate = False else: action, resource, immediate = sub resource.subscribe(action, self, immediate) for sub in self.notifies: self.subscribe(*sub) self._validate() self._register() utils.log("Added new resource '%s'" % (str(self), ))