diff --git a/pillarsdk/nodes.py b/pillarsdk/nodes.py index 1fce060..83ebf61 100755 --- a/pillarsdk/nodes.py +++ b/pillarsdk/nodes.py @@ -31,6 +31,30 @@ class Node(List, Find, Create, Post, Update, Delete, Replace): url = utils.join_url_params(url, params) return cls(api.get(url)) + def update(self, attributes=None, api=None): + api = api or self.api + attributes = attributes or self.to_dict() + etag = attributes['_etag'] + attributes.pop('_id') + attributes.pop('_etag') + attributes.pop('_created') + attributes.pop('_updated') + attributes.pop('_links') + attributes.pop('allowed_methods') + url = utils.join_url(self.path, str(self['_id'])) + headers = utils.merge_dict( + self.http_headers(), + {'If-Match': str(etag)}) + new_attributes = api.put(url, attributes, headers) + self.error = None + self.merge(new_attributes) + return self.success() + + def has_method(self, method): + if method in self.allowed_methods: + return True + return False + class NodeType(List, Find, Create, Post, Delete): """NodeType class wrapping the REST node_types endpoint