Add allowed VLAN to Virtual Server - Python F5-SDK

I’m trying to set the allowed vlan on a virtual server using the Python SDK.

Here’s my code

newvs = vs.virtual.create(name='myvs', destination='10.0.0.1:80')
newvs.mask = '255.255.255.255'
newvs.pool = 'mypool'
newvs.vlansDisabled = False
newvs.vlansEnabled = True
newvs.vlan = 'myvlan'
newvs.update()

The script runs successfully but the vlan is not added to the allowed vlan list.

If I add the vlan manually via the config utility and browse the API I noticed the vlan option uses square brackets [].

vlans: [ “/Common/myvlan” ]

Please advise. :slightly_smiling_face:

After a few hours of troubleshooting I found the solution.

newvs.vlans = ['myvlan']

I would advise against using an absolute update on a BIG-IP object as this activates the custom checkbox for every setting - unless this is your intent

Instead of

newvs = vs.virtual.create(name='myvs', destination='10.0.0.1:80')
newvs.mask = '255.255.255.255'
newvs.update()

Use this approach

newvs = vs.virtual.create(name='myvs', destination='10.0.0.1:80')
newvs.update(mask='255.255.255.255')