Forum Discussion

Bin_Qiu_195313's avatar
Bin_Qiu_195313
Icon for Nimbostratus rankNimbostratus
Apr 23, 2015

How to use REST to create a Virtual Server with profile

I want to use REST to create a virtual server with profile. Below code is not work. The virtual server got created, but profiles are not set right

 

def create_http_virtual(bigip, name, address, port, pool):
36      payload = {}
37   
38       define test virtual
39      payload['kind'] = 'tm:ltm:virtual:virtualstate'
40      payload['name'] = name
41      payload['description'] = 'A Python REST client test virtual server'
42      payload['destination'] = '%s:%s' % (address, port)
43      payload['mask'] = '255.255.255.255'
44      payload['ipProtocol'] = 'tcp'
45      payload['sourceAddressTranslation'] = { 'type' : 'automap' }
46      payload['profiles'] = [
47          { 'kind' : 'ltm:virtual:profile', 'name' : 'http' },
48          { 'kind' : 'ltm:virtual:profile', 'name' : 'tcp' }
49      ]
50      payload['pool'] = pool
51   
52      bigip.post('%s/ltm/virtual' % BIGIP_URL_BASE, data=json.dumps(payload))
53   
  • Very helpful post. I used the following code to add profiles.

     

     add TCP and HTTP profiles to virtual server
    self.profiles = []
    
    if self.payload['ipProtocol'] == 'tcp':
        self.profile = {}
        self.profile['name'] = "tcp-lan-optimized-default"
        self.profiles.append(self.profile)
    
    if self.serviceNumber == "80":
        self.profile = {}
        self.profile['name'] = "http-default"
        self.profiles.append(self.profile)
    
    self.payload['profiles'] = self.profiles
  • It's perhaps worth mentioning that with protocol profiles, you need to add the 'context' key if you specify more than one.

     

    If you specify only one, it will be used as the Client Side profile and the Server Side profile will be set to "(Same as Client)".

     

    But if you want them to be different, you need to use something like this:

     

    profiles = [
      {
        'name': '/Common/tcp-lan-optimized',
        'context': 'serverside'
      },
      {
        'name': '/Common/tcp-wan-optimized',
        'context': 'clientside'
      }
    ]

    This is from the Ruby code we use to set both of the TCP profiles.

     

    We have been able to use the REST interface to create VIPs with all of their subcomponents without the need for a POST followed by a PUT, so far. That includes most profiles, persistence profiles, enabled VLANs, iRules... I haven't come across something I couldn't set on the first pass.

     

    This running BIGIP 12.1.2 software, though. Other versions may have more limitations.