The following scripts and detailed steps should help the one who will have to create hundreds of KVMs in Apigee edge.
Problem statement: Creation of 100's (10-12 pages) of KVM parameters in Edge-UI
Manual creation :
a. Login to APIGEE Edge
b. Under API-->Environment configuration, click Key Value Map tab
c. Make sure that selected environment is correct environment from drop down(Dev, SIT, UAT, Prod)
d. click +key Value Map
e. In the name filed add KeyValueMap1 and click Add button
f. click created KeyValueMap1 and the click edit button --> and add & save
name:key1
value:value_one
name:Key2
value:value_two
Automatation: Following is what I thought to automate this and I hope this will help someone across Apigee community.
It was not straight forward to come with this solution. There is limitation with design of KVM.
a. its always allows you to create only one KVM with one or more key-value maps.
b. this is because, the parent element KVM name is not an `array element` by design.
c. Just for vekvm.pngrification, if we try creating multiple KVMs with postman or curl though JSON request :
{
"message": "Can not deserialize instance of com.apigee.keyvaluemap.resource.KeyValueMap out of START_ARRAY token\n at [Source: org.apache.cxf.transport.http.AbstractHTTPDestination$1@7bc705af; line: 1, column: 1]","contexts": []
}
however, I have 2 scripts for you to overcome of this problem -
The data.json file format is something like this:
prep_kvm_json.sh & kvmcreate.sh
#!/bin/bash ## prep_kvm_json.sh ## The script is to read data.json and preapre KVM JSON and to be passd as an arugument later to curl {post} ## @author manjukar ## @since 08.28.2017 ## cd /home/user1/ if [ ! -d KVM ] then mkdir KVM cp data.json /home/user1/KVM/ cd /home/user1/KVM/ csplit data.json '/^}$/+1' {*} rm -rf /home/user1/KVM/data.json else cp data.json /home/user1/KVM/ cd /home/user1/KVM/ csplit data.json '/^}$/+1' {*} rm -rf /home/user1/KVM/data.json fi #!/bin/bash ## kvmcreate.sh ## execute this script after execution prep_kvm_json.sh ## The script is to read KVM_JSON and to be passd as an arugument to curl {post} ## POST http://ManagemenHostIP:8080/v1/organizations/o1/environments/e1/keyvaluemaps/ -d "@filename" ## @author manjukar ## @since 08.28.2017 ## CURL='/usr/bin/curl' kvmhttp="http://ManagemenHostIP:8080/v1/organizations/o1/environments/e1/keyvaluemaps/" for file in /home/user1/KVM/* do echo ${file} CURLARGS="-u UIadministartor:adminpassword -X POST -H Content-Type:application/json -d "@${file}"" echo "********************" map_name="$($CURL $CURLARGS $kvmhttp )" echo $map_name >> KVMFile done;