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

Can't add multiple proxmox clusters to proxbox PLUGINS_CONFIG block. Issue with dict vs list #150

Open
vicbreen opened this issue Oct 2, 2023 · 2 comments
Assignees
Labels
accepted This issue has been accepted for implementation bug Further discussion is needed to determine this issue's scope and/or implementation

Comments

@vicbreen
Copy link

vicbreen commented Oct 2, 2023

I'm trying to add the netbox-proxbox plugin and running into an issue. In the plugin config there is supposed to be a list of dictionaries, each dict being individual proxmox clusters. i'm just trying to test with a single cluster, so my "proxmox" list has a single dict element. However, the error i'm getting running the update.py script seems to indicate it's doing a dict.get() against the "proxmox" list() which obviously won't work.

I was able to fix this problem by eliminating the list square brackets so there's just the single dictionary defined. But this fix makes it so only one cluster can be configured, and I would like to add 3 or 4 of them when I put this into production use.

Am I doing something wrong?

Config blob from configuration.py using template config from documentation

PLUGINS = ['netbox_napalm_plugin', 'netbox_proxbox']

PLUGINS_CONFIG = {
    'netbox_napalm_plugin': {
        'NAPALM_USERNAME': 'bada',
        'NAPALM_PASSWORD': 'boom',
    },
    'netbox_proxbox': {
        'proxmox': [
            {
                'domain': 'pve1.mydomain.net',    # May also be IP address
                'http_port': 8006,
                'user': 'root@pam',   # always required
                # 'password': 'Strong@P4ssword', # only required, if you don't want to use token based authentication
                'token': {
                    # Only type the token name and not the 'user@pam:tokenID' format
                    'name': 'MyToken',
                    'value': 'MyP455w0rd'
                },
                'ssl': True
            },
            # { planning to add another cluster dict here }
        ],
        'netbox': {
            'domain': 'localhost',     # Ensure localhost is added to ALLOWED_HOSTS
            'http_port': 8001,     # Gunicorn port.
            'token': 'l33tstr1ngh3r3',
            'ssl': False,	# There is no support to SSL on Netbox yet, so let it always False.
            'settings': {
                'virtualmachine_role_id' : 0,
                'node_role_id' : 0,
                'site_id': 0
            }
        }
    }
}

Output from netbox update.py script

Installing collected packages: pyserial, proxmoxer, yamlordereddictloader, ttp, transitions, pyparsing, pyeapi, pyasn1-modules, netutils, lxml, future, bcrypt, ttp-templates, textfsm, python-ldap, pynetbox, pynacl, paramiko, ntc-templates, netbox-proxbox, django-auth-ldap, scp, ncclient, netmiko, junos-eznc, napalm, netbox-napalm-plugin
Successfully installed bcrypt-4.0.1 django-auth-ldap-4.5.0 future-0.18.3 junos-eznc-2.6.7 lxml-4.9.3 napalm-4.1.0 ncclient-0.6.13 netbox-napalm-plugin-0.1.6 netbox-proxbox-0.0.5 netmiko-4.2.0 netutils-1.6.0 ntc-templates-3.5.0 paramiko-3.3.1 proxmoxer-2.0.1 pyasn1-modules-0.3.0 pyeapi-1.0.2 pynacl-1.5.0 pynetbox-7.2.0 pyparsing-3.1.1 pyserial-3.5 python-ldap-3.4.3 scp-0.14.5 textfsm-1.1.3 transitions-0.9.0 ttp-0.9.5 ttp-templates-0.3.5 yamlordereddictloader-0.4.2
Applying database migrations (python3 netbox/manage.py migrate)...
Traceback (most recent call last):
  File "/opt/netbox/netbox/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/opt/netbox/venv/lib64/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/opt/netbox/venv/lib64/python3.11/site-packages/django/core/management/__init__.py", line 382, in execute
    settings.INSTALLED_APPS
  File "/opt/netbox/venv/lib64/python3.11/site-packages/django/conf/__init__.py", line 102, in __getattr__
    self._setup(name)
  File "/opt/netbox/venv/lib64/python3.11/site-packages/django/conf/__init__.py", line 89, in _setup
    self._wrapped = Settings(settings_module)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib64/python3.11/site-packages/django/conf/__init__.py", line 217, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/opt/netbox/netbox/netbox/settings.py", line 729, in <module>
    plugin = importlib.import_module(plugin_name)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/opt/netbox/venv/lib64/python3.11/site-packages/netbox_proxbox/__init__.py", line 40, in <module>
    from . import proxbox_api
  File "/opt/netbox/venv/lib64/python3.11/site-packages/netbox_proxbox/proxbox_api/__init__.py", line 1, in <module>
    from . import (
  File "/opt/netbox/venv/lib64/python3.11/site-packages/netbox_proxbox/proxbox_api/update.py", line 2, in <module>
    from .plugins_config import (
  File "/opt/netbox/venv/lib64/python3.11/site-packages/netbox_proxbox/proxbox_api/plugins_config.py", line 73, in <module>
    PROXMOX = PROXMOX_SETTING.get("domain", DEFAULT_PROXMOX)
              ^^^^^^^^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'get'

I have confirmed the below config works when running update.py, by eliminating the list brackets and having a single 'proxmox' dict element in PLUGINS_CONFIG.

PLUGINS = ['netbox_napalm_plugin', 'netbox_proxbox']

PLUGINS_CONFIG = {
    'netbox_napalm_plugin': {
        'NAPALM_USERNAME': 'bada',
        'NAPALM_PASSWORD': 'boom',
    },
    'netbox_proxbox': {
        'proxmox': 
            {
                'domain': 'pve1.mydomain.net',    # May also be IP address
                'http_port': 8006,
                'user': 'root@pam',   # always required
                # 'password': 'Strong@P4ssword', # only required, if you don't want to use token based authentication
                'token': {
                    # Only type the token name and not the 'user@pam:tokenID' format
                    'name': 'MyToken',
                    'value': 'MyP455w0rd'
                },
                'ssl': True
            },

        'netbox': {
            'domain': 'localhost',     # Ensure localhost is added to ALLOWED_HOSTS
            'http_port': 8001,     # Gunicorn port.
            'token': 'l33tstr1ngh3r3',
            'ssl': False,	# There is no support to SSL on Netbox yet, so let it always False.
            'settings': {
                'virtualmachine_role_id' : 0,
                'node_role_id' : 0,
                'site_id': 0
            }
        }
    }
}
@emersonfelipesp emersonfelipesp self-assigned this Oct 9, 2023
@emersonfelipesp emersonfelipesp added bug Further discussion is needed to determine this issue's scope and/or implementation accepted This issue has been accepted for implementation labels Oct 9, 2023
alryaz added a commit to alryaz/netbox-proxbox that referenced this issue Oct 10, 2023
@alryaz
Copy link

alryaz commented Oct 10, 2023

I pushed a commit that seems to solve this issue.

Unfortunately I also pushed another commit that contains a password + token fallback workaround (a little quality of life improvement).

I can revert my branch back to its "fix-only" state if such PR is unacceptable (given that two commits are being merged).

@scott-donnelly
Copy link

scott-donnelly commented Oct 12, 2023

I have got the same issue

File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/opt/netbox-3.5.8/venv/lib/python3.10/site-packages/netbox_proxbox/__init__.py", line 40, in <module>
    from . import proxbox_api
  File "/opt/netbox-3.5.8/venv/lib/python3.10/site-packages/netbox_proxbox/proxbox_api/__init__.py", line 1, in <module>
    from . import (
  File "/opt/netbox-3.5.8/venv/lib/python3.10/site-packages/netbox_proxbox/proxbox_api/update.py", line 2, in <module>
    from .plugins_config import (
  File "/opt/netbox-3.5.8/venv/lib/python3.10/site-packages/netbox_proxbox/proxbox_api/plugins_config.py", line 73, in <module>
    PROXMOX = PROXMOX_SETTING.get("domain", DEFAULT_PROXMOX)
AttributeError: 'list' object has no attribute 'get'

After removing the lists from inside the proxmox dictionary I've run into another error

  File "/opt/netbox-3.5.8/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 56, in inner
    response = get_response(request)
  File "/opt/netbox-3.5.8/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/opt/netbox-3.5.8/venv/lib/python3.10/site-packages/django/views/generic/base.py", line 103, in view
    return self.dispatch(request, *args, **kwargs)
  File "/opt/netbox-3.5.8/venv/lib/python3.10/site-packages/django/contrib/auth/mixins.py", line 109, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/opt/netbox-3.5.8/venv/lib/python3.10/site-packages/django/views/generic/base.py", line 142, in dispatch
    return handler(request, *args, **kwargs)
  File "/opt/netbox-3.5.8/venv/lib/python3.10/site-packages/netbox_proxbox/views.py", line 93, in get
    "virtualmachines_table": VMUpdateResult(proxbox_api.update.all(remove_unused = True)["virtualmachines"]),
  File "/opt/netbox-3.5.8/venv/lib/python3.10/site-packages/netbox_proxbox/proxbox_api/update.py", line 434, in all
    node_updated = nodes(proxmox_json = px_node_each, proxmox_cluster = proxmox_cluster)
  File "/opt/netbox-3.5.8/venv/lib/python3.10/site-packages/netbox_proxbox/proxbox_api/update.py", line 361, in nodes
    netbox_node = create.dcim.node(proxmox_json)
  File "/opt/netbox-3.5.8/venv/lib/python3.10/site-packages/netbox_proxbox/proxbox_api/create/dcim.py", line 145, in node
    node_json["device_role"] = extras.role(role_id = NETBOX_NODE_ROLE_ID).id
AttributeError: 'str' object has no attribute 'id'

Will wait to see what is done here before opening a separate issue for my second error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This issue has been accepted for implementation bug Further discussion is needed to determine this issue's scope and/or implementation
Projects
None yet
Development

No branches or pull requests

4 participants