netbox-memory-input 0.2__tar.gz → 0.3__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.3/PKG-INFO +11 -0
- netbox_memory_input-0.3/netbox_memory_input/forms.py +84 -0
- netbox_memory_input-0.3/netbox_memory_input.egg-info/PKG-INFO +11 -0
- {netbox_memory_input-0.2 → netbox_memory_input-0.3}/setup.py +2 -2
- netbox_memory_input-0.2/PKG-INFO +0 -7
- netbox_memory_input-0.2/netbox_memory_input/forms.py +0 -57
- netbox_memory_input-0.2/netbox_memory_input.egg-info/PKG-INFO +0 -7
- {netbox_memory_input-0.2 → netbox_memory_input-0.3}/README.md +0 -0
- {netbox_memory_input-0.2 → netbox_memory_input-0.3}/netbox_memory_input/__init__.py +0 -0
- {netbox_memory_input-0.2 → netbox_memory_input-0.3}/netbox_memory_input.egg-info/SOURCES.txt +0 -0
- {netbox_memory_input-0.2 → netbox_memory_input-0.3}/netbox_memory_input.egg-info/dependency_links.txt +0 -0
- {netbox_memory_input-0.2 → netbox_memory_input-0.3}/netbox_memory_input.egg-info/not-zip-safe +0 -0
- {netbox_memory_input-0.2 → netbox_memory_input-0.3}/netbox_memory_input.egg-info/top_level.txt +0 -0
- {netbox_memory_input-0.2 → netbox_memory_input-0.3}/setup.cfg +0 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: netbox_memory_input
|
|
3
|
+
Version: 0.3
|
|
4
|
+
Summary: Input VM memory in GB instead of MB in NetBox.
|
|
5
|
+
Home-page: https://eww.at
|
|
6
|
+
Author: jannis
|
|
7
|
+
License: AGPLv3
|
|
8
|
+
Dynamic: author
|
|
9
|
+
Dynamic: home-page
|
|
10
|
+
Dynamic: license
|
|
11
|
+
Dynamic: summary
|
|
@@ -0,0 +1,84 @@
|
|
|
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. The value may come from a saved instance
|
|
39
|
+
# (edit) or from initial data supplied via the URL query string (clone),
|
|
40
|
+
# in which case self.instance is a new, unsaved object.
|
|
41
|
+
memory_mb = self._get_initial_mb('memory')
|
|
42
|
+
if memory_mb:
|
|
43
|
+
gb_value = round(memory_mb / 1000, 2) # Round to 2 decimal places
|
|
44
|
+
logger.debug(f"Setting initial memory value: {memory_mb}MB -> {gb_value}GB")
|
|
45
|
+
self.initial['memory'] = gb_value
|
|
46
|
+
|
|
47
|
+
# Handle disk conversion
|
|
48
|
+
disk_mb = self._get_initial_mb('disk')
|
|
49
|
+
if disk_mb:
|
|
50
|
+
gb_value = round(disk_mb / 1000, 2) # Round to 2 decimal places
|
|
51
|
+
logger.debug(f"Setting initial disk value: {disk_mb}MB -> {gb_value}GB")
|
|
52
|
+
self.initial['disk'] = gb_value
|
|
53
|
+
|
|
54
|
+
def _get_initial_mb(self, field):
|
|
55
|
+
"""Return the source value in MB from the instance (edit) or the initial
|
|
56
|
+
clone data, or None if there is nothing to convert."""
|
|
57
|
+
instance_value = getattr(self.instance, field, None)
|
|
58
|
+
if instance_value:
|
|
59
|
+
return instance_value
|
|
60
|
+
# Clone: value arrives as a string in initial data from the query string.
|
|
61
|
+
initial_value = self.initial.get(field)
|
|
62
|
+
if initial_value in (None, ''):
|
|
63
|
+
return None
|
|
64
|
+
try:
|
|
65
|
+
return float(initial_value)
|
|
66
|
+
except (TypeError, ValueError):
|
|
67
|
+
logger.debug(f"Could not parse initial {field} value: {initial_value!r}")
|
|
68
|
+
return None
|
|
69
|
+
|
|
70
|
+
def clean_memory(self):
|
|
71
|
+
memory = self.cleaned_data.get('memory')
|
|
72
|
+
if memory is not None:
|
|
73
|
+
memory_mb = int(memory * 1000)
|
|
74
|
+
logger.debug(f"Converting memory {memory}GB to {memory_mb}MB")
|
|
75
|
+
return memory_mb
|
|
76
|
+
return None
|
|
77
|
+
|
|
78
|
+
def clean_disk(self):
|
|
79
|
+
disk = self.cleaned_data.get('disk')
|
|
80
|
+
if disk is not None:
|
|
81
|
+
disk_mb = int(disk * 1000)
|
|
82
|
+
logger.debug(f"Converting disk {disk}GB to {disk_mb}MB")
|
|
83
|
+
return disk_mb
|
|
84
|
+
return None
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: netbox_memory_input
|
|
3
|
+
Version: 0.3
|
|
4
|
+
Summary: Input VM memory in GB instead of MB in NetBox.
|
|
5
|
+
Home-page: https://eww.at
|
|
6
|
+
Author: jannis
|
|
7
|
+
License: AGPLv3
|
|
8
|
+
Dynamic: author
|
|
9
|
+
Dynamic: home-page
|
|
10
|
+
Dynamic: license
|
|
11
|
+
Dynamic: summary
|
|
@@ -2,9 +2,9 @@ from setuptools import find_packages, setup
|
|
|
2
2
|
|
|
3
3
|
setup(
|
|
4
4
|
name='netbox_memory_input',
|
|
5
|
-
version='0.
|
|
5
|
+
version='0.3',
|
|
6
6
|
description='Input VM memory in GB instead of MB in NetBox.',
|
|
7
|
-
url='https://
|
|
7
|
+
url='https://eww.at',
|
|
8
8
|
author='jannis',
|
|
9
9
|
license='AGPLv3',
|
|
10
10
|
install_requires=[],
|
netbox_memory_input-0.2/PKG-INFO
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
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
|
-
|
|
9
|
-
logger.debug("MemoryGBVirtualMachineForm module loaded")
|
|
10
|
-
|
|
11
|
-
class MemoryGBVirtualMachineForm(VirtualMachineForm):
|
|
12
|
-
# Override both memory and disk fields
|
|
13
|
-
memory = forms.FloatField(
|
|
14
|
-
required=False,
|
|
15
|
-
label='Memory (GB)',
|
|
16
|
-
min_value=0.1, # Allow sub-GB values
|
|
17
|
-
widget=forms.NumberInput(attrs={'placeholder': 'Enter memory in GB'})
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
disk = forms.FloatField(
|
|
21
|
-
required=False,
|
|
22
|
-
label='Disk (GB)',
|
|
23
|
-
min_value=0.1, # Allow sub-GB values
|
|
24
|
-
widget=forms.NumberInput(attrs={'placeholder': 'Enter disk size in GB'})
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
def __init__(self, *args, **kwargs):
|
|
28
|
-
logger.debug("MemoryGBVirtualMachineForm initialization started")
|
|
29
|
-
super().__init__(*args, **kwargs)
|
|
30
|
-
|
|
31
|
-
# Handle memory conversion
|
|
32
|
-
if self.instance and self.instance.memory:
|
|
33
|
-
gb_value = round(self.instance.memory / 1000, 2) # Round to 2 decimal places
|
|
34
|
-
logger.debug(f"Setting initial memory value: {self.instance.memory}MB -> {gb_value}GB")
|
|
35
|
-
self.initial['memory'] = gb_value
|
|
36
|
-
|
|
37
|
-
# Handle disk conversion
|
|
38
|
-
if self.instance and self.instance.disk:
|
|
39
|
-
gb_value = round(self.instance.disk / 1000, 2) # Round to 2 decimal places
|
|
40
|
-
logger.debug(f"Setting initial disk value: {self.instance.disk}MB -> {gb_value}GB")
|
|
41
|
-
self.initial['disk'] = gb_value
|
|
42
|
-
|
|
43
|
-
def clean_memory(self):
|
|
44
|
-
memory = self.cleaned_data.get('memory')
|
|
45
|
-
if memory is not None:
|
|
46
|
-
memory_mb = int(memory * 1000)
|
|
47
|
-
logger.debug(f"Converting memory {memory}GB to {memory_mb}MB")
|
|
48
|
-
return memory_mb
|
|
49
|
-
return None
|
|
50
|
-
|
|
51
|
-
def clean_disk(self):
|
|
52
|
-
disk = self.cleaned_data.get('disk')
|
|
53
|
-
if disk is not None:
|
|
54
|
-
disk_mb = int(disk * 1000)
|
|
55
|
-
logger.debug(f"Converting disk {disk}GB to {disk_mb}MB")
|
|
56
|
-
return disk_mb
|
|
57
|
-
return None
|
|
File without changes
|
|
File without changes
|
{netbox_memory_input-0.2 → netbox_memory_input-0.3}/netbox_memory_input.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{netbox_memory_input-0.2 → netbox_memory_input-0.3}/netbox_memory_input.egg-info/not-zip-safe
RENAMED
|
File without changes
|
{netbox_memory_input-0.2 → netbox_memory_input-0.3}/netbox_memory_input.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|