Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
urohit011 committed Dec 4, 2024
2 parents 6756b7d + 7a10f03 commit 8ebbe83
Show file tree
Hide file tree
Showing 16 changed files with 363 additions and 40 deletions.
13 changes: 13 additions & 0 deletions ansible_collections/f5networks/f5os/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ F5Networks.F5OS Release Notes

.. contents:: Topics

v1.13.0
=======

Minor Changes
-------------

- f5os_ntp_server - added a new parameter, prefer, iburst

Bugfixes
--------

- f5os_system_image_import - bug fixed for importing system image in versions less than 1.7

v1.12.0
=======

Expand Down
2 changes: 1 addition & 1 deletion ansible_collections/f5networks/f5os/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Please see [f5execenv] documentation for further instructions how to use and bui
ansible_user: "{{ provider.user }}"
ansible_httpapi_password: "{{ provider.password }}"
ansible_httpapi_port: "{{ provider.server_port }}"
ansible_network_os: f5networks.f5_bigip.bigip
ansible_network_os: f5networks.f5os.f5os
ansible_httpapi_use_ssl: yes
ansible_httpapi_validate_certs: "{{ provider.validate_certs }}"
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,4 @@ plugins:
strategy: {}
test: {}
vars: {}
version: 1.12.0
version: 1.13.0
11 changes: 11 additions & 0 deletions ansible_collections/f5networks/f5os/changelogs/changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ releases:
- lag_bugfix.yaml
- tenant_virtual_disk_size_param.yaml
release_date: '2024-10-24'
1.13.0:
changes:
bugfixes:
- f5os_system_image_import - bug fixed for importing system image in versions
less than 1.7
minor_changes:
- f5os_ntp_server - added a new parameter, prefer, iburst
fragments:
- f5os_system_import_version_issue.yaml
- prefer_iburst_f5os_ntp_param.yaml
release_date: '2024-12-04'
1.2.0:
modules:
- description: Manage F5OS config backups.
Expand Down
2 changes: 1 addition & 1 deletion ansible_collections/f5networks/f5os/galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ tags:
- networking
- rseries
- velos
version: 1.12.0
version: 1.13.0
32 changes: 21 additions & 11 deletions ansible_collections/f5networks/f5os/plugins/httpapi/f5os.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import io
import json
import time

from ansible.module_utils.basic import to_text
from ansible.plugins.httpapi import HttpApiBase
Expand Down Expand Up @@ -93,17 +94,26 @@ def send_request(self, **kwargs):
url = url.replace(ROOT, '/api/data') if port == 443 else url
# allow for empty json to be passed as payload, useful for some endpoints
data = json.dumps(body) if body or body == {} else None
try:
self._display_request(method, url, body)
response, response_data = self.connection.send(url, data, method=method, **kwargs)
response_value = self._get_response_value(response_data)
return dict(
code=response.getcode(),
contents=self._response_to_json(response_value),
headers=dict(response.getheaders())
)
except HTTPError as e:
return dict(code=e.code, contents=handle_errors(e))
retries = 3
err_dict = dict()
for r1 in range(retries):
try:
self._display_request(method, url, body)
response, response_data = self.connection.send(url, data, method=method, **kwargs)
response_value = self._get_response_value(response_data)
return dict(
code=response.getcode(),
contents=self._response_to_json(response_value),
headers=dict(response.getheaders())
)
except HTTPError as e:
return dict(code=e.code, contents=handle_errors(e))
except AnsibleConnectionFailure as e:
time.sleep(10)
err_dict.update({'error': str(e)})
continue
raise F5ModuleError(f'{err_dict}')
# raise F5ModuleError('Failed to send request after {0} retries'.format(retries))

def _display_request(self, method, url, data=None):
if data:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

# This collection version needs to be updated at each release
CURRENT_COLL_VERSION = "1.12.0"
CURRENT_COLL_VERSION = "1.13.0"
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
description:
- Specifies the key ID which identifies the key used for authentication.
type: int
prefer:
description:
- Specifies that this server should be the preferred one if true. Specify false if not.
type: bool
iburst:
description:
- Specifies to enable iburst for the NTP service. Specify false to disable it.
type: bool
state:
description:
- The NTP server state.
Expand All @@ -38,13 +46,16 @@
default: present
author:
- Rohit Upadhyay (@rupadhyay)
- Prateek Ramani (@ramani)
'''

EXAMPLES = r'''
- name: Create an ntp server
f5os_ntp_server:
server: "1.2.3.4"
key_id: 10
prefer: true
iburst: true
- name: Update an ntp server
f5os_ntp_server:
Expand Down Expand Up @@ -85,21 +96,26 @@

class Parameters(AnsibleF5Parameters):
api_map = {

}

api_attributes = [
'server',
'key_id',
'iburst',
'prefer',
]

returnables = [
'server',
'key_id',
'iburst',
'prefer'
]

updatables = [
'key_id'
'key_id',
'iburst',
'prefer',
]


Expand All @@ -112,6 +128,14 @@ def server(self):
def key_id(self):
return self._values['config'].get('f5-openconfig-system-ntp:key-id')

@property
def iburst(self):
return self._values['config'].get('iburst')

@property
def prefer(self):
return self._values['config'].get('prefer')


class ModuleParameters(Parameters):
pass
Expand Down Expand Up @@ -158,6 +182,18 @@ def __default(self, param):
except AttributeError:
return attr1

@property
def prefer(self):
if (self.want.prefer and self.have.prefer) or (not self.want.prefer and not self.have.prefer):
return None
return self.want.prefer

@property
def iburst(self):
if (self.want.iburst and self.have.iburst) or (not self.want.iburst and not self.have.iburst):
return None
return self.want.iburst


class ModuleManager(object):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -290,6 +326,12 @@ def create_on_device(self):
if params.get('key_id'):
payload['server'][0]['config']['f5-openconfig-system-ntp:key-id'] = params['key_id']

if 'prefer' in params:
payload['server'][0]['config']['prefer'] = params['prefer']

if 'iburst' in params:
payload['server'][0]['config']['iburst'] = params['iburst']

uri = "/openconfig-system:system/ntp/openconfig-system:servers"
response = self.client.post(uri, data=payload)

Expand All @@ -306,12 +348,19 @@ def update_on_device(self):
'address': self.want.server,
'config': {
'address': self.want.server,
'f5-openconfig-system-ntp:key-id': params['key_id']
}
}
]
}

if 'key_id' in params:
payload['server'][0]['config']['f5-openconfig-system-ntp:key-id'] = params['key_id']

if 'prefer' in params:
payload['server'][0]['config']['prefer'] = params['prefer']

if 'iburst' in params:
payload['server'][0]['config']['iburst'] = params['iburst']
response = self.client.patch(uri, data=payload)
if response['code'] not in [200, 201, 202, 204]:
raise F5ModuleError(response['contents'])
Expand Down Expand Up @@ -341,6 +390,8 @@ def __init__(self):
argument_spec = dict(
server=dict(required=True),
key_id=dict(type='int'),
prefer=dict(type='bool'),
iburst=dict(type='bool'),
state=dict(
default='present',
choices=['present', 'absent']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
- Specifies Salt for generating primary key.
required: True
type: str
force_update:
description:
- Force update the primary key on F5OS Device.
type: bool
default: False
version_added: "1.13.0"
state:
description:
- Primary key on F5OS Device state.
Expand All @@ -35,6 +41,8 @@
- present
- absent
default: present
notes:
- This module does not support deleting the primary key.
author:
- Ravinder Reddy (@chinthalapalli)
'''
Expand All @@ -45,6 +53,13 @@
passphrase: "test-passphrase"
salt: "test-salt"
state: present
- name: Update Primary Key on F5OS Device
f5os_primarykey:
passphrase: "test-passphrase"
salt: "test-salt"
state: present
force_update: true
'''

RETURN = r'''
Expand All @@ -67,7 +82,7 @@
from ansible.module_utils.connection import Connection

from ansible_collections.f5networks.f5os.plugins.module_utils.client import (
F5Client, send_teem
F5Client
)
from ansible_collections.f5networks.f5os.plugins.module_utils.common import (
F5ModuleError, AnsibleF5Parameters
Expand Down Expand Up @@ -207,11 +222,11 @@ def exec_module(self):
result.update(**changes)
result.update(dict(changed=changed))
self._announce_deprecations(result)
send_teem(self.client, start)
# send_teem(self.client, start)
return result

def present(self):
if not self.exists():
if not self.exists() or self.want.force_update:
return self.create()

def absent(self):
Expand All @@ -234,12 +249,13 @@ def update(self):
return True

def remove(self):
if self.module.check_mode: # pragma: no cover
return True
self.remove_from_device()
if self.exists():
raise F5ModuleError("Failed to delete the resource.")
return True
pass
# if self.module.check_mode: # pragma: no cover
# return True
# self.remove_from_device()
# # if self.exists():
# # raise F5ModuleError("Failed to delete the resource.")
# return True

def create(self):
self._set_changed_options()
Expand Down Expand Up @@ -293,6 +309,7 @@ def __init__(self):
argument_spec = dict(
passphrase=dict(type='str', no_log=True, required=True),
salt=dict(type='str', no_log=True, required=True),
force_update=dict(type='bool', default=False),
state=dict(
default='present',
choices=['present', 'absent']
Expand Down
Loading

0 comments on commit 8ebbe83

Please sign in to comment.