Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #27 from nautobot/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ubajze authored Aug 4, 2021
2 parents b4d3406 + efa97dc commit 6fc6714
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .bandit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
skips: []
# No need to check for security issues in the test scripts!
exclude_dirs:
- "nautobot_plugin_chatops_ansible/tests/"
- "nautobot_chatops_ansible/tests/"
2 changes: 1 addition & 1 deletion nautobot_chatops_ansible/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Plugin declaration for nautobot_chatops_ansible."""

__version__ = "1.0.0"
__version__ = "1.0.1"

from nautobot.extras.plugins import PluginConfig

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@
},
"created": "2020-07-11T11:55:46.171153Z",
"modified": "2020-07-11T11:55:46.171166Z",
"name": "Nautobot SoT Agg Inventory",
"name": "NautobotSOT",
"description": "All data from Nautobot SoT Agg API (plugin)",
"organization": 1,
"kind": "",
Expand Down
6 changes: 3 additions & 3 deletions nautobot_chatops_ansible/tests/test_tower.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def test_get_tower_inventory_id(self):
test_tower = Tower(
origin=SLACK_ORIGIN, tower_uri="https://mocktower", username="mock", password="mock", verify_ssl=False
)
inventory_id = test_tower.get_tower_inventory_id(inventory_name="Nautobot SoT Agg Inventory")
inventory_id = test_tower.get_tower_inventory_id(inventory_name="NautobotSOT")
self.assertEqual(inventory_id, 6)
self.assertFalse(test_tower.tower_verify_ssl)

Expand All @@ -127,8 +127,8 @@ def test_get_tower_inventory_groups(self):
test_tower = Tower(
origin=SLACK_ORIGIN, tower_uri="https://mocktower", username="mock", password="mock", verify_ssl=False
)
inventory_id = 6
inv_groups = test_tower.get_tower_inventory_groups(inventory_id)
inventory_name = "NautobotSOT"
inv_groups = test_tower.get_tower_inventory_groups(inventory_name)
self.assertEqual(inv_groups["count"], 34)
self.assertEqual(len(inv_groups["results"]), 25)
self.assertEqual(inv_groups["results"][0]["name"], "access_switch")
Expand Down
10 changes: 7 additions & 3 deletions nautobot_chatops_ansible/tower.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,20 @@ def get_tower_inventory_groups(self, inventory):
Returns:
(json): JSON data of the Tower groups
"""
return self._get_tower(f"inventories/{inventory}/groups/")
# Get the inventory ID from the name
inventory_id = self.get_tower_inventory_id(inventory_name=inventory)

# Return the groups of the inventory
return self._get_tower(f"inventories/{inventory_id}/groups/")

def get_tower_group_id(self, inventory_id: int, group_name: str): # pylint: disable=inconsistent-return-statements
"""Gets Group ID from groups.
Args:
group_name (str): Name of the desired group
inventory_id (str): The inventory ID
inventory_id (int): The inventory ID
"""
groups = self.get_tower_inventory_groups(inventory=inventory_id)["results"]
groups = self._get_tower(f"inventories/{inventory_id}/groups/")["results"]
for group in groups:
if group["name"] == group_name:
return group["id"]
Expand Down
7 changes: 5 additions & 2 deletions nautobot_chatops_ansible/worker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Worker functions implementing Nautobot "ansible" command and subcommands."""
from collections import namedtuple
import json
import logging
import os

from django_rq import job
Expand All @@ -17,6 +18,8 @@

Origin = namedtuple("Origin", ["name", "slug"])

LOGGER = logging.getLogger("nautobot_plugin_chatops_ansible")


def ansible_logo(dispatcher):
"""Construct an image_element containing the locally hosted Ansible logo."""
Expand Down Expand Up @@ -88,16 +91,16 @@ def get_inventory(dispatcher, inventory, group):

if not group:
data = tower.get_tower_inventory_groups(inventory=inventory)
LOGGER.debug("Data result: %s", data)
dispatcher.prompt_from_menu(
f"ansible get-inventory {inventory}",
f"ansible get-inventory '{inventory}'",
"Select inventory group",
[(entry["name"], entry["name"]) for entry in data["results"]],
)
return False

inventory_id = tower.get_tower_inventory_id(inventory_name=inventory)
group_id = tower.get_tower_group_id(inventory_id=inventory_id, group_name=group)

data = tower.get_tower_inventory_hosts(group_id=group_id)

dispatcher.send_blocks(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nautobot-chatops-ansible"
version = "1.0.0"
version = "1.0.1"
description = "Nautobot Chatpops Ansible Tower integration"
authors = ["Network to Code, LLC <opensource@networktocode.com>"]

Expand Down

0 comments on commit 6fc6714

Please sign in to comment.