mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-21 11:37:21 -06:00
#1493: Extended DeviceRole to include a toggle indicating applicability to virtual machines
This commit is contained in:
parent
0deae84ecb
commit
a6599874db
@ -404,7 +404,7 @@ class DeviceRoleSerializer(ValidatedModelSerializer):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = DeviceRole
|
model = DeviceRole
|
||||||
fields = ['id', 'name', 'slug', 'color']
|
fields = ['id', 'name', 'slug', 'color', 'vm_role']
|
||||||
|
|
||||||
|
|
||||||
class NestedDeviceRoleSerializer(serializers.ModelSerializer):
|
class NestedDeviceRoleSerializer(serializers.ModelSerializer):
|
||||||
|
@ -531,7 +531,7 @@ class DeviceRoleForm(BootstrapMixin, forms.ModelForm):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = DeviceRole
|
model = DeviceRole
|
||||||
fields = ['name', 'slug', 'color']
|
fields = ['name', 'slug', 'color', 'vm_role']
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
20
netbox/dcim/migrations/0045_devicerole_vm_role.py
Normal file
20
netbox/dcim/migrations/0045_devicerole_vm_role.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.4 on 2017-09-29 16:09
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('dcim', '0044_virtualization'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='devicerole',
|
||||||
|
name='vm_role',
|
||||||
|
field=models.BooleanField(default=True, help_text='Virtual machines may be assigned to this role', verbose_name='VM Role'),
|
||||||
|
),
|
||||||
|
]
|
@ -743,11 +743,17 @@ class DeviceBayTemplate(models.Model):
|
|||||||
class DeviceRole(models.Model):
|
class DeviceRole(models.Model):
|
||||||
"""
|
"""
|
||||||
Devices are organized by functional role; for example, "Core Switch" or "File Server". Each DeviceRole is assigned a
|
Devices are organized by functional role; for example, "Core Switch" or "File Server". Each DeviceRole is assigned a
|
||||||
color to be used when displaying rack elevations.
|
color to be used when displaying rack elevations. The vm_role field determines whether the role is applicable to
|
||||||
|
virtual machines as well.
|
||||||
"""
|
"""
|
||||||
name = models.CharField(max_length=50, unique=True)
|
name = models.CharField(max_length=50, unique=True)
|
||||||
slug = models.SlugField(unique=True)
|
slug = models.SlugField(unique=True)
|
||||||
color = ColorField()
|
color = ColorField()
|
||||||
|
vm_role = models.BooleanField(
|
||||||
|
default=True,
|
||||||
|
verbose_name="VM Role",
|
||||||
|
help_text="Virtual machines may be assigned to this role"
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['name']
|
ordering = ['name']
|
||||||
|
@ -369,7 +369,7 @@ class DeviceRoleTable(BaseTable):
|
|||||||
|
|
||||||
class Meta(BaseTable.Meta):
|
class Meta(BaseTable.Meta):
|
||||||
model = DeviceRole
|
model = DeviceRole
|
||||||
fields = ('pk', 'name', 'device_count', 'color', 'slug', 'actions')
|
fields = ('pk', 'name', 'device_count', 'color', 'vm_role', 'slug', 'actions')
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -253,7 +253,7 @@ class VirtualMachineCSVForm(forms.ModelForm):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
role = forms.ModelChoiceField(
|
role = forms.ModelChoiceField(
|
||||||
queryset=DeviceRole.objects.all(),
|
queryset=DeviceRole.objects.filter(vm_role=True),
|
||||||
required=False,
|
required=False,
|
||||||
to_field_name='name',
|
to_field_name='name',
|
||||||
help_text='Name of functional role',
|
help_text='Name of functional role',
|
||||||
@ -289,7 +289,7 @@ class VirtualMachineBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm):
|
|||||||
pk = forms.ModelMultipleChoiceField(queryset=VirtualMachine.objects.all(), widget=forms.MultipleHiddenInput)
|
pk = forms.ModelMultipleChoiceField(queryset=VirtualMachine.objects.all(), widget=forms.MultipleHiddenInput)
|
||||||
status = forms.ChoiceField(choices=add_blank_choice(STATUS_CHOICES), required=False, initial='')
|
status = forms.ChoiceField(choices=add_blank_choice(STATUS_CHOICES), required=False, initial='')
|
||||||
cluster = forms.ModelChoiceField(queryset=Cluster.objects.all(), required=False)
|
cluster = forms.ModelChoiceField(queryset=Cluster.objects.all(), required=False)
|
||||||
role = forms.ModelChoiceField(queryset=DeviceRole.objects.all(), required=False)
|
role = forms.ModelChoiceField(queryset=DeviceRole.objects.filter(vm_role=True), required=False)
|
||||||
tenant = forms.ModelChoiceField(queryset=Tenant.objects.all(), required=False)
|
tenant = forms.ModelChoiceField(queryset=Tenant.objects.all(), required=False)
|
||||||
platform = forms.ModelChoiceField(queryset=Platform.objects.all(), required=False)
|
platform = forms.ModelChoiceField(queryset=Platform.objects.all(), required=False)
|
||||||
vcpus = forms.IntegerField(required=False, label='vCPUs')
|
vcpus = forms.IntegerField(required=False, label='vCPUs')
|
||||||
@ -321,7 +321,7 @@ class VirtualMachineFilterForm(BootstrapMixin, CustomFieldFilterForm):
|
|||||||
label='Cluster'
|
label='Cluster'
|
||||||
)
|
)
|
||||||
role = FilterChoiceField(
|
role = FilterChoiceField(
|
||||||
queryset=DeviceRole.objects.annotate(filter_count=Count('virtual_machines')),
|
queryset=DeviceRole.objects.filter(vm_role=True).annotate(filter_count=Count('virtual_machines')),
|
||||||
to_field_name='slug',
|
to_field_name='slug',
|
||||||
null_option=(0, 'None')
|
null_option=(0, 'None')
|
||||||
)
|
)
|
||||||
|
@ -181,6 +181,7 @@ class VirtualMachine(CreatedUpdatedModel, CustomFieldModel):
|
|||||||
)
|
)
|
||||||
role = models.ForeignKey(
|
role = models.ForeignKey(
|
||||||
to='dcim.DeviceRole',
|
to='dcim.DeviceRole',
|
||||||
|
limit_choices_to={'vm_role': True},
|
||||||
on_delete=models.PROTECT,
|
on_delete=models.PROTECT,
|
||||||
related_name='virtual_machines',
|
related_name='virtual_machines',
|
||||||
blank=True,
|
blank=True,
|
||||||
|
Loading…
Reference in New Issue
Block a user