Forum Discussion

Maylin's avatar
Maylin
Icon for Nimbostratus rankNimbostratus
Feb 02, 2021

Trying to create VIPs via Python and get an error

Here is the snippet of code that is used to create the VIPs on the f5;

 

rv0=revisedServer.replace("dev_","test_vip_")

  print (eachServer[0][3].upper())

  rv1=eachServer[0][3].upper()

  params = {'name': rv0, 'source': "0.0.0.0/0", 'description': "TEST VS",'protocol': rv1,'pool': revisedServer,'profiles': profiles,'partition': 'Common','sourceAddressTranslation': {'type': 'snat'},'vlansEnabled': 'True','vlans': ['/Common/Dev'],'arp':'disabled','icmpecho':'disabled','state':'disabled','port':eachServer[0][1],'tagMode':'none'}

  print (params)

#LETS CREATE VIRTIUAL SERVERS IF THE SERVER ALREADY EXISTS KEEP IT MOVING

  try:

   ltm.virtuals.virtual.create(**params)

  except Exception as e:

   print (e)

 

 

 

When run I get the following error:

 

 

400 Unexpected Error: Bad Request for uri: https://pltbigip01.pexdev.corp:443/mgmt/tm/ltm/virtual/

Text: '{"code":400,"message":"Instance contains a string","errorStack":[],"apiError":1}'

 

Does anyone know why?

 

 

2 Replies

  • your 'vlansEnabled' receives a boolean as value. Booleans aren't strings.

    So instead of:

    'vlansEnabled': 'True',

    Try:

    'vlansEnabled': True,

    There maybe other errors, so use this as a reference to make sure the values match the expected type:

    params = {'name': vs_name,
              'destination': '{}:{}'.format('192.168.100.10', str(80)),
              'mask': '255.255.255.255',
              'description': 'Created by Python',
              'pool': my_pool,
              'profiles': profiles,
              'partition': 'Common',
              'sourceAddressTranslation': {'type': 'automap'},
              'vlansEnabled': True,
              'vlans': ['/Common/internal']
              }
     
    ltm.virtuals.virtual.create(**params)

    Cheers.

    Rodrigo