-
- def __getattr__(self, name):
- # Proxy non-extension methods to the real driver.
- if (not name.startswith('_') and not name.startswith('ex_')
- and hasattr(self.real, name)):
- return getattr(self.real, name)
- else:
- return super(BaseComputeNodeDriver, self).__getattr__(name)
-
- def search_for(self, term, list_method, key=lambda item: item.id):
+ # Transform entries in create_kwargs. For each key K, if this class
+ # has an _init_K method, remove the entry and call _init_K with the
+ # corresponding value. If _init_K returns None, the entry stays out
+ # of the dictionary (we expect we're holding the value somewhere
+ # else, like an instance variable). Otherwise, _init_K returns a
+ # key-value tuple pair, and we add that entry to create_kwargs.
+ for key in self.create_kwargs.keys():
+ init_method = getattr(self, '_init_' + key, None)
+ if init_method is not None:
+ new_pair = init_method(self.create_kwargs.pop(key))
+ if new_pair is not None:
+ self.create_kwargs[new_pair[0]] = new_pair[1]
+
+ def _init_ping_host(self, ping_host):
+ self.ping_host = ping_host
+
+ def search_for(self, term, list_method, key=attrgetter('id'), **kwargs):
+ """Return one matching item from a list of cloud objects.
+
+ Raises ValueError if the number of matching objects is not exactly 1.
+
+ Arguments:
+ * term: The value that identifies a matching item.
+ * list_method: A string that names the method to call on this
+ instance's libcloud driver for a list of objects.
+ * key: A function that accepts a cloud object and returns a
+ value search for a `term` match on each item. Returns the
+ object's 'id' attribute by default.
+ """