-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #158 from netdevopsbr/nextjs
Deploy basic Next.js app to start Standalone version of Proxbox
- Loading branch information
Showing
60 changed files
with
6,625 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from enum import Enum | ||
|
||
class ProxmoxModeOptions(str, Enum): | ||
single = "single" | ||
multi = "multi" | ||
|
||
class ProxmoxUpperPaths(str, Enum): | ||
access = "access" | ||
cluster = "cluster" | ||
nodes = "nodes" | ||
storage = "storage" | ||
version = "version" | ||
|
||
class ProxmoxAccessPaths(str, Enum): | ||
domains = "domains" | ||
groups = "groups" | ||
openid = "openid" | ||
roles = "roles" | ||
tfa = "tfa" | ||
users = "users" | ||
acl = "acl" | ||
password = "password" | ||
permissions = "permissions" | ||
ticket = "ticket" | ||
|
||
class ProxmoxClusterPaths(str, Enum): | ||
acme = "acme" | ||
backup = "backup" | ||
backup_info = "backup-info" | ||
ceph = "ceph" | ||
config = "config" | ||
firewall = "firewall" | ||
ha = "ha" | ||
jobs = "jobs" | ||
mapping = "mapping" | ||
metrics = "metrics" | ||
replication = "replication" | ||
sdn = "sdn" | ||
log = "log" | ||
nextid = "nextid" | ||
options = "options" | ||
resources = "resources" | ||
status = "status" | ||
tasks = "tasks" | ||
|
||
class ClusterResourcesType(str, Enum): | ||
vm = "vm" | ||
storage = "storage" | ||
node = "node" | ||
sdn = "sdn" | ||
|
||
|
||
class ClusterResourcesTypeResponse(str, Enum): | ||
node = "node" | ||
storage = "storage" | ||
pool = "pool" | ||
qemu = "qemu" | ||
lxc = "lxc" | ||
openvz = "openvz" | ||
sdn = "sdn" | ||
|
||
|
||
class ProxmoxNodesPaths(str, Enum): | ||
node = "node" | ||
|
||
class ResourceType(Enum): | ||
node = "node" | ||
storage = "storage" | ||
pool = "pool" | ||
qemu = "qemu" | ||
lxc = "lxc" | ||
openvz = "openvz" | ||
sdn = "sdn" | ||
|
||
class NodeStatus(Enum): | ||
unknown = "unknown" | ||
online = "online" | ||
offline = "offline" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class ProxboxException(Exception): | ||
def __init__( | ||
self, | ||
message: str, | ||
detail: str | None = None, | ||
python_exception: str | None = None, | ||
): | ||
self.message = message | ||
self.detail = detail | ||
self.python_exception = python_exception |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from fastapi import APIRouter, Depends | ||
|
||
from typing import Annotated, Any | ||
|
||
from netbox_proxbox.backend.schemas import PluginConfig | ||
from netbox_proxbox.backend.schemas.netbox import NetboxSessionSchema | ||
from netbox_proxbox.backend.session.netbox import NetboxSession | ||
from netbox_proxbox.backend.routes.proxbox import netbox_settings | ||
|
||
router = APIRouter() | ||
|
||
async def netbox_session( | ||
netbox_settings: Annotated[NetboxSessionSchema, Depends(netbox_settings)], | ||
): | ||
"""Instantiate 'NetboxSession' class with user parameters and return Netbox HTTP connection to make API calls""" | ||
return await NetboxSession(netbox_settings).pynetbox() | ||
|
||
# Make Session reusable | ||
NetboxSessionDep = Annotated[Any, Depends(netbox_session)] | ||
|
||
@router.get("/status") | ||
async def netbox_status( | ||
nb: NetboxSessionDep | ||
): | ||
return nb.status() | ||
|
||
@router.get("/devices") | ||
async def netbox_devices(nb: NetboxSessionDep): | ||
"Return a list of all devices registered on Netbox." | ||
raw_list = [] | ||
|
||
device_list = nb.nb_session.dcim.device_roles.all() | ||
for device in device_list: | ||
raw_list.append(device) | ||
|
||
return raw_list | ||
|
||
@router.get("/openapi") | ||
async def netbox_devices(nb: NetboxSessionDep): | ||
return nb.openapi() | ||
|
||
@router.get("/") | ||
async def netbox( | ||
status: Annotated[Any, Depends(netbox_status)], | ||
config: Annotated[Any, Depends(netbox_settings)] | ||
): | ||
return { | ||
"config": config, | ||
"status": status | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
from typing import Annotated | ||
|
||
from fastapi import APIRouter, Depends, Query | ||
|
||
from netbox_proxbox.backend.schemas import PluginConfig | ||
from netbox_proxbox.backend.schemas.netbox import NetboxSessionSchema | ||
from netbox_proxbox.backend.schemas.proxmox import ProxmoxMultiClusterConfig | ||
from netbox_proxbox.backend.exception import ProxboxException | ||
|
||
router = APIRouter() | ||
|
||
PROXBOX_PLUGIN_NAME = "netbox_proxbox" | ||
|
||
@router.get("/netbox/plugins-config") | ||
async def netbox_plugins_config( | ||
plugin_name: Annotated[ | ||
str, | ||
Query( | ||
title="Netbox Plugin Name", | ||
description="Netbox plugin name to get configuration from PLUGINS_CONFIG variable located at Netbox 'configuration.py' file." | ||
) | ||
] | None = PROXBOX_PLUGIN_NAME, | ||
list_all: Annotated[ | ||
bool, | ||
Query( | ||
title="List All Plugins", | ||
description="Return all plugins configuration from PLUGINS_CONFIG variable located at Netbox 'configuration.py' file.", | ||
) | ||
] | None = False | ||
): | ||
""" | ||
PLUGIN_CONFIG variable defined by user in Netbox 'configuration.py' file | ||
""" | ||
|
||
try: | ||
from netbox.settings import PLUGINS_CONFIG | ||
except Exception as e: | ||
raise ProxboxException( | ||
message = "Could not import PLUGINS CONFIG from configuration.py", | ||
python_exception = f"{e}" | ||
) | ||
|
||
# If ?list=all=True | ||
# Return complete PLUGINS_CONFIG (including other plugins) | ||
if list_all: | ||
return PLUGINS_CONFIG | ||
|
||
# Message error to not found plugins. | ||
plugin_not_found = f"Could not get '{plugin_name}' plugin config from 'PLUGINS_CONFIG' variable located at Netbox 'configuration.py'" | ||
|
||
# Search for configuration of another plugin. This feature is not recommended and may cause security issues, use at your own risk. | ||
if plugin_name != PROXBOX_PLUGIN_NAME: | ||
return PLUGINS_CONFIG.get(plugin_name, { | ||
"error": { | ||
"message": plugin_not_found | ||
} | ||
} | ||
) | ||
|
||
try: | ||
return PluginConfig(**PLUGINS_CONFIG.get(plugin_name, { | ||
"error": { | ||
"message": plugin_not_found | ||
} | ||
} | ||
) | ||
) | ||
|
||
except Exception as e: | ||
raise ProxboxException( | ||
message = "Plugin configuration at PLUGINS_CONFIG (configuration.py) is probably incorrect.", | ||
detail = "Could not feed 'PluginConfig' pydantic model with config provided from 'PLUGINS_CONFIG'.", | ||
python_exception = f"{e}", | ||
) | ||
|
||
|
||
@router.get("/netbox/default-settings") | ||
async def proxbox_netbox_default(): | ||
""" | ||
Default Plugins settings | ||
""" | ||
|
||
from netbox_proxbox import ProxboxConfig | ||
return ProxboxConfig.default_settings | ||
|
||
|
||
@router.get("/settings") | ||
async def proxbox_settings( | ||
plugins_config: Annotated[PluginConfig, Depends(netbox_plugins_config)], | ||
default_settings: Annotated[PluginConfig, Depends(proxbox_netbox_default)], | ||
list_all: Annotated[ | ||
bool, | ||
Query( | ||
title="List All Plugins", | ||
description="Return all plugins configuration from PLUGINS_CONFIG variable located at Netbox 'configuration.py' file.", | ||
) | ||
] | None = False | ||
): | ||
""" | ||
TODO: Compare PLUGINS_CONFIG defined by user with default settings from ProxboxConfig.default_settings | ||
""" | ||
return plugins_config | ||
|
||
ProxboxConfigDep = Annotated[PluginConfig, Depends(proxbox_settings)] | ||
|
||
@router.get("/settings/netbox") | ||
async def netbox_settings( | ||
proxbox_config: ProxboxConfigDep | ||
): | ||
""" | ||
Get user configuration for Netbox from PLUGINS_CONFIG | ||
""" | ||
return proxbox_config.netbox | ||
|
||
|
||
|
||
@router.get("/settings/proxmox") | ||
async def proxmox_settings( | ||
proxbox_config: ProxboxConfigDep | ||
): | ||
""" | ||
Get user configuration for Proxmox from PLUGINS_CONFIG | ||
""" | ||
return proxbox_config.proxmox | ||
|
||
|
||
NetboxConfigDep = Annotated[NetboxSessionSchema, Depends(netbox_settings)] | ||
ProxmoxConfigDep = Annotated[ProxmoxMultiClusterConfig, Depends(proxmox_settings)] | ||
|
Oops, something went wrong.