Skip to content

Commit

Permalink
Merge pull request #469 from nautobot/develop
Browse files Browse the repository at this point in the history
Develop to main for release
  • Loading branch information
joewesch authored Dec 20, 2024
2 parents 6fa35e2 + c0672c8 commit 6a9def4
Show file tree
Hide file tree
Showing 45 changed files with 4,096 additions and 2,136 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# networktocode.nautobot Release Notes

v5.5.0
======

New Modules
-----------

- networktocode.nautobot.job_button - Creates or removes job buttons from Nautobot
- networktocode.nautobot.dynamic_group - Creates or removes dynamic groups from Nautobot
- networktocode.nautobot.static_group_association - Creates or removes static group associations from Nautobot
- networktocode.nautobot.metadata_type - Creates or removes metadata types from Nautobot
- networktocode.nautobot.metadata_choice - Creates or removes metadata choices from Nautobot
- networktocode.nautobot.object_metadata - Creates or removes object metadata from Nautobot

Minor Changes
-------------
- (#464) Added full support for caching to GraphQL Inventory plugin
- (#465) Changed `parent_location_type` to allow for explicit name attribute lookup

v5.4.0
======

Expand Down
24 changes: 24 additions & 0 deletions changelogs/changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -521,3 +521,27 @@ releases:
- (#438) Added cloud_network option to `circuit_termination` module
- (#446) Added module option to multiple existing modules
- (#449) Changed lookup plugin to allow for multiple `id` filters
5.5.0:
modules:
- description: Creates or removes job buttons from Nautobot
name: job_button
namespace: ''
- description: Creates or removes dynamic groups from Nautobot
name: dynamic_group
namespace: ''
- description: Creates or removes static group associations from Nautobot
name: static_group_association
namespace: ''
- description: Creates or removes metadata types from Nautobot
name: metadata_type
namespace: ''
- description: Creates or removes metadata choices from Nautobot
name: metadata_choice
namespace: ''
- description: Creates or removes object metadata from Nautobot
name: object_metadata
namespace: ''
changes:
minor_changes:
- (#464) Added full support for caching to GraphQL Inventory plugin
- (#465) Changed `parent_location_type` to allow for explicit name attribute lookup
7 changes: 5 additions & 2 deletions development/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ ARG PYTHON_VER
FROM ghcr.io/nautobot/nautobot:${NAUTOBOT_VER}-py${PYTHON_VER} as nautobot

# Copy in the requirements file
COPY ./development/requirements.txt /opt/nautobot/requirements.txt
COPY --chown=nautobot:nautobot ./development/requirements.txt /opt/nautobot/requirements.txt

# Install the requirements
RUN pip install -r /opt/nautobot/requirements.txt

# Copy in the jobs
COPY --chown=nautobot:nautobot ./development/jobs /opt/nautobot/jobs

# Copy in the development configuration file
COPY ./development/nautobot_config.py /opt/nautobot/nautobot_config.py
COPY --chown=nautobot:nautobot ./development/nautobot_config.py /opt/nautobot/nautobot_config.py
4 changes: 4 additions & 0 deletions development/dev.env
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ NAUTOBOT_REDIS_PORT=6379
# NAUTOBOT_REDIS_SSL=True
NAUTOBOT_SECRET_KEY=0123456789abcdef0123456789abcdef01234567

NAUTOBOT_DEBUG=True
NAUTOBOT_LOG_DEPRECATION_WARNINGS=True
NAUTOBOT_LOG_LEVEL=DEBUG

# Needed for Postgres should match the values for Nautobot above
PGPASSWORD=decinablesprewad
POSTGRES_DB=nautobot
Expand Down
17 changes: 16 additions & 1 deletion development/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,23 @@ services:
<<: *nautobot-base
worker:
entrypoint: "nautobot-server rqworker"
#### ENABLE CELERY ######
# This is what is required to add a celery worker. This broke CI so is disabled for now.
# - "sh"
# - "-c" # this is to evaluate the $NAUTOBOT_LOG_LEVEL from the env
# - "nautobot-server celery worker -l $$NAUTOBOT_LOG_LEVEL --events" ## $$ because of docker-compose
# depends_on:
# nautobot:
# condition: "service_healthy"
# healthcheck:
# interval: "30s"
# timeout: "10s"
# start_period: "30s"
# retries: 3
# test: ["CMD", "bash", "-c", "nautobot-server celery inspect ping --destination celery@$$HOSTNAME"] ## $$ because of docker-compose
###########################
depends_on:
- "nautobot"
- "nautobot"
<<: *nautobot-base
postgres:
image: "postgres:13"
Expand Down
13 changes: 13 additions & 0 deletions development/jobs/example_job_button_receiver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from nautobot.apps.jobs import JobButtonReceiver, register_jobs


class ExampleSimpleJobButtonReceiver(JobButtonReceiver):
class Meta:
name = "Example Simple Job Button Receiver"

def receive_job_button(self, obj):
self.logger.info("Running Job Button Receiver.", extra={"object": obj})
# Add job logic here


register_jobs(ExampleSimpleJobButtonReceiver)
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace: networktocode
name: nautobot

# The version of the collection. Must be compatible with semantic versioning
version: 5.4.0
version: 5.5.0

# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
readme: README.md
Expand Down
38 changes: 34 additions & 4 deletions plugins/inventory/gql_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,27 @@ def create_tag_groups(self, device, tag_attr):
else:
self.display.display(f"Could not find value for tags.{tag_attr} on device {device_name}")

def main(self):
"""Main function."""
if not HAS_NETUTILS:
raise AnsibleError("networktocode.nautobot.gql_inventory requires netutils. Please pip install netutils.")
def get_results(self):
"""Check the cache for the results and return it if it exists, otherwise query the API and return the results."""
json_data = None
cache_key = self.get_cache_key(self.api_endpoint)

user_cache_setting = self.get_option("cache")
attempt_to_read_cache = user_cache_setting and self.use_cache

need_to_fetch = True
if attempt_to_read_cache:
try:
json_data = self._cache[cache_key]
# Successfully read the cache, so we don't need to fetch the data
need_to_fetch = False
except KeyError:
self.display.v("Cache key not found in cache or it was expired.")

if not need_to_fetch:
self.display.v("Using cached results.")
self.display.vvvv(f"Cached response: {json_data}")
return json_data

base_query = {
"query": {
Expand Down Expand Up @@ -422,6 +439,19 @@ def main(self):
if "errors" in json_data:
raise AnsibleParserError(to_native(json_data["errors"][0]["message"]))

if user_cache_setting:
# If we got here and the user has caching enabled, we need to cache the results
self._cache[cache_key] = json_data

return json_data

def main(self):
"""Main function."""
if not HAS_NETUTILS:
raise AnsibleError("networktocode.nautobot.gql_inventory requires netutils. Please pip install netutils.")

json_data = self.get_results()

for device in json_data["data"].get("devices", []) + json_data["data"].get("virtual_machines", []):
hostname = device["name"]
self.inventory.add_host(host=hostname)
Expand Down
7 changes: 7 additions & 0 deletions plugins/lookup/lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def get_endpoint(nautobot, term):
"device-types": {"endpoint": nautobot.dcim.device_types},
"device-redundancy-groups": {"endpoint": nautobot.dcim.device_redundancy_groups},
"devices": {"endpoint": nautobot.dcim.devices},
"dynamic-groups": {"endpoint": nautobot.extras.dynamic_groups},
"export-templates": {"endpoint": nautobot.dcim.export_templates},
"front-port-templates": {"endpoint": nautobot.dcim.front_port_templates},
"front-ports": {"endpoint": nautobot.dcim.front_ports},
Expand All @@ -206,15 +207,20 @@ def get_endpoint(nautobot, term):
"inventory-items": {"endpoint": nautobot.dcim.inventory_items},
"ip-addresses": {"endpoint": nautobot.ipam.ip_addresses},
"ip-address-to-interface": {"endpoint": nautobot.ipam.ip_address_to_interface},
"job-buttons": {"endpoint": nautobot.extras.job_buttons},
"jobs": {"endpoint": nautobot.extras.jobs},
"locations": {"endpoint": nautobot.dcim.locations},
"location-types": {"endpoint": nautobot.dcim.location_types},
"manufacturers": {"endpoint": nautobot.dcim.manufacturers},
"metadata-choices": {"endpoint": nautobot.extras.metadata_choices},
"metadata-types": {"endpoint": nautobot.extras.metadata_types},
"module-bay-templates": {"endpoint": nautobot.dcim.module_bay_templates},
"module-bays": {"endpoint": nautobot.dcim.module_bays},
"module-types": {"endpoint": nautobot.dcim.module_types},
"modules": {"endpoint": nautobot.dcim.modules},
"namespaces": {"endpoint": nautobot.ipam.namespaces},
"object-changes": {"endpoint": nautobot.extras.object_changes},
"object-metadata": {"endpoint": nautobot.extras.object_metadata},
"platforms": {"endpoint": nautobot.dcim.platforms},
"power-connections": {"endpoint": nautobot.dcim.power_connections},
"power-outlet-templates": {"endpoint": nautobot.dcim.power_outlet_templates},
Expand All @@ -237,6 +243,7 @@ def get_endpoint(nautobot, term):
"secrets": {"endpoint": nautobot.extras.secrets},
"secrets-groups": {"endpoint": nautobot.extras.secrets_groups},
"services": {"endpoint": nautobot.ipam.services},
"static-group-associations": {"endpoint": nautobot.extras.static_group_associations},
"statuses": {"endpoint": nautobot.extras.statuses},
"tags": {"endpoint": nautobot.extras.tags},
"teams": {"endpoint": nautobot.extras.teams},
Expand Down
12 changes: 11 additions & 1 deletion plugins/module_utils/extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@
ENDPOINT_NAME_MAPPING,
)

NB_DYNAMIC_GROUPS = "dynamic_groups"
NB_TAGS = "tags"
NB_STATUS = "statuses"
NB_RELATIONSHIP_ASSOCIATIONS = "relationship_associations"
NB_STATIC_GROUP_ASSOCIATIONS = "static_group_associations"
NB_CUSTOM_FIELDS = "custom_fields"
NB_CUSTOM_FIELD_CHOICES = "custom_field_choices"
NB_CONTACT = "contacts"
NB_TEAM = "teams"
NB_JOB_BUTTONS = "job_buttons"
NB_OBJECT_METADATA = "object_metadata"
NB_METADATA_CHOICES = "metadata_choices"
NB_METADATA_TYPES = "metadata_types"


class NautobotExtrasModule(NautobotModule):
Expand Down Expand Up @@ -46,10 +52,14 @@ def run(self):
name = data["name"]
elif endpoint_name == "relationship_associations":
name = f"{data['source_type']} -> {data['destination_type']}"
elif endpoint_name == "static_group_association":
name = f"{data['dynamic_group']} -> {data['associated_object_id']}"
elif endpoint_name == "custom_field":
name = data["label"]
elif endpoint_name == "custom_field_choice":
elif endpoint_name in ["custom_field_choice", "metadata_choice"]:
name = data["value"]
elif endpoint_name in ["object_metadata"]:
name = data.get("value", data.get("contact", data.get("team")))
else:
name = data.get("id")

Expand Down
24 changes: 24 additions & 0 deletions plugins/module_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,15 @@
"contacts",
"custom_fields",
"custom_field_choices",
"metadata_choices",
"metadata_types",
"object_metadata",
"dynamic_groups",
"jobs",
"job_buttons",
"relationship_associations",
"roles",
"static_group_associations",
"statuses",
"tags",
"teams",
Expand Down Expand Up @@ -123,6 +130,7 @@
cluster_type="name",
controller="name",
device="name",
dynamic_group="name",
role="name",
device_type="model",
export_targets="name",
Expand Down Expand Up @@ -198,6 +206,7 @@
"dcim.rearport": "rear_ports",
"device": "devices",
"device_type": "device_types",
"dynamic_group": "dynamic_groups",
"export_targets": "route_targets",
"group": "tenant_groups",
"groups": "groups",
Expand All @@ -207,10 +216,12 @@
"interface_template": "interface_templates",
"ip_addresses": "ip_addresses",
"ipaddresses": "ip_addresses",
"job": "jobs",
"lag": "interfaces",
"location": "locations",
"location_type": "location_types",
"manufacturer": "manufacturers",
"metadata_type": "metadata_types",
"module_bay_template": "module_bay_templates",
"module_bay": "module_bays",
"module_type": "module_types",
Expand Down Expand Up @@ -287,6 +298,7 @@
"devices": "device",
"device_types": "device_type",
"device_redundancy_groups": "device_redundancy_group",
"dynamic_groups": "dynamic_group",
"front_ports": "front_port",
"front_port_templates": "front_port_template",
"groups": "group",
Expand All @@ -295,14 +307,18 @@
"inventory_items": "inventory_item",
"ip_addresses": "ip_address",
"ip_address_to_interface": "ip_address_to_interface",
"job_buttons": "job_button",
"locations": "location",
"location_types": "location_type",
"manufacturers": "manufacturer",
"metadata_choices": "metadata_choice",
"metadata_types": "metadata_type",
"module_bay_templates": "module_bay_template",
"module_bays": "module_bay",
"module_types": "module_type",
"modules": "module",
"namespaces": "namespace",
"object_metadata": "object_metadata",
"permissions": "permission",
"platforms": "platform",
"power_feeds": "power_feed",
Expand All @@ -322,6 +338,7 @@
"roles": "role",
"route_targets": "route_target",
"services": "services",
"static_group_associations": "static_group_association",
"statuses": "statuses",
"tags": "tags",
"teams": "team",
Expand Down Expand Up @@ -373,6 +390,7 @@
"device": set(["name"]),
"device_redundancy_group": set(["name"]),
"device_type": set(["model"]),
"dynamic_group": set(["name"]),
"front_port": set(["name", "device", "rear_port"]),
"front_port_template": set(["name", "device_type", "rear_port_template"]),
"group": set(["name"]),
Expand All @@ -385,17 +403,22 @@
"ip_addresses": set(["address", "namespace", "device", "interfaces", "vm_interfaces"]),
"ipaddresses": set(["address", "namespace", "device", "interfaces", "vm_interfaces"]),
"ip_address_to_interface": set(["ip_address", "interface", "vm_interface"]),
"job_button": set(["name"]),
"lag": set(["name"]),
"location": set(["name", "id", "parent"]),
"location_type": set(["name"]),
"manufacturer": set(["name"]),
"master": set(["name"]),
"metadata_choice": set(["value", "metadata_type"]),
"metadata_type": set(["name"]),
"module_bay_template": set(["name"]),
"module_bay": set(["name", "parent_device", "parent_module"]),
"module_type": set(["model"]),
"module": set(["module_type", "parent_module_bay", "location"]),
"namespace": set(["name"]),
"nat_inside": set(["namespace", "address"]),
"object_metadata": set(["metadata_type", "assigned_object_type", "assigned_object_id", "value"]),
"parent_location_type": set(["name"]),
"parent_module_bay": set(["name", "parent_device", "parent_module"]),
"parent_module": set(["module_type", "parent_module_bay"]),
"parent_rack_group": set(["name"]),
Expand All @@ -421,6 +444,7 @@
"role": set(["name"]),
"route_target": set(["name"]),
"services": set(["device", "virtual_machine", "name", "port", "protocol"]),
"static_group_association": set(["dynamic_group", "associated_object_type", "associated_object_id"]),
"statuses": set(["name"]),
"tags": set(["name"]),
"tagged_vlans": set(["group", "name", "location", "vid", "vlan_group", "tenant"]),
Expand Down
Loading

0 comments on commit 6a9def4

Please sign in to comment.