Forum Discussion
Diga_171140
Nimbostratus
Apr 06, 2016How to create Virtual server in GTM using Python payload methond ?
Hi , I have tried below code for creating VS in GTM under GSLB Server, but getting 403 error, can some please help.
import requests, json, time
BIGIP_ADDRESS = '1.1.1.1'
BIGIP_USER = 'admin'
BIGIP_PASS = 'admin'
SLEEP_TIME = 20
SERVER_NAME = 'abc.test.com'
VS_ADDRESS = '2.2.2.2'
VS_PORT = '443'
def create_vs(bigip, server_name, vs_address, vs_port):
payload = {}
payload['kind'] = 'tm:gtm:server:virtual-servers:LTM-1:virtual-serversstate1'
payload['name'] = server_name
payload['virtualServers'] = [ {
'kind' : 'tm:gtm:server:LTM-test01:virtual-servers','name' : server_name,
'destination' : '%s:%s' % (vs_address, vs_port)}]
return bigip.post('%s/gtm/server/' % BIGIP_URL_BASE, data=json.dumps(payload))
bigip = requests.session()
bigip.auth = (BIGIP_USER, BIGIP_PASS)
bigip.verify = False
bigip.headers.update({'Content-Type' : 'application/json'})
print ("created REST resource for BIG-IP at %s..." % BIGIP_ADDRESS)
BIGIP_URL_BASE = 'https://%s/mgmt/tm' % BIGIP_ADDRESS
b = create_vs(bigip, SERVER_NAME, VS_ADDRESS, VS_PORT)
print ("created Virtual Server \"%s\" with %s:%s..." % (SERVER_NAME, VS_ADDRESS, VS_PORT))
print (b)9 Replies
- JRahm
Admin
can you post the error? - Diga_171140
Nimbostratus
I trying to catch error code and it is response code is 400. I am not able to catch error. if you know how to catch error in this programme please let me know, thanks for your intevene. - Diga_171140
Nimbostratus
error code is 400 and 403 - Diga_171140
Nimbostratus
It's SOLVED
def create_VS(bigip,name,address): payload = {} define test virtual payload['kind'] = "tm:gtm:server:virtual-servers:virtual-serversstate" payload['name'] = name payload['destination'] = "%s:%s" % (address, port) print (payload) bigip.post('https://gtm.gtm.com/mgmt/tm/gtm/server/LTM-test01/virtual-servers/', data=json.dumps(payload))- Diga_171140
Nimbostratus
def create_VS(bigip,name,address,port): payload = {} define test virtual payload['kind'] = "tm:gtm:server:virtual-servers:virtual-serversstate" payload['name'] = name payload['destination'] = "%s:%s" % (address, port) print (payload) bigip.post('https://gtm.gtm.com/mgmt/tm/gtm/server/LTM-test01/virtual-servers/', data=json.dumps(payload))
- JRahm
Admin
there are different messages with those codes, would need to see the actual json return data to be helpful. I use Chrome's advanced rest client when troubleshooting and investigating new methods, might start there. - Diga_171140
Nimbostratus
how to get the actual error code in chrome, could you please explain. - Diga_171140
Nimbostratus
def create_VS(bigip,name,address,port): payload = {} define test virtual payload['kind'] = "tm:gtm:server:virtual-servers:virtual-serversstate" payload['name'] = name payload['destination'] = "%s:%s" % (address, port) print (payload) bigip.post('https://gtm.gtm.com/mgmt/tm/gtm/server/LTM-test01/virtual-servers/', data=json.dumps(payload)) - Diga_171140
Nimbostratus
problem has been sloved, but if you could give he methof to catch the errro in chrome, it will be very helful to me.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
