Forum Discussion
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
- Bin_Qiu_195313NimbostratusAny one experience the same? The above code is from F5 iREST example code
- Bin_Qiu_195313NimbostratusI got away with the issue by doing below 1) create VIP VIPName with empty profiles 2) add profile to /ltm/virtual/${VIPName}/profiles. 3) Modify the VIP via PUT to modify the irules for the VIP. But, the below JSON to modify the VIP to add rules does not work "rules":["/Common/_sys_https_redirect"] It complain that {"code":400,"message":"Found invalid JSON body in the request.","errorStack":[]} if i used "rules":['/Common/_sys_https_redirect'] It complain that {"code":400,"message":"\"[ '/Common/_sys_https_redirect' ]\" unexpected argument","errorStack":[]} Please help.
- jwitkoNimbostratusAlso having this same issue.
- Joel_NewtonCirrus
Hi, Bin,
I got this to work. I'm using PowerShell so my syntax is a little different, but the gist of the JSON is the same. For me, it worked with the below value for 'kind.' I also tested the value you used, and that worked as well.
$JSONBody = @{kind='tm:ltm:virtual:virtualstate';name='VirtualServerName';description='Description';partition='Common';destination='10.1.1.1:80';source='0.0.0.0';pool='PoolName';ipProtocol='tcp';mask='255.255.255.255';connectionLimit=0} $ProfileItems = @() $ProfileItems += @{kind='tm:ltm:virtual:profiles:profilesstate';name='ssl_profile'} $ProfileItems += @{kind='tm:ltm:virtual:profiles:profilesstate';name='http'} $JSONBody.profiles = $ProfileItems
What behavior are you seeing when you attempt to do it - an error or no profiles are set?
- tatmotivCirrostratus
When using partitions in json data, you'll need to replace "/" with "~" for path determination. Given the example above, try using "~Common~_sys_https_redirect" instead of "/Common/_sys_https_redirect".
- Diga_171140Nimbostratusis anyone knows how to modify fallbackPersistence using payload and how to use all option while creating VIP using python.
- Sanjay_ShitoleEmployee
Hello I tested this for HTTP VS
First make a POST of Generic Virtual Server with HTTP
curl -k --user admin:admin -H "Accept: application/json" -H "Content-Type:application/json" -X POST -d@ServiceRouting_forHTTP.json https://173.36.215.237/mgmt/tm/ltm/virtual/ | python -m json.tool
Payload file below ServiceRouting_forHTTP.json
{ "addressStatus": "yes", "autoLasthop": "default", "cmpEnabled": "yes", "connectionLimit": 0, "destination": "/Common/192.168.32.11:80", "enabled": true, "fullPath": "ServiceRouting_forHTTP", "generation": 37093, "gtmScore": 0, "ipProtocol": "tcp", "kind": "tm:ltm:virtual:virtualstate", "mask": "255.255.255.255", "mirror": "disabled", "mobileAppTunnel": "disabled", "name": "ServiceRouting_forHTTP", "nat64": "disabled", "policiesReference": { "isSubcollection": true, "link": "" }, "pool": "/Common/S4HPool", "profilesReference": { "isSubcollection": true, "link": "" }, "rateLimit": "disabled", "rateLimitDstMask": 0, "rateLimitMode": "object", "rateLimitSrcMask": 0, "selfLink": "", "source": "0.0.0.0/0", "sourceAddressTranslation": { "type": "automap" }, "sourcePort": "preserve", "synCookieStatus": "not-activated", "translateAddress": "enabled", "translatePort": "enabled", "vlansDisabled": true, "vsIndex": 32 }
Then make a PUT so that we add the HTTP Profile and also the iRule
curl -s -k -u admin:admin -H 'Content-Type: application/json' -X PUT https://173.36.215.237/mgmt/tm/ltm/virtual/ServiceRouting_forHTTP -d '{"profiles":[{"name":"http"},{"name":"tcp"}], "rules": ["/Common/Testing_class"]}' |python -m json.tool
- Sanjay_ShitoleEmployee
Hello I tested this for HTTP VS
First make a POST of Generic Virtual Server with HTTP
curl -k --user admin:admin -H "Accept: application/json" -H "Content-Type:application/json" -X POST -d@ServiceRouting_forHTTP.json https://173.36.215.237/mgmt/tm/ltm/virtual/ | python -m json.tool
Payload file below ServiceRouting_forHTTP.json
{ "addressStatus": "yes", "autoLasthop": "default", "cmpEnabled": "yes", "connectionLimit": 0, "destination": "/Common/192.168.32.11:80", "enabled": true, "fullPath": "ServiceRouting_forHTTP", "generation": 37093, "gtmScore": 0, "ipProtocol": "tcp", "kind": "tm:ltm:virtual:virtualstate", "mask": "255.255.255.255", "mirror": "disabled", "mobileAppTunnel": "disabled", "name": "ServiceRouting_forHTTP", "nat64": "disabled", "policiesReference": { "isSubcollection": true, "link": "" }, "pool": "/Common/S4HPool", "profilesReference": { "isSubcollection": true, "link": "" }, "rateLimit": "disabled", "rateLimitDstMask": 0, "rateLimitMode": "object", "rateLimitSrcMask": 0, "selfLink": "", "source": "0.0.0.0/0", "sourceAddressTranslation": { "type": "automap" }, "sourcePort": "preserve", "synCookieStatus": "not-activated", "translateAddress": "enabled", "translatePort": "enabled", "vlansDisabled": true, "vsIndex": 32 }
Then make a PUT so that we add the HTTP Profile and also the iRule
curl -s -k -u admin:admin -H 'Content-Type: application/json' -X PUT https://173.36.215.237/mgmt/tm/ltm/virtual/ServiceRouting_forHTTP -d '{"profiles":[{"name":"http"},{"name":"tcp"}], "rules": ["/Common/Testing_class"]}' |python -m json.tool
- Sanjay_ShitoleEmployee
Hello I tested this for HTTP VS
First make a POST of Generic Virtual Server with HTTP
curl -k --user admin:admin -H "Accept: application/json" -H "Content-Type:application/json" -X POST -d@ServiceRouting_forHTTP.json https://173.36.215.237/mgmt/tm/ltm/virtual/ | python -m json.tool
Payload file below ServiceRouting_forHTTP.json
{ "addressStatus": "yes", "autoLasthop": "default", "cmpEnabled": "yes", "connectionLimit": 0, "destination": "/Common/192.168.32.11:80", "enabled": true, "fullPath": "ServiceRouting_forHTTP", "generation": 37093, "gtmScore": 0, "ipProtocol": "tcp", "kind": "tm:ltm:virtual:virtualstate", "mask": "255.255.255.255", "mirror": "disabled", "mobileAppTunnel": "disabled", "name": "ServiceRouting_forHTTP", "nat64": "disabled", "policiesReference": { "isSubcollection": true, "link": "" }, "pool": "/Common/S4HPool", "profilesReference": { "isSubcollection": true, "link": "" }, "rateLimit": "disabled", "rateLimitDstMask": 0, "rateLimitMode": "object", "rateLimitSrcMask": 0, "selfLink": "", "source": "0.0.0.0/0", "sourceAddressTranslation": { "type": "automap" }, "sourcePort": "preserve", "synCookieStatus": "not-activated", "translateAddress": "enabled", "translatePort": "enabled", "vlansDisabled": true, "vsIndex": 32 }
Then make a PUT so that we add the HTTP Profile and also the iRule
curl -s -k -u admin:admin -H 'Content-Type: application/json' -X PUT https://173.36.215.237/mgmt/tm/ltm/virtual/ServiceRouting_forHTTP -d '{"profiles":[{"name":"http"},{"name":"tcp"}], "rules": ["/Common/Testing_class"]}' |python -m json.tool
- Sanjay_ShitoleEmployee
Hello I tested this for HTTP VS
First make a POST of Generic Virtual Server with HTTP
curl -k --user admin:admin -H "Accept: application/json" -H "Content-Type:application/json" -X POST -d@ServiceRouting_forHTTP.json https://173.36.215.237/mgmt/tm/ltm/virtual/ | python -m json.tool
Payload file below ServiceRouting_forHTTP.json
{ "addressStatus": "yes", "autoLasthop": "default", "cmpEnabled": "yes", "connectionLimit": 0, "destination": "/Common/192.168.32.11:80", "enabled": true, "fullPath": "ServiceRouting_forHTTP", "generation": 37093, "gtmScore": 0, "ipProtocol": "tcp", "kind": "tm:ltm:virtual:virtualstate", "mask": "255.255.255.255", "mirror": "disabled", "mobileAppTunnel": "disabled", "name": "ServiceRouting_forHTTP", "nat64": "disabled", "policiesReference": { "isSubcollection": true, "link": "" }, "pool": "/Common/S4HPool", "profilesReference": { "isSubcollection": true, "link": "" }, "rateLimit": "disabled", "rateLimitDstMask": 0, "rateLimitMode": "object", "rateLimitSrcMask": 0, "selfLink": "", "source": "0.0.0.0/0", "sourceAddressTranslation": { "type": "automap" }, "sourcePort": "preserve", "synCookieStatus": "not-activated", "translateAddress": "enabled", "translatePort": "enabled", "vlansDisabled": true, "vsIndex": 32 }
Then make a PUT so that we add the HTTP Profile and also the iRule
curl -s -k -u admin:admin -H 'Content-Type: application/json' -X PUT https://173.36.215.237/mgmt/tm/ltm/virtual/ServiceRouting_forHTTP -d '{"profiles":[{"name":"http"},{"name":"tcp"}], "rules": ["/Common/Testing_class"]}' |python -m json.tool
Recent Discussions
Related Content
* 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