Skip to content

Vlan changes to several devices in the same script call not possible #38

@f4mf4t4l

Description

@f4mf4t4l

I try to configure a vlan on multiple devices. When doing this within one script i get an exception on the second device. The vlan was set though.

Script:

import urllib3

from pyaoscx.session import Session 
from pyaoscx.vlan import Vlan 

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

vlan_id = "16"

s1 = Session("switch1", "10.04")
s1.open("user", "password")

vlan1 = Vlan(s1, vlan_id)
vlan1.apply()

s1.close()

s2 = Session("switch2", "10.04")
s2.open("user", "password")

vlan2 = Vlan(s2, vlan_id)
vlan2.apply()

s2.close()

Exception:

Traceback (most recent call last):
  File "./test1.py", line 26, in <module>
    vlan2.apply()
    └ <pyaoscx.vlan.Vlan object at 0x7355221a6280>
  File ".virtualenvs/pyaoscx26/lib/python3.9/site-packages/pyaoscx/pyaoscx_module.py", line 40, in ensure_connected
    return fnct(self, *args, **kwargs)
           │    │      │       └ {}
           │    │      └ ()
           │    └ <pyaoscx.vlan.Vlan object at 0x7355221a6280>
           └ <function Vlan.apply at 0x7355221feaf0>
  File ".virtualenvs/pyaoscx26/lib/python3.9/site-packages/pyaoscx/vlan.py", line 213, in apply
    modified = self.create()
    │          └ <pyaoscx.vlan.Vlan object at 0x7355221a6280>
    └ False
  File ".virtualenvs/pyaoscx26/lib/python3.9/site-packages/pyaoscx/pyaoscx_module.py", line 40, in ensure_connected
    return fnct(self, *args, **kwargs)
           │    │      │       └ {}
           │    │      └ ()
           │    └ <pyaoscx.vlan.Vlan object at 0x7355221a6280>
           └ <function Vlan.create at 0x7355221fed30>
  File "/home/fam/.virtualenvs/pyaoscx26/lib/python3.9/site-packages/pyaoscx/vlan.py", line 299, in create
    return self._post_data(vlan_data)
           │               └ {'mgmd_enable': {}, 'id': 16, 'name': 'VLAN 16'}
           └ <pyaoscx.vlan.Vlan object at 0x7355221a6280>
  File ".virtualenvs/pyaoscx26/lib/python3.9/site-packages/pyaoscx/pyaoscx_module.py", line 253, in _post_data
    self.get()
    └ <pyaoscx.vlan.Vlan object at 0x7355221a6280>
  File ".virtualenvs/pyaoscx26/lib/python3.9/site-packages/pyaoscx/pyaoscx_module.py", line 40, in ensure_connected
    return fnct(self, *args, **kwargs)
           │    │      │       └ {}
           │    │      └ ()
           │    └ <pyaoscx.vlan.Vlan object at 0x7355221a6280>
           └ <function Vlan.get at 0x7355221fe940>
  File "/home/fam/.virtualenvs/pyaoscx26/lib/python3.9/site-packages/pyaoscx/vlan.py", line 86, in get
    self.vsx_sync = data.pop("vsx_sync")
    │               └ {'aclmac_in_cfg': None, 'aclmac_in_cfg_version': None, 'aclv4_in_cfg': None, 'aclv4_in_cfg_version': None, 'aclv4_out_cfg': None...
    └ <pyaoscx.vlan.Vlan object at 0x7355221a6280>
  File ".virtualenvs/pyaoscx26/lib/python3.9/site-packages/pyaoscx/vlan.py", line 308, in vsx_sync
    device.get(selector="status")
    └ <pyaoscx.device.Device object at 0x7355221a6790>
  File ".virtualenvs/pyaoscx26/lib/python3.9/site-packages/pyaoscx/pyaoscx_module.py", line 40, in ensure_connected
    return fnct(self, *args, **kwargs)
           │    │      │       └ {'selector': 'status'}
           │    │      └ ()
           │    └ <pyaoscx.device.Device object at 0x7355221a6790>
           └ <function Device.get at 0x7355221c9c10>
  File ".virtualenvs/pyaoscx26/lib/python3.9/site-packages/pyaoscx/device.py", line 74, in get
    raise GenericOperationError(response.text, response.status_code)
          │                     │              └ <Response [401]>
          │                     └ <Response [401]>
          └ <class 'pyaoscx.exceptions.generic_op_error.GenericOperationError'>
pyaoscx.exceptions.generic_op_error.GenericOperationError: 'GENERIC OPERATION ERROR: Unauthorized: Code: 401'

The problem exists since pyaoscx version 2.2.0, where the class “Singleton” was introduced in pyaoscx_factory.py. It looks like the old instance is cached.
There is a workaround by setting the following after each session close:

Device._Singleton__instance = None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions