pynetbox icon indicating copy to clipboard operation
pynetbox copied to clipboard

Can't create virtual machines

Open syncopsta opened this issue 3 years ago • 1 comments

Code:

import pynetbox
nb = pynetbox.api('http://localhost', token=<token>)
nb.http_session.verify = False

vm = nb.virtualization.virtual_machines.create(dict(
        name="testing",
        cluster={"name":"prx"}
))
print(repr(vm))
vm.save()

Error:

/usr/lib/python3/dist-packages/urllib3/connectionpool.py:1015: InsecureRequestWarning: Unverified HTTPS request is being made to host 'localhost'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  warnings.warn(

Traceback (most recent call last):
  File "/root/test.py", line 10, in <module>
    vm.save()
  File "/usr/local/lib/python3.9/dist-packages/pynetbox/core/response.py", line 529, in save
    updates = self.updates()
  File "/usr/local/lib/python3.9/dist-packages/pynetbox/core/response.py", line 505, in updates
    if self.id:
  File "/usr/local/lib/python3.9/dist-packages/pynetbox/core/response.py", line 298, in __getattr__
    raise AttributeError('object has no attribute "{}"'.format(k))
AttributeError: object has no attribute "id"

root@netbox:~# pip3 show pynetbox Name: pynetbox Version: 6.6.2

Netbox version is v3.3.2

Am I doing something wrong?

syncopsta avatar Sep 21 '22 13:09 syncopsta

Works here:

>>> netbox.status()["netbox-version"]
'3.3.4'
>>> pynetbox.__version__
'6.6.2'
>>> vm = netbox.virtualization.virtual_machines.create(dict(name="TestVM123", cluster={"name":"Cluster1"}))
>>> vm
TestVM123
>>> print(repr(vm))
TestVM123
>>> vm.save()
False
>>>

Am I doing something wrong?

Probably, my guess is that you have incorrect URL:

http://localhost

InsecureRequestWarning: Unverified HTTPS request is being made to host 'localhost'

so apparently there is a redirect that messes up the results.

markkuleinio avatar Sep 25 '22 10:09 markkuleinio

Closing this for cleanup see markkuleinio note above.

arthanson avatar Nov 18 '22 19:11 arthanson