Skip to content

Commit 4b203df

Browse files
authored
Merge pull request netbox-community#1323 from Ido-Don/github-issue-#975
fixing bug netbox-community#975
2 parents 33f3bc0 + 30cb663 commit 4b203df

File tree

7 files changed

+252
-0
lines changed

7 files changed

+252
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bugfixes:
2+
- netbox_ip_address - Fixed the problem preventing assignment of an IP address to a network interface

plugins/module_utils/netbox_ipam.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ def run(self):
205205
else:
206206
name = data.get("name")
207207

208+
if self.endpoint == "ip_addresses":
209+
if "interface" in data:
210+
data["assigned_object_id"] = data["interface"]
211+
data["assigned_object_type"] = "dcim.interface"
212+
208213
if self.endpoint in SLUG_REQUIRED:
209214
if not data.get("slug"):
210215
data["slug"] = self._to_slug(name)

tests/integration/targets/v3.5/tasks/netbox_ip_address.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,52 @@
348348
- test_sixteen['diff']['after']['state'] == "present"
349349
- test_sixteen['msg'] == "ip_address 10.120.10.1/32 created"
350350
- test_sixteen['ip_address']['address'] == "10.120.10.1/32"
351+
352+
- name: "17 - Create IP address on GigabitEthernet2 - test100 with interface value - State: present"
353+
netbox.netbox.netbox_ip_address:
354+
netbox_url: http://localhost:32768
355+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
356+
data:
357+
family: 4
358+
address: 10.10.200.31/16
359+
interface:
360+
device: test100
361+
name: GigabitEthernet2
362+
register: test_seventeen
363+
364+
- name: 17 - ASSERT
365+
ansible.builtin.assert:
366+
that:
367+
- test_seventeen is changed
368+
- test_seventeen['diff']['before']['state'] == "absent"
369+
- test_seventeen['diff']['after']['state'] == "present"
370+
- test_seventeen['msg'] == "ip_address 10.10.200.31/16 created"
371+
- test_seventeen['ip_address']['address'] == "10.10.200.31/16"
372+
- test_seventeen['ip_address']['family'] == 4
373+
- test_seventeen['ip_address']['assigned_object_type'] == "dcim.interface"
374+
- test_seventeen['ip_address']['assigned_object_id'] == 4
375+
376+
- name: "18 - Create IP address on GigabitEthernet2 - test100 with interface value - State: new"
377+
netbox.netbox.netbox_ip_address:
378+
netbox_url: http://localhost:32768
379+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
380+
data:
381+
family: 4
382+
prefix: 10.10.0.0/16
383+
interface:
384+
name: GigabitEthernet2
385+
device: test100
386+
state: new
387+
register: test_eighteen
388+
389+
- name: 18 - ASSERT
390+
ansible.builtin.assert:
391+
that:
392+
- test_eighteen is changed
393+
- test_eighteen['diff']['before']['state'] == "absent"
394+
- test_eighteen['diff']['after']['state'] == "present"
395+
- test_eighteen['msg'] == "ip_address 10.10.0.2/16 created"
396+
- test_eighteen['ip_address']['address'] == "10.10.0.2/16"
397+
- test_eighteen['ip_address']['family'] == 4
398+
- test_eighteen['ip_address']['assigned_object_type'] == "dcim.interface"
399+
- test_eighteen['ip_address']['assigned_object_id'] == 4

tests/integration/targets/v3.6/tasks/netbox_ip_address.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,52 @@
348348
- test_sixteen['diff']['after']['state'] == "present"
349349
- test_sixteen['msg'] == "ip_address 10.120.10.1/32 created"
350350
- test_sixteen['ip_address']['address'] == "10.120.10.1/32"
351+
352+
- name: "17 - Create IP address on GigabitEthernet2 - test100 with interface value - State: present"
353+
netbox.netbox.netbox_ip_address:
354+
netbox_url: http://localhost:32768
355+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
356+
data:
357+
family: 4
358+
address: 10.10.200.31/16
359+
interface:
360+
device: test100
361+
name: GigabitEthernet2
362+
register: test_seventeen
363+
364+
- name: 17 - ASSERT
365+
ansible.builtin.assert:
366+
that:
367+
- test_seventeen is changed
368+
- test_seventeen['diff']['before']['state'] == "absent"
369+
- test_seventeen['diff']['after']['state'] == "present"
370+
- test_seventeen['msg'] == "ip_address 10.10.200.31/16 created"
371+
- test_seventeen['ip_address']['address'] == "10.10.200.31/16"
372+
- test_seventeen['ip_address']['family'] == 4
373+
- test_seventeen['ip_address']['assigned_object_type'] == "dcim.interface"
374+
- test_seventeen['ip_address']['assigned_object_id'] == 4
375+
376+
- name: "18 - Create IP address on GigabitEthernet2 - test100 with interface value - State: new"
377+
netbox.netbox.netbox_ip_address:
378+
netbox_url: http://localhost:32768
379+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
380+
data:
381+
family: 4
382+
prefix: 10.10.0.0/16
383+
interface:
384+
name: GigabitEthernet2
385+
device: test100
386+
state: new
387+
register: test_eighteen
388+
389+
- name: 18 - ASSERT
390+
ansible.builtin.assert:
391+
that:
392+
- test_eighteen is changed
393+
- test_eighteen['diff']['before']['state'] == "absent"
394+
- test_eighteen['diff']['after']['state'] == "present"
395+
- test_eighteen['msg'] == "ip_address 10.10.0.2/16 created"
396+
- test_eighteen['ip_address']['address'] == "10.10.0.2/16"
397+
- test_eighteen['ip_address']['family'] == 4
398+
- test_eighteen['ip_address']['assigned_object_type'] == "dcim.interface"
399+
- test_eighteen['ip_address']['assigned_object_id'] == 4

tests/integration/targets/v3.7/tasks/netbox_ip_address.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,52 @@
350350
- test_sixteen['diff']['after']['state'] == "present"
351351
- test_sixteen['msg'] == "ip_address 10.120.10.1/32 created"
352352
- test_sixteen['ip_address']['address'] == "10.120.10.1/32"
353+
354+
- name: "17 - Create IP address on GigabitEthernet2 - test100 with interface value - State: present"
355+
netbox.netbox.netbox_ip_address:
356+
netbox_url: http://localhost:32768
357+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
358+
data:
359+
family: 4
360+
address: 10.10.200.31/16
361+
interface:
362+
device: test100
363+
name: GigabitEthernet2
364+
register: test_seventeen
365+
366+
- name: 17 - ASSERT
367+
ansible.builtin.assert:
368+
that:
369+
- test_seventeen is changed
370+
- test_seventeen['diff']['before']['state'] == "absent"
371+
- test_seventeen['diff']['after']['state'] == "present"
372+
- test_seventeen['msg'] == "ip_address 10.10.200.31/16 created"
373+
- test_seventeen['ip_address']['address'] == "10.10.200.31/16"
374+
- test_seventeen['ip_address']['family'] == 4
375+
- test_seventeen['ip_address']['assigned_object_type'] == "dcim.interface"
376+
- test_seventeen['ip_address']['assigned_object_id'] == 4
377+
378+
- name: "18 - Create IP address on GigabitEthernet2 - test100 with interface value - State: new"
379+
netbox.netbox.netbox_ip_address:
380+
netbox_url: http://localhost:32768
381+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
382+
data:
383+
family: 4
384+
prefix: 10.10.0.0/16
385+
interface:
386+
name: GigabitEthernet2
387+
device: test100
388+
state: new
389+
register: test_eighteen
390+
391+
- name: 18 - ASSERT
392+
ansible.builtin.assert:
393+
that:
394+
- test_eighteen is changed
395+
- test_eighteen['diff']['before']['state'] == "absent"
396+
- test_eighteen['diff']['after']['state'] == "present"
397+
- test_eighteen['msg'] == "ip_address 10.10.0.2/16 created"
398+
- test_eighteen['ip_address']['address'] == "10.10.0.2/16"
399+
- test_eighteen['ip_address']['family'] == 4
400+
- test_eighteen['ip_address']['assigned_object_type'] == "dcim.interface"
401+
- test_eighteen['ip_address']['assigned_object_id'] == 4

tests/integration/targets/v4.0/tasks/netbox_ip_address.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,52 @@
350350
- test_sixteen['diff']['after']['state'] == "present"
351351
- test_sixteen['msg'] == "ip_address 10.120.10.1/32 created"
352352
- test_sixteen['ip_address']['address'] == "10.120.10.1/32"
353+
354+
- name: "17 - Create IP address on GigabitEthernet2 - test100 with interface value - State: present"
355+
netbox.netbox.netbox_ip_address:
356+
netbox_url: http://localhost:32768
357+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
358+
data:
359+
family: 4
360+
address: 10.10.200.31/16
361+
interface:
362+
device: test100
363+
name: GigabitEthernet2
364+
register: test_seventeen
365+
366+
- name: 17 - ASSERT
367+
ansible.builtin.assert:
368+
that:
369+
- test_seventeen is changed
370+
- test_seventeen['diff']['before']['state'] == "absent"
371+
- test_seventeen['diff']['after']['state'] == "present"
372+
- test_seventeen['msg'] == "ip_address 10.10.200.31/16 created"
373+
- test_seventeen['ip_address']['address'] == "10.10.200.31/16"
374+
- test_seventeen['ip_address']['family'] == 4
375+
- test_seventeen['ip_address']['assigned_object_type'] == "dcim.interface"
376+
- test_seventeen['ip_address']['assigned_object_id'] == 4
377+
378+
- name: "18 - Create IP address on GigabitEthernet2 - test100 with interface value - State: new"
379+
netbox.netbox.netbox_ip_address:
380+
netbox_url: http://localhost:32768
381+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
382+
data:
383+
family: 4
384+
prefix: 10.10.0.0/16
385+
interface:
386+
name: GigabitEthernet2
387+
device: test100
388+
state: new
389+
register: test_eighteen
390+
391+
- name: 18 - ASSERT
392+
ansible.builtin.assert:
393+
that:
394+
- test_eighteen is changed
395+
- test_eighteen['diff']['before']['state'] == "absent"
396+
- test_eighteen['diff']['after']['state'] == "present"
397+
- test_eighteen['msg'] == "ip_address 10.10.0.2/16 created"
398+
- test_eighteen['ip_address']['address'] == "10.10.0.2/16"
399+
- test_eighteen['ip_address']['family'] == 4
400+
- test_eighteen['ip_address']['assigned_object_type'] == "dcim.interface"
401+
- test_eighteen['ip_address']['assigned_object_id'] == 4

tests/integration/targets/v4.1/tasks/netbox_ip_address.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,52 @@
350350
- test_sixteen['diff']['after']['state'] == "present"
351351
- test_sixteen['msg'] == "ip_address 10.120.10.1/32 created"
352352
- test_sixteen['ip_address']['address'] == "10.120.10.1/32"
353+
354+
- name: "17 - Create IP address on GigabitEthernet2 - test100 with interface value - State: present"
355+
netbox.netbox.netbox_ip_address:
356+
netbox_url: http://localhost:32768
357+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
358+
data:
359+
family: 4
360+
address: 10.10.200.31/16
361+
interface:
362+
device: test100
363+
name: GigabitEthernet2
364+
register: test_seventeen
365+
366+
- name: 17 - ASSERT
367+
ansible.builtin.assert:
368+
that:
369+
- test_seventeen is changed
370+
- test_seventeen['diff']['before']['state'] == "absent"
371+
- test_seventeen['diff']['after']['state'] == "present"
372+
- test_seventeen['msg'] == "ip_address 10.10.200.31/16 created"
373+
- test_seventeen['ip_address']['address'] == "10.10.200.31/16"
374+
- test_seventeen['ip_address']['family'] == 4
375+
- test_seventeen['ip_address']['assigned_object_type'] == "dcim.interface"
376+
- test_seventeen['ip_address']['assigned_object_id'] == 4
377+
378+
- name: "18 - Create IP address on GigabitEthernet2 - test100 with interface value - State: new"
379+
netbox.netbox.netbox_ip_address:
380+
netbox_url: http://localhost:32768
381+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
382+
data:
383+
family: 4
384+
prefix: 10.10.0.0/16
385+
interface:
386+
name: GigabitEthernet2
387+
device: test100
388+
state: new
389+
register: test_eighteen
390+
391+
- name: 18 - ASSERT
392+
ansible.builtin.assert:
393+
that:
394+
- test_eighteen is changed
395+
- test_eighteen['diff']['before']['state'] == "absent"
396+
- test_eighteen['diff']['after']['state'] == "present"
397+
- test_eighteen['msg'] == "ip_address 10.10.0.2/16 created"
398+
- test_eighteen['ip_address']['address'] == "10.10.0.2/16"
399+
- test_eighteen['ip_address']['family'] == 4
400+
- test_eighteen['ip_address']['assigned_object_type'] == "dcim.interface"
401+
- test_eighteen['ip_address']['assigned_object_id'] == 4

0 commit comments

Comments
 (0)