项目作者: ksator

项目描述 :
Microservice to collect Junos show commands. Based on Ansible and Docker
高级语言: Dockerfile
项目地址: git://github.com/ksator/microservice-collect-junos-show-commands.git
创建时间: 2019-06-06T13:05:15Z
项目社区:https://github.com/ksator/microservice-collect-junos-show-commands

开源协议:MIT License

下载


Docker Cloud Automated build Docker Cloud Build Status Docker Pulls MicroBadger Layers (tag) MicroBadger Size (tag)

Description

This microservice collects Junos show commands
It uses Docker and Ansible.
This microservice:

  • instanciates a container
  • executes the service (collects Junos show commands)
  • stops the container
  • removes the container

The Docker image is ksator/collect-show-commands

Usage

Install Docker

Pull the Docker image

  1. $ docker pull ksator/collect-show-commands

Verify

  1. $ docker images ksator/collect-show-commands
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. ksator/collect-show-commands latest bd211df7c333 18 minutes ago 544MB

Create the microservice inputs

Create this structure:

  • An inputs directory. With these files:
    • An Ansible Inventory file (hosts.ini) with following variables:
      • ansible_host: IP of the device
      • ansible_ssh_user: Username to use for the connection
      • ansible_ssh_pass: Password to use for the connection
    • A YAML file (show-commands-to-collect.yml) to indicate the list of Junos show commands you want to collect
  1. $ ls inputs
  2. hosts.ini show-commands-to-collect.yml

Ansible inventory example:

  1. $ more inputs/hosts.ini
  2. [spines]
  3. demo-qfx10k2-14 ansible_host=172.25.90.67
  4. demo-qfx10k2-15 ansible_host=172.25.90.68
  5. [leaves]
  6. demo-qfx5110-9 ansible_host=172.25.90.63
  7. demo-qfx5110-10 ansible_host=172.25.90.64
  8. [all:vars]
  9. netconf_port=830
  10. ansible_ssh_user=ansible
  11. ansible_ssh_pass=juniper123

Configure the details you want to collect.
Example:

  1. $ more inputs/show-commands-to-collect.yml
  2. ---
  3. cli:
  4. - "show chassis hardware"
  5. - "show version"

Run the microservice

This will instanciate a container, execute the service, stop the container and remove the container.

  1. $ docker run -it --rm -v ${PWD}/inputs:/inputs -v ${PWD}/outputs:/outputs ksator/collect-show-commands
  2. Collect Junos show commands
  3. PLAY [collect show commands from devices] *****************************************************************************************************************************************************************************************************************************************
  4. TASK [include_vars] ***************************************************************************************************************************************************************************************************************************************************************
  5. ok: [demo-qfx5110-9]
  6. ok: [demo-qfx5110-10]
  7. ok: [demo-qfx10k2-14]
  8. ok: [demo-qfx10k2-15]
  9. TASK [include_vars] ***************************************************************************************************************************************************************************************************************************************************************
  10. ok: [demo-qfx5110-9]
  11. ok: [demo-qfx5110-10]
  12. ok: [demo-qfx10k2-15]
  13. ok: [demo-qfx10k2-14]
  14. TASK [collect-commands : Create output directory for each device] *****************************************************************************************************************************************************************************************************************
  15. changed: [demo-qfx5110-10]
  16. changed: [demo-qfx10k2-14]
  17. changed: [demo-qfx10k2-15]
  18. changed: [demo-qfx5110-9]
  19. TASK [collect-commands : run the junos show commands and save the output] *********************************************************************************************************************************************************************************************************
  20. ok: [demo-qfx5110-10] => (item=show chassis hardware)
  21. ok: [demo-qfx10k2-14] => (item=show chassis hardware)
  22. ok: [demo-qfx10k2-15] => (item=show chassis hardware)
  23. ok: [demo-qfx5110-9] => (item=show chassis hardware)
  24. ok: [demo-qfx10k2-14] => (item=show version)
  25. ok: [demo-qfx10k2-15] => (item=show version)
  26. ok: [demo-qfx5110-10] => (item=show version)
  27. ok: [demo-qfx5110-9] => (item=show version)
  28. PLAY RECAP ************************************************************************************************************************************************************************************************************************************************************************
  29. demo-qfx10k2-14 : ok=4 changed=1 unreachable=0 failed=0
  30. demo-qfx10k2-15 : ok=4 changed=1 unreachable=0 failed=0
  31. demo-qfx5110-10 : ok=4 changed=1 unreachable=0 failed=0
  32. demo-qfx5110-9 : ok=4 changed=1 unreachable=0 failed=0

List the containers.
The container doesnt exist anymore

  1. $ docker ps
  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  1. $ docker ps -a
  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

Check the microservice output

Here’s the output generated

  1. $ tree outputs/
  2. outputs/
  3. ├── demo-qfx10k2-14
  4. ├── show chassis hardware.txt
  5. └── show version.txt
  6. ├── demo-qfx10k2-15
  7. ├── show chassis hardware.txt
  8. └── show version.txt
  9. ├── demo-qfx5110-10
  10. ├── show chassis hardware.txt
  11. └── show version.txt
  12. └── demo-qfx5110-9
  13. ├── show chassis hardware.txt
  14. └── show version.txt
  15. 4 directories, 8 files
  1. $ more outputs/demo-qfx5110-9/show\ chassis\ hardware.txt
  2. Hardware inventory:
  3. Item Version Part number Serial number Description
  4. Chassis WT3718030014 QFX5110-32Q
  5. Pseudo CB 0
  6. Routing Engine 0 BUILTIN BUILTIN RE-QFX5110-32Q
  7. FPC 0 REV 08 650-077245 WT3718030014 QFX5110-32Q
  8. CPU BUILTIN BUILTIN FPC CPU
  9. PIC 0 BUILTIN BUILTIN 32x 40G-QSFP
  10. Xcvr 0 REV 01 740-056705 UUD0N6C QSFP+40GE-LX4
  11. Xcvr 1 REV 01 740-056705 UU20A9Z QSFP+40GE-LX4
  12. Xcvr 2 REV 01 740-056705 UUC1DWV QSFP+40GE-LX4
  13. Xcvr 3 REV 02 740-062254 1AMP23030FX QSFP+40GE-LX4
  14. Xcvr 6 REV 01 740-032986 QA520077 QSFP+-40G-SR4
  15. Power Supply 0 REV 04 740-041741 1GA27292724 JPSU-650W-AC-AFO
  16. Power Supply 1 REV 04 740-041741 1GA27292768 JPSU-650W-AC-AFO
  17. Fan Tray 0 fan-ctrl-0 0, Front to Back Airflow - AFO
  18. Fan Tray 1 fan-ctrl-0 1, Front to Back Airflow - AFO
  19. Fan Tray 2 fan-ctrl-1 2, Front to Back Airflow - AFO
  20. Fan Tray 3 fan-ctrl-1 3, Front to Back Airflow - AFO
  21. Fan Tray 4 fan-ctrl-2 4, Front to Back Airflow - AFO