Skip to content

Add Device42 to Infrahub sync example with demo server integration#91

Merged
BeArchiTek merged 6 commits intomainfrom
copilot/fix-87
Sep 16, 2025
Merged

Add Device42 to Infrahub sync example with demo server integration#91
BeArchiTek merged 6 commits intomainfrom
copilot/fix-87

Conversation

Copy link
Contributor

Copilot AI commented Sep 16, 2025

This PR implements a complete Device42 to Infrahub synchronization example, addressing the gap in popular sync options mentioned in issue #87.

Overview

Device42 is a comprehensive IT asset management and documentation solution that was notably missing from the examples directory despite being a popular choice for infrastructure management. This implementation provides a production-ready sync adapter that leverages the existing GenericRestApiAdapter framework.

Changes Made

Core Adapter Implementation

  • New Device42 Adapter (infrahub_sync/adapters/device42.py): Extends GenericRestApiAdapter with Device42-specific configuration including basic authentication, API v2.0 endpoints, proper environment variable handling, and Device42-specific response format parsing
  • Backward Compatibility Fix (infrahub_sync/adapters/genericrestapi.py): Added missing aliases (GenericRestApiAdapter, GenericRestApiModel) to resolve import issues in existing adapters
  • Enhanced GenericRestAPIAdapter: Added smart response key detection and debug mode for better API troubleshooting

Complete Example Structure

Created a comprehensive device42_to_infrahub example following the established pattern used by NetBox, LibreNMS, and other integrations:

  • Configuration Template (config.yml): Maps Device42 objects to Infrahub schema with proper field mappings, transforms, and dependency ordering
  • Source Models (device42/sync_models.py): Device42-specific data models
  • Destination Models (infrahub/sync_models.py): Corresponding Infrahub object models
  • Sync Adapters for both source and destination systems

Device42-Specific Features

  • Response Format Handling: Properly handles Device42's {"objects": [...], "total_count": N} API response format
  • Pagination Support: Added _fetch_paginated_data() method for handling large datasets with automatic pagination
  • Debug Mode: Configurable debug logging that shows API response structure and pagination information
  • Demo Server Integration: Pre-configured with Device42's demo server (http://swaggerdemo.device42.com) using credentials guest:device42_rocks!

Data Mapping Coverage

The example handles common Device42 objects:

  • Organizations (customers) → OrganizationGeneric
  • Location hierarchy (buildings, rooms) → LocationGeneric
  • Infrastructure (racks) → InfraRack
  • Hardware models → ChoiceDeviceType
  • Device inventory → InfraDevice
  • Network interfaces (from IP records) → InfraInterfaceL2L3

Documentation

Includes comprehensive documentation (README.md) covering:

  • Setup and configuration instructions
  • Demo server usage examples
  • Environment variable options
  • API endpoint details
  • Device42-specific response format handling
  • Troubleshooting guide with debug mode instructions
  • Customization examples (filters, transforms)

Usage Example

For production use:

source:
  name: device42
  settings:
    url: "https://device42.example.com"
    username: "your-username" 
    password: "your-password"

For testing with demo server:

source:
  name: device42
  settings:
    url: "http://swaggerdemo.device42.com"
    username: "guest"
    password: "device42_rocks!"
    verify_ssl: false
    debug: true  # Enable debug logging
infrahub-sync sync examples/device42_to_infrahub/config.yml

The implementation follows the same patterns as existing examples, ensuring consistency and maintainability while providing a robust foundation for Device42 integrations with enhanced API handling capabilities.

Fixes #87.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Sep 16, 2025

Deploying infrahub-sync with  Cloudflare Pages  Cloudflare Pages

Latest commit: f7b1061
Status: ✅  Deploy successful!
Preview URL: https://e5c1ad46.infrahub-sync.pages.dev
Branch Preview URL: https://copilot-fix-87.infrahub-sync.pages.dev

View logs

Co-authored-by: BeArchiTek <1334310+BeArchiTek@users.noreply.github.com>
Copilot AI changed the title [WIP] internal: Device42 Example Add Device42 to Infrahub sync example Sep 16, 2025
Copilot AI requested a review from BeArchiTek September 16, 2025 12:02
@BeArchiTek
Copy link
Contributor

@copilot based on the docs https://api.device42.com, add the authentication. use http://swaggerdemo.device42.com/ and use credentials guest:device42_rocks! in your example.

Add anything you see fit in the GenericRestAPIAdapter to work with device42

Co-authored-by: BeArchiTek <1334310+BeArchiTek@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 16, 2025

@copilot based on the docs https://api.device42.com, add the authentication. use http://swaggerdemo.device42.com/ and use credentials guest:device42_rocks! in your example.

Add anything you see fi...

Updated the Device42 adapter with the demo server credentials and enhanced API handling:

Demo Server Integration (commit e2bdbfb):

  • Config now uses http://swaggerdemo.device42.com with guest:device42_rocks! credentials
  • Set verify_ssl: false for demo server compatibility

Device42-Specific Enhancements:

  • Proper handling of Device42's {"objects": [...], "total_count": N} response format
  • Added pagination support with _fetch_paginated_data() method
  • Debug logging shows pagination info and remaining record counts

GenericRestAPIAdapter Improvements:

  • Smart response key detection (tries objects, data, results, items)
  • Debug mode shows available API response keys for troubleshooting
  • Enhanced error handling and response format detection

The adapter now properly handles Device42's API structure and includes a debug mode to help with API response analysis. Ready for testing with the demo server!

Copilot AI changed the title Add Device42 to Infrahub sync example Add Device42 to Infrahub sync example with demo server integration Sep 16, 2025
@BeArchiTek BeArchiTek marked this pull request as ready for review September 16, 2025 13:34
@BeArchiTek BeArchiTek merged commit 34a6358 into main Sep 16, 2025
14 checks passed
@BeArchiTek BeArchiTek deleted the copilot/fix-87 branch September 16, 2025 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

internal: Device42 Example using GenericRestAPI Adapter

2 participants