Skip to content

Commit

Permalink
Merge pull request #39 from netfoundry/feature/ha_enabled_flag
Browse files Browse the repository at this point in the history
Feature/ha enabled flag
  • Loading branch information
emoscardini authored Jul 24, 2024
2 parents 2002186 + 1e7fbf4 commit e061e76
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changelog

All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.0.20] - 2024-07-24

### Added

- Add ha argument to enable ha flag in configuration
- Add ha cleanup

## [1.0.19] - 2023-12-28

### Added
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ This Python script automates the process of downloading, configuring and enrolli
- Binding(required): Specifies an API to bind to this webListener. Built-in APIs are
- Example: --webs 'health-check' '0.0.0.0:8081' '0.0.0.0:8081' 'health-checks'

### HA Options
- `--ha`: Enable ha flag to True (Default: False)

## Router Creation Options

Create a new router on the controller before enrollment:
Expand Down
42 changes: 32 additions & 10 deletions ziti_router_auto_enroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
ca: {{ identity.ca }}
ctrl:
endpoint: {{ ctrl.endpoint }}
{%- if ha %}
ha:
enabled: true
{%- endif %}
{%- if proxy %}
proxy:
type: {{ proxy.proxy_type }}
Expand Down Expand Up @@ -533,6 +537,17 @@ def add_create_router_arguments(parser):
create_router_group.add_argument('--routerName',type=str,
help='Router name created in controller')

def add_router_ha_arguments(parser):
"""
Add ha option argument to the parser.
:param parser: The argparse.ArgumentParser instance to add the arguments to.
"""
router_ha_group = parser.add_argument_group("HA")
router_ha_group.add_argument('--ha',
action='store_true',
help="Enable ha flag")

def check_root_permissions():
"""
Check to see if this is running as root privileges & exit if not.
Expand Down Expand Up @@ -634,24 +649,28 @@ def check_parameters_file(args, parser):
logging.warning("Overriding parameter file value for %s,"
" with value set via cli", arg)

def cleanup_previous_versions():
def cleanup_previous_versions(args):
"""
Removes previous ziti binaries that are present in the system
:args:args (argparse.Namespace): A Namespace object containing the parsed arguments.
"""
files_to_remove = [
"/opt/netfoundry/ziti/ziti-router/ziti-router",
"/opt/netfoundry/ziti/ziti"
"/ziti-router",
"/ziti",
"/endpoints"
]

logging.info("Removing previous binaries")

for binary_file in files_to_remove:
if os.path.isfile(binary_file):
for file in files_to_remove:
file_to_remove = args.installDir + file
if os.path.isfile(file_to_remove):
try:
logging.debug("Removing file: %s", binary_file)
os.remove(binary_file)
logging.debug("Removing file: %s", file_to_remove)
os.remove(file_to_remove)
except OSError:
logging.error("Unable to remove %s", binary_file)
logging.error("Unable to remove %s", file_to_remove)
sys.exit(1)

def create_file(name, path, content="", permissions=0o644):
Expand Down Expand Up @@ -729,7 +748,7 @@ def create_parser():
:return: A Namespace containing arguments
"""
__version__ = '1.0.19'
__version__ = '1.0.20'
parser = argparse.ArgumentParser()

add_general_arguments(parser, __version__)
Expand All @@ -744,6 +763,7 @@ def create_parser():
add_router_fabric_link_arguments(parser)
add_router_listener_arguments(parser)
add_router_web_arguments(parser)
add_router_ha_arguments(parser)
add_create_router_arguments(parser)

return parser
Expand Down Expand Up @@ -1916,6 +1936,8 @@ def create_template(args, controller_info):
template_vars['listeners'] = set_listeners(args)
if args.disableHealthChecks:
template_vars['webs'] = set_webs(args)
if args.ha:
template_vars['ha'] = True

template = Template(CONFIG_TEMPLATE_STRING)
filled_out_template = template.render(template_vars)
Expand Down Expand Up @@ -1966,7 +1988,7 @@ def main(args):
if not args.printConfig:
if not args.skipSystemd:
manage_systemd_service('ziti-router.service','stop')
cleanup_previous_versions()
cleanup_previous_versions(args)

# print template
if args.printTemplate:
Expand Down

0 comments on commit e061e76

Please sign in to comment.