Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to set / update primary_ip4 on virtual machine per API PATCH request #2342

Closed
hensoko opened this issue Aug 9, 2018 · 3 comments
Closed
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@hensoko
Copy link

hensoko commented Aug 9, 2018

Hi,

we're experiencing some issues with setting primary IPs on virtual machines via Netbox API (PATCH request). We're running Netbox 2.4.2 (even happened with 2.4.0 / 2.4.1) in a Debian 8 Environment with Python 3.5.4 / PostgreSQL 10.3 and Nginx 1.12.2 as reverse proxy. I found thread on the mailing list describing excatly the same issue: https://groups.google.com/forum/#!topic/netbox-discuss/bqLY8cyU2ns

Environment

  • Python version: 3.5.4
  • NetBox version: 2.4.2

Steps to Reproduce

  • Create a virtual machine
  • curl -i -sSL -H "Authorization: Token <token>" -H "Content-Type: application/json" -H "Accept: application/json" -X PATCH -d '{"primary_ip4":12341}' https://<netbox_url>/api/virtualization/virtual-machines/1231/

Expected Behavior

The primary ip address gets set / updated

Actual behaviour

HTTP/1.1 500 Internal Server Error
Server: nginx
Date: Thu, 09 Aug 2018 10:35:02 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 1890
Connection: keep-alive
X-Frame-Options: SAMEORIGIN
API-Version: 2.4
Vary: Cookie, Origin

<!DOCTYPE html>
<html lang="en">

<head>
    <title>Server Error</title>
    <link rel="stylesheet" href="/static/bootstrap-3.3.7-dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="/static/font-awesome-4.7.0/css/font-awesome.min.css">
    <meta charset="UTF-8">
</head>

<body>
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-6 col-md-offset-3">
                <div class="panel panel-danger" style="margin-top: 200px">
                    <div class="panel-heading">
                        <strong>
                            <i class="fa fa-warning"></i>
                            Server Error
                        </strong>
                    </div>
                    <div class="panel-body">
                        
                            <p>
                                There was a problem with your request. Please contact an administrator.
                            </p>
                        
                        <hr />
                        <p>
                            The complete exception is provided below:
                        </p>
<pre><strong>&lt;class &#39;django.db.utils.IntegrityError&#39;&gt;</strong><br />
duplicate key value violates unique constraint &quot;virtualization_virtualmachine_primary_ip4_id_key&quot;
DETAIL:  Key (primary_ip4_id)=(12341) already exists.
</pre>
                        <p>
                            If further assistance is required, please post to the <a href="https://groups.google.com/forum/#!forum/netbox-discuss">NetBox mailing list</a>.
                        </p>
                        <div class="text-right">
                            <a href="/" class="btn btn-primary">Home Page</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
@jeremystretch
Copy link
Member

The IntegrityError indicates that this IP address is already assigned as the primary IP for a different VM: It can't also be assigned to this one. However, this should return a validation error rather than an exception.

It seems that the serializer isn't validating the OneToOneField properly. I'll need to dig into this more.

@jeremystretch jeremystretch added type: bug A confirmed report of unexpected behavior in the application status: accepted This issue has been accepted for implementation labels Aug 9, 2018
@hensoko
Copy link
Author

hensoko commented Aug 9, 2018

Hey,

thanks for the quick reply. I just checked it in the database. Actually the IP-Address is set as primary on a different virtual machine where it is not assigend to an interface. So this seems to be the reason for the database error but I think it shouldn't be possible to set an ip address as primary when this ip address isn't actually assigned to an interface of this device / virtual machine, right?

Besides that: thanks for the great work so far, we're first-time users of netbox and very happy about it and the progress it made until today :).

Regards

Hendrik

@hensoko hensoko changed the title Unable to set / upadate primary_ip4 on virtual machine per API PATCH request Unable to set / update primary_ip4 on virtual machine per API PATCH request Aug 9, 2018
@hensoko
Copy link
Author

hensoko commented Aug 12, 2018

Hey @jeremystretch,

thanks for fixing this. But I still have the occurence that if an IP-Address is reassigned to another VM the primay IP configuration of the former VM does not get removed.

I guess the primary IP assignment should be removed from the VM in the moment the actual IP-Address is no longer assigned to this perticular VM.

Do you agree?

@lock lock bot locked as resolved and limited conversation to collaborators Jan 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

2 participants