lib/arborist/client.rb in arborist-0.0.1.pre20160128152542 vs lib/arborist/client.rb in arborist-0.0.1.pre20160606141735
- old
+ new
@@ -56,14 +56,15 @@
return self.send_tree_api_request( request )
end
### Return the manager's current node tree.
- def make_list_request( from: nil )
+ def make_list_request( from: nil, depth: nil )
header = {}
self.log.debug "From is: %p" % [ from ]
header[:from] = from if from
+ header[:depth] = depth if depth
return self.pack_message( :list, header )
end
@@ -73,23 +74,58 @@
return self.send_tree_api_request( request )
end
### Return the manager's current node tree.
- def make_fetch_request( criteria, include_down: false, properties: :all )
+ def make_fetch_request( criteria, include_down: false, properties: :all, exclude: {} )
header = {}
header[ :include_down ] = true if include_down
header[ :return ] = properties if properties != :all
- return self.pack_message( :fetch, header, criteria )
+ return self.pack_message( :fetch, header, [ criteria, exclude ] )
end
+ ### Mark a node as 'acknowledged' if it's down, or 'disabled' if
+ ### it's up. (A pre-emptive acknowledgement.) Requires the node
+ ### +identifier+, an acknowledgement +message+, and +sender+. You
+ ### can optionally include a +via+ (source), and override the default
+ ### +time+ of now.
+ def acknowledge( node, message, sender, via=nil, time=Time.now )
+ data = {
+ node => {
+ ack: {
+ message: message,
+ sender: sender,
+ via: via,
+ time: time.to_s
+ }
+ }
+ }
+
+ request = self.make_update_request( data )
+ self.send_tree_api_request( request )
+ return true
+ end
+ alias_method :ack, :acknowledge
+
+
+ ### Clear an acknowledged/disabled +node+.
+ def clear_acknowledgement( node )
+ data = { node => { ack: nil } }
+ request = self.make_update_request( data )
+ self.send_tree_api_request( request )
+ return true
+ end
+ alias_method :clear_ack, :clear_acknowledgement
+
+
### Update the identified nodes in the manager with the specified data.
def update( *args )
request = self.make_update_request( *args )
- return self.send_tree_api_request( request )
+ self.send_tree_api_request( request )
+ return true
end
### Update the identified nodes in the manager with the specified data.
def make_update_request( data )
@@ -128,9 +164,66 @@
### Remove the subscription with the specified +subid+.
def make_unsubscribe_request( subid )
self.log.debug "Making unsubscribe request for subid: %s" % [ subid ]
return self.pack_message( :unsubscribe, subscription_id: subid )
+ end
+
+
+ ### Remove a node
+ def prune( *args )
+ request = self.make_prune_request( *args )
+ response = self.send_tree_api_request( request )
+ return response
+ end
+
+
+ ### Remove the node with the specified +identfier+.
+ def make_prune_request( identifier )
+ self.log.debug "Making prune request for identifier: %s" % [ identifier ]
+
+ return self.pack_message( :prune, identifier: identifier )
+ end
+
+
+ ### Add a new node to the tree.
+ def graft( *args )
+ request = self.make_graft_request( *args )
+ response = self.send_tree_api_request( request )
+ return response
+ end
+
+
+ ### Add a node with the specified +identifier+ and +arguments+.
+ def make_graft_request( identifier, attributes={} )
+ self.log.debug "Making graft request for identifer: %s" % [ identifier ]
+
+ parent = attributes.delete( :parent )
+ type = attributes.delete( :type )
+
+ header = {
+ identifier: identifier,
+ parent: parent,
+ type: type
+ }
+
+ return self.pack_message( :graft, header, attributes )
+ end
+
+
+ ### Modify operational attributes of a node.
+ def modify( *args )
+ request = self.make_modify_request( *args )
+ response = self.send_tree_api_request( request )
+ return true
+ end
+
+
+ ### Modify the operations +attributes+ of the node with the specified +identifier+.
+ def make_modify_request( identifier, attributes={} )
+ self.log.debug "Making modify request for identifer: %s" % [ identifier ]
+
+ return self.pack_message( :modify, {identifier: identifier}, attributes )
end
### Send the packed +request+ via the Tree API socket, raise an error on
### unsuccessful response, and return the response body.