15 from gateway_msgs.msg
import RemoteRule
27 Parent interface for flip and pull interfaces. 30 def __init__(self, default_rule_blacklist, default_rules, all_targets):
32 @param default_rule_blacklist : used when in flip/pull all mode 33 @type dictionary of gateway 34 @param default_rules : static rules to flip/pull on startup 35 @type gateway_msgs.msg.RemoteRule[] 36 @param all_targets : static flip/pull all targets to flip/pull to on startup 43 self.
active = utils.create_empty_connection_type_dictionary()
51 self.
watchlist = utils.create_empty_connection_type_dictionary()
64 for rule
in default_rules:
66 for gateway
in all_targets:
75 Add a remote rule to the watchlist for monitoring. 77 @param remote_rule : the remote rule to add to the watchlist 78 @type gateway_msgs.msg.RemoteRule 80 @return the remote rule, or None if the rule already exists. 81 @rtype gateway_msgs.msg.RemoteRule || None 85 rule_already_exists =
False 88 for watched_rule
in self.
watchlist[remote_rule.rule.type]:
89 if watched_rule.gateway == remote_rule.gateway
and \
90 watched_rule.rule.name == remote_rule.rule.name
and \
91 watched_rule.rule.node == remote_rule.rule.node:
92 rule_already_exists =
True 94 if not rule_already_exists:
95 self.
watchlist[remote_rule.rule.type].append(remote_rule)
102 Remove a rule. Be a bit careful looking for a rule to remove, depending 103 on the node name, which can be set (exact rule/node name match) or 104 None in which case all nodes of that kind of flip will match. 106 Handle the remapping appropriately. 108 @param remote_rule : the remote rule to remove from the watchlist. 109 @type gateway_msgs.msg.RemoteRule 111 @return Rules remaining in the watchlist 114 if remote_rule.rule.node:
118 self.
watchlist[remote_rule.rule.type].remove(remote_rule)
128 for existing_rule
in self.
watchlist[remote_rule.rule.type]:
129 if (existing_rule.gateway == remote_rule.gateway)
and \
130 (existing_rule.rule.name == remote_rule.rule.name):
131 existing_rules.append(existing_rule)
132 for rule
in existing_rules:
133 self.
watchlist[remote_rule.rule.type].remove(rule)
135 return existing_rules
139 Instead of watching/acting on specific rules, take action 140 on everything except for rules in a blacklist. 142 @param gateway : target remote gateway string id 145 @param blacklist : do not act on rules matching these patterns 146 @type gateway_msgs.msg.Rule[] 148 @return success or failure depending on if it ahs already been set or not 157 for rule
in blacklist:
158 self.
_blacklist[gateway][rule.type].append(rule)
160 for connection_type
in utils.connection_types:
161 remote_rule = RemoteRule()
162 remote_rule.gateway = gateway
163 remote_rule.rule.name =
'.*' 164 remote_rule.rule.node =
None 165 remote_rule.rule.type = connection_type
168 rule
for rule
in self.
watchlist[connection_type]
if rule.gateway != gateway]
170 self.
watchlist[connection_type].append(remote_rule)
176 Remove the add all rule for the specified gateway. 178 @param gateway : target remote gateway string id 184 for connection_type
in utils.connection_types:
185 for rule
in self.
watchlist[connection_type]:
186 if rule.gateway == gateway:
189 self.
watchlist[connection_type].remove(rule)
200 name_match_result = re.match(rule_name, name)
201 if name_match_result
and name_match_result.group() == name:
202 if utils.is_all_pattern(rule_name):
206 node_match_result = re.match(rule.rule.node, node)
207 if node_match_result
and node_match_result.group() == node:
215 Gets the local registrations for GatewayInfo consumption (flipped ins/pulls). 217 We don't need to show the service and node uri's here. 219 Basic operation : convert Registration -> RemoteRule for each registration 221 @return the list of registrations corresponding to remote interactions 224 local_registrations = []
225 for connection_type
in utils.connection_types:
227 remote_rule = RemoteRule()
228 remote_rule.gateway = registration.remote_gateway
229 remote_rule.rule.name = registration.connection.rule.name
230 remote_rule.rule.node = registration.connection.rule.node
231 remote_rule.rule.type = connection_type
232 local_registrations.append(remote_rule)
233 return local_registrations
237 Gets the watchlist for GatewayInfo consumption. 239 @return the list of flip rules that are being watched 240 @rtype gateway_msgs.msg.RemoteRule[] 243 for connection_type
in utils.connection_types:
244 watchlist.extend(copy.deepcopy(self.
watchlist[connection_type]))
246 for remote
in watchlist:
247 if not remote.rule.node:
248 remote.rule.node =
'None' 257 Check to see if a registration exists. Note that it doesn't use the 258 local node name in the check. We will get things like unflip requests that 259 don't have this variable set (that gets autogenerated when registering 260 the flip), but we need to find the matching registration. 262 We then return the registration that matches. 264 @param remote_gateway : string remote gateway id 266 @param remote_name, remote_node, connection_type : remote connection details 269 @return matching registration or none 270 @rtype utils.Registration 273 matched_registration =
None 276 if (registration.remote_gateway == remote_gateway)
and \
277 (registration.connection.rule.name == remote_name)
and \
278 (registration.connection.rule.node == remote_node)
and \
279 (registration.connection.rule.type == connection_type):
280 matched_registration = registration
285 return matched_registration
289 Check if a particular connection is in the blacklist. Use this to 290 filter connections from the flip_all command. 292 @todo move to utils - should be shared with the public interface. 294 for blacklist_rule
in self.
_blacklist[gateway][connection_type]:
295 name_match_result = re.match(blacklist_rule.name, name)
296 if name_match_result
and name_match_result.group() == name:
297 if blacklist_rule.node:
298 node_match_result = re.match(blacklist_rule.node, node)
299 if node_match_result
and node_match_result.group() == node:
def __init__(self, default_rule_blacklist, default_rules, all_targets)
def is_matched(self, rule, rule_name, name, node)
Accessors for Gateway Info.
def getLocalRegistrations(self)
def _is_in_blacklist(self, gateway, connection_type, name, node)
def find_registration_match(self, remote_gateway, remote_name, remote_node, connection_type)
Utilities.
def add_all(self, gateway, blacklist)
def remove_rule(self, remote_rule)
def remove_all(self, gateway)
def add_rule(self, remote_rule)
Rules.