Skip to content

Commit

Permalink
Route "set" and "validate_config" actions to any object nodes
Browse files Browse the repository at this point in the history
If not explicitely routed through --node or --local

This will avoids creating a new local instance for a remote
object on "set", for example.
  • Loading branch information
cvaroqui committed Dec 4, 2019
1 parent 5f88e21 commit 60aa1cd
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/svc.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def signal_handler(*args):
"gen_cert",
"get",
"keys",
"print_config",
"validate_config",
"set",
"unset",
)
Expand Down Expand Up @@ -1315,10 +1315,19 @@ def prepare_async_options(self):
del options[opt]
return options

def is_remote_action(self, action):
if want_context() and (self.options.node or self.command_is_scoped() or action not in ACTION_ASYNC):
return True
if self.options.node is not None and self.options.node != "":
return True
if action in ACTION_ANY_NODE and not self.exists():
return True
return False

def async_action(self, action, wait=None, timeout=None):
if action in ACTION_NO_ASYNC:
return
if (want_context() and (self.options.node or self.command_is_scoped() or action not in ACTION_ASYNC)) or (self.options.node is not None and self.options.node != ""):
if self.is_remote_action(action):
options = self.prepare_async_options()
ret = self.daemon_service_action(action=action, options=options, node=self.options.node, action_mode=False)
if isinstance(ret, (dict, list)):
Expand Down Expand Up @@ -1983,14 +1992,16 @@ def daemon_service_action(self, action=None, options=None, server=None, node=Non
if options is None:
options = {}
req = {
"action": "service_action",
"action": "object_action",
"options": {
"path": self.path,
"sync": sync,
"action": action,
"options": options,
}
}
if not node and action in ACTION_ANY_NODE:
node = "ANY"
display_node = node if node else server
if action_mode:
self.log.info("request action '%s' on node %s", action, display_node)
Expand Down

0 comments on commit 60aa1cd

Please sign in to comment.