Skip to content

Commit

Permalink
Add SITE_HOST arg to ocs-agent-cli (#354)
Browse files Browse the repository at this point in the history
This makes it easier to have docker-based agents grab their instance
config from a specific host block.
  • Loading branch information
mhasself authored Nov 13, 2023
1 parent d1712f6 commit da25bd8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
4 changes: 4 additions & 0 deletions docs/developer/docker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ Environment variables used to configure the Agent are listed in the following ta
* - ``INSTANCE_ID``
- ``--instance-id``
- Agent instance-id, e.g. ``aggregator``
* - ``SITE_HOST``
- ``--site-host``
- Hostname to use when looking up the instance configuration in
the Site Config File, e.g. ``host1``.
* - ``SITE_HUB``
- ``--site-hub``
- WAMP server address, e.g. ``ws://10.10.10.10:8001/ws``
Expand Down
23 changes: 17 additions & 6 deletions ocs/agent_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@
ocs-agent-cli --instance-id INSTANCE_ID
``ocs-agent-cli`` will also inspect environment variables for commonly passed
arguments to facilitate configuration within Docker containers. Supported
arguments include, ``--instance-id`` as ``INSTANCE_ID``, ``--site-hub`` as
``SITE_HUB``, ``--site-http`` as ``SITE_HTTP``, and ``--crossbar-timeout`` as
``CROSSBAR_TIMEOUT``.
``ocs-agent-cli`` will also inspect environment variables for commonly
passed arguments to facilitate configuration within Docker containers.
Those environment variables, if defined and non-trivial, will be
passed to the agent script unless they are overridden explicitly on
the ``ocs-agent-cli`` command line. The environment variables and
arguments are:
- ``INSTANCE_ID``, will be the default value for ``--instance-id``
- ``SITE_HOST``, for ``--site-host``
- ``SITE_HUB``, for ``--site-hub``
- ``SITE_HTTP``, for ``--site-http``
- ``CROSSBAR_TIMEOUT``, for ``--crossbar-timeout``
``ocs-agent-cli`` relies on the Agent being run belonging to an OCS Plugin. If
the Agent is not an OCS Plugin it can be run directly using both the
Expand All @@ -45,6 +53,7 @@ def _get_parser():
parser.add_argument('--instance-id', default=None, help="Agent unique instance-id. E.g. 'aggregator' or 'fakedata-1'.")
parser.add_argument('--site-hub', default=None, help="Site hub address.")
parser.add_argument('--site-http', default=None, help="Site HTTP address.")
parser.add_argument('--site-host', default=None, help="Declare the host the instance is configured in.")
# Default set in site_config.py within add_arguments()
parser.add_argument('--crossbar-timeout', type=int, help="Length of time in seconds "
"that the Agent will try to reconnect to the crossbar server before "
Expand Down Expand Up @@ -139,7 +148,9 @@ def main(args=None):
# E.g. --my-new-arg should be {"my_new_arg": "MY_NEW_ARG"}
optional_env = {"site_hub": "SITE_HUB",
"site_http": "SITE_HTTP",
"crossbar_timeout": "CROSSBAR_TIMEOUT"}
"site_host": "SITE_HOST",
"crossbar_timeout": "CROSSBAR_TIMEOUT",
}

for _name, _var in optional_env.items():
# Args passed on cli take priority
Expand Down

0 comments on commit da25bd8

Please sign in to comment.