<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2017 F5 Networks Inc.
# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
__metaclass__ = type


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

DOCUMENTATION = r'''
---
module: bigip_software
short_description: Manage BIG-IP software versions and hotfixes
description:
   - Manage BIG-IP software versions and hotfixes.
version_added: 2.4
options:
  force:
    description:
      - If C(yes) will upload the file every time and replace the file on the
        device. If C(no), the file will only be uploaded if it does not already
        exist. Generally should be C(yes) only in cases where you have reason
        to believe that the image was corrupted during upload.
      - If C(yes) with C(reuse_inactive_volume) is specified and C(volume) is
        not specified, Software will be installed / activated regardless of
        current running version to a new or an existing volume.
    default: no
    choices:
      - yes
      - no
  reuse_inactive_volume:
    description:
      - Automatically chooses the first inactive volume in alphanumeric order.
        If there is no inactive volume, new volume with incremented volume name
        will be created. For example, if HD1.1 is currently active and no other
        volume exists, then the module will create HD1.2 and install the
        software. If volume name does not end with numeric character,
        then add C(.1) to the current active volume name. When C(volume) is
        specified, this option will be ignored.
  state:
    description:
      - When C(present), ensures that the software is uploaded/downloaded.
      - When C(installed), ensures that the software is uploaded/downloaded
        and installed on the system. The device is B(not) rebooted into
        the new software.
      - When C(activated), ensures that the software is uploaded/downloaded,
        installed, and the system is rebooted to the new software.
      - When C(absent), only the uploaded/downloaded image will be removed from
        the system.
    default: activated
    choices:
      - absent
      - activated
      - installed
      - present
  volume:
    description:
      - The volume to install the software and, optionally, the hotfix to. This
        parameter is only required when the C(state) is C(activated) or
        C(installed).
  software:
    description:
      - The path to the software (base image) to install. The parameter must be
        provided if the C(state) is either C(installed) or C(activated). If this
        parameter begins with either C(http://) or C(https://), the path will be
        assumed to be a remote source.
      - When providing link to the software ISO, if the ISO name is
        different than the one listed inside the C(software_md5sum) md5sum file.
        We will change it accordingly when saving the files on the device. This
        might lead to ISO names not matching the links provided in C(software).
    aliases:
      - base_image
  hotfix:
    description:
      - The path to an optional Hotfix to install. This parameter requires that
        the C(software) parameter be specified or the corresponding software
        image exists on the unit. If this parameter begins with either C(http://)
        or C(https://), the path will be assumed to be a remote source.
      - When providing link to the hotfix ISO, if the ISO name
        is different than the one listed inside the C(hotfix_md5) md5sum file.
        We will change it accordingly while saving the files on the device.
        This might lead to ISO names not matching the links provided
        in C(hotfix).
    aliases:
      - hotfix_image
  software_md5sum:
    description:
      - The link to an MD5 sum file of the remote software ISO image,
        it is required when C(software) parameter is used and that parameter is
        a remote URL.
      - Parameter only used when and C(state) is C(installed), C(activated),
        or C(present).
  hotfix_md5sum:
    description:
      - The link to an MD5 sum file of the remote hotfix ISO image,
        it is required when C(hotfix) parameter is used and that parameter is
        a remote URL.
      - Parameter only used when and C(state) is C(installed), C(activated),
        or C(present).
  remote_src:
    description:
       - Parameter to enable remote source usage. When set to C(yes) bigip will
         attempt to download and verify the images using the links provided in
         C(software), C(hotfix), C(software_md5sum) and C(hotfix_md5sum).
       - This parameter also makes the C(software_md5sum) and C(hotfix_md5sum)
         mandatory when C(state is C(present), C(activated) or C(installed).
    default: 'no'
notes:
  - Requires the isoparser Python package on the host. This can be installed
    with pip install isoparser
  - Requires the lxml Python package on the host. This can be installed
    with pip install lxml
extends_documentation_fragment: f5
requirements:
  - isoparser
author:
  - <NAME> (@caphrim007)
  - <NAME> (@wojtek0806)
'''

EXAMPLES = r'''
- name: Remove uploaded hotfix
  bigip_software:
    server: lb.mydomain.com
    user: admin
    password: <PASSWORD>
    hotfix: /root/Hotfix-BIGIP-11.6.0.3.0.412-HF3.iso
    state: absent
  delegate_to: localhost

- name: Upload hotfix
  bigip_software:
    server: lb.mydomain.com
    user: admin
    password: <PASSWORD>
    hotfix: /root/Hotfix-BIGIP-11.6.0.3.0.412-HF3.iso
    state: present
  delegate_to: localhost

- name: Remove uploaded base image
  bigip_software:
    server: lb.mydomain.com
    user: admin
    password: <PASSWORD>
    software: /root/BIGIP-11.6.0.0.0.401.iso
    state: absent
  delegate_to: localhost

- name: Upload base image
  bigip_software:
    server: lb.mydomain.com
    user: admin
    password: <PASSWORD>
    software: /root/BIGIP-11.6.0.0.0.401.iso
    state: present
  delegate_to: localhost

- name: Upload base image and hotfix
  bigip_software:
    server: lb.mydomain.com
    user: admin
    password: <PASSWORD>
    software: /root/BIGIP-11.6.0.0.0.401.iso
    hotfix: /root/Hotfix-BIGIP-11.6.0.3.0.412-HF3.iso
    state: present
  delegate_to: localhost

- name: Remove uploaded base image and hotfix
  bigip_software:
    server: lb.mydomain.com
    user: admin
    password: <PASSWORD>
    software: /root/BIGIP-11.6.0.0.0.401.iso
    hotfix: /root/Hotfix-BIGIP-11.6.0.3.0.412-HF3.iso
    state: absent
  delegate_to: localhost

- name: Install (upload, install) base image. Create volume if not exists
  bigip_software:
    server: lb.mydomain.com
    user: admin
    password: <PASSWORD>
    software: /root/BIGIP-11.6.0.0.0.401.iso
    volume: HD1.1
    state: installed
  delegate_to: localhost

- name: Install (upload, install) base image and hotfix. Create volume if not exists
  bigip_software:
    server: lb.mydomain.com
    user: admin
    password: "<PASSWORD><commit_msg>remove extraneous quote<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2017 F5 Networks Inc.
# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
__metaclass__ = type


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

DOCUMENTATION = r'''
---
module: bigip_software
short_description: Manage BIG-IP software versions and hotfixes
description:
   - Manage BIG-IP software versions and hotfixes.
version_added: 2.4
options:
  force:
    description:
      - If C(yes) will upload the file every time and replace the file on the
        device. If C(no), the file will only be uploaded if it does not already
        exist. Generally should be C(yes) only in cases where you have reason
        to believe that the image was corrupted during upload.
      - If C(yes) with C(reuse_inactive_volume) is specified and C(volume) is
        not specified, Software will be installed / activated regardless of
        current running version to a new or an existing volume.
    default: no
    choices:
      - yes
      - no
  reuse_inactive_volume:
    description:
      - Automatically chooses the first inactive volume in alphanumeric order.
        If there is no inactive volume, new volume with incremented volume name
        will be created. For example, if HD1.1 is currently active and no other
        volume exists, then the module will create HD1.2 and install the
        software. If volume name does not end with numeric character,
        then add C(.1) to the current active volume name. When C(volume) is
        specified, this option will be ignored.
  state:
    description:
      - When C(present), ensures that the software is uploaded/downloaded.
      - When C(installed), ensures that the software is uploaded/downloaded
        and installed on the system. The device is B(not) rebooted into
        the new software.
      - When C(activated), ensures that the software is uploaded/downloaded,
        installed, and the system is rebooted to the new software.
      - When C(absent), only the uploaded/downloaded image will be removed from
        the system.
    default: activated
    choices:
      - absent
      - activated
      - installed
      - present
  volume:
    description:
      - The volume to install the software and, optionally, the hotfix to. This
        parameter is only required when the C(state) is C(activated) or
        C(installed).
  software:
    description:
      - The path to the software (base image) to install. The parameter must be
        provided if the C(state) is either C(installed) or C(activated). If this
        parameter begins with either C(http://) or C(https://), the path will be
        assumed to be a remote source.
      - When providing link to the software ISO, if the ISO name is
        different than the one listed inside the C(software_md5sum) md5sum file.
        We will change it accordingly when saving the files on the device. This
        might lead to ISO names not matching the links provided in C(software).
    aliases:
      - base_image
  hotfix:
    description:
      - The path to an optional Hotfix to install. This parameter requires that
        the C(software) parameter be specified or the corresponding software
        image exists on the unit. If this parameter begins with either C(http://)
        or C(https://), the path will be assumed to be a remote source.
      - When providing link to the hotfix ISO, if the ISO name
        is different than the one listed inside the C(hotfix_md5) md5sum file.
        We will change it accordingly while saving the files on the device.
        This might lead to ISO names not matching the links provided
        in C(hotfix).
    aliases:
      - hotfix_image
  software_md5sum:
    description:
      - The link to an MD5 sum file of the remote software ISO image,
        it is required when C(software) parameter is used and that parameter is
        a remote URL.
      - Parameter only used when and C(state) is C(installed), C(activated),
        or C(present).
  hotfix_md5sum:
    description:
      - The link to an MD5 sum file of the remote hotfix ISO image,
        it is required when C(hotfix) parameter is used and that parameter is
        a remote URL.
      - Parameter only used when and C(state) is C(installed), C(activated),
        or C(present).
  remote_src:
    description:
       - Parameter to enable remote source usage. When set to C(yes) bigip will
         attempt to download and verify the images using the links provided in
         C(software), C(hotfix), C(software_md5sum) and C(hotfix_md5sum).
       - This parameter also makes the C(software_md5sum) and C(hotfix_md5sum)
         mandatory when C(state is C(present), C(activated) or C(installed).
    default: 'no'
notes:
  - Requires the isoparser Python package on the host. This can be installed
    with pip install isoparser
  - Requires the lxml Python package on the host. This can be installed
    with pip install lxml
extends_documentation_fragment: f5
requirements:
  - isoparser
author:
  - <NAME> (@caphrim007)
  - <NAME> (@wojtek0806)
'''

EXAMPLES = r'''
- name: Remove uploaded hotfix
  bigip_software:
    server: lb.mydomain.com
    user: admin
    password: <PASSWORD>
    hotfix: /root/Hotfix-BIGIP-11.6.0.3.0.412-HF3.iso
    state: absent
  delegate_to: localhost

- name: Upload hotfix
  bigip_software:
    server: lb.mydomain.com
    user: admin
    password: <PASSWORD>
    hotfix: /root/Hotfix-BIGIP-11.6.0.3.0.412-HF3.iso
    state: present
  delegate_to: localhost

- name: Remove uploaded base image
  bigip_software:
    server: lb.mydomain.com
    user: admin
    password: <PASSWORD>
    software: /root/BIGIP-11.6.0.0.0.401.iso
    state: absent
  delegate_to: localhost

- name: Upload base image
  bigip_software:
    server: lb.mydomain.com
    user: admin
    password: <PASSWORD>
    software: /root/BIGIP-11.6.0.0.0.401.iso
    state: present
  delegate_to: localhost

- name: Upload base image and hotfix
  bigip_software:
    server: lb.mydomain.com
    user: admin
    password: <PASSWORD>
    software: /root/BIGIP-11.6.0.0.0.401.iso
    hotfix: /root/Hotfix-BIGIP-11.6.0.3.0.412-HF3.iso
    state: present
  delegate_to: localhost

- name: Remove uploaded base image and hotfix
  bigip_software:
    server: lb.mydomain.com
    user: admin
    password: <PASSWORD>
    software: /root/BIGIP-11.6.0.0.0.401.iso
    hotfix: /root/Hotfix-BIGIP-11.6.0.3.0.412-HF3.iso
    state: absent
  delegate_to: localhost

- name: Install (upload, install) base image. Create volume if not exists
  bigip_software:
    server: lb.mydomain.com
    user: admin
    password: <PASSWORD>
    software: /root/BIGIP-11.6.0.0.0.401.iso
    volume: HD1.1
    state: installed
  delegate_to: localhost

- name: Install (upload, install) base image and hotfix. Create volume if not exists
  bigip_software:
    server: lb.mydomain.com
    user: admin
    password: <PASSWORD>
{'fraction_non_alphanumeric': 0.07599972084583712, 'fraction_numerical': 0.017586712261846604, 'mean_word_length': 2.7114737114737113, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 18, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3931664', 'n_tokens_mistral': 4379, 'n_tokens_neox': 4176, 'n_words': 1655}