Skip to content

Commit

Permalink
T6287: Config-sync add the ability to configure API port
Browse files Browse the repository at this point in the history
Add the ability to configure the API port if the API on the secondary
server works on a non-default port.
The primary node will connect to configured port for config-sync

```
set service config-sync secondary address '192.0.2.11'
set service config-sync secondary port '8443'
```

(cherry picked from commit a7c3f20)

# Conflicts:
#	src/helpers/vyos_config_sync.py
  • Loading branch information
sever-sever authored and mergify[bot] committed May 1, 2024
1 parent f69604d commit 65e894b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
4 changes: 4 additions & 0 deletions interface-definitions/service_config-sync.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
</constraint>
</properties>
</leafNode>
#include <include/port-number.xml.i>
<leafNode name="port">
<defaultValue>443</defaultValue>
</leafNode>
<leafNode name="timeout">
<properties>
<help>Connection API timeout</help>
Expand Down
37 changes: 28 additions & 9 deletions src/helpers/vyos_config_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,29 @@ def retrieve_config(section: Optional[List[str]] = None) -> Optional[Dict[str, A
def set_remote_config(
address: str,
key: str,
<<<<<<< HEAD
commands: List[Dict[str, Any]]) -> Optional[Dict[str, Any]]:
=======
op: str,
mask: Dict[str, Any],
config: Dict[str, Any],
port: int) -> Optional[Dict[str, Any]]:
>>>>>>> a7c3f202f (T6287: Config-sync add the ability to configure API port)
"""Loads the VyOS configuration in JSON format to a remote host.
Args:
address (str): The address of the remote host.
key (str): The key to use for loading the configuration.
<<<<<<< HEAD
commands (list): List of set/load commands for request, given as:
[{'op': str, 'path': list[str], 'section': dict},
...]
=======
op (str): The operation to perform (set or load).
mask (dict): The dict of paths in sections.
config (dict): The dict of masked config data.
port (int): The remote API port
>>>>>>> a7c3f202f (T6287: Config-sync add the ability to configure API port)
Returns:
Optional[Dict[str, Any]]: The response from the remote host as a
Expand All @@ -105,7 +119,7 @@ def set_remote_config(
# Disable the InsecureRequestWarning
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

url = f'https://{address}/configure-section'
url = f'https://{address}:{port}/configure-section'
data = json.dumps({
'commands': commands,
'key': key
Expand All @@ -128,7 +142,8 @@ def is_section_revised(section: List[str]) -> bool:
def config_sync(secondary_address: str,
secondary_key: str,
sections: List[list[str]],
mode: str):
mode: str,
secondary_port: int):
"""Retrieve a config section from primary router in JSON format and send it to
secondary router
"""
Expand Down Expand Up @@ -156,7 +171,14 @@ def config_sync(secondary_address: str,

set_config = set_remote_config(address=secondary_address,
key=secondary_key,
<<<<<<< HEAD
commands=commands)
=======
op=mode,
mask=mask_dict,
config=config_dict,
port=secondary_port)
>>>>>>> a7c3f202f (T6287: Config-sync add the ability to configure API port)

logger.debug(f"Set config for sections '{sections}': {set_config}")

Expand All @@ -176,14 +198,12 @@ def config_sync(secondary_address: str,
secondary_address = config.get('secondary', {}).get('address')
secondary_address = bracketize_ipv6(secondary_address)
secondary_key = config.get('secondary', {}).get('key')
secondary_port = int(config.get('secondary', {}).get('port', 443))
sections = config.get('section')
timeout = int(config.get('secondary', {}).get('timeout'))

if not all([
mode, secondary_address, secondary_key, sections
]):
logger.error(
"Missing required configuration data for config synchronization.")
if not all([mode, secondary_address, secondary_key, sections]):
logger.error("Missing required configuration data for config synchronization.")
exit(0)

# Generate list_sections of sections/subsections
Expand All @@ -198,5 +218,4 @@ def config_sync(secondary_address: str,
else:
list_sections.append([section])

config_sync(secondary_address, secondary_key,
list_sections, mode)
config_sync(secondary_address, secondary_key, list_sections, mode, secondary_port)

0 comments on commit 65e894b

Please sign in to comment.