From 4cb5b9f20da270e84d9748b9576200a92d844e6b Mon Sep 17 00:00:00 2001 From: Alvaro Arriola Date: Thu, 4 Jul 2019 14:10:56 +0200 Subject: [PATCH 1/8] Added more startup_scripts and initializers examples. --- initializers/aggregates.yml | 2 + initializers/cluster_types.yml | 2 + initializers/clusters.yml | 2 + initializers/dcim_interfaces.yml | 12 ++++ initializers/ip_addresses.yml | 18 ++++++ initializers/prefixes.yml | 12 ++++ initializers/rirs.yml | 3 + initializers/tenants.yml | 4 ++ initializers/virtual_machines.yml | 9 +++ initializers/virtualization_interfaces.yml | 14 +++++ initializers/vlan_groups.yml | 6 ++ initializers/vlans.yml | 9 +++ initializers/vrfs.yml | 5 ++ startup_scripts/104_tenant_groups.py | 19 ++++++ startup_scripts/105_tenants.py | 45 ++++++++++++++ startup_scripts/120_cluster_types.py | 19 ++++++ startup_scripts/125_rirs.py | 19 ++++++ startup_scripts/130_aggregates.py | 47 ++++++++++++++ startup_scripts/150_clusters.py | 57 +++++++++++++++++ startup_scripts/155_vrfs.py | 47 ++++++++++++++ startup_scripts/160_prefix_vlan_roles.py | 19 ++++++ startup_scripts/170_vlan_groups.py | 46 ++++++++++++++ startup_scripts/180_vlans.py | 50 +++++++++++++++ startup_scripts/190_prefixes.py | 53 ++++++++++++++++ startup_scripts/200_virtual_machines.py | 59 ++++++++++++++++++ .../210_virtualization_interfaces.py | 47 ++++++++++++++ startup_scripts/215_dcim_interfaces.py | 46 ++++++++++++++ startup_scripts/220_ip_addresses.py | 61 +++++++++++++++++++ 28 files changed, 732 insertions(+) create mode 100644 initializers/aggregates.yml create mode 100644 initializers/cluster_types.yml create mode 100644 initializers/clusters.yml create mode 100644 initializers/dcim_interfaces.yml create mode 100644 initializers/ip_addresses.yml create mode 100644 initializers/prefixes.yml create mode 100644 initializers/rirs.yml create mode 100644 initializers/tenants.yml create mode 100644 initializers/virtual_machines.yml create mode 100644 initializers/virtualization_interfaces.yml create mode 100644 initializers/vlan_groups.yml create mode 100644 initializers/vlans.yml create mode 100644 initializers/vrfs.yml create mode 100644 startup_scripts/104_tenant_groups.py create mode 100644 startup_scripts/105_tenants.py create mode 100644 startup_scripts/120_cluster_types.py create mode 100644 startup_scripts/125_rirs.py create mode 100644 startup_scripts/130_aggregates.py create mode 100644 startup_scripts/150_clusters.py create mode 100644 startup_scripts/155_vrfs.py create mode 100644 startup_scripts/160_prefix_vlan_roles.py create mode 100644 startup_scripts/170_vlan_groups.py create mode 100644 startup_scripts/180_vlans.py create mode 100644 startup_scripts/190_prefixes.py create mode 100644 startup_scripts/200_virtual_machines.py create mode 100644 startup_scripts/210_virtualization_interfaces.py create mode 100644 startup_scripts/215_dcim_interfaces.py create mode 100644 startup_scripts/220_ip_addresses.py diff --git a/initializers/aggregates.yml b/initializers/aggregates.yml new file mode 100644 index 0000000..8e73070 --- /dev/null +++ b/initializers/aggregates.yml @@ -0,0 +1,2 @@ +#- prefix: 10.0.0.0/16 +# rir: RFC1918 diff --git a/initializers/cluster_types.yml b/initializers/cluster_types.yml new file mode 100644 index 0000000..03365ae --- /dev/null +++ b/initializers/cluster_types.yml @@ -0,0 +1,2 @@ +#- name: Hyper-V +# slug: hyper-v diff --git a/initializers/clusters.yml b/initializers/clusters.yml new file mode 100644 index 0000000..6eff3d0 --- /dev/null +++ b/initializers/clusters.yml @@ -0,0 +1,2 @@ +#- name: cluster1 +# type: Hyper-V diff --git a/initializers/dcim_interfaces.yml b/initializers/dcim_interfaces.yml new file mode 100644 index 0000000..12ddbad --- /dev/null +++ b/initializers/dcim_interfaces.yml @@ -0,0 +1,12 @@ +#- device: router1 +# enabled: true +# form_factor: 0 +# name: router2 +#- device: 9901-2.bwi-stf.lab +# enabled: true +# form_factor: 0 +# name: Loopback0 +#- device: switch1 +# enabled: true +# form_factor: 0 +# name: Vlan5 diff --git a/initializers/ip_addresses.yml b/initializers/ip_addresses.yml new file mode 100644 index 0000000..445dd9c --- /dev/null +++ b/initializers/ip_addresses.yml @@ -0,0 +1,18 @@ + +#- address: 10.1.1.1/24 +# device: router1 +# family: 4 +# interface: Loopback0 +# status: 1 +# vrf: vrf1 +#- address: 10.1.1.2/24 +# device: switch1 +# family: 4 +# interface: Vlan5 +# status: 1 +#- address: 10.1.1.10/24 +# description: reserved IP +# family: 4 +# status: 2 +# tenant: tenant1 + diff --git a/initializers/prefixes.yml b/initializers/prefixes.yml new file mode 100644 index 0000000..2aeb74f --- /dev/null +++ b/initializers/prefixes.yml @@ -0,0 +1,12 @@ +#- description: prefix1 +# prefix: 10.1.1.0/24 +# site: AMS 1 +# status: 1 +# tenant: tenant1 +# vlan: vlan1 +#- description: prefix2 +# prefix: 10.1.2.0/24 +# site: AMS 2 +# status: 1 +# tenant: tenant2 +# vlan: vlan2 \ No newline at end of file diff --git a/initializers/rirs.yml b/initializers/rirs.yml new file mode 100644 index 0000000..f819c40 --- /dev/null +++ b/initializers/rirs.yml @@ -0,0 +1,3 @@ +#- is_private: true +# name: RFC1918 +# slug: rfc1918 diff --git a/initializers/tenants.yml b/initializers/tenants.yml new file mode 100644 index 0000000..2af9953 --- /dev/null +++ b/initializers/tenants.yml @@ -0,0 +1,4 @@ +#- name: tenant1 +# slug: tenant1 +#- name: tenant2 +# slug: tenant2 diff --git a/initializers/virtual_machines.yml b/initializers/virtual_machines.yml new file mode 100644 index 0000000..23536bc --- /dev/null +++ b/initializers/virtual_machines.yml @@ -0,0 +1,9 @@ +#- cluster: cluster1 +# comments: VM1 +# disk: 200 +# memory: 4096 +# name: virtual machine 1 +# platform: Platform 2 +# status: 1 +# tenant: tenant1 +# vcpus: 8 \ No newline at end of file diff --git a/initializers/virtualization_interfaces.yml b/initializers/virtualization_interfaces.yml new file mode 100644 index 0000000..000613f --- /dev/null +++ b/initializers/virtualization_interfaces.yml @@ -0,0 +1,14 @@ +#- description: Network Interface 1 +# enabled: true +# form_factor: 0 +# mac_address: 00:77:77:77:77:77 +# mtu: 1500 +# name: Network Interface 1 +# virtual_machine: virtual_machine1 +#- description: Network Interface 2 +# enabled: true +# form_factor: 0 +# mac_address: 00:55:55:55:55:55 +# mtu: 1500 +# name: Network Interface 2 +# virtual_machine: virtual_machine1 \ No newline at end of file diff --git a/initializers/vlan_groups.yml b/initializers/vlan_groups.yml new file mode 100644 index 0000000..11a48fc --- /dev/null +++ b/initializers/vlan_groups.yml @@ -0,0 +1,6 @@ +#- name: VLAN group 1 +# site: AMS 1 +# slug: vlan-group-2 +#- name: VLAN group 2 +# site: AMS 1 +# slug: vlan-group-2 diff --git a/initializers/vlans.yml b/initializers/vlans.yml new file mode 100644 index 0000000..8591192 --- /dev/null +++ b/initializers/vlans.yml @@ -0,0 +1,9 @@ +#- name: vlan1 +# site: AMS 1 +# status: 1 +# vid: 5 +#- group: VLAN group 2 +# name: vlan2 +# site: AMS 1 +# status: 1 +# vid: 1300 \ No newline at end of file diff --git a/initializers/vrfs.yml b/initializers/vrfs.yml new file mode 100644 index 0000000..7d9ba85 --- /dev/null +++ b/initializers/vrfs.yml @@ -0,0 +1,5 @@ +#- enforce_unique: true +# name: vrf1 +# tenant: tenant1 +#- enforce_unique: true +# name: vrf2 diff --git a/startup_scripts/104_tenant_groups.py b/startup_scripts/104_tenant_groups.py new file mode 100644 index 0000000..94c58ad --- /dev/null +++ b/startup_scripts/104_tenant_groups.py @@ -0,0 +1,19 @@ +from tenancy.models import TenantGroup +from ruamel.yaml import YAML +from pathlib import Path +import sys + +file = Path('/opt/netbox/initializers/tenant_groups.yml') +if not file.is_file(): + sys.exit() + +with file.open('r') as stream: + yaml = YAML(typ='safe') + tenant_groups = yaml.load(stream) + + if tenant_groups is not None: + for params in tenant_groups: + tenant_group, created = TenantGroup.objects.get_or_create(**params) + + if created: + print("Created Tenant Group", tenant_group.name) diff --git a/startup_scripts/105_tenants.py b/startup_scripts/105_tenants.py new file mode 100644 index 0000000..8ae8ea8 --- /dev/null +++ b/startup_scripts/105_tenants.py @@ -0,0 +1,45 @@ +from tenancy.models import Tenant, TenantGroup +from extras.models import CustomField, CustomFieldValue +from ruamel.yaml import YAML + +from pathlib import Path +import sys + +file = Path('/opt/netbox/initializers/tenants.yml') +if not file.is_file(): + sys.exit() + +with file.open('r') as stream: + yaml = YAML(typ='safe') + tenants = yaml.load(stream) + + optional_assocs = { + 'group': (TenantGroup, 'name') + } + + if tenants is not None: + for params in tenants: + custom_fields = params.pop('custom_fields', None) + + for assoc, details in optional_assocs.items(): + if assoc in params: + model, field = details + query = { field: params.pop(assoc) } + + params[assoc] = model.objects.get(**query) + + tenant, created = Tenant.objects.get_or_create(**params) + + if created: + if custom_fields is not None: + for cf_name, cf_value in custom_fields.items(): + custom_field = CustomField.objects.get(name=cf_name) + custom_field_value = CustomFieldValue.objects.create( + field=custom_field, + obj=tenant, + value=cf_value + ) + + tenant.custom_field_values.add(custom_field_value) + + print("Created Tenant", tenant.name) diff --git a/startup_scripts/120_cluster_types.py b/startup_scripts/120_cluster_types.py new file mode 100644 index 0000000..5211ea5 --- /dev/null +++ b/startup_scripts/120_cluster_types.py @@ -0,0 +1,19 @@ +from virtualization.models import ClusterType +from ruamel.yaml import YAML +from pathlib import Path +import sys + +file = Path('/opt/netbox/initializers/cluster_types.yml') +if not file.is_file(): + sys.exit() + +with file.open('r') as stream: + yaml = YAML(typ='safe') + cluster_types = yaml.load(stream) + + if cluster_types is not None: + for params in cluster_types: + cluster_type, created = ClusterType.objects.get_or_create(**params) + + if created: + print("Created Cluster Type", cluster_type.name) diff --git a/startup_scripts/125_rirs.py b/startup_scripts/125_rirs.py new file mode 100644 index 0000000..d120545 --- /dev/null +++ b/startup_scripts/125_rirs.py @@ -0,0 +1,19 @@ +from ipam.models import RIR +from ruamel.yaml import YAML +from pathlib import Path +import sys + +file = Path('/opt/netbox/initializers/rirs.yml') +if not file.is_file(): + sys.exit() + +with file.open('r') as stream: + yaml = YAML(typ='safe') + rirs = yaml.load(stream) + + if rirs is not None: + for params in rirs: + rir, created = RIR.objects.get_or_create(**params) + + if created: + print("Created RIR", rir.name) diff --git a/startup_scripts/130_aggregates.py b/startup_scripts/130_aggregates.py new file mode 100644 index 0000000..c82aa95 --- /dev/null +++ b/startup_scripts/130_aggregates.py @@ -0,0 +1,47 @@ +from ipam.models import Aggregate, RIR +from ruamel.yaml import YAML +from extras.models import CustomField, CustomFieldValue + +from netaddr import IPNetwork +from pathlib import Path +import sys + +file = Path('/opt/netbox/initializers/aggregates.yml') +if not file.is_file(): + sys.exit() + +with file.open('r') as stream: + yaml = YAML(typ='safe') + aggregates = yaml.load(stream) + + required_assocs = { + 'rir': (RIR, 'name') + } + + if aggregates is not None: + for params in aggregates: + custom_fields = params.pop('custom_fields', None) + params['prefix'] = IPNetwork(params['prefix']) + + for assoc, details in required_assocs.items(): + model, field = details + query = { field: params.pop(assoc) } + + params[assoc] = model.objects.get(**query) + + aggregate, created = Aggregate.objects.get_or_create(**params) + + if created: + if custom_fields is not None: + for cf_name, cf_value in custom_fields.items(): + custom_field = CustomField.objects.get(name=cf_name) + custom_field_value = CustomFieldValue.objects.create( + field=custom_field, + obj=aggregate, + value=cf_value + ) + + aggregate.custom_field_values.add(custom_field_value) + + print("Created Aggregate", aggregate.prefix) + diff --git a/startup_scripts/150_clusters.py b/startup_scripts/150_clusters.py new file mode 100644 index 0000000..bc8a268 --- /dev/null +++ b/startup_scripts/150_clusters.py @@ -0,0 +1,57 @@ +from dcim.models import Site +from virtualization.models import Cluster, ClusterType, ClusterGroup +from extras.models import CustomField, CustomFieldValue +from ruamel.yaml import YAML + +from pathlib import Path +import sys + +file = Path('/opt/netbox/initializers/clusters.yml') +if not file.is_file(): + sys.exit() + +with file.open('r') as stream: + yaml = YAML(typ='safe') + clusters = yaml.load(stream) + + required_assocs = { + 'type': (ClusterType, 'name') + } + + optional_assocs = { + 'site': (Site, 'name'), + 'group': (ClusterGroup, 'name') + } + + if clusters is not None: + for params in clusters: + custom_fields = params.pop('custom_fields', None) + + for assoc, details in required_assocs.items(): + model, field = details + query = { field: params.pop(assoc) } + + params[assoc] = model.objects.get(**query) + + for assoc, details in optional_assocs.items(): + if assoc in params: + model, field = details + query = { field: params.pop(assoc) } + + params[assoc] = model.objects.get(**query) + + cluster, created = Cluster.objects.get_or_create(**params) + + if created: + if custom_fields is not None: + for cf_name, cf_value in custom_fields.items(): + custom_field = CustomField.objects.get(name=cf_name) + custom_field_value = CustomFieldValue.objects.create( + field=custom_field, + obj=cluster, + value=cf_value + ) + + cluster.custom_field_values.add(custom_field_value) + + print("Created cluster", cluster.name) diff --git a/startup_scripts/155_vrfs.py b/startup_scripts/155_vrfs.py new file mode 100644 index 0000000..4d7a927 --- /dev/null +++ b/startup_scripts/155_vrfs.py @@ -0,0 +1,47 @@ +from ipam.models import VRF +from tenancy.models import Tenant +from ruamel.yaml import YAML +from extras.models import CustomField, CustomFieldValue + +from pathlib import Path +import sys + +file = Path('/opt/netbox/initializers/vrfs.yml') +if not file.is_file(): + sys.exit() + +with file.open('r') as stream: + yaml = YAML(typ='safe') + vrfs = yaml.load(stream) + + optional_assocs = { + 'tenant': (Tenant, 'name') + } + + if vrfs is not None: + for params in vrfs: + custom_fields = params.pop('custom_fields', None) + + for assoc, details in optional_assocs.items(): + if assoc in params: + model, field = details + query = { field: params.pop(assoc) } + + params[assoc] = model.objects.get(**query) + + vrf, created = VRF.objects.get_or_create(**params) + + if created: + if custom_fields is not None: + for cf_name, cf_value in custom_fields.items(): + custom_field = CustomField.objects.get(name=cf_name) + custom_field_value = CustomFieldValue.objects.create( + field=custom_field, + obj=vrf, + value=cf_value + ) + + vrf.custom_field_values.add(custom_field_value) + + print("Created VRF", vrf.name) + diff --git a/startup_scripts/160_prefix_vlan_roles.py b/startup_scripts/160_prefix_vlan_roles.py new file mode 100644 index 0000000..6a460bd --- /dev/null +++ b/startup_scripts/160_prefix_vlan_roles.py @@ -0,0 +1,19 @@ +from ipam.models import Role +from ruamel.yaml import YAML +from pathlib import Path +import sys + +file = Path('/opt/netbox/initializers/prefix_vlan_roles.yml') +if not file.is_file(): + sys.exit() + +with file.open('r') as stream: + yaml = YAML(typ='safe') + roles = yaml.load(stream) + + if roles is not None: + for params in roles: + role, created = Role.objects.get_or_create(**params) + + if created: + print("Created Prefix/VLAN Role", role.name) diff --git a/startup_scripts/170_vlan_groups.py b/startup_scripts/170_vlan_groups.py new file mode 100644 index 0000000..06673dd --- /dev/null +++ b/startup_scripts/170_vlan_groups.py @@ -0,0 +1,46 @@ +from dcim.models import Site +from ipam.models import VLANGroup +from extras.models import CustomField, CustomFieldValue +from ruamel.yaml import YAML + +from pathlib import Path +import sys + +file = Path('/opt/netbox/initializers/vlan_groups.yml') +if not file.is_file(): + sys.exit() + +with file.open('r') as stream: + yaml = YAML(typ='safe') + vlan_groups = yaml.load(stream) + + optional_assocs = { + 'site': (Site, 'name') + } + + if vlan_groups is not None: + for params in vlan_groups: + custom_fields = params.pop('custom_fields', None) + + for assoc, details in optional_assocs.items(): + if assoc in params: + model, field = details + query = { field: params.pop(assoc) } + + params[assoc] = model.objects.get(**query) + + vlan_group, created = VLANGroup.objects.get_or_create(**params) + + if created: + if custom_fields is not None: + for cf_name, cf_value in custom_fields.items(): + custom_field = CustomField.objects.get(name=cf_name) + custom_field_value = CustomFieldValue.objects.create( + field=custom_field, + obj=vlan_group, + value=cf_value + ) + + vlan_group.custom_field_values.add(custom_field_value) + + print("Created VLAN Group", vlan_group.name) diff --git a/startup_scripts/180_vlans.py b/startup_scripts/180_vlans.py new file mode 100644 index 0000000..12f2cd1 --- /dev/null +++ b/startup_scripts/180_vlans.py @@ -0,0 +1,50 @@ +from dcim.models import Site +from ipam.models import VLAN, VLANGroup, Role +from tenancy.models import Tenant +from extras.models import CustomField, CustomFieldValue +from ruamel.yaml import YAML + +from pathlib import Path +import sys + +file = Path('/opt/netbox/initializers/vlans.yml') +if not file.is_file(): + sys.exit() + +with file.open('r') as stream: + yaml = YAML(typ='safe') + vlans = yaml.load(stream) + + optional_assocs = { + 'site': (Site, 'name'), + 'tenant': (Tenant, 'name'), + 'group': (VLANGroup, 'name'), + 'role': (Role, 'name') + } + + if vlans is not None: + for params in vlans: + custom_fields = params.pop('custom_fields', None) + + for assoc, details in optional_assocs.items(): + if assoc in params: + model, field = details + query = { field: params.pop(assoc) } + + params[assoc] = model.objects.get(**query) + + vlan, created = VLAN.objects.get_or_create(**params) + + if created: + if custom_fields is not None: + for cf_name, cf_value in custom_fields.items(): + custom_field = CustomField.objects.get(name=cf_name) + custom_field_value = CustomFieldValue.objects.create( + field=custom_field, + obj=vlan, + value=cf_value + ) + + vlan.custom_field_values.add(custom_field_value) + + print("Created VLAN", vlan.name) diff --git a/startup_scripts/190_prefixes.py b/startup_scripts/190_prefixes.py new file mode 100644 index 0000000..208feb8 --- /dev/null +++ b/startup_scripts/190_prefixes.py @@ -0,0 +1,53 @@ +from dcim.models import Site +from ipam.models import Prefix, VLAN, Role, VRF +from tenancy.models import Tenant +from extras.models import CustomField, CustomFieldValue +from ruamel.yaml import YAML + +from netaddr import IPNetwork +from pathlib import Path +import sys + +file = Path('/opt/netbox/initializers/prefixes.yml') +if not file.is_file(): + sys.exit() + +with file.open('r') as stream: + yaml = YAML(typ='safe') + prefixes = yaml.load(stream) + + optional_assocs = { + 'site': (Site, 'name'), + 'tenant': (Tenant, 'name'), + 'vlan': (VLAN, 'name'), + 'role': (Role, 'name'), + 'vrf': (VRF, 'name') + } + + if prefixes is not None: + for params in prefixes: + custom_fields = params.pop('custom_fields', None) + params['prefix'] = IPNetwork(params['prefix']) + + for assoc, details in optional_assocs.items(): + if assoc in params: + model, field = details + query = { field: params.pop(assoc) } + + params[assoc] = model.objects.get(**query) + + prefix, created = Prefix.objects.get_or_create(**params) + + if created: + if custom_fields is not None: + for cf_name, cf_value in custom_fields.items(): + custom_field = CustomField.objects.get(name=cf_name) + custom_field_value = CustomFieldValue.objects.create( + field=custom_field, + obj=prefix, + value=cf_value + ) + + prefix.custom_field_values.add(custom_field_value) + + print("Created Prefix", prefix.prefix) diff --git a/startup_scripts/200_virtual_machines.py b/startup_scripts/200_virtual_machines.py new file mode 100644 index 0000000..8845819 --- /dev/null +++ b/startup_scripts/200_virtual_machines.py @@ -0,0 +1,59 @@ +from dcim.models import Site, Platform, DeviceRole +from virtualization.models import Cluster, VirtualMachine +from tenancy.models import Tenant +from extras.models import CustomField, CustomFieldValue +from ruamel.yaml import YAML + +from pathlib import Path +import sys + +file = Path('/opt/netbox/initializers/virtual_machines.yml') +if not file.is_file(): + sys.exit() + +with file.open('r') as stream: + yaml = YAML(typ='safe') + virtual_machines = yaml.load(stream) + + required_assocs = { + 'cluster': (Cluster, 'name') + } + + optional_assocs = { + 'tenant': (Tenant, 'name'), + 'platform': (Platform, 'name'), + 'role': (DeviceRole, 'name') + } + + if virtual_machines is not None: + for params in virtual_machines: + custom_fields = params.pop('custom_fields', None) + + for assoc, details in required_assocs.items(): + model, field = details + query = { field: params.pop(assoc) } + + params[assoc] = model.objects.get(**query) + + for assoc, details in optional_assocs.items(): + if assoc in params: + model, field = details + query = { field: params.pop(assoc) } + + params[assoc] = model.objects.get(**query) + + virtual_machine, created = VirtualMachine.objects.get_or_create(**params) + + if created: + if custom_fields is not None: + for cf_name, cf_value in custom_fields.items(): + custom_field = CustomField.objects.get(name=cf_name) + custom_field_value = CustomFieldValue.objects.create( + field=custom_field, + obj=virtual_machine, + value=cf_value + ) + + virtual_machine.custom_field_values.add(custom_field_value) + + print("Created virtual machine", virtual_machine.name) diff --git a/startup_scripts/210_virtualization_interfaces.py b/startup_scripts/210_virtualization_interfaces.py new file mode 100644 index 0000000..f76f876 --- /dev/null +++ b/startup_scripts/210_virtualization_interfaces.py @@ -0,0 +1,47 @@ +from dcim.models import Interface +from virtualization.models import VirtualMachine +from extras.models import CustomField, CustomFieldValue +from ruamel.yaml import YAML + +from pathlib import Path +import sys + +file = Path('/opt/netbox/initializers/virtualization_interfaces.yml') +if not file.is_file(): + sys.exit() + +with file.open('r') as stream: + yaml = YAML(typ='safe') + interfaces = yaml.load(stream) + + optional_assocs = { + 'virtual_machine': (VirtualMachine, 'name') + } + + if interfaces is not None: + for params in interfaces: + custom_fields = params.pop('custom_fields', None) + + for assoc, details in optional_assocs.items(): + if assoc in params: + model, field = details + query = { field: params.pop(assoc) } + + params[assoc] = model.objects.get(**query) + + interface, created = Interface.objects.get_or_create(**params) + + if created: + if custom_fields is not None: + for cf_name, cf_value in custom_fields.items(): + custom_field = CustomField.objects.get(name=cf_name) + custom_field_value = CustomFieldValue.objects.create( + field=custom_field, + obj=interface, + value=cf_value + ) + + interface.custom_field_values.add(custom_field_value) + + print("Created interface", interface.name, interface.virtual_machine.name) + diff --git a/startup_scripts/215_dcim_interfaces.py b/startup_scripts/215_dcim_interfaces.py new file mode 100644 index 0000000..38b9f61 --- /dev/null +++ b/startup_scripts/215_dcim_interfaces.py @@ -0,0 +1,46 @@ +from dcim.models import Interface, Device +from extras.models import CustomField, CustomFieldValue +from ruamel.yaml import YAML + +from pathlib import Path +import sys + +file = Path('/opt/netbox/initializers/dcim_interfaces.yml') +if not file.is_file(): + sys.exit() + +with file.open('r') as stream: + yaml = YAML(typ='safe') + interfaces = yaml.load(stream) + + optional_assocs = { + 'device': (Device, 'name') + } + + if interfaces is not None: + for params in interfaces: + custom_fields = params.pop('custom_fields', None) + + for assoc, details in optional_assocs.items(): + if assoc in params: + model, field = details + query = { field: params.pop(assoc) } + + params[assoc] = model.objects.get(**query) + + interface, created = Interface.objects.get_or_create(**params) + + if created: + if custom_fields is not None: + for cf_name, cf_value in custom_fields.items(): + custom_field = CustomField.objects.get(name=cf_name) + custom_field_value = CustomFieldValue.objects.create( + field=custom_field, + obj=interface, + value=cf_value + ) + + interface.custom_field_values.add(custom_field_value) + + print("Created interface", interface.name, interface.device.name) + diff --git a/startup_scripts/220_ip_addresses.py b/startup_scripts/220_ip_addresses.py new file mode 100644 index 0000000..2310a2a --- /dev/null +++ b/startup_scripts/220_ip_addresses.py @@ -0,0 +1,61 @@ +from ipam.models import IPAddress, VRF +from dcim.models import Device, Interface +from virtualization.models import VirtualMachine +from tenancy.models import Tenant +from extras.models import CustomField, CustomFieldValue +from ruamel.yaml import YAML + +from netaddr import IPNetwork +from pathlib import Path +import sys + +file = Path('/opt/netbox/initializers/ip_addresses.yml') +if not file.is_file(): + sys.exit() + +with file.open('r') as stream: + yaml = YAML(typ='safe') + ip_addresses = yaml.load(stream) + + optional_assocs = { + 'tenant': (Tenant, 'name'), + 'vrf': (VRF, 'name'), + 'interface': (Interface, 'name') + } + + if ip_addresses is not None: + for params in ip_addresses: + vm = params.pop('virtual_machine', None) + device = params.pop('device', None) + custom_fields = params.pop('custom_fields', None) + params['address'] = IPNetwork(params['address']) + + for assoc, details in optional_assocs.items(): + if assoc in params: + model, field = details + if assoc == 'interface': + if vm: + vm_id = VirtualMachine.objects.get(name=vm).id + query = { field: params.pop(assoc), "virtual_machine_id": vm_id } + elif device: + dev_id = Device.objects.get(name=device).id + query = { field: params.pop(assoc), "device_id": dev_id } + else: + query = { field: params.pop(assoc) } + params[assoc] = model.objects.get(**query) + + ip_address, created = IPAddress.objects.get_or_create(**params) + + if created: + if custom_fields is not None: + for cf_name, cf_value in custom_fields.items(): + custom_field = CustomField.objects.get(name=cf_name) + custom_field_value = CustomFieldValue.objects.create( + field=custom_field, + obj=ip_address, + value=cf_value + ) + + ip_address.custom_field_values.add(custom_field_value) + + print("Created IP Address", ip_address.address) From 0b5214d247111c75f64726f119db37c32f4db93e Mon Sep 17 00:00:00 2001 From: Alvaro Arriola Date: Thu, 10 Oct 2019 16:52:29 +0200 Subject: [PATCH 2/8] Fixed aesthetics. --- initializers/aggregates.yml | 2 ++ initializers/clusters.yml | 3 +++ initializers/dcim_interfaces.yml | 12 ++++-------- initializers/ip_addresses.yml | 9 ++------- initializers/prefix_vlan_roles.yml | 2 ++ initializers/prefixes.yml | 11 ++++++++++- initializers/rirs.yml | 3 +++ initializers/tenants.yml | 1 + initializers/tenants_groups.yml | 4 ++++ initializers/virtual_machines.yml | 11 ++++++++++- initializers/virtualization_interfaces.yml | 2 -- initializers/vlans.yml | 4 +++- initializers/vrfs.yml | 4 ++++ .../{104_tenant_groups.py => 110_tenant_groups.py} | 2 +- startup_scripts/{105_tenants.py => 120_tenants.py} | 2 +- startup_scripts/{110_devices.py => 130_devices.py} | 0 .../{120_cluster_types.py => 140_cluster_types.py} | 2 +- startup_scripts/{125_rirs.py => 150_rirs.py} | 2 +- .../{130_aggregates.py => 160_aggregates.py} | 3 +-- startup_scripts/{150_clusters.py => 170_clusters.py} | 2 +- startup_scripts/{155_vrfs.py => 180_vrfs.py} | 3 +-- ...prefix_vlan_roles.py => 190_prefix_vlan_roles.py} | 2 +- .../{170_vlan_groups.py => 200_vlan_groups.py} | 2 +- startup_scripts/{180_vlans.py => 210_vlans.py} | 5 +++-- startup_scripts/{190_prefixes.py => 220_prefixes.py} | 5 +++-- ...0_virtual_machines.py => 230_virtual_machines.py} | 2 +- ...nterfaces.py => 240_virtualization_interfaces.py} | 3 +-- ...215_dcim_interfaces.py => 250_dcim_interfaces.py} | 2 +- .../{220_ip_addresses.py => 260_ip_addresses.py} | 2 +- 29 files changed, 67 insertions(+), 40 deletions(-) create mode 100644 initializers/prefix_vlan_roles.yml create mode 100644 initializers/tenants_groups.yml rename startup_scripts/{104_tenant_groups.py => 110_tenant_groups.py} (87%) rename startup_scripts/{105_tenants.py => 120_tenants.py} (95%) rename startup_scripts/{110_devices.py => 130_devices.py} (100%) rename startup_scripts/{120_cluster_types.py => 140_cluster_types.py} (88%) rename startup_scripts/{125_rirs.py => 150_rirs.py} (89%) rename startup_scripts/{130_aggregates.py => 160_aggregates.py} (95%) rename startup_scripts/{150_clusters.py => 170_clusters.py} (96%) rename startup_scripts/{155_vrfs.py => 180_vrfs.py} (96%) rename startup_scripts/{160_prefix_vlan_roles.py => 190_prefix_vlan_roles.py} (86%) rename startup_scripts/{170_vlan_groups.py => 200_vlan_groups.py} (95%) rename startup_scripts/{180_vlans.py => 210_vlans.py} (90%) rename startup_scripts/{190_prefixes.py => 220_prefixes.py} (90%) rename startup_scripts/{200_virtual_machines.py => 230_virtual_machines.py} (95%) rename startup_scripts/{210_virtualization_interfaces.py => 240_virtualization_interfaces.py} (93%) rename startup_scripts/{215_dcim_interfaces.py => 250_dcim_interfaces.py} (93%) rename startup_scripts/{220_ip_addresses.py => 260_ip_addresses.py} (97%) diff --git a/initializers/aggregates.yml b/initializers/aggregates.yml index 8e73070..3dc65e6 100644 --- a/initializers/aggregates.yml +++ b/initializers/aggregates.yml @@ -1,2 +1,4 @@ #- prefix: 10.0.0.0/16 # rir: RFC1918 +#- prefix: fd00:ccdd::/32 +# rir: RFC4193 ULA diff --git a/initializers/clusters.yml b/initializers/clusters.yml index 6eff3d0..a8dc121 100644 --- a/initializers/clusters.yml +++ b/initializers/clusters.yml @@ -1,2 +1,5 @@ #- name: cluster1 # type: Hyper-V +#- name: cluster2 +# type: Hyper-V +# site: SING 1 diff --git a/initializers/dcim_interfaces.yml b/initializers/dcim_interfaces.yml index 12ddbad..e02bf07 100644 --- a/initializers/dcim_interfaces.yml +++ b/initializers/dcim_interfaces.yml @@ -1,12 +1,8 @@ -#- device: router1 +#- device: server01 # enabled: true # form_factor: 0 -# name: router2 -#- device: 9901-2.bwi-stf.lab +# name: to-server02 +#- device: server02 # enabled: true # form_factor: 0 -# name: Loopback0 -#- device: switch1 -# enabled: true -# form_factor: 0 -# name: Vlan5 +# name: to-server01 diff --git a/initializers/ip_addresses.yml b/initializers/ip_addresses.yml index 445dd9c..7427a4a 100644 --- a/initializers/ip_addresses.yml +++ b/initializers/ip_addresses.yml @@ -1,18 +1,13 @@ - #- address: 10.1.1.1/24 -# device: router1 -# family: 4 +# device: server01 # interface: Loopback0 # status: 1 # vrf: vrf1 #- address: 10.1.1.2/24 -# device: switch1 -# family: 4 +# device: server02 # interface: Vlan5 # status: 1 #- address: 10.1.1.10/24 # description: reserved IP -# family: 4 # status: 2 # tenant: tenant1 - diff --git a/initializers/prefix_vlan_roles.yml b/initializers/prefix_vlan_roles.yml new file mode 100644 index 0000000..309acc9 --- /dev/null +++ b/initializers/prefix_vlan_roles.yml @@ -0,0 +1,2 @@ +#- name: Main Management +# slug: main-management diff --git a/initializers/prefixes.yml b/initializers/prefixes.yml index 2aeb74f..8644a9e 100644 --- a/initializers/prefixes.yml +++ b/initializers/prefixes.yml @@ -9,4 +9,13 @@ # site: AMS 2 # status: 1 # tenant: tenant2 -# vlan: vlan2 \ No newline at end of file +# vlan: vlan2 +# is_pool: true +# vrf: vrf2 +# tenant: tenant2 +#- description: ipv6 prefix1 +# prefix: fd00:ccdd:a000:1::/64 +# site: AMS 2 +# status: 1 +# tenant: tenant2 +# vlan: vlan2 diff --git a/initializers/rirs.yml b/initializers/rirs.yml index f819c40..1a0c84d 100644 --- a/initializers/rirs.yml +++ b/initializers/rirs.yml @@ -1,3 +1,6 @@ #- is_private: true # name: RFC1918 # slug: rfc1918 +#- is_private: true +# name: RFC4193 ULA +# slug: rfc4193-ula diff --git a/initializers/tenants.yml b/initializers/tenants.yml index 2af9953..86db54f 100644 --- a/initializers/tenants.yml +++ b/initializers/tenants.yml @@ -2,3 +2,4 @@ # slug: tenant1 #- name: tenant2 # slug: tenant2 +# group: Tenant Group 2 diff --git a/initializers/tenants_groups.yml b/initializers/tenants_groups.yml new file mode 100644 index 0000000..53f0ce8 --- /dev/null +++ b/initializers/tenants_groups.yml @@ -0,0 +1,4 @@ +#- name: Tenant Group 1 +# slug: tenant-group-1 +#- name: Tenant Group 2 +# slug: tenant-group-2 diff --git a/initializers/virtual_machines.yml b/initializers/virtual_machines.yml index 23536bc..8fd57ed 100644 --- a/initializers/virtual_machines.yml +++ b/initializers/virtual_machines.yml @@ -6,4 +6,13 @@ # platform: Platform 2 # status: 1 # tenant: tenant1 -# vcpus: 8 \ No newline at end of file +# vcpus: 8 +#- cluster: cluster1 +# comments: VM2 +# disk: 100 +# memory: 2048 +# name: virtual machine 2 +# platform: Platform 2 +# status: 1 +# tenant: tenant1 +# vcpus: 8 diff --git a/initializers/virtualization_interfaces.yml b/initializers/virtualization_interfaces.yml index 000613f..15a64ab 100644 --- a/initializers/virtualization_interfaces.yml +++ b/initializers/virtualization_interfaces.yml @@ -1,13 +1,11 @@ #- description: Network Interface 1 # enabled: true -# form_factor: 0 # mac_address: 00:77:77:77:77:77 # mtu: 1500 # name: Network Interface 1 # virtual_machine: virtual_machine1 #- description: Network Interface 2 # enabled: true -# form_factor: 0 # mac_address: 00:55:55:55:55:55 # mtu: 1500 # name: Network Interface 2 diff --git a/initializers/vlans.yml b/initializers/vlans.yml index 8591192..6e7353d 100644 --- a/initializers/vlans.yml +++ b/initializers/vlans.yml @@ -2,8 +2,10 @@ # site: AMS 1 # status: 1 # vid: 5 +# role: Main Management +# description: VLAN 5 for MGMT #- group: VLAN group 2 # name: vlan2 # site: AMS 1 # status: 1 -# vid: 1300 \ No newline at end of file +# vid: 1300 diff --git a/initializers/vrfs.yml b/initializers/vrfs.yml index 7d9ba85..0f3684d 100644 --- a/initializers/vrfs.yml +++ b/initializers/vrfs.yml @@ -1,5 +1,9 @@ #- enforce_unique: true # name: vrf1 # tenant: tenant1 +# description: main VRF #- enforce_unique: true # name: vrf2 +# rd: "6500:6500" +# tenant: tenant2 +# tenant_group: Tenant Group 2 diff --git a/startup_scripts/104_tenant_groups.py b/startup_scripts/110_tenant_groups.py similarity index 87% rename from startup_scripts/104_tenant_groups.py rename to startup_scripts/110_tenant_groups.py index 94c58ad..eaf75dc 100644 --- a/startup_scripts/104_tenant_groups.py +++ b/startup_scripts/110_tenant_groups.py @@ -16,4 +16,4 @@ with file.open('r') as stream: tenant_group, created = TenantGroup.objects.get_or_create(**params) if created: - print("Created Tenant Group", tenant_group.name) + print("πŸ”³ Created Tenant Group", tenant_group.name) diff --git a/startup_scripts/105_tenants.py b/startup_scripts/120_tenants.py similarity index 95% rename from startup_scripts/105_tenants.py rename to startup_scripts/120_tenants.py index 8ae8ea8..8252dc7 100644 --- a/startup_scripts/105_tenants.py +++ b/startup_scripts/120_tenants.py @@ -42,4 +42,4 @@ with file.open('r') as stream: tenant.custom_field_values.add(custom_field_value) - print("Created Tenant", tenant.name) + print("πŸ‘©β€πŸ’» Created Tenant", tenant.name) diff --git a/startup_scripts/110_devices.py b/startup_scripts/130_devices.py similarity index 100% rename from startup_scripts/110_devices.py rename to startup_scripts/130_devices.py diff --git a/startup_scripts/120_cluster_types.py b/startup_scripts/140_cluster_types.py similarity index 88% rename from startup_scripts/120_cluster_types.py rename to startup_scripts/140_cluster_types.py index 5211ea5..9bd4be1 100644 --- a/startup_scripts/120_cluster_types.py +++ b/startup_scripts/140_cluster_types.py @@ -16,4 +16,4 @@ with file.open('r') as stream: cluster_type, created = ClusterType.objects.get_or_create(**params) if created: - print("Created Cluster Type", cluster_type.name) + print("🧰 Created Cluster Type", cluster_type.name) diff --git a/startup_scripts/125_rirs.py b/startup_scripts/150_rirs.py similarity index 89% rename from startup_scripts/125_rirs.py rename to startup_scripts/150_rirs.py index d120545..9cee56f 100644 --- a/startup_scripts/125_rirs.py +++ b/startup_scripts/150_rirs.py @@ -16,4 +16,4 @@ with file.open('r') as stream: rir, created = RIR.objects.get_or_create(**params) if created: - print("Created RIR", rir.name) + print("πŸ—ΊοΈ Created RIR", rir.name) diff --git a/startup_scripts/130_aggregates.py b/startup_scripts/160_aggregates.py similarity index 95% rename from startup_scripts/130_aggregates.py rename to startup_scripts/160_aggregates.py index c82aa95..f932709 100644 --- a/startup_scripts/130_aggregates.py +++ b/startup_scripts/160_aggregates.py @@ -43,5 +43,4 @@ with file.open('r') as stream: aggregate.custom_field_values.add(custom_field_value) - print("Created Aggregate", aggregate.prefix) - + print("πŸ—žοΈ Created Aggregate", aggregate.prefix) diff --git a/startup_scripts/150_clusters.py b/startup_scripts/170_clusters.py similarity index 96% rename from startup_scripts/150_clusters.py rename to startup_scripts/170_clusters.py index bc8a268..597f73f 100644 --- a/startup_scripts/150_clusters.py +++ b/startup_scripts/170_clusters.py @@ -54,4 +54,4 @@ with file.open('r') as stream: cluster.custom_field_values.add(custom_field_value) - print("Created cluster", cluster.name) + print("πŸ—„οΈ Created cluster", cluster.name) diff --git a/startup_scripts/155_vrfs.py b/startup_scripts/180_vrfs.py similarity index 96% rename from startup_scripts/155_vrfs.py rename to startup_scripts/180_vrfs.py index 4d7a927..d611c04 100644 --- a/startup_scripts/155_vrfs.py +++ b/startup_scripts/180_vrfs.py @@ -43,5 +43,4 @@ with file.open('r') as stream: vrf.custom_field_values.add(custom_field_value) - print("Created VRF", vrf.name) - + print("πŸ“¦ Created VRF", vrf.name) diff --git a/startup_scripts/160_prefix_vlan_roles.py b/startup_scripts/190_prefix_vlan_roles.py similarity index 86% rename from startup_scripts/160_prefix_vlan_roles.py rename to startup_scripts/190_prefix_vlan_roles.py index 6a460bd..61fa606 100644 --- a/startup_scripts/160_prefix_vlan_roles.py +++ b/startup_scripts/190_prefix_vlan_roles.py @@ -16,4 +16,4 @@ with file.open('r') as stream: role, created = Role.objects.get_or_create(**params) if created: - print("Created Prefix/VLAN Role", role.name) + print("⛹️‍ Created Prefix/VLAN Role", role.name) diff --git a/startup_scripts/170_vlan_groups.py b/startup_scripts/200_vlan_groups.py similarity index 95% rename from startup_scripts/170_vlan_groups.py rename to startup_scripts/200_vlan_groups.py index 06673dd..54250fb 100644 --- a/startup_scripts/170_vlan_groups.py +++ b/startup_scripts/200_vlan_groups.py @@ -43,4 +43,4 @@ with file.open('r') as stream: vlan_group.custom_field_values.add(custom_field_value) - print("Created VLAN Group", vlan_group.name) + print("🏘️ Created VLAN Group", vlan_group.name) diff --git a/startup_scripts/180_vlans.py b/startup_scripts/210_vlans.py similarity index 90% rename from startup_scripts/180_vlans.py rename to startup_scripts/210_vlans.py index 12f2cd1..ab6bd2b 100644 --- a/startup_scripts/180_vlans.py +++ b/startup_scripts/210_vlans.py @@ -1,6 +1,6 @@ from dcim.models import Site from ipam.models import VLAN, VLANGroup, Role -from tenancy.models import Tenant +from tenancy.models import Tenant, TenantGroup from extras.models import CustomField, CustomFieldValue from ruamel.yaml import YAML @@ -18,6 +18,7 @@ with file.open('r') as stream: optional_assocs = { 'site': (Site, 'name'), 'tenant': (Tenant, 'name'), + 'tenant_group': (TenantGroup, 'name'), 'group': (VLANGroup, 'name'), 'role': (Role, 'name') } @@ -47,4 +48,4 @@ with file.open('r') as stream: vlan.custom_field_values.add(custom_field_value) - print("Created VLAN", vlan.name) + print("🏠 Created VLAN", vlan.name) diff --git a/startup_scripts/190_prefixes.py b/startup_scripts/220_prefixes.py similarity index 90% rename from startup_scripts/190_prefixes.py rename to startup_scripts/220_prefixes.py index 208feb8..d13578a 100644 --- a/startup_scripts/190_prefixes.py +++ b/startup_scripts/220_prefixes.py @@ -1,6 +1,6 @@ from dcim.models import Site from ipam.models import Prefix, VLAN, Role, VRF -from tenancy.models import Tenant +from tenancy.models import Tenant, TenantGroup from extras.models import CustomField, CustomFieldValue from ruamel.yaml import YAML @@ -19,6 +19,7 @@ with file.open('r') as stream: optional_assocs = { 'site': (Site, 'name'), 'tenant': (Tenant, 'name'), + 'tenant_group': (TenantGroup, 'name'), 'vlan': (VLAN, 'name'), 'role': (Role, 'name'), 'vrf': (VRF, 'name') @@ -50,4 +51,4 @@ with file.open('r') as stream: prefix.custom_field_values.add(custom_field_value) - print("Created Prefix", prefix.prefix) + print("πŸ“Œ Created Prefix", prefix.prefix) diff --git a/startup_scripts/200_virtual_machines.py b/startup_scripts/230_virtual_machines.py similarity index 95% rename from startup_scripts/200_virtual_machines.py rename to startup_scripts/230_virtual_machines.py index 8845819..449df8a 100644 --- a/startup_scripts/200_virtual_machines.py +++ b/startup_scripts/230_virtual_machines.py @@ -56,4 +56,4 @@ with file.open('r') as stream: virtual_machine.custom_field_values.add(custom_field_value) - print("Created virtual machine", virtual_machine.name) + print("πŸ–₯️ Created virtual machine", virtual_machine.name) diff --git a/startup_scripts/210_virtualization_interfaces.py b/startup_scripts/240_virtualization_interfaces.py similarity index 93% rename from startup_scripts/210_virtualization_interfaces.py rename to startup_scripts/240_virtualization_interfaces.py index f76f876..e1c2b8d 100644 --- a/startup_scripts/210_virtualization_interfaces.py +++ b/startup_scripts/240_virtualization_interfaces.py @@ -43,5 +43,4 @@ with file.open('r') as stream: interface.custom_field_values.add(custom_field_value) - print("Created interface", interface.name, interface.virtual_machine.name) - + print("🧷 Created interface", interface.name, interface.virtual_machine.name) diff --git a/startup_scripts/215_dcim_interfaces.py b/startup_scripts/250_dcim_interfaces.py similarity index 93% rename from startup_scripts/215_dcim_interfaces.py rename to startup_scripts/250_dcim_interfaces.py index 38b9f61..eca5415 100644 --- a/startup_scripts/215_dcim_interfaces.py +++ b/startup_scripts/250_dcim_interfaces.py @@ -42,5 +42,5 @@ with file.open('r') as stream: interface.custom_field_values.add(custom_field_value) - print("Created interface", interface.name, interface.device.name) + print("🧷 Created interface", interface.name, interface.device.name) diff --git a/startup_scripts/220_ip_addresses.py b/startup_scripts/260_ip_addresses.py similarity index 97% rename from startup_scripts/220_ip_addresses.py rename to startup_scripts/260_ip_addresses.py index 2310a2a..13c755d 100644 --- a/startup_scripts/220_ip_addresses.py +++ b/startup_scripts/260_ip_addresses.py @@ -58,4 +58,4 @@ with file.open('r') as stream: ip_address.custom_field_values.add(custom_field_value) - print("Created IP Address", ip_address.address) + print("🧬 Created IP Address", ip_address.address) From 821d6c8672acc3757f95ff944efb79419db1d85f Mon Sep 17 00:00:00 2001 From: Alvaro Arriola Date: Thu, 10 Oct 2019 17:35:06 +0200 Subject: [PATCH 3/8] Fixed further requirements. --- initializers/dcim_interfaces.yml | 4 ++-- initializers/ip_addresses.yml | 6 ++--- initializers/prefixes.yml | 6 ++--- initializers/virtual_machines.yml | 4 ++-- initializers/vlans.yml | 4 ++-- startup_scripts/210_vlans.py | 6 +++++ startup_scripts/220_prefixes.py | 6 +++++ startup_scripts/230_virtual_machines.py | 6 +++++ .../240_virtualization_interfaces.py | 11 ++++----- startup_scripts/250_dcim_interfaces.py | 23 +++++++++++++------ startup_scripts/260_ip_addresses.py | 10 ++++++++ 11 files changed, 61 insertions(+), 25 deletions(-) diff --git a/initializers/dcim_interfaces.yml b/initializers/dcim_interfaces.yml index e02bf07..8e6281e 100644 --- a/initializers/dcim_interfaces.yml +++ b/initializers/dcim_interfaces.yml @@ -1,8 +1,8 @@ #- device: server01 # enabled: true -# form_factor: 0 +# form_factor: Virtual # name: to-server02 #- device: server02 # enabled: true -# form_factor: 0 +# form_factor: Virtual # name: to-server01 diff --git a/initializers/ip_addresses.yml b/initializers/ip_addresses.yml index 7427a4a..abcc918 100644 --- a/initializers/ip_addresses.yml +++ b/initializers/ip_addresses.yml @@ -1,13 +1,13 @@ #- address: 10.1.1.1/24 # device: server01 # interface: Loopback0 -# status: 1 +# status: Active # vrf: vrf1 #- address: 10.1.1.2/24 # device: server02 # interface: Vlan5 -# status: 1 +# status: Active #- address: 10.1.1.10/24 # description: reserved IP -# status: 2 +# status: Reserved # tenant: tenant1 diff --git a/initializers/prefixes.yml b/initializers/prefixes.yml index 8644a9e..ef6330a 100644 --- a/initializers/prefixes.yml +++ b/initializers/prefixes.yml @@ -1,13 +1,13 @@ #- description: prefix1 # prefix: 10.1.1.0/24 # site: AMS 1 -# status: 1 +# status: Active # tenant: tenant1 # vlan: vlan1 #- description: prefix2 # prefix: 10.1.2.0/24 # site: AMS 2 -# status: 1 +# status: Active # tenant: tenant2 # vlan: vlan2 # is_pool: true @@ -16,6 +16,6 @@ #- description: ipv6 prefix1 # prefix: fd00:ccdd:a000:1::/64 # site: AMS 2 -# status: 1 +# status: Active # tenant: tenant2 # vlan: vlan2 diff --git a/initializers/virtual_machines.yml b/initializers/virtual_machines.yml index 8fd57ed..ca61a80 100644 --- a/initializers/virtual_machines.yml +++ b/initializers/virtual_machines.yml @@ -4,7 +4,7 @@ # memory: 4096 # name: virtual machine 1 # platform: Platform 2 -# status: 1 +# status: Active # tenant: tenant1 # vcpus: 8 #- cluster: cluster1 @@ -13,6 +13,6 @@ # memory: 2048 # name: virtual machine 2 # platform: Platform 2 -# status: 1 +# status: Active # tenant: tenant1 # vcpus: 8 diff --git a/initializers/vlans.yml b/initializers/vlans.yml index 6e7353d..c78f6ca 100644 --- a/initializers/vlans.yml +++ b/initializers/vlans.yml @@ -1,11 +1,11 @@ #- name: vlan1 # site: AMS 1 -# status: 1 +# status: Active # vid: 5 # role: Main Management # description: VLAN 5 for MGMT #- group: VLAN group 2 # name: vlan2 # site: AMS 1 -# status: 1 +# status: Active # vid: 1300 diff --git a/startup_scripts/210_vlans.py b/startup_scripts/210_vlans.py index ab6bd2b..c667354 100644 --- a/startup_scripts/210_vlans.py +++ b/startup_scripts/210_vlans.py @@ -1,5 +1,6 @@ from dcim.models import Site from ipam.models import VLAN, VLANGroup, Role +from ipam.constants import VLAN_STATUS_CHOICES from tenancy.models import Tenant, TenantGroup from extras.models import CustomField, CustomFieldValue from ruamel.yaml import YAML @@ -34,6 +35,11 @@ with file.open('r') as stream: 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) if created: diff --git a/startup_scripts/220_prefixes.py b/startup_scripts/220_prefixes.py index d13578a..69d78f2 100644 --- a/startup_scripts/220_prefixes.py +++ b/startup_scripts/220_prefixes.py @@ -1,5 +1,6 @@ from dcim.models import Site from ipam.models import Prefix, VLAN, Role, VRF +from ipam.constants import PREFIX_STATUS_CHOICES from tenancy.models import Tenant, TenantGroup from extras.models import CustomField, CustomFieldValue from ruamel.yaml import YAML @@ -37,6 +38,11 @@ with file.open('r') as stream: 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) if created: diff --git a/startup_scripts/230_virtual_machines.py b/startup_scripts/230_virtual_machines.py index 449df8a..af30ee2 100644 --- a/startup_scripts/230_virtual_machines.py +++ b/startup_scripts/230_virtual_machines.py @@ -1,5 +1,6 @@ from dcim.models import Site, Platform, DeviceRole from virtualization.models import Cluster, VirtualMachine +from virtualization.constants import VM_STATUS_CHOICES from tenancy.models import Tenant from extras.models import CustomField, CustomFieldValue from ruamel.yaml import YAML @@ -42,6 +43,11 @@ with file.open('r') as stream: 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) if created: diff --git a/startup_scripts/240_virtualization_interfaces.py b/startup_scripts/240_virtualization_interfaces.py index e1c2b8d..8d2ca96 100644 --- a/startup_scripts/240_virtualization_interfaces.py +++ b/startup_scripts/240_virtualization_interfaces.py @@ -14,7 +14,7 @@ with file.open('r') as stream: yaml = YAML(typ='safe') interfaces = yaml.load(stream) - optional_assocs = { + required_assocs = { 'virtual_machine': (VirtualMachine, 'name') } @@ -22,12 +22,11 @@ with file.open('r') as stream: for params in interfaces: custom_fields = params.pop('custom_fields', None) - for assoc, details in optional_assocs.items(): - if assoc in params: - model, field = details - query = { field: params.pop(assoc) } + for assoc, details in required_assocs.items(): + model, field = details + query = { field: params.pop(assoc) } - params[assoc] = model.objects.get(**query) + params[assoc] = model.objects.get(**query) interface, created = Interface.objects.get_or_create(**params) diff --git a/startup_scripts/250_dcim_interfaces.py b/startup_scripts/250_dcim_interfaces.py index eca5415..b0baf39 100644 --- a/startup_scripts/250_dcim_interfaces.py +++ b/startup_scripts/250_dcim_interfaces.py @@ -1,4 +1,5 @@ from dcim.models import Interface, Device +from dcim.constants import IFACE_TYPE_CHOICES from extras.models import CustomField, CustomFieldValue from ruamel.yaml import YAML @@ -13,7 +14,7 @@ with file.open('r') as stream: yaml = YAML(typ='safe') interfaces = yaml.load(stream) - optional_assocs = { + required_assocs = { 'device': (Device, 'name') } @@ -21,12 +22,21 @@ with file.open('r') as stream: for params in interfaces: custom_fields = params.pop('custom_fields', None) - for assoc, details in optional_assocs.items(): - if assoc in params: - model, field = details - query = { field: params.pop(assoc) } + for assoc, details in required_assocs.items(): + model, field = details + 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) @@ -43,4 +53,3 @@ with file.open('r') as stream: interface.custom_field_values.add(custom_field_value) print("🧷 Created interface", interface.name, interface.device.name) - diff --git a/startup_scripts/260_ip_addresses.py b/startup_scripts/260_ip_addresses.py index 13c755d..589c5d3 100644 --- a/startup_scripts/260_ip_addresses.py +++ b/startup_scripts/260_ip_addresses.py @@ -1,4 +1,5 @@ from ipam.models import IPAddress, VRF +from ipam.constants import IPADDRESS_STATUS_CHOICES from dcim.models import Device, Interface from virtualization.models import VirtualMachine from tenancy.models import Tenant @@ -30,6 +31,10 @@ with file.open('r') as stream: custom_fields = params.pop('custom_fields', None) 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(): if assoc in params: model, field = details @@ -44,6 +49,11 @@ with file.open('r') as stream: query = { field: params.pop(assoc) } 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) if created: From 4e1ac2392d820886198de62a381cbc2e14b7c1bd Mon Sep 17 00:00:00 2001 From: Alvaro Arriola Date: Fri, 11 Oct 2019 15:46:32 +0200 Subject: [PATCH 4/8] Added newline and breaks. --- initializers/virtualization_interfaces.yml | 2 +- startup_scripts/210_vlans.py | 1 + startup_scripts/220_prefixes.py | 1 + startup_scripts/230_virtual_machines.py | 1 + startup_scripts/260_ip_addresses.py | 1 + 5 files changed, 5 insertions(+), 1 deletion(-) diff --git a/initializers/virtualization_interfaces.yml b/initializers/virtualization_interfaces.yml index 15a64ab..deff914 100644 --- a/initializers/virtualization_interfaces.yml +++ b/initializers/virtualization_interfaces.yml @@ -9,4 +9,4 @@ # mac_address: 00:55:55:55:55:55 # mtu: 1500 # name: Network Interface 2 -# virtual_machine: virtual_machine1 \ No newline at end of file +# virtual_machine: virtual_machine1 diff --git a/startup_scripts/210_vlans.py b/startup_scripts/210_vlans.py index c667354..e3a0ef1 100644 --- a/startup_scripts/210_vlans.py +++ b/startup_scripts/210_vlans.py @@ -39,6 +39,7 @@ with file.open('r') as stream: for vlan_status in VLAN_STATUS_CHOICES: if params['status'] in vlan_status: params['status'] = vlan_status[0] + break vlan, created = VLAN.objects.get_or_create(**params) diff --git a/startup_scripts/220_prefixes.py b/startup_scripts/220_prefixes.py index 69d78f2..a832c88 100644 --- a/startup_scripts/220_prefixes.py +++ b/startup_scripts/220_prefixes.py @@ -42,6 +42,7 @@ with file.open('r') as stream: for prefix_status in PREFIX_STATUS_CHOICES: if params['status'] in prefix_status: params['status'] = prefix_status[0] + break prefix, created = Prefix.objects.get_or_create(**params) diff --git a/startup_scripts/230_virtual_machines.py b/startup_scripts/230_virtual_machines.py index af30ee2..065b600 100644 --- a/startup_scripts/230_virtual_machines.py +++ b/startup_scripts/230_virtual_machines.py @@ -47,6 +47,7 @@ with file.open('r') as stream: for vm_status in VM_STATUS_CHOICES: if params['status'] in vm_status: params['status'] = vm_status[0] + break virtual_machine, created = VirtualMachine.objects.get_or_create(**params) diff --git a/startup_scripts/260_ip_addresses.py b/startup_scripts/260_ip_addresses.py index 589c5d3..f7f2bc7 100644 --- a/startup_scripts/260_ip_addresses.py +++ b/startup_scripts/260_ip_addresses.py @@ -53,6 +53,7 @@ with file.open('r') as stream: for ip_status in IPADDRESS_STATUS_CHOICES: if params['status'] in ip_status: params['status'] = ip_status[0] + break ip_address, created = IPAddress.objects.get_or_create(**params) From 2d25907cba66fed39b2cdb401753a22909502310 Mon Sep 17 00:00:00 2001 From: Alvaro Arriola Date: Fri, 11 Oct 2019 17:30:38 +0200 Subject: [PATCH 5/8] Fixing typos. --- initializers/ip_addresses.yml | 4 ++-- initializers/prefixes.yml | 1 - initializers/{tenants_groups.yml => tenant_groups.yml} | 0 initializers/virtualization_interfaces.yml | 4 ++-- initializers/vlan_groups.yml | 2 +- initializers/vrfs.yml | 1 - startup_scripts/250_dcim_interfaces.py | 8 ++++---- 7 files changed, 9 insertions(+), 11 deletions(-) rename initializers/{tenants_groups.yml => tenant_groups.yml} (100%) diff --git a/initializers/ip_addresses.yml b/initializers/ip_addresses.yml index abcc918..29a3917 100644 --- a/initializers/ip_addresses.yml +++ b/initializers/ip_addresses.yml @@ -1,11 +1,11 @@ #- address: 10.1.1.1/24 # device: server01 -# interface: Loopback0 +# interface: to-server02 # status: Active # vrf: vrf1 #- address: 10.1.1.2/24 # device: server02 -# interface: Vlan5 +# interface: to-server01 # status: Active #- address: 10.1.1.10/24 # description: reserved IP diff --git a/initializers/prefixes.yml b/initializers/prefixes.yml index ef6330a..f70685c 100644 --- a/initializers/prefixes.yml +++ b/initializers/prefixes.yml @@ -12,7 +12,6 @@ # vlan: vlan2 # is_pool: true # vrf: vrf2 -# tenant: tenant2 #- description: ipv6 prefix1 # prefix: fd00:ccdd:a000:1::/64 # site: AMS 2 diff --git a/initializers/tenants_groups.yml b/initializers/tenant_groups.yml similarity index 100% rename from initializers/tenants_groups.yml rename to initializers/tenant_groups.yml diff --git a/initializers/virtualization_interfaces.yml b/initializers/virtualization_interfaces.yml index deff914..37d3252 100644 --- a/initializers/virtualization_interfaces.yml +++ b/initializers/virtualization_interfaces.yml @@ -3,10 +3,10 @@ # mac_address: 00:77:77:77:77:77 # mtu: 1500 # name: Network Interface 1 -# virtual_machine: virtual_machine1 +# virtual_machine: virtual machine 1 #- description: Network Interface 2 # enabled: true # mac_address: 00:55:55:55:55:55 # mtu: 1500 # name: Network Interface 2 -# virtual_machine: virtual_machine1 +# virtual_machine: virtual machine 1 diff --git a/initializers/vlan_groups.yml b/initializers/vlan_groups.yml index 11a48fc..81546eb 100644 --- a/initializers/vlan_groups.yml +++ b/initializers/vlan_groups.yml @@ -1,6 +1,6 @@ #- name: VLAN group 1 # site: AMS 1 -# slug: vlan-group-2 +# slug: vlan-group-1 #- name: VLAN group 2 # site: AMS 1 # slug: vlan-group-2 diff --git a/initializers/vrfs.yml b/initializers/vrfs.yml index 0f3684d..fd50d87 100644 --- a/initializers/vrfs.yml +++ b/initializers/vrfs.yml @@ -6,4 +6,3 @@ # name: vrf2 # rd: "6500:6500" # tenant: tenant2 -# tenant_group: Tenant Group 2 diff --git a/startup_scripts/250_dcim_interfaces.py b/startup_scripts/250_dcim_interfaces.py index b0baf39..ce7e7bd 100644 --- a/startup_scripts/250_dcim_interfaces.py +++ b/startup_scripts/250_dcim_interfaces.py @@ -28,11 +28,11 @@ with file.open('r') as stream: params[assoc] = model.objects.get(**query) - if 'form_factor' in params: + if 'type' 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] + for type_choices in outer_list[1]: + if params['type'] in type_choices: + params['type'] = type_choices[0] break else: continue From 992a8f1d5f4bd2896694197e1d20231d9cfe3bd7 Mon Sep 17 00:00:00 2001 From: Alvaro Arriola Date: Fri, 11 Oct 2019 18:08:22 +0200 Subject: [PATCH 6/8] More typos. Tested all changes. --- initializers/dcim_interfaces.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/initializers/dcim_interfaces.yml b/initializers/dcim_interfaces.yml index 8e6281e..9a73a47 100644 --- a/initializers/dcim_interfaces.yml +++ b/initializers/dcim_interfaces.yml @@ -1,8 +1,8 @@ #- device: server01 # enabled: true -# form_factor: Virtual +# type: Virtual # name: to-server02 #- device: server02 # enabled: true -# form_factor: Virtual +# type: Virtual # name: to-server01 From 5defc38294228e49ec0c6fc8c66cd9ef62a4c5b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=A4der?= Date: Sat, 12 Oct 2019 14:23:11 +0200 Subject: [PATCH 7/8] Add missing `break` --- startup_scripts/130_devices.py | 1 + 1 file changed, 1 insertion(+) diff --git a/startup_scripts/130_devices.py b/startup_scripts/130_devices.py index 16c6f9e..2d8d3ca 100644 --- a/startup_scripts/130_devices.py +++ b/startup_scripts/130_devices.py @@ -53,6 +53,7 @@ with file.open('r') as stream: for rack_face in RACK_FACE_CHOICES: if params['face'] in rack_face: params['face'] = rack_face[0] + break device, created = Device.objects.get_or_create(**params) From e894cdaa064fe902dab58772075e61c9392465e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=A4der?= Date: Sat, 12 Oct 2019 14:23:41 +0200 Subject: [PATCH 8/8] Reformat initializers and add some IPv6 examples --- initializers/aggregates.yml | 10 +++--- initializers/cluster_types.yml | 4 +-- initializers/clusters.yml | 10 +++--- initializers/dcim_interfaces.yml | 16 ++++----- initializers/device_types.yml | 2 +- initializers/ip_addresses.yml | 39 ++++++++++++++------- initializers/manufacturers.yml | 4 +-- initializers/platforms.yml | 2 +- initializers/prefix_vlan_roles.yml | 4 +-- initializers/prefixes.yml | 40 +++++++++++----------- initializers/rirs.yml | 15 ++++---- initializers/tenant_groups.yml | 8 ++--- initializers/tenants.yml | 10 +++--- initializers/virtual_machines.yml | 36 +++++++++---------- initializers/virtualization_interfaces.yml | 24 ++++++------- initializers/vlan_groups.yml | 12 +++---- initializers/vlans.yml | 22 ++++++------ initializers/vrfs.yml | 16 ++++----- 18 files changed, 146 insertions(+), 128 deletions(-) diff --git a/initializers/aggregates.yml b/initializers/aggregates.yml index 3dc65e6..d923a04 100644 --- a/initializers/aggregates.yml +++ b/initializers/aggregates.yml @@ -1,4 +1,6 @@ -#- prefix: 10.0.0.0/16 -# rir: RFC1918 -#- prefix: fd00:ccdd::/32 -# rir: RFC4193 ULA +# - prefix: 10.0.0.0/16 +# rir: RFC1918 +# - prefix: fd00:ccdd::/32 +# rir: RFC4193 ULA +# - prefix: 2001:db8::/32 +# rir: RFC3849 diff --git a/initializers/cluster_types.yml b/initializers/cluster_types.yml index 03365ae..136dd1d 100644 --- a/initializers/cluster_types.yml +++ b/initializers/cluster_types.yml @@ -1,2 +1,2 @@ -#- name: Hyper-V -# slug: hyper-v +# - name: Hyper-V +# slug: hyper-v diff --git a/initializers/clusters.yml b/initializers/clusters.yml index a8dc121..1b1aca0 100644 --- a/initializers/clusters.yml +++ b/initializers/clusters.yml @@ -1,5 +1,5 @@ -#- name: cluster1 -# type: Hyper-V -#- name: cluster2 -# type: Hyper-V -# site: SING 1 +# - name: cluster1 +# type: Hyper-V +# - name: cluster2 +# type: Hyper-V +# site: SING 1 diff --git a/initializers/dcim_interfaces.yml b/initializers/dcim_interfaces.yml index 9a73a47..18920fe 100644 --- a/initializers/dcim_interfaces.yml +++ b/initializers/dcim_interfaces.yml @@ -1,8 +1,8 @@ -#- device: server01 -# enabled: true -# type: Virtual -# name: to-server02 -#- device: server02 -# enabled: true -# type: Virtual -# name: to-server01 +# - device: server01 +# enabled: true +# type: Virtual +# name: to-server02 +# - device: server02 +# enabled: true +# type: Virtual +# name: to-server01 diff --git a/initializers/device_types.yml b/initializers/device_types.yml index d0e4c36..9b27da3 100644 --- a/initializers/device_types.yml +++ b/initializers/device_types.yml @@ -17,7 +17,7 @@ # custom_fields: # text_field: Description # - model: Other -# manufacturer: NoName +# manufacturer: No Name # slug: other # custom_fields: # text_field: Description diff --git a/initializers/ip_addresses.yml b/initializers/ip_addresses.yml index 29a3917..5738749 100644 --- a/initializers/ip_addresses.yml +++ b/initializers/ip_addresses.yml @@ -1,13 +1,26 @@ -#- address: 10.1.1.1/24 -# device: server01 -# interface: to-server02 -# status: Active -# vrf: vrf1 -#- address: 10.1.1.2/24 -# device: server02 -# interface: to-server01 -# status: Active -#- address: 10.1.1.10/24 -# description: reserved IP -# status: Reserved -# tenant: tenant1 +# - address: 10.1.1.1/24 +# device: server01 +# interface: to-server02 +# status: Active +# vrf: vrf1 +# - address: 2001:db8:a000:1::1/64 +# device: server01 +# interface: to-server02 +# status: Active +# vrf: vrf1 +# - address: 10.1.1.2/24 +# device: server02 +# interface: to-server01 +# status: Active +# - address: 2001:db8:a000:1::2/64 +# device: server02 +# interface: to-server01 +# status: Active +# - address: 10.1.1.10/24 +# description: reserved IP +# status: Reserved +# tenant: tenant1 +# - address: 2001:db8:a000:1::10/64 +# description: reserved IP +# status: Reserved +# tenant: tenant1 diff --git a/initializers/manufacturers.yml b/initializers/manufacturers.yml index d737a5f..023e8e1 100644 --- a/initializers/manufacturers.yml +++ b/initializers/manufacturers.yml @@ -2,5 +2,5 @@ # slug: manufacturer-1 # - name: Manufacturer 2 # slug: manufacturer-2 -# - name: NoName -# slug: noname +# - name: No Name +# slug: no-name diff --git a/initializers/platforms.yml b/initializers/platforms.yml index 732dbeb..b0b7ba3 100644 --- a/initializers/platforms.yml +++ b/initializers/platforms.yml @@ -10,6 +10,6 @@ # napalm_args: "{'arg1': 'value1', 'arg2': 'value2'}" # - name: Platform 3 # slug: platform-3 -# manufacturer: NoName +# manufacturer: No Name # napalm_driver: driver3 # napalm_args: "{'arg1': 'value1', 'arg2': 'value2'}" diff --git a/initializers/prefix_vlan_roles.yml b/initializers/prefix_vlan_roles.yml index 309acc9..0ea7720 100644 --- a/initializers/prefix_vlan_roles.yml +++ b/initializers/prefix_vlan_roles.yml @@ -1,2 +1,2 @@ -#- name: Main Management -# slug: main-management +# - name: Main Management +# slug: main-management diff --git a/initializers/prefixes.yml b/initializers/prefixes.yml index f70685c..a7e6815 100644 --- a/initializers/prefixes.yml +++ b/initializers/prefixes.yml @@ -1,20 +1,20 @@ -#- description: prefix1 -# prefix: 10.1.1.0/24 -# site: AMS 1 -# status: Active -# tenant: tenant1 -# vlan: vlan1 -#- description: prefix2 -# prefix: 10.1.2.0/24 -# site: AMS 2 -# status: Active -# tenant: tenant2 -# vlan: vlan2 -# is_pool: true -# vrf: vrf2 -#- description: ipv6 prefix1 -# prefix: fd00:ccdd:a000:1::/64 -# site: AMS 2 -# status: Active -# tenant: tenant2 -# vlan: vlan2 +# - description: prefix1 +# prefix: 10.1.1.0/24 +# site: AMS 1 +# status: Active +# tenant: tenant1 +# vlan: vlan1 +# - description: prefix2 +# prefix: 10.1.2.0/24 +# site: AMS 2 +# status: Active +# tenant: tenant2 +# vlan: vlan2 +# is_pool: true +# vrf: vrf2 +# - description: ipv6 prefix1 +# prefix: 2001:db8:a000:1::/64 +# site: AMS 2 +# status: Active +# tenant: tenant2 +# vlan: vlan2 diff --git a/initializers/rirs.yml b/initializers/rirs.yml index 1a0c84d..0aacd59 100644 --- a/initializers/rirs.yml +++ b/initializers/rirs.yml @@ -1,6 +1,9 @@ -#- is_private: true -# name: RFC1918 -# slug: rfc1918 -#- is_private: true -# name: RFC4193 ULA -# slug: rfc4193-ula +# - is_private: true +# name: RFC1918 +# slug: rfc1918 +# - is_private: true +# name: RFC4193 ULA +# slug: rfc4193-ula +# - is_private: true +# name: RFC3849 +# slug: rfc3849 diff --git a/initializers/tenant_groups.yml b/initializers/tenant_groups.yml index 53f0ce8..87ecd4d 100644 --- a/initializers/tenant_groups.yml +++ b/initializers/tenant_groups.yml @@ -1,4 +1,4 @@ -#- name: Tenant Group 1 -# slug: tenant-group-1 -#- name: Tenant Group 2 -# slug: tenant-group-2 +# - name: Tenant Group 1 +# slug: tenant-group-1 +# - name: Tenant Group 2 +# slug: tenant-group-2 diff --git a/initializers/tenants.yml b/initializers/tenants.yml index 86db54f..1dbfbe5 100644 --- a/initializers/tenants.yml +++ b/initializers/tenants.yml @@ -1,5 +1,5 @@ -#- name: tenant1 -# slug: tenant1 -#- name: tenant2 -# slug: tenant2 -# group: Tenant Group 2 +# - name: tenant1 +# slug: tenant1 +# - name: tenant2 +# slug: tenant2 +# group: Tenant Group 2 diff --git a/initializers/virtual_machines.yml b/initializers/virtual_machines.yml index ca61a80..5da75a2 100644 --- a/initializers/virtual_machines.yml +++ b/initializers/virtual_machines.yml @@ -1,18 +1,18 @@ -#- cluster: cluster1 -# comments: VM1 -# disk: 200 -# memory: 4096 -# name: virtual machine 1 -# platform: Platform 2 -# status: Active -# tenant: tenant1 -# vcpus: 8 -#- cluster: cluster1 -# comments: VM2 -# disk: 100 -# memory: 2048 -# name: virtual machine 2 -# platform: Platform 2 -# status: Active -# tenant: tenant1 -# vcpus: 8 +# - cluster: cluster1 +# comments: VM1 +# disk: 200 +# memory: 4096 +# name: virtual machine 1 +# platform: Platform 2 +# status: Active +# tenant: tenant1 +# vcpus: 8 +# - cluster: cluster1 +# comments: VM2 +# disk: 100 +# memory: 2048 +# name: virtual machine 2 +# platform: Platform 2 +# status: Active +# tenant: tenant1 +# vcpus: 8 diff --git a/initializers/virtualization_interfaces.yml b/initializers/virtualization_interfaces.yml index 37d3252..aeedd58 100644 --- a/initializers/virtualization_interfaces.yml +++ b/initializers/virtualization_interfaces.yml @@ -1,12 +1,12 @@ -#- description: Network Interface 1 -# enabled: true -# mac_address: 00:77:77:77:77:77 -# mtu: 1500 -# name: Network Interface 1 -# virtual_machine: virtual machine 1 -#- description: Network Interface 2 -# enabled: true -# mac_address: 00:55:55:55:55:55 -# mtu: 1500 -# name: Network Interface 2 -# virtual_machine: virtual machine 1 +# - description: Network Interface 1 +# enabled: true +# mac_address: 00:77:77:77:77:77 +# mtu: 1500 +# name: Network Interface 1 +# virtual_machine: virtual machine 1 +# - description: Network Interface 2 +# enabled: true +# mac_address: 00:55:55:55:55:55 +# mtu: 1500 +# name: Network Interface 2 +# virtual_machine: virtual machine 1 diff --git a/initializers/vlan_groups.yml b/initializers/vlan_groups.yml index 81546eb..3e0bb00 100644 --- a/initializers/vlan_groups.yml +++ b/initializers/vlan_groups.yml @@ -1,6 +1,6 @@ -#- name: VLAN group 1 -# site: AMS 1 -# slug: vlan-group-1 -#- name: VLAN group 2 -# site: AMS 1 -# slug: vlan-group-2 +# - name: VLAN group 1 +# site: AMS 1 +# slug: vlan-group-1 +# - name: VLAN group 2 +# site: AMS 1 +# slug: vlan-group-2 diff --git a/initializers/vlans.yml b/initializers/vlans.yml index c78f6ca..26532c7 100644 --- a/initializers/vlans.yml +++ b/initializers/vlans.yml @@ -1,11 +1,11 @@ -#- name: vlan1 -# site: AMS 1 -# status: Active -# vid: 5 -# role: Main Management -# description: VLAN 5 for MGMT -#- group: VLAN group 2 -# name: vlan2 -# site: AMS 1 -# status: Active -# vid: 1300 +# - name: vlan1 +# site: AMS 1 +# status: Active +# vid: 5 +# role: Main Management +# description: VLAN 5 for MGMT +# - group: VLAN group 2 +# name: vlan2 +# site: AMS 1 +# status: Active +# vid: 1300 diff --git a/initializers/vrfs.yml b/initializers/vrfs.yml index fd50d87..40b9031 100644 --- a/initializers/vrfs.yml +++ b/initializers/vrfs.yml @@ -1,8 +1,8 @@ -#- enforce_unique: true -# name: vrf1 -# tenant: tenant1 -# description: main VRF -#- enforce_unique: true -# name: vrf2 -# rd: "6500:6500" -# tenant: tenant2 +# - enforce_unique: true +# name: vrf1 +# tenant: tenant1 +# description: main VRF +# - enforce_unique: true +# name: vrf2 +# rd: "6500:6500" +# tenant: tenant2