netbox-memory-input 0.1__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.
@@ -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,8 @@
1
+ Metadata-Version: 2.1
2
+ Name: netbox_memory_input
3
+ Version: 0.1
4
+ Summary: Input VM memory in GB instead of MB in NetBox.
5
+ Home-page: https://itandtel.at
6
+ Author: jannis
7
+ License: AGPLv3
8
+
@@ -0,0 +1,6 @@
1
+ netbox_memory_input/__init__.py,sha256=qwsTIAvn8yJvTa3CFopYXJ-ekV2koBWn0zN_IaKngpo,515
2
+ netbox_memory_input/forms.py,sha256=puMmFjEpQwEEncI2UBZYfhmtBnyPBihaya13R4q7RCM,2445
3
+ netbox_memory_input-0.1.dist-info/METADATA,sha256=C5IQKBC0qKZE4zDqP1AZQESdHTpLd52Z1jt0ULoUS6s,180
4
+ netbox_memory_input-0.1.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
5
+ netbox_memory_input-0.1.dist-info/top_level.txt,sha256=uYtlPMHeWfXbS_2BAox6tlUn03jxODZaCrKBT8Lwo4U,20
6
+ netbox_memory_input-0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.1.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ netbox_memory_input