This repository has been archived by the owner on Jun 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding support for snmp profiles (#392)
- Loading branch information
Showing
3 changed files
with
402 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import absolute_import, division, print_function | ||
__metaclass__ = type | ||
|
||
# Copyright 2019 Palo Alto Networks, Inc | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
ANSIBLE_METADATA = {'metadata_version': '1.1', | ||
'status': ['preview'], | ||
'supported_by': 'community'} | ||
|
||
DOCUMENTATION = ''' | ||
--- | ||
module: panos_snmp_profile | ||
short_description: Manage SNMP server profiles. | ||
description: | ||
- Manages SNMP server profiles. | ||
author: "Garfield Lee Freeman (@shinmog)" | ||
version_added: "2.8" | ||
requirements: | ||
- pan-python | ||
- pandevice >= 0.11.1 | ||
notes: | ||
- Panorama is supported. | ||
- Check mode is supported. | ||
extends_documentation_fragment: | ||
- panos.transitional_provider | ||
- panos.vsys_shared | ||
- panos.device_group | ||
options: | ||
name: | ||
description: | ||
- Name of the profile. | ||
required: true | ||
version: | ||
description: | ||
- SNMP version. | ||
choices: | ||
- v2c | ||
- v3 | ||
default: "v2c" | ||
''' | ||
|
||
EXAMPLES = ''' | ||
# Create snmp profile | ||
- name: Create snmp profile | ||
panos_snmp_profile: | ||
provider: '{{ provider }}' | ||
name: 'my-profile' | ||
''' | ||
|
||
RETURN = ''' | ||
# Default return values | ||
''' | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
from ansible.module_utils.network.panos.panos import get_connection | ||
|
||
|
||
try: | ||
from pandevice.device import SnmpServerProfile | ||
from pandevice.errors import PanDeviceError | ||
except ImportError: | ||
pass | ||
|
||
|
||
def main(): | ||
helper = get_connection( | ||
vsys_shared=True, | ||
device_group=True, | ||
with_state=True, | ||
with_classic_provider_spec=True, | ||
min_pandevice_version=(0, 11, 1), | ||
min_panos_version=(7, 1, 0), | ||
argument_spec=dict( | ||
name=dict(required=True), | ||
version=dict(default='v2c', choices=['v2c', 'v3']), | ||
), | ||
) | ||
module = AnsibleModule( | ||
argument_spec=helper.argument_spec, | ||
supports_check_mode=True, | ||
required_one_of=helper.required_one_of, | ||
) | ||
|
||
# Verify imports, build pandevice object tree. | ||
parent = helper.get_pandevice_parent(module) | ||
|
||
try: | ||
listing = SnmpServerProfile.refreshall(parent) | ||
except PanDeviceError as e: | ||
module.fail_json(msg='Failed refresh: {0}'.format(e)) | ||
|
||
spec = { | ||
'name': module.params['name'], | ||
'version': module.params['version'], | ||
} | ||
obj = SnmpServerProfile(**spec) | ||
parent.add(obj) | ||
|
||
changed = helper.apply_state(obj, listing, module) | ||
module.exit_json(changed=changed, msg='Done') | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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 |
---|---|---|
@@ -0,0 +1,133 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import absolute_import, division, print_function | ||
__metaclass__ = type | ||
|
||
# Copyright 2019 Palo Alto Networks, Inc | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
ANSIBLE_METADATA = {'metadata_version': '1.1', | ||
'status': ['preview'], | ||
'supported_by': 'community'} | ||
|
||
DOCUMENTATION = ''' | ||
--- | ||
module: panos_snmp_v2c_server | ||
short_description: Manage SNMP v2c servers. | ||
description: | ||
- Manages SNMP v2c servers. | ||
author: "Garfield Lee Freeman (@shinmog)" | ||
version_added: "2.8" | ||
requirements: | ||
- pan-python | ||
- pandevice >= 0.11.1 | ||
notes: | ||
- Panorama is supported. | ||
- Check mode is supported. | ||
extends_documentation_fragment: | ||
- panos.transitional_provider | ||
- panos.vsys_shared | ||
- panos.device_group | ||
options: | ||
snmp_profile: | ||
description: | ||
- Name of the SNMP server profile. | ||
required: true | ||
name: | ||
description: | ||
- Name of the server. | ||
required: true | ||
manager: | ||
description: | ||
- IP address or FQDN of SNMP manager to use. | ||
community: | ||
description: | ||
- SNMP community | ||
''' | ||
|
||
EXAMPLES = ''' | ||
# Create a snmp v2 server | ||
- name: Create snmp v2 server | ||
panos_snmp_v2c_server: | ||
provider: '{{ provider }}' | ||
snmp_profile: 'my-profile' | ||
name: 'my-v2c-server' | ||
manager: '192.168.55.10' | ||
community: 'foobar' | ||
''' | ||
|
||
RETURN = ''' | ||
# Default return values | ||
''' | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
from ansible.module_utils.network.panos.panos import get_connection | ||
|
||
|
||
try: | ||
from pandevice.device import SnmpServerProfile | ||
from pandevice.device import SnmpV2cServer | ||
from pandevice.errors import PanDeviceError | ||
except ImportError: | ||
pass | ||
|
||
|
||
def main(): | ||
helper = get_connection( | ||
vsys_shared=True, | ||
device_group=True, | ||
with_state=True, | ||
with_classic_provider_spec=True, | ||
min_pandevice_version=(0, 11, 1), | ||
min_panos_version=(7, 1, 0), | ||
argument_spec=dict( | ||
snmp_profile=dict(required=True), | ||
name=dict(required=True), | ||
manager=dict(), | ||
community=dict(), | ||
), | ||
) | ||
module = AnsibleModule( | ||
argument_spec=helper.argument_spec, | ||
supports_check_mode=True, | ||
required_one_of=helper.required_one_of, | ||
) | ||
|
||
# Verify imports, build pandevice object tree. | ||
parent = helper.get_pandevice_parent(module) | ||
|
||
sp = SnmpServerProfile(module.params['snmp_profile']) | ||
parent.add(sp) | ||
try: | ||
sp.refresh() | ||
except PanDeviceError as e: | ||
module.fail_json(msg='Failed refresh: {0}'.format(e)) | ||
|
||
listing = sp.findall(SnmpV2cServer) | ||
|
||
spec = { | ||
'name': module.params['name'], | ||
'manager': module.params['manager'], | ||
'community': module.params['community'], | ||
} | ||
obj = SnmpV2cServer(**spec) | ||
sp.add(obj) | ||
|
||
changed = helper.apply_state(obj, listing, module) | ||
module.exit_json(changed=changed, msg='Done') | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Oops, something went wrong.