Fixed further requirements.
This commit is contained in:
parent
0b5214d247
commit
821d6c8672
@ -1,8 +1,8 @@
|
|||||||
#- device: server01
|
#- device: server01
|
||||||
# enabled: true
|
# enabled: true
|
||||||
# form_factor: 0
|
# form_factor: Virtual
|
||||||
# name: to-server02
|
# name: to-server02
|
||||||
#- device: server02
|
#- device: server02
|
||||||
# enabled: true
|
# enabled: true
|
||||||
# form_factor: 0
|
# form_factor: Virtual
|
||||||
# name: to-server01
|
# name: to-server01
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
#- address: 10.1.1.1/24
|
#- address: 10.1.1.1/24
|
||||||
# device: server01
|
# device: server01
|
||||||
# interface: Loopback0
|
# interface: Loopback0
|
||||||
# status: 1
|
# status: Active
|
||||||
# vrf: vrf1
|
# vrf: vrf1
|
||||||
#- address: 10.1.1.2/24
|
#- address: 10.1.1.2/24
|
||||||
# device: server02
|
# device: server02
|
||||||
# interface: Vlan5
|
# interface: Vlan5
|
||||||
# status: 1
|
# status: Active
|
||||||
#- address: 10.1.1.10/24
|
#- address: 10.1.1.10/24
|
||||||
# description: reserved IP
|
# description: reserved IP
|
||||||
# status: 2
|
# status: Reserved
|
||||||
# tenant: tenant1
|
# tenant: tenant1
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
#- description: prefix1
|
#- description: prefix1
|
||||||
# prefix: 10.1.1.0/24
|
# prefix: 10.1.1.0/24
|
||||||
# site: AMS 1
|
# site: AMS 1
|
||||||
# status: 1
|
# status: Active
|
||||||
# tenant: tenant1
|
# tenant: tenant1
|
||||||
# vlan: vlan1
|
# vlan: vlan1
|
||||||
#- description: prefix2
|
#- description: prefix2
|
||||||
# prefix: 10.1.2.0/24
|
# prefix: 10.1.2.0/24
|
||||||
# site: AMS 2
|
# site: AMS 2
|
||||||
# status: 1
|
# status: Active
|
||||||
# tenant: tenant2
|
# tenant: tenant2
|
||||||
# vlan: vlan2
|
# vlan: vlan2
|
||||||
# is_pool: true
|
# is_pool: true
|
||||||
@ -16,6 +16,6 @@
|
|||||||
#- description: ipv6 prefix1
|
#- description: ipv6 prefix1
|
||||||
# prefix: fd00:ccdd:a000:1::/64
|
# prefix: fd00:ccdd:a000:1::/64
|
||||||
# site: AMS 2
|
# site: AMS 2
|
||||||
# status: 1
|
# status: Active
|
||||||
# tenant: tenant2
|
# tenant: tenant2
|
||||||
# vlan: vlan2
|
# vlan: vlan2
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
# memory: 4096
|
# memory: 4096
|
||||||
# name: virtual machine 1
|
# name: virtual machine 1
|
||||||
# platform: Platform 2
|
# platform: Platform 2
|
||||||
# status: 1
|
# status: Active
|
||||||
# tenant: tenant1
|
# tenant: tenant1
|
||||||
# vcpus: 8
|
# vcpus: 8
|
||||||
#- cluster: cluster1
|
#- cluster: cluster1
|
||||||
@ -13,6 +13,6 @@
|
|||||||
# memory: 2048
|
# memory: 2048
|
||||||
# name: virtual machine 2
|
# name: virtual machine 2
|
||||||
# platform: Platform 2
|
# platform: Platform 2
|
||||||
# status: 1
|
# status: Active
|
||||||
# tenant: tenant1
|
# tenant: tenant1
|
||||||
# vcpus: 8
|
# vcpus: 8
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
#- name: vlan1
|
#- name: vlan1
|
||||||
# site: AMS 1
|
# site: AMS 1
|
||||||
# status: 1
|
# status: Active
|
||||||
# vid: 5
|
# vid: 5
|
||||||
# role: Main Management
|
# role: Main Management
|
||||||
# description: VLAN 5 for MGMT
|
# description: VLAN 5 for MGMT
|
||||||
#- group: VLAN group 2
|
#- group: VLAN group 2
|
||||||
# name: vlan2
|
# name: vlan2
|
||||||
# site: AMS 1
|
# site: AMS 1
|
||||||
# status: 1
|
# status: Active
|
||||||
# vid: 1300
|
# vid: 1300
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from dcim.models import Site
|
from dcim.models import Site
|
||||||
from ipam.models import VLAN, VLANGroup, Role
|
from ipam.models import VLAN, VLANGroup, Role
|
||||||
|
from ipam.constants import VLAN_STATUS_CHOICES
|
||||||
from tenancy.models import Tenant, TenantGroup
|
from tenancy.models import Tenant, TenantGroup
|
||||||
from extras.models import CustomField, CustomFieldValue
|
from extras.models import CustomField, CustomFieldValue
|
||||||
from ruamel.yaml import YAML
|
from ruamel.yaml import YAML
|
||||||
@ -34,6 +35,11 @@ with file.open('r') as stream:
|
|||||||
|
|
||||||
params[assoc] = model.objects.get(**query)
|
params[assoc] = model.objects.get(**query)
|
||||||
|
|
||||||
|
if 'status' in params:
|
||||||
|
for vlan_status in VLAN_STATUS_CHOICES:
|
||||||
|
if params['status'] in vlan_status:
|
||||||
|
params['status'] = vlan_status[0]
|
||||||
|
|
||||||
vlan, created = VLAN.objects.get_or_create(**params)
|
vlan, created = VLAN.objects.get_or_create(**params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from dcim.models import Site
|
from dcim.models import Site
|
||||||
from ipam.models import Prefix, VLAN, Role, VRF
|
from ipam.models import Prefix, VLAN, Role, VRF
|
||||||
|
from ipam.constants import PREFIX_STATUS_CHOICES
|
||||||
from tenancy.models import Tenant, TenantGroup
|
from tenancy.models import Tenant, TenantGroup
|
||||||
from extras.models import CustomField, CustomFieldValue
|
from extras.models import CustomField, CustomFieldValue
|
||||||
from ruamel.yaml import YAML
|
from ruamel.yaml import YAML
|
||||||
@ -37,6 +38,11 @@ with file.open('r') as stream:
|
|||||||
|
|
||||||
params[assoc] = model.objects.get(**query)
|
params[assoc] = model.objects.get(**query)
|
||||||
|
|
||||||
|
if 'status' in params:
|
||||||
|
for prefix_status in PREFIX_STATUS_CHOICES:
|
||||||
|
if params['status'] in prefix_status:
|
||||||
|
params['status'] = prefix_status[0]
|
||||||
|
|
||||||
prefix, created = Prefix.objects.get_or_create(**params)
|
prefix, created = Prefix.objects.get_or_create(**params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from dcim.models import Site, Platform, DeviceRole
|
from dcim.models import Site, Platform, DeviceRole
|
||||||
from virtualization.models import Cluster, VirtualMachine
|
from virtualization.models import Cluster, VirtualMachine
|
||||||
|
from virtualization.constants import VM_STATUS_CHOICES
|
||||||
from tenancy.models import Tenant
|
from tenancy.models import Tenant
|
||||||
from extras.models import CustomField, CustomFieldValue
|
from extras.models import CustomField, CustomFieldValue
|
||||||
from ruamel.yaml import YAML
|
from ruamel.yaml import YAML
|
||||||
@ -42,6 +43,11 @@ with file.open('r') as stream:
|
|||||||
|
|
||||||
params[assoc] = model.objects.get(**query)
|
params[assoc] = model.objects.get(**query)
|
||||||
|
|
||||||
|
if 'status' in params:
|
||||||
|
for vm_status in VM_STATUS_CHOICES:
|
||||||
|
if params['status'] in vm_status:
|
||||||
|
params['status'] = vm_status[0]
|
||||||
|
|
||||||
virtual_machine, created = VirtualMachine.objects.get_or_create(**params)
|
virtual_machine, created = VirtualMachine.objects.get_or_create(**params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
|
@ -14,7 +14,7 @@ with file.open('r') as stream:
|
|||||||
yaml = YAML(typ='safe')
|
yaml = YAML(typ='safe')
|
||||||
interfaces = yaml.load(stream)
|
interfaces = yaml.load(stream)
|
||||||
|
|
||||||
optional_assocs = {
|
required_assocs = {
|
||||||
'virtual_machine': (VirtualMachine, 'name')
|
'virtual_machine': (VirtualMachine, 'name')
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,8 +22,7 @@ with file.open('r') as stream:
|
|||||||
for params in interfaces:
|
for params in interfaces:
|
||||||
custom_fields = params.pop('custom_fields', None)
|
custom_fields = params.pop('custom_fields', None)
|
||||||
|
|
||||||
for assoc, details in optional_assocs.items():
|
for assoc, details in required_assocs.items():
|
||||||
if assoc in params:
|
|
||||||
model, field = details
|
model, field = details
|
||||||
query = { field: params.pop(assoc) }
|
query = { field: params.pop(assoc) }
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from dcim.models import Interface, Device
|
from dcim.models import Interface, Device
|
||||||
|
from dcim.constants import IFACE_TYPE_CHOICES
|
||||||
from extras.models import CustomField, CustomFieldValue
|
from extras.models import CustomField, CustomFieldValue
|
||||||
from ruamel.yaml import YAML
|
from ruamel.yaml import YAML
|
||||||
|
|
||||||
@ -13,7 +14,7 @@ with file.open('r') as stream:
|
|||||||
yaml = YAML(typ='safe')
|
yaml = YAML(typ='safe')
|
||||||
interfaces = yaml.load(stream)
|
interfaces = yaml.load(stream)
|
||||||
|
|
||||||
optional_assocs = {
|
required_assocs = {
|
||||||
'device': (Device, 'name')
|
'device': (Device, 'name')
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,13 +22,22 @@ with file.open('r') as stream:
|
|||||||
for params in interfaces:
|
for params in interfaces:
|
||||||
custom_fields = params.pop('custom_fields', None)
|
custom_fields = params.pop('custom_fields', None)
|
||||||
|
|
||||||
for assoc, details in optional_assocs.items():
|
for assoc, details in required_assocs.items():
|
||||||
if assoc in params:
|
|
||||||
model, field = details
|
model, field = details
|
||||||
query = { field: params.pop(assoc) }
|
query = { field: params.pop(assoc) }
|
||||||
|
|
||||||
params[assoc] = model.objects.get(**query)
|
params[assoc] = model.objects.get(**query)
|
||||||
|
|
||||||
|
if 'form_factor' in params:
|
||||||
|
for outer_list in IFACE_TYPE_CHOICES:
|
||||||
|
for ffactor_choices in outer_list[1]:
|
||||||
|
if params['form_factor'] in ffactor_choices:
|
||||||
|
params['form_factor'] = ffactor_choices[0]
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
break
|
||||||
|
|
||||||
interface, created = Interface.objects.get_or_create(**params)
|
interface, created = Interface.objects.get_or_create(**params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
@ -43,4 +53,3 @@ with file.open('r') as stream:
|
|||||||
interface.custom_field_values.add(custom_field_value)
|
interface.custom_field_values.add(custom_field_value)
|
||||||
|
|
||||||
print("🧷 Created interface", interface.name, interface.device.name)
|
print("🧷 Created interface", interface.name, interface.device.name)
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from ipam.models import IPAddress, VRF
|
from ipam.models import IPAddress, VRF
|
||||||
|
from ipam.constants import IPADDRESS_STATUS_CHOICES
|
||||||
from dcim.models import Device, Interface
|
from dcim.models import Device, Interface
|
||||||
from virtualization.models import VirtualMachine
|
from virtualization.models import VirtualMachine
|
||||||
from tenancy.models import Tenant
|
from tenancy.models import Tenant
|
||||||
@ -30,6 +31,10 @@ with file.open('r') as stream:
|
|||||||
custom_fields = params.pop('custom_fields', None)
|
custom_fields = params.pop('custom_fields', None)
|
||||||
params['address'] = IPNetwork(params['address'])
|
params['address'] = IPNetwork(params['address'])
|
||||||
|
|
||||||
|
if vm and device:
|
||||||
|
print("IP Address can only specify one of the following: virtual_machine or device.")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
for assoc, details in optional_assocs.items():
|
for assoc, details in optional_assocs.items():
|
||||||
if assoc in params:
|
if assoc in params:
|
||||||
model, field = details
|
model, field = details
|
||||||
@ -44,6 +49,11 @@ with file.open('r') as stream:
|
|||||||
query = { field: params.pop(assoc) }
|
query = { field: params.pop(assoc) }
|
||||||
params[assoc] = model.objects.get(**query)
|
params[assoc] = model.objects.get(**query)
|
||||||
|
|
||||||
|
if 'status' in params:
|
||||||
|
for ip_status in IPADDRESS_STATUS_CHOICES:
|
||||||
|
if params['status'] in ip_status:
|
||||||
|
params['status'] = ip_status[0]
|
||||||
|
|
||||||
ip_address, created = IPAddress.objects.get_or_create(**params)
|
ip_address, created = IPAddress.objects.get_or_create(**params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
|
Loading…
Reference in New Issue
Block a user