Repository: netbox-community/netbox

Issue:
Set VRF for available IPs to same VRF as parent prefix
<!--
    NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED.

    This form is only for reporting reproducible bugs. If you need assistance
    with NetBox installation, or if you have a general question, please start a
    discussion instead: https://github.com/netbox-community/netbox/discussions

    Please describe the environment in which you are running NetBox. Be sure
    that you are running an unmodified instance of the latest stable release
    before submitting a bug report, and that any plugins have been disabled.
-->
### Environment
* Python version: 3.7.3
* NetBox version: 2.10.1

<!--
    Describe in detail the exact steps that someone else can take to reproduce
    this bug using the current stable release of NetBox. Begin with the
    creation of any necessary database objects and call out every operation
    being performed explicitly. If reporting a bug in the REST API, be sure to
    reconstruct the raw HTTP request(s) being made: Don't rely on a client
    library such as pynetbox.
-->
### Steps to Reproduce
1. Create prefix in VRF Global
2. Change VRF of the prefix to a specific VRF
3. Go to /ipam/prefixes/{prefix-id}/ip-addresses/

<!-- What did you expect to happen? -->
### Expected Behavior
The available IP's are preset to the VRF of the parent prefix.
When clicking the "x available IPs" button, it will create an IP with the VRF of the parent prefix.

When using the button "+ add an ip address", the VRF is set correctly since it's redirecting to `/ipam/ip-addresses/add/?address=172.16.20.6/24&vrf=4&tenant_group=&tenant=`

<!-- What happened instead? -->
### Observed Behavior
The available IP's are still linked to VRF Global.
When clicking the "x available IPs" button, it will create an IP with VRF Global.

![image](https://user-images.githubusercontent.com/3859276/105998755-43eac480-60ad-11eb-9b13-fadc94a38583.png)




Discussion:
@DanSheps I'd call this a bug, not a feature. As I get more non-networking folks using netbox to self-assign IPs this is going to cause significant confusion.
I understand where you are coming from, but this isn't exactly a bug.

Resolving patch:
diff --git a/netbox/ipam/tables.py b/netbox/ipam/tables.py
--- a/netbox/ipam/tables.py
+++ b/netbox/ipam/tables.py
@@ -37,7 +37,7 @@
 {% if record.pk %}
     <a href="{{ record.get_absolute_url }}">{{ record.address }}</a>
 {% elif perms.ipam.add_ipaddress %}
-    <a href="{% url 'ipam:ipaddress_add' %}?address={{ record.1 }}{% if prefix.vrf %}&vrf={{ prefix.vrf.pk }}{% endif %}{% if prefix.tenant %}&tenant={{ prefix.tenant.pk }}{% endif %}" class="btn btn-xs btn-success">{% if record.0 <= 65536 %}{{ record.0 }}{% else %}Many{% endif %} IP{{ record.0|pluralize }} available</a>
+    <a href="{% url 'ipam:ipaddress_add' %}?address={{ record.1 }}{% if object.vrf %}&vrf={{ object.vrf.pk }}{% endif %}{% if object.tenant %}&tenant={{ object.tenant.pk }}{% endif %}" class="btn btn-xs btn-success">{% if record.0 <= 65536 %}{{ record.0 }}{% else %}Many{% endif %} IP{{ record.0|pluralize }} available</a>
 {% else %}
     {% if record.0 <= 65536 %}{{ record.0 }}{% else %}Many{% endif %} IP{{ record.0|pluralize }} available
 {% endif %}
@@ -50,8 +50,8 @@
 VRF_LINK = """
 {% if record.vrf %}
     <a href="{{ record.vrf.get_absolute_url }}">{{ record.vrf }}</a>
-{% elif prefix.vrf %}
-    {{ prefix.vrf }}
+{% elif object.vrf %}
+    <a href="{{ object.vrf.get_absolute_url }}">{{ object.vrf }}</a>
 {% else %}
     Global
 {% endif %}
@@ -114,6 +114,8 @@
     <a href="{% url 'tenancy:tenant' slug=record.tenant.slug %}" title="{{ record.tenant.description }}">{{ record.tenant }}</a>
 {% elif record.vrf.tenant %}
     <a href="{% url 'tenancy:tenant' slug=record.vrf.tenant.slug %}" title="{{ record.vrf.tenant.description }}">{{ record.vrf.tenant }}</a>*
+{% elif object.tenant %}
+    <a href="{% url 'tenancy:tenant' slug=object.tenant.slug %}" title="{{ object.tenant.description }}">{{ object.tenant }}</a>
 {% else %}
     &mdash;
 {% endif %}


Test patch: