Skip to content

Commit

Permalink
Adds new modules for config and firmware management
Browse files Browse the repository at this point in the history
- add new modules for config and firmware management
- adds documentation for new modules
  • Loading branch information
tchiapuziowong committed Jan 30, 2020
1 parent b72fff9 commit 5d04e4f
Show file tree
Hide file tree
Showing 10 changed files with 782 additions and 0 deletions.
73 changes: 73 additions & 0 deletions docs/aoscx_backup_config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# module: aoscx_backup_config

description: This module downloads an existing configuration from AOS-CX devices.

##### ARGUMENTS
```YAML
config_name:
description: "Config file or checkpoint to be downloaded. When using TFTP
only running-config or startup-config can be used"
type: str
default: 'running-config'
required: false
output_file:
description: "File name and path for locally downloading configuration,
only JSON version of configuration will be downloaded"
type: str
required: false
remote_output_file_tftp_path:
description: "TFTP server address and path for copying off configuration,
must be reachable through provided vrf
ex) tftp://192.168.1.2/config.txt"
type: str
required: false
config_type:
description: Configuration type to be downloaded, JSON or CLI version of the config.
type: str
choices: ['json', 'cli']
default: 'json'
required: false
vrf:
description: VRF to be used to contact TFTP server, required if remote_output_file_tftp_path is provided
type: str
required: false
```
##### EXAMPLES
```YAML
- name: Copy Running Config to local as JSON
aoscx_backup_config:
config_name: 'running-config'
output_file: '/home/admin/running-config.json'

- name: Copy Startup Config to local as JSON
aoscx_backup_config:
config_name: 'startup-config'
output_file: '/home/admin/startup-config.json'

- name: Copy Checkpoint Config to local as JSON
aoscx_backup_config:
config_name: 'checkpoint1'
output_file: '/home/admin/checkpoint1.json'

- name: Copy Running Config to TFTP server as JSON
aoscx_backup_config:
config_name: 'running-config'
remote_output_file_tftp_path: 'tftp://192.168.1.2/running.json'
config_type: 'json'
vrf: 'mgmt'

- name: Copy Running Config to TFTP server as CLI
aoscx_backup_config:
config_name: 'running-config'
remote_output_file_tftp_path: 'tftp://192.168.1.2/running.cli'
config_type: 'cli'
vrf: 'mgmt'

- name: Copy Startup Config to TFTP server as CLI
aoscx_backup_config:
config_name: 'startup-config'
remote_output_file_tftp_path: 'tftp://192.168.1.2/startup.cli'
config_type: 'cli'
vrf: 'mgmt'
```
24 changes: 24 additions & 0 deletions docs/aoscx_boot_firmware.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# module: aoscx_boot_firmware

description: This module boots the AOS-CX switch with the image present to the specified partition.

##### ARGUMENTS
```YAML
partition_name:
description: Name of the partition for device to boot to.
type: str
default: 'primary'
choices: ['primary', 'secondary']
required: false
```
##### EXAMPLES
```YAML
- name: Boot to primary
aoscx_boot_firmware:
partition_name: 'primary'

- name: Boot to secondary
aoscx_boot_firmware:
partition_name: 'secondary'
```
35 changes: 35 additions & 0 deletions docs/aoscx_checkpoint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# module: aoscx_checkpoint

description: This module creates a new checkpoint or copies an existing checkpoint to the running or startup config of an AOS-CX switch.

##### ARGUMENTS
```YAML
source_config:
description: Name of the source configuration from which checkpoint needs
to be created or copied.
required: False
default: 'running-config'

destination_config:
description: Name of the destination configuration or name of checkpoint.
required: False
default: 'startup-config'
```
##### EXAMPLES
```YAML
- name: Copy running-config to startup-config
aoscx_checkpoint:
source_config: 'running-config'
destination_config: 'startup-config'

- name: Copy startup-config to running-config
aoscx_checkpoint:
source_config: 'startup-config'
destination_config: 'running-config'

- name: Copy running-config to backup checkpoint
aoscx_checkpoint:
source_config: 'running-config'
destination_config: 'checkpoint_20200128'
```
60 changes: 60 additions & 0 deletions docs/aoscx_upload_config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# module: aoscx_upload_config

description: This module uploads a configuration onto the switch stored locally or it can also upload the configuration from a TFTP server.

##### ARGUMENTS
```YAML
config_name:
description: "Config file or checkpoint to be uploaded to. When using TFTP
only running-config or startup-config can be used"
type: str
default: 'running-config'
required: false
config_json:
description: "JSON file name and path for locally uploading configuration,
only JSON version of configuration can be uploaded"
type: str
required: false
config_file:
description: "File name and path for locally uploading configuration,
will be converted to JSON,
only JSON version of configuration can be uploaded"
type: str
required: false
remote_config_file_tftp_path:
description: "TFTP server address and path for uploading configuration,
can be JSON or CLI format, must be reachable through provided vrf
ex) tftp://192.168.1.2/config.txt"
type: str
required: false
vrf:
description: VRF to be used to contact TFTP server, required if remote_output_file_tftp_path is provided
type: str
required: false
```
##### EXAMPLES
```YAML
- name: Copy Running Config from local JSON file as JSON
aoscx_upload_config:
config_name: 'running-config'
remote_config_file_tftp_path: '/user/admin/running.json'

- name: Copy Running Config from TFTP server as JSON
aoscx_upload_config:
config_name: 'running-config'
remote_config_file_tftp_path: 'tftp://192.168.1.2/running.json'
vrf: 'mgmt'

- name: Copy CLI from TFTP Server to Running Config
aoscx_upload_config:
config_name: 'running-config'
remote_config_file_tftp_path: 'tftp://192.168.1.2/running.cli'
vrf: 'mgmt'

- name: Copy CLI from TFTP Server to Startup Config
aoscx_upload_config:
config_name: 'startup-config'
remote_config_file_tftp_path: 'tftp://192.168.1.2/startup.cli'
vrf: 'mgmt'
```
47 changes: 47 additions & 0 deletions docs/aoscx_upload_firmware.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# module: aoscx_upload_firmware

description: This module uploads a firmware image onto the switch stored locally or it can also upload the firmware from an HTTP server.

##### ARGUMENTS
```YAML
partition_name:
description: Name of the partition for the image to be uploaded.
type: str
default: 'primary'
choices: ['primary', 'secondary']
required: false
firmware_file_path:
description: File name and path for locally uploading firmware image
type: str
required: false
remote_firmware_file_path:
description: "HTTP server address and path for uploading firmware image,
must be reachable through provided vrf
ex) http://192.168.1.2:8000/TL_10_04_0030A.swi"
type: str
required: false
config_type:
description: Configuration type to be downloaded, JSON or CLI version of the config.
type: str
choices: ['json', 'cli']
default: 'json'
required: false
vrf:
description: VRF to be used to contact HTTP server, required if remote_firmware_file_path is provided
type: str
required: false
```
##### EXAMPLES
```YAML
- name: Upload firmware to primary through HTTP
aoscx_upload_firmware:
partition_name: 'primary'
remote_firmware_file_path: 'http://192.168.1.2:8000/TL_10_04_0030P.swi'
vrf: 'mgmt'

- name: Upload firmware to secondary through local
aoscx_upload_firmware:
partition_name: 'secondary'
firmware_file_path: '/tftpboot/TL_10_04_0030A.swi'
```
143 changes: 143 additions & 0 deletions library/aoscx_backup_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# (C) Copyright 2019-2020 Hewlett Packard Enterprise Development LP.
# GNU General Public License v3.0+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)


ANSIBLE_METADATA = {
'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'certified'
}

DOCUMENTATION = '''
---
module: aoscx_backup_config
version_added: "2.8"
short_description: Download an existing configuration from AOS-CX switch.
description:
- This module downloads an existing configuration from AOS-CX devices.
author: Aruba Networks (@ArubaNetworks)
options:
config_name:
description: "Config file or checkpoint to be downloaded. When using TFTP
only running-config or startup-config can be used"
type: str
default: 'running-config'
required: false
output_file:
description: "File name and path for locally downloading configuration,
only JSON version of configuration will be downloaded"
type: str
required: false
remote_output_file_tftp_path:
description: "TFTP server address and path for copying off configuration,
must be reachable through provided vrf
ex) tftp://192.168.1.2/config.txt"
type: str
required: false
config_type:
description: Configuration type to be downloaded, JSON or CLI version of the config.
type: str
choices: ['json', 'cli']
default: 'json'
required: false
vrf:
description: VRF to be used to contact TFTP server, required if remote_output_file_tftp_path is provided
type: str
required: false
''' # NOQA

EXAMPLES = '''
- name: Copy Running Config to local as JSON
aoscx_backup_config:
config_name: 'running-config'
output_file: '/home/admin/running-config.json'
- name: Copy Startup Config to local as JSON
aoscx_backup_config:
config_name: 'startup-config'
output_file: '/home/admin/startup-config.json'
- name: Copy Checkpoint Config to local as JSON
aoscx_backup_config:
config_name: 'checkpoint1'
output_file: '/home/admin/checkpoint1.json'
- name: Copy Running Config to TFTP server as JSON
aoscx_backup_config:
config_name: 'running-config'
remote_output_file_tftp_path: 'tftp://192.168.1.2/running.json'
config_type: 'json'
vrf: 'mgmt'
- name: Copy Running Config to TFTP server as CLI
aoscx_backup_config:
config_name: 'running-config'
remote_output_file_tftp_path: 'tftp://192.168.1.2/running.cli'
config_type: 'cli'
vrf: 'mgmt'
- name: Copy Startup Config to TFTP server as CLI
aoscx_backup_config:
config_name: 'startup-config'
remote_output_file_tftp_path: 'tftp://192.168.1.2/startup.cli'
config_type: 'cli'
vrf: 'mgmt'
'''

RETURN = r''' # '''

from ansible.module_utils.aoscx import ArubaAnsibleModule
import json


def main():
module_args = dict(
config_name=dict(type='str', default='running-config'),
output_file=dict(type='str', default=None),
remote_output_file_tftp_path=dict(type='str', default=None),
config_type=dict(type='str', default='json', choices=['json', 'cli']),
vrf=dict(type='str')
)

aruba_ansible_module = ArubaAnsibleModule(module_args=module_args)

tftp_path = \
aruba_ansible_module.module.params['remote_output_file_tftp_path']
vrf = aruba_ansible_module.module.params['vrf']
config_name = aruba_ansible_module.module.params['config_name']
config_type = aruba_ansible_module.module.params['config_type']
config_file = aruba_ansible_module.module.params['output_file']

if tftp_path is not None:
if vrf is None:
aruba_ansible_module.module.fail_json(
msg="VRF needs to be provided in order to TFTP "
"the configuration from the switch")
tftp_path_replace = tftp_path.replace("/", "%2F")
tftp_path_encoded = tftp_path_replace.replace(":", "%3A")
if config_name != 'running-config' or config_name != 'startup-config':
aruba_ansible_module.module.fail_json(
msg="Only running-config or "
"startup-config can be backed-up using TFTP")
aruba_ansible_module.copy_switch_config_to_remote_location(
config_name, config_type, tftp_path_encoded, vrf)
else:

config_json = aruba_ansible_module.get_switch_config(
store_config=False)
with open(config_file, 'w') as to_file:
formatted_file = json.dumps(config_json, indent=4)
to_file.write(formatted_file)

result = dict(changed=aruba_ansible_module.changed,
warnings=aruba_ansible_module.warnings)
result["changed"] = True
aruba_ansible_module.module.exit_json(**result)


if __name__ == '__main__':
main()
Loading

0 comments on commit 5d04e4f

Please sign in to comment.