Skip to content

Commit

Permalink
Add SITE_HOST arg to ocs-agent-cli
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 committed Sep 20, 2023
1 parent 5b3cb97 commit a775dec
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 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
21 changes: 16 additions & 5 deletions ocs/agent_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@
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``, and ``--site-http`` as ``SITE_HTTP``.
``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``
``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 @@ -44,6 +52,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.")

# Not passed through to Agent
parser.add_argument('--agent', default=None, help="Path to non-plugin OCS Agent.")
Expand Down Expand Up @@ -133,7 +142,9 @@ def main(args=None):
# Format is {"arg name within argparse": "ENVIRONMENT VARIABLE NAME"}
# E.g. --my-new-arg should be {"my_new_arg": "MY_NEW_ARG"}
optional_env = {"site_hub": "SITE_HUB",
"site_http": "SITE_HTTP"}
"site_http": "SITE_HTTP",
"site_host": "SITE_HOST",
}

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

0 comments on commit a775dec

Please sign in to comment.