netbox-nutanix 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- netbox_nutanix/__init__.py +65 -0
- netbox_nutanix/api/__init__.py +1 -0
- netbox_nutanix/api/urls.py +3 -0
- netbox_nutanix/client.py +200 -0
- netbox_nutanix/forms.py +104 -0
- netbox_nutanix/navigation.py +34 -0
- netbox_nutanix/templates/netbox_nutanix/compare.html +243 -0
- netbox_nutanix/templates/netbox_nutanix/dashboard.html +436 -0
- netbox_nutanix/templates/netbox_nutanix/import.html +182 -0
- netbox_nutanix/templatetags/__init__.py +0 -0
- netbox_nutanix/templatetags/nutanix_tags.py +16 -0
- netbox_nutanix/urls.py +14 -0
- netbox_nutanix/views.py +1246 -0
- netbox_nutanix-0.1.0.dist-info/METADATA +164 -0
- netbox_nutanix-0.1.0.dist-info/RECORD +18 -0
- netbox_nutanix-0.1.0.dist-info/WHEEL +5 -0
- netbox_nutanix-0.1.0.dist-info/licenses/LICENSE +190 -0
- netbox_nutanix-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""
|
|
2
|
+
NetBox Nutanix Plugin
|
|
3
|
+
|
|
4
|
+
Provides a dashboard for viewing and importing VMs from Nutanix Prism Central.
|
|
5
|
+
Supports multiple Prism Centrals with per-server caching and VM import to NetBox.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from netbox.plugins import PluginConfig
|
|
9
|
+
|
|
10
|
+
__version__ = "0.1.0"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class NutanixConfig(PluginConfig):
|
|
14
|
+
"""Plugin configuration for NetBox Nutanix integration."""
|
|
15
|
+
|
|
16
|
+
name = "netbox_nutanix"
|
|
17
|
+
verbose_name = "Nutanix"
|
|
18
|
+
description = "View and import VMs from Nutanix Prism Central"
|
|
19
|
+
version = __version__
|
|
20
|
+
author = "Jeremy Worden"
|
|
21
|
+
author_email = "jeremy.worden@gmail.com"
|
|
22
|
+
base_url = "nutanix"
|
|
23
|
+
min_version = "4.7.5"
|
|
24
|
+
|
|
25
|
+
required_settings = []
|
|
26
|
+
|
|
27
|
+
default_settings = {
|
|
28
|
+
"top_level_menu": True,
|
|
29
|
+
# List of Prism Central hostnames to choose from
|
|
30
|
+
"prism_centrals": [],
|
|
31
|
+
# Optional saved credentials per Prism Central, keyed by hostname, to skip the
|
|
32
|
+
# manual login form (e.g. a read-only service account):
|
|
33
|
+
# "prism_credentials": {
|
|
34
|
+
# "pc-01.example.com": {"username": "svc-netbox@example.com", "password": "..."},
|
|
35
|
+
# }
|
|
36
|
+
"prism_credentials": {},
|
|
37
|
+
# Connection settings
|
|
38
|
+
"port": 9440,
|
|
39
|
+
"timeout": 60,
|
|
40
|
+
"verify_ssl": False, # False for self-signed Prism certificates
|
|
41
|
+
# Name matching for duplicate detection: "exact", "hostname" (strip domain), or "regex"
|
|
42
|
+
"name_match_mode": "exact",
|
|
43
|
+
"name_match_pattern": r"^([^.]+)",
|
|
44
|
+
# Import/sync settings (same meaning as netbox-vcenter-server)
|
|
45
|
+
"normalize_imported_name": True,
|
|
46
|
+
"default_tag": "",
|
|
47
|
+
"default_role": "",
|
|
48
|
+
"default_platform": "",
|
|
49
|
+
"default_vrf": "",
|
|
50
|
+
"default_tenant": "",
|
|
51
|
+
# Map Nutanix guest OS (from Nutanix Guest Tools, e.g. "linux:64:Ubuntu-22.04")
|
|
52
|
+
# to NetBox platforms: [{"pattern": r"Ubuntu", "platform": "ubuntu"}, ...]
|
|
53
|
+
"platform_mappings": [],
|
|
54
|
+
# Sync the Nutanix VM description into NetBox comments of existing VMs
|
|
55
|
+
"sync_vm_notes": False,
|
|
56
|
+
# Name of a Text custom field on Virtual Machine to fill with the guest OS
|
|
57
|
+
"guest_os_custom_field": "",
|
|
58
|
+
# Move VMs to the NetBox cluster named like their Nutanix cluster
|
|
59
|
+
"sync_cluster": False,
|
|
60
|
+
"auto_create_clusters": False,
|
|
61
|
+
"auto_create_cluster_type": "",
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
config = NutanixConfig
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""API module for NetBox Nutanix plugin."""
|
netbox_nutanix/client.py
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"""Nutanix Prism Central v4 REST API client.
|
|
2
|
+
|
|
3
|
+
Returns VMs normalized to the same dict shape the netbox-vcenter-server views use,
|
|
4
|
+
so the import/compare logic is shared in spirit with that plugin.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import logging
|
|
8
|
+
from typing import Optional
|
|
9
|
+
|
|
10
|
+
import requests
|
|
11
|
+
import urllib3
|
|
12
|
+
|
|
13
|
+
logger = logging.getLogger(__name__)
|
|
14
|
+
|
|
15
|
+
PAGE_LIMIT = 100
|
|
16
|
+
VMS_PATH = "/api/vmm/v4.0/ahv/config/vms"
|
|
17
|
+
CLUSTERS_PATH = "/api/clustermgmt/v4.0/config/clusters"
|
|
18
|
+
SUBNETS_PATH = "/api/networking/v4.0/config/subnets"
|
|
19
|
+
|
|
20
|
+
MIB = 1024 * 1024
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class PrismAPIError(Exception):
|
|
24
|
+
"""Raised when Prism Central returns an error status for a required call."""
|
|
25
|
+
|
|
26
|
+
def __init__(self, status: int, message: str):
|
|
27
|
+
super().__init__(message)
|
|
28
|
+
self.status = status
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _ref_id(ref) -> Optional[str]:
|
|
32
|
+
return ref.get("extId") if isinstance(ref, dict) else None
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _bytes_to_mb(value) -> Optional[int]:
|
|
36
|
+
return round(value / MIB) if value else None
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def normalize_vm(vm: dict, clusters: dict, subnets: dict, datacenter: str) -> dict:
|
|
40
|
+
"""Convert a v4 VM object to the plugin's normalized VM dict.
|
|
41
|
+
|
|
42
|
+
Interfaces are named eth1..N and disks "Hard disk 1..N" (API order) to match the
|
|
43
|
+
vSphere naming already on VMs migrated from VMware, so updates don't duplicate them.
|
|
44
|
+
"""
|
|
45
|
+
sockets = vm.get("numSockets")
|
|
46
|
+
vcpus = None
|
|
47
|
+
if sockets:
|
|
48
|
+
vcpus = sockets * (vm.get("numCoresPerSocket") or 1) * (vm.get("numThreadsPerCore") or 1)
|
|
49
|
+
|
|
50
|
+
disks = []
|
|
51
|
+
for index, disk in enumerate(vm.get("disks") or [], start=1):
|
|
52
|
+
size_mb = _bytes_to_mb((disk.get("backingInfo") or {}).get("diskSizeBytes"))
|
|
53
|
+
if size_mb is not None:
|
|
54
|
+
disks.append({"name": f"Hard disk {index}", "size_mb": size_mb})
|
|
55
|
+
|
|
56
|
+
interfaces = []
|
|
57
|
+
ip_addresses = []
|
|
58
|
+
for index, nic in enumerate(vm.get("nics") or [], start=1):
|
|
59
|
+
backing = nic.get("nicBackingInfo") or nic.get("backingInfo") or {}
|
|
60
|
+
network = nic.get("nicNetworkInfo") or nic.get("networkInfo") or {}
|
|
61
|
+
learned = (network.get("ipv4Info") or {}).get("learnedIpAddresses") or []
|
|
62
|
+
configured = ((network.get("ipv4Config") or {}).get("ipAddress") or {}).get("value")
|
|
63
|
+
nic_ips = [ip["value"] for ip in learned if ip.get("value")]
|
|
64
|
+
if configured and configured not in nic_ips:
|
|
65
|
+
nic_ips.insert(0, configured)
|
|
66
|
+
mac = backing.get("macAddress")
|
|
67
|
+
interfaces.append(
|
|
68
|
+
{
|
|
69
|
+
"name": f"eth{index}",
|
|
70
|
+
"mac": mac.lower() if mac else None,
|
|
71
|
+
"connected": bool(backing.get("isConnected")),
|
|
72
|
+
"ip_addresses": nic_ips,
|
|
73
|
+
"subnet": subnets.get(_ref_id(network.get("subnet"))),
|
|
74
|
+
}
|
|
75
|
+
)
|
|
76
|
+
for ip in nic_ips:
|
|
77
|
+
if ip not in ip_addresses:
|
|
78
|
+
ip_addresses.append(ip)
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
"name": vm.get("name"),
|
|
82
|
+
"uuid": vm.get("extId"),
|
|
83
|
+
"power_state": "on" if vm.get("powerState") == "ON" else "off",
|
|
84
|
+
"vcpus": vcpus,
|
|
85
|
+
"memory_mb": _bytes_to_mb(vm.get("memorySizeBytes")),
|
|
86
|
+
"disk_mb": sum(d["size_mb"] for d in disks) if disks else None,
|
|
87
|
+
"disks": disks,
|
|
88
|
+
"cluster": clusters.get(_ref_id(vm.get("cluster"))),
|
|
89
|
+
"host": None, # host names need clustermgmt hosts permission; not resolved in v1
|
|
90
|
+
"datacenter": datacenter,
|
|
91
|
+
"guest_os": (vm.get("guestTools") or {}).get("guestOsVersion"),
|
|
92
|
+
"notes": (vm.get("description") or "").strip(),
|
|
93
|
+
"ip_addresses": ip_addresses,
|
|
94
|
+
"primary_ip": ip_addresses[0] if ip_addresses else None,
|
|
95
|
+
"interfaces": interfaces,
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
class PrismClient:
|
|
100
|
+
"""Read-only client for Prism Central v4 APIs (HTTP Basic auth)."""
|
|
101
|
+
|
|
102
|
+
def __init__(
|
|
103
|
+
self,
|
|
104
|
+
server: str,
|
|
105
|
+
username: str,
|
|
106
|
+
password: str,
|
|
107
|
+
verify_ssl: bool = False,
|
|
108
|
+
port: int = 9440,
|
|
109
|
+
timeout: int = 60,
|
|
110
|
+
):
|
|
111
|
+
self.server = server
|
|
112
|
+
self.base_url = f"https://{server}:{port}"
|
|
113
|
+
self.timeout = timeout
|
|
114
|
+
self.session = requests.Session()
|
|
115
|
+
self.session.auth = (username, password)
|
|
116
|
+
self.session.verify = verify_ssl
|
|
117
|
+
self.session.headers["Accept"] = "application/json"
|
|
118
|
+
if not verify_ssl:
|
|
119
|
+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
|
120
|
+
|
|
121
|
+
def _get(self, path: str, params: dict = None) -> dict:
|
|
122
|
+
response = self.session.get(f"{self.base_url}{path}", params=params, timeout=self.timeout)
|
|
123
|
+
if response.status_code >= 400:
|
|
124
|
+
raise PrismAPIError(response.status_code, f"{path} returned HTTP {response.status_code}")
|
|
125
|
+
return response.json()
|
|
126
|
+
|
|
127
|
+
def _list(self, path: str) -> list:
|
|
128
|
+
"""Fetch every page of a v4 list endpoint."""
|
|
129
|
+
items = []
|
|
130
|
+
page = 0
|
|
131
|
+
while True:
|
|
132
|
+
payload = self._get(path, {"$limit": PAGE_LIMIT, "$page": page})
|
|
133
|
+
data = payload.get("data") or []
|
|
134
|
+
if not isinstance(data, list):
|
|
135
|
+
break
|
|
136
|
+
items.extend(data)
|
|
137
|
+
total = (payload.get("metadata") or {}).get("totalAvailableResults")
|
|
138
|
+
if not data or len(data) < PAGE_LIMIT or (total is not None and len(items) >= total):
|
|
139
|
+
break
|
|
140
|
+
page += 1
|
|
141
|
+
return items
|
|
142
|
+
|
|
143
|
+
def _lookup(self, path: str) -> list:
|
|
144
|
+
"""List an optional lookup endpoint; permission errors degrade to an empty list.
|
|
145
|
+
|
|
146
|
+
A 401 means the credentials are bad, so it is re-raised to fail the sync early.
|
|
147
|
+
"""
|
|
148
|
+
try:
|
|
149
|
+
return self._list(path)
|
|
150
|
+
except PrismAPIError as e:
|
|
151
|
+
if e.status == 401:
|
|
152
|
+
raise
|
|
153
|
+
logger.warning(f"Prism lookup {path} on {self.server} unavailable: {e}")
|
|
154
|
+
return []
|
|
155
|
+
|
|
156
|
+
def fetch_clusters(self) -> dict:
|
|
157
|
+
"""Map cluster extId -> name, excluding the Prism Central's own cluster entry."""
|
|
158
|
+
clusters = {}
|
|
159
|
+
for cluster in self._lookup(CLUSTERS_PATH):
|
|
160
|
+
functions = (cluster.get("config") or {}).get("clusterFunction") or []
|
|
161
|
+
if "PRISM_CENTRAL" in functions:
|
|
162
|
+
continue
|
|
163
|
+
clusters[cluster.get("extId")] = cluster.get("name")
|
|
164
|
+
return clusters
|
|
165
|
+
|
|
166
|
+
def fetch_subnets(self) -> dict:
|
|
167
|
+
return {s.get("extId"): s.get("name") for s in self._lookup(SUBNETS_PATH)}
|
|
168
|
+
|
|
169
|
+
def fetch_all_vms(self) -> list:
|
|
170
|
+
logger.info(f"Fetching VMs from Prism Central {self.server}")
|
|
171
|
+
clusters = self.fetch_clusters()
|
|
172
|
+
subnets = self.fetch_subnets()
|
|
173
|
+
datacenter = self.server.split(".")[0]
|
|
174
|
+
vms = []
|
|
175
|
+
for raw in self._list(VMS_PATH):
|
|
176
|
+
try:
|
|
177
|
+
vms.append(normalize_vm(raw, clusters, subnets, datacenter))
|
|
178
|
+
except Exception as e: # one bad VM shouldn't sink the sync
|
|
179
|
+
logger.warning(f"Error processing VM {raw.get('name', 'unknown')}: {e}")
|
|
180
|
+
logger.info(f"Fetched {len(vms)} VMs from {self.server}")
|
|
181
|
+
return vms
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def connect_and_fetch(
|
|
185
|
+
server: str, username: str, password: str, verify_ssl: bool = False, port: int = 9440, timeout: int = 60
|
|
186
|
+
) -> tuple[Optional[list], Optional[str]]:
|
|
187
|
+
"""Fetch all VMs from a Prism Central. Returns (vms, None) or (None, error message)."""
|
|
188
|
+
client = PrismClient(server, username, password, verify_ssl=verify_ssl, port=port, timeout=timeout)
|
|
189
|
+
try:
|
|
190
|
+
return client.fetch_all_vms(), None
|
|
191
|
+
except PrismAPIError as e:
|
|
192
|
+
logger.error(f"Prism Central {server} error: {e}")
|
|
193
|
+
if e.status == 401:
|
|
194
|
+
return None, "Authentication failed: Invalid username or password"
|
|
195
|
+
if e.status == 403:
|
|
196
|
+
return None, "Access denied: account lacks permission to list VMs"
|
|
197
|
+
return None, f"Prism Central error: {e}"
|
|
198
|
+
except requests.RequestException as e:
|
|
199
|
+
logger.error(f"Prism Central {server} connection failed: {e}")
|
|
200
|
+
return None, f"Connection failed: {e}"
|
netbox_nutanix/forms.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""Forms for NetBox Nutanix plugin."""
|
|
2
|
+
|
|
3
|
+
from django import forms
|
|
4
|
+
from django.conf import settings
|
|
5
|
+
from virtualization.models import Cluster
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ClusterChoiceField(forms.ModelChoiceField):
|
|
9
|
+
"""Custom ModelChoiceField that displays Cluster Group > Cluster Name."""
|
|
10
|
+
|
|
11
|
+
def label_from_instance(self, obj):
|
|
12
|
+
"""Return label in 'Group > Name' format."""
|
|
13
|
+
if obj.group:
|
|
14
|
+
return f"{obj.group.name} > {obj.name}"
|
|
15
|
+
return obj.name
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class NutanixConnectForm(forms.Form):
|
|
19
|
+
"""Form for connecting to a Prism Central."""
|
|
20
|
+
|
|
21
|
+
server = forms.ChoiceField(
|
|
22
|
+
label="Prism Central",
|
|
23
|
+
help_text="Select the Prism Central to connect to",
|
|
24
|
+
widget=forms.Select(attrs={"class": "form-select"}),
|
|
25
|
+
)
|
|
26
|
+
username = forms.CharField(
|
|
27
|
+
label="Username",
|
|
28
|
+
required=False,
|
|
29
|
+
help_text="Enter your username as user@domain (DOMAIN\\user is rejected by Prism Central)",
|
|
30
|
+
widget=forms.TextInput(attrs={"class": "form-control", "placeholder": "user@domain"}),
|
|
31
|
+
)
|
|
32
|
+
password = forms.CharField(
|
|
33
|
+
label="Password",
|
|
34
|
+
required=False,
|
|
35
|
+
widget=forms.PasswordInput(attrs={"class": "form-control"}),
|
|
36
|
+
)
|
|
37
|
+
verify_ssl = forms.BooleanField(
|
|
38
|
+
label="Verify SSL Certificate",
|
|
39
|
+
required=False,
|
|
40
|
+
initial=False,
|
|
41
|
+
help_text="Enable for trusted certificates (disable for self-signed)",
|
|
42
|
+
widget=forms.CheckboxInput(attrs={"class": "form-check-input"}),
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
def __init__(self, *args, **kwargs):
|
|
46
|
+
super().__init__(*args, **kwargs)
|
|
47
|
+
# Populate server choices from plugin config
|
|
48
|
+
config = settings.PLUGINS_CONFIG.get("netbox_nutanix", {})
|
|
49
|
+
servers = config.get("prism_centrals", [])
|
|
50
|
+
self.fields["server"].choices = [(s, s) for s in servers]
|
|
51
|
+
self.stored_credentials = config.get("prism_credentials", {})
|
|
52
|
+
|
|
53
|
+
def clean(self):
|
|
54
|
+
"""Require username/password only when the server has no saved credentials."""
|
|
55
|
+
cleaned_data = super().clean()
|
|
56
|
+
server = cleaned_data.get("server")
|
|
57
|
+
username = cleaned_data.get("username")
|
|
58
|
+
password = cleaned_data.get("password")
|
|
59
|
+
|
|
60
|
+
if not self.stored_credentials.get(server) and not (username and password):
|
|
61
|
+
raise forms.ValidationError(
|
|
62
|
+
"Username and password are required for this server (no saved credentials configured)."
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
return cleaned_data
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class VMImportForm(forms.Form):
|
|
69
|
+
"""Form for importing VMs from Nutanix to NetBox."""
|
|
70
|
+
|
|
71
|
+
cluster = ClusterChoiceField(
|
|
72
|
+
queryset=Cluster.objects.select_related("group").order_by("group__name", "name"),
|
|
73
|
+
label="Target Cluster",
|
|
74
|
+
help_text="NetBox cluster to assign the imported VMs to",
|
|
75
|
+
widget=forms.Select(attrs={"class": "form-select"}),
|
|
76
|
+
)
|
|
77
|
+
selected_vms = forms.CharField(
|
|
78
|
+
widget=forms.HiddenInput(),
|
|
79
|
+
help_text="JSON list of selected VM names",
|
|
80
|
+
)
|
|
81
|
+
nutanix_server = forms.CharField(
|
|
82
|
+
widget=forms.HiddenInput(),
|
|
83
|
+
help_text="Source Prism Central",
|
|
84
|
+
)
|
|
85
|
+
update_existing = forms.BooleanField(
|
|
86
|
+
label="Update existing VMs",
|
|
87
|
+
required=False,
|
|
88
|
+
initial=False,
|
|
89
|
+
help_text="Update vCPUs, memory, disk, status, and IP address for VMs that already exist in NetBox",
|
|
90
|
+
widget=forms.CheckboxInput(attrs={"class": "form-check-input"}),
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
def clean_selected_vms(self):
|
|
94
|
+
"""Parse the selected VMs JSON string."""
|
|
95
|
+
import json
|
|
96
|
+
|
|
97
|
+
data = self.cleaned_data.get("selected_vms", "[]")
|
|
98
|
+
try:
|
|
99
|
+
vms = json.loads(data)
|
|
100
|
+
if not isinstance(vms, list):
|
|
101
|
+
raise forms.ValidationError("Invalid VM selection format")
|
|
102
|
+
return vms
|
|
103
|
+
except json.JSONDecodeError:
|
|
104
|
+
raise forms.ValidationError("Invalid VM selection data")
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Navigation menu items for NetBox Nutanix plugin."""
|
|
2
|
+
|
|
3
|
+
from django.conf import settings
|
|
4
|
+
from netbox.plugins import PluginMenu, PluginMenuItem
|
|
5
|
+
|
|
6
|
+
_menu = PluginMenu(
|
|
7
|
+
label="Nutanix",
|
|
8
|
+
groups=(
|
|
9
|
+
(
|
|
10
|
+
"Virtual Machines",
|
|
11
|
+
(
|
|
12
|
+
PluginMenuItem(
|
|
13
|
+
link="plugins:netbox_nutanix:dashboard",
|
|
14
|
+
link_text="Import Dashboard",
|
|
15
|
+
permissions=["virtualization.view_virtualmachine"],
|
|
16
|
+
),
|
|
17
|
+
PluginMenuItem(
|
|
18
|
+
link="plugins:netbox_nutanix:compare",
|
|
19
|
+
link_text="Compare with NetBox",
|
|
20
|
+
permissions=["virtualization.view_virtualmachine"],
|
|
21
|
+
),
|
|
22
|
+
),
|
|
23
|
+
),
|
|
24
|
+
),
|
|
25
|
+
icon_class="mdi mdi-server-network",
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# top_level_menu=False puts this plugin's items under the shared "Plugins" menu
|
|
30
|
+
# (grouped by plugin name) instead of its own top-level sidebar menu.
|
|
31
|
+
if settings.PLUGINS_CONFIG.get("netbox_nutanix", {}).get("top_level_menu", True):
|
|
32
|
+
menu = _menu
|
|
33
|
+
else:
|
|
34
|
+
menu_items = tuple(item for group in _menu.groups for item in group.items)
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
{% extends 'base/layout.html' %}
|
|
2
|
+
{% load helpers %}
|
|
3
|
+
|
|
4
|
+
{% block title %}Nutanix vs NetBox Comparison{% endblock %}
|
|
5
|
+
|
|
6
|
+
{% block content %}
|
|
7
|
+
<div class="row mb-4">
|
|
8
|
+
<div class="col-md-12">
|
|
9
|
+
<div class="card">
|
|
10
|
+
<div class="card-header d-flex justify-content-between align-items-center">
|
|
11
|
+
<h5 class="card-title mb-0">
|
|
12
|
+
<i class="mdi mdi-compare"></i> Compare Nutanix with NetBox
|
|
13
|
+
</h5>
|
|
14
|
+
<div>
|
|
15
|
+
<select class="form-select form-select-sm d-inline-block w-auto" id="server-select">
|
|
16
|
+
<option value="">Select Nutanix...</option>
|
|
17
|
+
{% for s in servers %}
|
|
18
|
+
<option value="{{ s }}" {% if s == server %}selected{% endif %}>{{ s }}</option>
|
|
19
|
+
{% endfor %}
|
|
20
|
+
</select>
|
|
21
|
+
</div>
|
|
22
|
+
</div>
|
|
23
|
+
<div class="card-body">
|
|
24
|
+
{% if not server %}
|
|
25
|
+
<div class="alert alert-info">
|
|
26
|
+
<i class="mdi mdi-information"></i>
|
|
27
|
+
Select a Prism Central to compare with NetBox VMs.
|
|
28
|
+
</div>
|
|
29
|
+
{% elif not cached_data %}
|
|
30
|
+
<div class="alert alert-warning">
|
|
31
|
+
<i class="mdi mdi-alert"></i>
|
|
32
|
+
No cached data for <strong>{{ server }}</strong>.
|
|
33
|
+
<a href="{% url 'plugins:netbox_nutanix:dashboard' %}?server={{ server }}">Sync first</a>.
|
|
34
|
+
</div>
|
|
35
|
+
{% else %}
|
|
36
|
+
<!-- Summary Stats -->
|
|
37
|
+
<div class="row mb-4">
|
|
38
|
+
<div class="col-md-3">
|
|
39
|
+
<div class="card bg-primary text-white">
|
|
40
|
+
<div class="card-body text-center">
|
|
41
|
+
<h3 class="mb-0">{{ in_both_count }}</h3>
|
|
42
|
+
<small>In Both</small>
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
</div>
|
|
46
|
+
<div class="col-md-3">
|
|
47
|
+
<div class="card bg-success text-white">
|
|
48
|
+
<div class="card-body text-center">
|
|
49
|
+
<h3 class="mb-0">{{ only_nutanix_count }}</h3>
|
|
50
|
+
<small>Only in Nutanix</small>
|
|
51
|
+
</div>
|
|
52
|
+
</div>
|
|
53
|
+
</div>
|
|
54
|
+
<div class="col-md-3">
|
|
55
|
+
<div class="card bg-secondary text-white">
|
|
56
|
+
<div class="card-body text-center">
|
|
57
|
+
<h3 class="mb-0">{{ only_netbox_count }}</h3>
|
|
58
|
+
<small>Only in NetBox</small>
|
|
59
|
+
</div>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
<div class="col-md-3">
|
|
63
|
+
<div class="card bg-danger text-white">
|
|
64
|
+
<div class="card-body text-center">
|
|
65
|
+
<h3 class="mb-0">{{ diff_count }}</h3>
|
|
66
|
+
<small>Differences</small>
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
|
|
72
|
+
<!-- Only in Nutanix (Can Import) -->
|
|
73
|
+
{% if comparison.only_in_nutanix %}
|
|
74
|
+
<h5 class="mt-4 mb-3">
|
|
75
|
+
<span class="badge bg-success text-white">{{ only_nutanix_count }}</span>
|
|
76
|
+
Only in Nutanix (Can Import)
|
|
77
|
+
</h5>
|
|
78
|
+
<div class="table-responsive mb-4">
|
|
79
|
+
<table class="table table-sm table-hover table-striped">
|
|
80
|
+
<thead class="table-success">
|
|
81
|
+
<tr>
|
|
82
|
+
<th>VM Name</th>
|
|
83
|
+
<th>Power</th>
|
|
84
|
+
<th>vCPUs</th>
|
|
85
|
+
<th>Memory</th>
|
|
86
|
+
<th>Disk</th>
|
|
87
|
+
<th>Cluster</th>
|
|
88
|
+
</tr>
|
|
89
|
+
</thead>
|
|
90
|
+
<tbody>
|
|
91
|
+
{% for vm in comparison.only_in_nutanix %}
|
|
92
|
+
<tr>
|
|
93
|
+
<td><strong>{{ vm.name }}</strong></td>
|
|
94
|
+
<td>
|
|
95
|
+
{% if vm.power_state == 'on' %}
|
|
96
|
+
<span class="badge bg-success text-white">ON</span>
|
|
97
|
+
{% else %}
|
|
98
|
+
<span class="badge bg-secondary text-white">OFF</span>
|
|
99
|
+
{% endif %}
|
|
100
|
+
</td>
|
|
101
|
+
<td>{{ vm.vcpus|default:'-' }}</td>
|
|
102
|
+
<td>{{ vm.memory_mb|default:'-' }}</td>
|
|
103
|
+
<td>{{ vm.disk_mb|default:'-' }}</td>
|
|
104
|
+
<td>{% firstof vm.cluster vm.host '-' %}</td>
|
|
105
|
+
</tr>
|
|
106
|
+
{% endfor %}
|
|
107
|
+
</tbody>
|
|
108
|
+
</table>
|
|
109
|
+
</div>
|
|
110
|
+
{% endif %}
|
|
111
|
+
|
|
112
|
+
<!-- VMs with Differences -->
|
|
113
|
+
{% if diff_count > 0 %}
|
|
114
|
+
<div class="d-flex justify-content-between align-items-center mt-4 mb-3">
|
|
115
|
+
<h5 class="mb-0">
|
|
116
|
+
<span class="badge bg-danger text-white">{{ diff_count }}</span>
|
|
117
|
+
VMs with Differences
|
|
118
|
+
</h5>
|
|
119
|
+
<form method="post" action="{% url 'plugins:netbox_nutanix:sync_differences' %}" class="d-inline">
|
|
120
|
+
{% csrf_token %}
|
|
121
|
+
<input type="hidden" name="server" value="{{ server }}">
|
|
122
|
+
<button type="submit" class="btn btn-sm btn-primary"
|
|
123
|
+
onclick="return confirm('Sync {{ diff_count }} VM(s) with differences from Nutanix to NetBox?');">
|
|
124
|
+
<i class="mdi mdi-sync"></i> Sync All Differences
|
|
125
|
+
</button>
|
|
126
|
+
</form>
|
|
127
|
+
</div>
|
|
128
|
+
<div class="table-responsive mb-4">
|
|
129
|
+
<table class="table table-sm table-hover table-striped">
|
|
130
|
+
<thead class="table-danger">
|
|
131
|
+
<tr>
|
|
132
|
+
<th>VM Name</th>
|
|
133
|
+
<th>Field</th>
|
|
134
|
+
<th>Nutanix</th>
|
|
135
|
+
<th>NetBox</th>
|
|
136
|
+
</tr>
|
|
137
|
+
</thead>
|
|
138
|
+
<tbody>
|
|
139
|
+
{% for vm in comparison.in_both %}
|
|
140
|
+
{% if vm.has_differences %}
|
|
141
|
+
{% if vm.diffs.vcpus %}
|
|
142
|
+
<tr>
|
|
143
|
+
<td><strong>{{ vm.name }}</strong></td>
|
|
144
|
+
<td>vCPUs</td>
|
|
145
|
+
<td>{{ vm.nutanix.vcpus|default:'-' }}</td>
|
|
146
|
+
<td>{{ vm.netbox.vcpus|default:'-' }}</td>
|
|
147
|
+
</tr>
|
|
148
|
+
{% endif %}
|
|
149
|
+
{% if vm.diffs.memory %}
|
|
150
|
+
<tr>
|
|
151
|
+
<td><strong>{{ vm.name }}</strong></td>
|
|
152
|
+
<td>Memory (MB)</td>
|
|
153
|
+
<td>{{ vm.nutanix.memory_mb|default:'-' }}</td>
|
|
154
|
+
<td>{{ vm.netbox.memory_mb|default:'-' }}</td>
|
|
155
|
+
</tr>
|
|
156
|
+
{% endif %}
|
|
157
|
+
{% if vm.diffs.disk %}
|
|
158
|
+
<tr>
|
|
159
|
+
<td><strong>{{ vm.name }}</strong></td>
|
|
160
|
+
<td>Disk (MB)</td>
|
|
161
|
+
<td>{{ vm.nutanix.disk_mb|default:'-' }}</td>
|
|
162
|
+
<td>{{ vm.netbox.disk_mb|default:'-' }}</td>
|
|
163
|
+
</tr>
|
|
164
|
+
{% endif %}
|
|
165
|
+
{% if vm.diffs.primary_ip %}
|
|
166
|
+
<tr>
|
|
167
|
+
<td><strong>{{ vm.name }}</strong></td>
|
|
168
|
+
<td>Primary IP</td>
|
|
169
|
+
<td>{{ vm.nutanix.primary_ip|default:'-' }}</td>
|
|
170
|
+
<td>{{ vm.netbox.primary_ip|default:'-' }}</td>
|
|
171
|
+
</tr>
|
|
172
|
+
{% endif %}
|
|
173
|
+
{% if vm.diffs.cluster %}
|
|
174
|
+
<tr>
|
|
175
|
+
<td><strong>{{ vm.name }}</strong></td>
|
|
176
|
+
<td>Cluster</td>
|
|
177
|
+
<td>{{ vm.nutanix_cluster|default:'-' }}</td>
|
|
178
|
+
<td>{{ vm.netbox.cluster|default:'-' }}</td>
|
|
179
|
+
</tr>
|
|
180
|
+
{% endif %}
|
|
181
|
+
{% if vm.diffs.notes %}
|
|
182
|
+
<tr>
|
|
183
|
+
<td><strong>{{ vm.name }}</strong></td>
|
|
184
|
+
<td>Description / Comments</td>
|
|
185
|
+
<td style="white-space: pre-wrap;">{{ vm.nutanix.notes|truncatechars:200 }}</td>
|
|
186
|
+
<td style="white-space: pre-wrap;">{{ vm.netbox.comments|default:'-'|truncatechars:200 }}</td>
|
|
187
|
+
</tr>
|
|
188
|
+
{% endif %}
|
|
189
|
+
{% endif %}
|
|
190
|
+
{% endfor %}
|
|
191
|
+
</tbody>
|
|
192
|
+
</table>
|
|
193
|
+
</div>
|
|
194
|
+
{% endif %}
|
|
195
|
+
|
|
196
|
+
<!-- Only in NetBox (Orphaned?) -->
|
|
197
|
+
{% if comparison.only_in_netbox %}
|
|
198
|
+
<h5 class="mt-4 mb-3">
|
|
199
|
+
<span class="badge bg-secondary text-white">{{ only_netbox_count }}</span>
|
|
200
|
+
Only in NetBox (Not in {{ server }})
|
|
201
|
+
</h5>
|
|
202
|
+
<div class="table-responsive mb-4">
|
|
203
|
+
<table class="table table-sm table-hover table-striped">
|
|
204
|
+
<thead class="table-secondary">
|
|
205
|
+
<tr>
|
|
206
|
+
<th>VM Name</th>
|
|
207
|
+
<th>vCPUs</th>
|
|
208
|
+
<th>Memory</th>
|
|
209
|
+
<th>NetBox Cluster</th>
|
|
210
|
+
</tr>
|
|
211
|
+
</thead>
|
|
212
|
+
<tbody>
|
|
213
|
+
{% for vm in comparison.only_in_netbox %}
|
|
214
|
+
<tr>
|
|
215
|
+
<td><strong>{{ vm.name }}</strong></td>
|
|
216
|
+
<td>{{ vm.vcpus|default:'-' }}</td>
|
|
217
|
+
<td>{{ vm.memory_mb|default:'-' }}</td>
|
|
218
|
+
<td>{{ vm.cluster|default:'-' }}</td>
|
|
219
|
+
</tr>
|
|
220
|
+
{% endfor %}
|
|
221
|
+
</tbody>
|
|
222
|
+
</table>
|
|
223
|
+
</div>
|
|
224
|
+
<p class="text-muted">
|
|
225
|
+
<i class="mdi mdi-information"></i>
|
|
226
|
+
These VMs exist in NetBox but were not found in <strong>{{ server }}</strong>.
|
|
227
|
+
They may be on a different Nutanix or have been deleted.
|
|
228
|
+
</p>
|
|
229
|
+
{% endif %}
|
|
230
|
+
{% endif %}
|
|
231
|
+
</div>
|
|
232
|
+
</div>
|
|
233
|
+
</div>
|
|
234
|
+
</div>
|
|
235
|
+
|
|
236
|
+
<script>
|
|
237
|
+
document.getElementById('server-select').addEventListener('change', function() {
|
|
238
|
+
if (this.value) {
|
|
239
|
+
window.location.href = '?server=' + this.value;
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
</script>
|
|
243
|
+
{% endblock %}
|