Forum Discussion

JSC's avatar
JSC
Icon for Nimbostratus rankNimbostratus
Apr 26, 2017

How to create GTM topology region members with iControl REST API?

We are trying to use REST iControl API in order to create a GTM topology Region

/mgmt/tm/gtm/region
. The JSON structure seems to be (Obtained from a get request):

{

'fullPath': '/Common/region_sample',

'kind': 'tm:gtm:region:regionstate',

'name': 'region_sample',

'partition': 'Common',

'regionMembers': [{'name': 'not country FR'}]

}

however, when posting the request, we got:

POST https://X.X.X.X/mgmt/tm/gtm/region/?ver=12.1.2 {}

-- result --

{u'apiError': 26214401,

u'code': 400,

u'errorStack': [],

u'message': u'Invalid region type: "not country FR"'}

We tried with an empty regionMembers array parameters, it works.

However, we didn't find the way to create the regionMembers (We also tried actions PUT and PATCH on
/mgmt/tm/gtm/region/~Common~region_sample/region-members
)

REST Documentation is poor on the subject.

Have someone successfully created them with REST?

thanks,

JSC
  • JSC's avatar
    JSC
    Icon for Nimbostratus rankNimbostratus

    Only solution find, use "tmsh" command within a REST post:

    if regionMembers != '':
        payload={}
        payload['command']='run'
        payload['utilCmdArgs']="-c 'tmsh modify gtm region /"+rPartition+"/"+rName+" region-members replace-all-with { "+regionMembers+" } && if [[ $? == 0 ]] ; then echo OK ; else echo KO ; fi' | jq ."
        resp = bigip.post('https://%s/mgmt/tm/util/bash?ver=12.1.2' % (BIGIP_ADDRESS), data=json.dumps(payload))
        if resp.status_code == requests.codes.ok and resp.json()['commandResult'].replace('\n','') == 'OK':
            print ' ~ Replace region_members = \''+str(resp.status_code)+'\' commandResult=\''+resp.json()['commandResult'].replace('\n','')+'\''
        else:
            print ' ~ Replace region_members = \''+str(resp.status_code)+'\' commandResult=\''+resp.json()['commandResult']+'\''
            pprint(resp.json())
            exit(1)
    
  • xukai's avatar
    xukai
    Icon for Nimbostratus rankNimbostratus

    i meet same error

    [root@localhost:Active:Standalone] ~ # curl -sk -u admin:admin https://localhost/mgmt/tm/gtm/region -H 'Content-Type: application/json' -X POST -d '{"name":"anhui_region_test","regionMembers":[{"name": "not country CN"}]}' | jq .
    {
    "code": 400,
    "message": "Invalid region type: \"not country CN\"",
    "errorStack": [],
    "apiError": 26214401
    }

     

    how  can i do