-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added information-output to system-upgrade & -reboot, updated info re…
…garding version-support
- Loading branch information
1 parent
6ee6a65
commit e1e7907
Showing
5 changed files
with
37 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,50 @@ | ||
from socket import socket, AF_INET, SOCK_STREAM | ||
from socket import socket, AF_INET, AF_INET6, SOCK_STREAM, gaierror | ||
from time import time, sleep | ||
from datetime import datetime | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
|
||
from ansible_collections.ansibleguy.opnsense.plugins.module_utils.defaults.main import CONNECTION_TEST_TIMEOUT | ||
|
||
|
||
def opn_reachable(module: AnsibleModule) -> bool: | ||
with socket(AF_INET, SOCK_STREAM) as s: | ||
def _opn_reachable_ipv(module: AnsibleModule, address_family: int) -> bool: | ||
with socket(address_family, SOCK_STREAM) as s: | ||
s.settimeout(CONNECTION_TEST_TIMEOUT) | ||
return s.connect_ex(( | ||
module.params['firewall'], | ||
module.params['api_port'] | ||
)) == 0 | ||
|
||
|
||
def _opn_reachable(module: AnsibleModule) -> bool: | ||
try: | ||
return _opn_reachable_ipv(module, AF_INET) | ||
|
||
except gaierror: | ||
return _opn_reachable_ipv(module, AF_INET6) | ||
|
||
|
||
def _wait_msg(module: AnsibleModule, msg: str): | ||
module.warn(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} | {msg}") | ||
|
||
|
||
def wait_for_response(module: AnsibleModule) -> bool: | ||
timeout = time() + module.params['wait_timeout'] | ||
|
||
if module.params['action'] == 'upgrade': | ||
# waiting longer for download/install to finish | ||
_wait_msg(module, 'Waiting download & upgrade to finish..') | ||
sleep(int(module.params['wait_timeout'] / 2)) | ||
|
||
else: | ||
# waiting for services to stop | ||
_wait_msg(module, 'Waiting for service to stop..') | ||
sleep(10) | ||
|
||
while time() < timeout: | ||
if opn_reachable(module=module): | ||
if _opn_reachable(module=module): | ||
_wait_msg(module, 'Got response!') | ||
return True | ||
|
||
_wait_msg(module, 'Waiting for response..') | ||
sleep(module.params['poll_interval']) | ||
|
||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters