netbox-memory-input 0.1__tar.gz
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_memory_input-0.1/PKG-INFO +7 -0
- netbox_memory_input-0.1/README.md +33 -0
- netbox_memory_input-0.1/netbox_memory_input/__init__.py +17 -0
- netbox_memory_input-0.1/netbox_memory_input/forms.py +64 -0
- netbox_memory_input-0.1/netbox_memory_input.egg-info/PKG-INFO +7 -0
- netbox_memory_input-0.1/netbox_memory_input.egg-info/SOURCES.txt +9 -0
- netbox_memory_input-0.1/netbox_memory_input.egg-info/dependency_links.txt +1 -0
- netbox_memory_input-0.1/netbox_memory_input.egg-info/not-zip-safe +1 -0
- netbox_memory_input-0.1/netbox_memory_input.egg-info/top_level.txt +1 -0
- netbox_memory_input-0.1/setup.cfg +4 -0
- netbox_memory_input-0.1/setup.py +15 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
A NetBox plugin that modifies the Virtual Machine form to accept memory and disk sizes in GB instead of MB.
|
|
2
|
+
|
|
3
|
+
## Features
|
|
4
|
+
|
|
5
|
+
- Converts memory input fields from MB to GB
|
|
6
|
+
- Converts disk size input fields from MB to GB
|
|
7
|
+
- Supports decimal values (e.g., 0.5 GB)
|
|
8
|
+
- Automatic conversion between GB and MB
|
|
9
|
+
- Debug logging for troubleshooting
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install netbox-memory-input
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Configuration
|
|
18
|
+
|
|
19
|
+
Add the plugin to your NetBox configuration (`configuration.py`):
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
PLUGINS = [
|
|
23
|
+
'netbox_memory_input',
|
|
24
|
+
]
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
After installation and configuration, the Virtual Machine form will automatically display and accept memory and disk sizes in GB instead of MB.
|
|
30
|
+
|
|
31
|
+
## License
|
|
32
|
+
|
|
33
|
+
This project is licensed under the GNU Affero General Public License v3.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from netbox.plugins import PluginConfig
|
|
2
|
+
|
|
3
|
+
class NetboxMemoryInputConfig(PluginConfig):
|
|
4
|
+
name = 'netbox_memory_input'
|
|
5
|
+
verbose_name = 'NetBox Memory Input'
|
|
6
|
+
description = 'Input VM memory in GB instead of MB'
|
|
7
|
+
version = '0.1'
|
|
8
|
+
base_url = ''
|
|
9
|
+
required_settings = []
|
|
10
|
+
min_version = '2.10.0'
|
|
11
|
+
|
|
12
|
+
def ready(self):
|
|
13
|
+
from . import forms
|
|
14
|
+
import virtualization.forms
|
|
15
|
+
virtualization.forms.VirtualMachineForm = forms.MemoryGBVirtualMachineForm
|
|
16
|
+
config = NetboxMemoryInputConfig
|
|
17
|
+
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
from django import forms
|
|
2
|
+
from virtualization.forms import VirtualMachineForm
|
|
3
|
+
import logging
|
|
4
|
+
|
|
5
|
+
logger = logging.getLogger('netbox.netbox_memory_input')
|
|
6
|
+
logger.setLevel(logging.DEBUG)
|
|
7
|
+
|
|
8
|
+
# Add debug handler if not present
|
|
9
|
+
if not logger.handlers:
|
|
10
|
+
handler = logging.FileHandler('/var/log/netbox/memory_input_debug.log')
|
|
11
|
+
handler.setLevel(logging.DEBUG)
|
|
12
|
+
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
13
|
+
handler.setFormatter(formatter)
|
|
14
|
+
logger.addHandler(handler)
|
|
15
|
+
|
|
16
|
+
logger.debug("MemoryGBVirtualMachineForm module loaded")
|
|
17
|
+
|
|
18
|
+
class MemoryGBVirtualMachineForm(VirtualMachineForm):
|
|
19
|
+
# Override both memory and disk fields
|
|
20
|
+
memory = forms.FloatField(
|
|
21
|
+
required=False,
|
|
22
|
+
label='Memory (GB)',
|
|
23
|
+
min_value=0.1, # Allow sub-GB values
|
|
24
|
+
widget=forms.NumberInput(attrs={'placeholder': 'Enter memory in GB'})
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
disk = forms.FloatField(
|
|
28
|
+
required=False,
|
|
29
|
+
label='Disk (GB)',
|
|
30
|
+
min_value=0.1, # Allow sub-GB values
|
|
31
|
+
widget=forms.NumberInput(attrs={'placeholder': 'Enter disk size in GB'})
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
def __init__(self, *args, **kwargs):
|
|
35
|
+
logger.debug("MemoryGBVirtualMachineForm initialization started")
|
|
36
|
+
super().__init__(*args, **kwargs)
|
|
37
|
+
|
|
38
|
+
# Handle memory conversion
|
|
39
|
+
if self.instance and self.instance.memory:
|
|
40
|
+
gb_value = round(self.instance.memory / 1000, 2) # Round to 2 decimal places
|
|
41
|
+
logger.debug(f"Setting initial memory value: {self.instance.memory}MB -> {gb_value}GB")
|
|
42
|
+
self.initial['memory'] = gb_value
|
|
43
|
+
|
|
44
|
+
# Handle disk conversion
|
|
45
|
+
if self.instance and self.instance.disk:
|
|
46
|
+
gb_value = round(self.instance.disk / 1000, 2) # Round to 2 decimal places
|
|
47
|
+
logger.debug(f"Setting initial disk value: {self.instance.disk}MB -> {gb_value}GB")
|
|
48
|
+
self.initial['disk'] = gb_value
|
|
49
|
+
|
|
50
|
+
def clean_memory(self):
|
|
51
|
+
memory = self.cleaned_data.get('memory')
|
|
52
|
+
if memory is not None:
|
|
53
|
+
memory_mb = int(memory * 1000)
|
|
54
|
+
logger.debug(f"Converting memory {memory}GB to {memory_mb}MB")
|
|
55
|
+
return memory_mb
|
|
56
|
+
return None
|
|
57
|
+
|
|
58
|
+
def clean_disk(self):
|
|
59
|
+
disk = self.cleaned_data.get('disk')
|
|
60
|
+
if disk is not None:
|
|
61
|
+
disk_mb = int(disk * 1000)
|
|
62
|
+
logger.debug(f"Converting disk {disk}GB to {disk_mb}MB")
|
|
63
|
+
return disk_mb
|
|
64
|
+
return None
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.py
|
|
3
|
+
netbox_memory_input/__init__.py
|
|
4
|
+
netbox_memory_input/forms.py
|
|
5
|
+
netbox_memory_input.egg-info/PKG-INFO
|
|
6
|
+
netbox_memory_input.egg-info/SOURCES.txt
|
|
7
|
+
netbox_memory_input.egg-info/dependency_links.txt
|
|
8
|
+
netbox_memory_input.egg-info/not-zip-safe
|
|
9
|
+
netbox_memory_input.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
netbox_memory_input
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from setuptools import find_packages, setup
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name='netbox_memory_input',
|
|
5
|
+
version='0.1',
|
|
6
|
+
description='Input VM memory in GB instead of MB in NetBox.',
|
|
7
|
+
url='https://itandtel.at',
|
|
8
|
+
author='jannis',
|
|
9
|
+
license='AGPLv3',
|
|
10
|
+
install_requires=[],
|
|
11
|
+
packages=find_packages(),
|
|
12
|
+
include_package_data=True,
|
|
13
|
+
zip_safe=False,
|
|
14
|
+
)
|
|
15
|
+
|