Chilkat Online Tools

CreateNodegroup Foxpro Example

Amazon Elastic Kubernetes Service

LOCAL loRest
LOCAL lnSuccess
LOCAL loAuthAws
LOCAL loJson
LOCAL loSbRequestBody
LOCAL loSbResponseBody
LOCAL lnRespStatusCode
LOCAL loJResp
LOCAL lcCode
LOCAL lcMessage
LOCAL j
LOCAL lnCount_j
LOCAL lcStrVal
LOCAL lcName
LOCAL lcEffect
LOCAL lcKey
LOCAL lcValue
LOCAL lcAmiType
LOCAL lcCapacityType
LOCAL lcClusterName
LOCAL lnCreatedAt
LOCAL lnDiskSize
LOCAL lcV_String
LOCAL lcId
LOCAL lcName
LOCAL lcVersion
LOCAL lnModifiedAt
LOCAL lcNodegroupArn
LOCAL lcNodegroupName
LOCAL lcNodeRole
LOCAL lcReleaseVersion
LOCAL lcEc2SshKey
LOCAL lcRemoteAccessSecurityGroup
LOCAL lnDesiredSize
LOCAL lnMaxSize
LOCAL lnMinSize
LOCAL lcStatus
LOCAL lcTagsString
LOCAL lnMaxUnavailable
LOCAL lnMaxUnavailablePercentage
LOCAL lcNodegroupVersion
LOCAL i
LOCAL lnCount_i

* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.

loRest = CreateObject('Chilkat_9_5_0.Rest')

loAuthAws = CreateObject('Chilkat_9_5_0.AuthAws')
loAuthAws.AccessKey = "AWS_ACCESS_KEY"
loAuthAws.SecretKey = "AWS_SECRET_KEY"

* Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
loAuthAws.Region = "us-west-2"
loAuthAws.ServiceName = "eks"
* SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
loRest.SetAuthAws(loAuthAws)

* URL: https://eks.us-west-2.amazonaws.com/
* Use the same region as specified above.
lnSuccess = loRest.Connect("eks.us-west-2.amazonaws.com",443,1,1)
IF (lnSuccess <> 1) THEN
    ? "ConnectFailReason: " + STR(loRest.ConnectFailReason)
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loAuthAws
    CANCEL
ENDIF

* The following code creates the JSON request body.
* The JSON created by this code is shown below.

* Use this online tool to generate code from sample JSON:
* Generate Code to Create JSON

loJson = CreateObject('Chilkat_9_5_0.JsonObject')
loJson.UpdateString("amiType","string")
loJson.UpdateString("capacityType","string")
loJson.UpdateString("clientRequestToken","string")
loJson.UpdateInt("diskSize",123)
loJson.UpdateString("instanceTypes[0]","string")
loJson.UpdateString("labels.string","string")
loJson.UpdateString("launchTemplate.id","string")
loJson.UpdateString("launchTemplate.name","string")
loJson.UpdateString("launchTemplate.version","string")
loJson.UpdateString("nodegroupName","string")
loJson.UpdateString("nodeRole","string")
loJson.UpdateString("releaseVersion","string")
loJson.UpdateString("remoteAccess.ec2SshKey","string")
loJson.UpdateString("remoteAccess.sourceSecurityGroups[0]","string")
loJson.UpdateInt("scalingConfig.desiredSize",123)
loJson.UpdateInt("scalingConfig.maxSize",123)
loJson.UpdateInt("scalingConfig.minSize",123)
loJson.UpdateString("subnets[0]","string")
loJson.UpdateString("tags.string","string")
loJson.UpdateString("taints[0].effect","string")
loJson.UpdateString("taints[0].key","string")
loJson.UpdateString("taints[0].value","string")
loJson.UpdateInt("updateConfig.maxUnavailable",123)
loJson.UpdateInt("updateConfig.maxUnavailablePercentage",123)
loJson.UpdateString("version","string")

* The JSON request body created by the above code:

* {
*   "amiType": "string",
*   "capacityType": "string",
*   "clientRequestToken": "string",
*   "diskSize": number,
*   "instanceTypes": [
*     "string"
*   ],
*   "labels": {
*     "string": "string"
*   },
*   "launchTemplate": {
*     "id": "string",
*     "name": "string",
*     "version": "string"
*   },
*   "nodegroupName": "string",
*   "nodeRole": "string",
*   "releaseVersion": "string",
*   "remoteAccess": {
*     "ec2SshKey": "string",
*     "sourceSecurityGroups": [
*       "string"
*     ]
*   },
*   "scalingConfig": {
*     "desiredSize": number,
*     "maxSize": number,
*     "minSize": number
*   },
*   "subnets": [
*     "string"
*   ],
*   "tags": {
*     "string": "string"
*   },
*   "taints": [
*     {
*       "effect": "string",
*       "key": "string",
*       "value": "string"
*     }
*   ],
*   "updateConfig": {
*     "maxUnavailable": number,
*     "maxUnavailablePercentage": number
*   },
*   "version": "string"
* }

loRest.AddHeader("Content-Type","application/x-amz-json-1.1")
loRest.AddHeader("X-Amz-Target","CreateNodegroup")

loSbRequestBody = CreateObject('Chilkat_9_5_0.StringBuilder')
loJson.EmitSb(loSbRequestBody)
loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestSb("POST","/clusters/{name}/node-groups",loSbRequestBody,loSbResponseBody)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loAuthAws
    RELEASE loJson
    RELEASE loSbRequestBody
    RELEASE loSbResponseBody
    CANCEL
ENDIF

lnRespStatusCode = loRest.ResponseStatusCode
? "response status code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode <> 200) THEN
    ? "Response Header:"
    ? loRest.ResponseHeader
    ? "Response Body:"
    ? loSbResponseBody.GetAsString()
    RELEASE loRest
    RELEASE loAuthAws
    RELEASE loJson
    RELEASE loSbRequestBody
    RELEASE loSbResponseBody
    CANCEL
ENDIF

loJResp = CreateObject('Chilkat_9_5_0.JsonObject')
loJResp.LoadSb(loSbResponseBody)

* The following code parses the JSON response.
* A sample JSON response is shown below the sample code.

* Use this online tool to generate parsing code from sample JSON:
* Generate Parsing Code from JSON

lcAmiType = loJResp.StringOf("nodegroup.amiType")
lcCapacityType = loJResp.StringOf("nodegroup.capacityType")
lcClusterName = loJResp.StringOf("nodegroup.clusterName")
lnCreatedAt = loJResp.IntOf("nodegroup.createdAt")
lnDiskSize = loJResp.IntOf("nodegroup.diskSize")
lcV_String = loJResp.StringOf("nodegroup.labels.string")
lcId = loJResp.StringOf("nodegroup.launchTemplate.id")
lcName = loJResp.StringOf("nodegroup.launchTemplate.name")
lcVersion = loJResp.StringOf("nodegroup.launchTemplate.version")
lnModifiedAt = loJResp.IntOf("nodegroup.modifiedAt")
lcNodegroupArn = loJResp.StringOf("nodegroup.nodegroupArn")
lcNodegroupName = loJResp.StringOf("nodegroup.nodegroupName")
lcNodeRole = loJResp.StringOf("nodegroup.nodeRole")
lcReleaseVersion = loJResp.StringOf("nodegroup.releaseVersion")
lcEc2SshKey = loJResp.StringOf("nodegroup.remoteAccess.ec2SshKey")
lcRemoteAccessSecurityGroup = loJResp.StringOf("nodegroup.resources.remoteAccessSecurityGroup")
lnDesiredSize = loJResp.IntOf("nodegroup.scalingConfig.desiredSize")
lnMaxSize = loJResp.IntOf("nodegroup.scalingConfig.maxSize")
lnMinSize = loJResp.IntOf("nodegroup.scalingConfig.minSize")
lcStatus = loJResp.StringOf("nodegroup.status")
lcTagsString = loJResp.StringOf("nodegroup.tags.string")
lnMaxUnavailable = loJResp.IntOf("nodegroup.updateConfig.maxUnavailable")
lnMaxUnavailablePercentage = loJResp.IntOf("nodegroup.updateConfig.maxUnavailablePercentage")
lcNodegroupVersion = loJResp.StringOf("nodegroup.version")
i = 0
lnCount_i = loJResp.SizeOfArray("nodegroup.health.issues")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcCode = loJResp.StringOf("nodegroup.health.issues[i].code")
    lcMessage = loJResp.StringOf("nodegroup.health.issues[i].message")
    j = 0
    lnCount_j = loJResp.SizeOfArray("nodegroup.health.issues[i].resourceIds")
    DO WHILE j < lnCount_j
        loJResp.J = j
        lcStrVal = loJResp.StringOf("nodegroup.health.issues[i].resourceIds[j]")
        j = j + 1
    ENDDO
    i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("nodegroup.instanceTypes")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcStrVal = loJResp.StringOf("nodegroup.instanceTypes[i]")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("nodegroup.remoteAccess.sourceSecurityGroups")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcStrVal = loJResp.StringOf("nodegroup.remoteAccess.sourceSecurityGroups[i]")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("nodegroup.resources.autoScalingGroups")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcName = loJResp.StringOf("nodegroup.resources.autoScalingGroups[i].name")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("nodegroup.subnets")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcStrVal = loJResp.StringOf("nodegroup.subnets[i]")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("nodegroup.taints")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcEffect = loJResp.StringOf("nodegroup.taints[i].effect")
    lcKey = loJResp.StringOf("nodegroup.taints[i].key")
    lcValue = loJResp.StringOf("nodegroup.taints[i].value")
    i = i + 1
ENDDO

* A sample JSON response body parsed by the above code:

* {
*   "nodegroup": {
*     "amiType": "string",
*     "capacityType": "string",
*     "clusterName": "string",
*     "createdAt": number,
*     "diskSize": number,
*     "health": {
*       "issues": [
*         {
*           "code": "string",
*           "message": "string",
*           "resourceIds": [
*             "string"
*           ]
*         }
*       ]
*     },
*     "instanceTypes": [
*       "string"
*     ],
*     "labels": {
*       "string": "string"
*     },
*     "launchTemplate": {
*       "id": "string",
*       "name": "string",
*       "version": "string"
*     },
*     "modifiedAt": number,
*     "nodegroupArn": "string",
*     "nodegroupName": "string",
*     "nodeRole": "string",
*     "releaseVersion": "string",
*     "remoteAccess": {
*       "ec2SshKey": "string",
*       "sourceSecurityGroups": [
*         "string"
*       ]
*     },
*     "resources": {
*       "autoScalingGroups": [
*         {
*           "name": "string"
*         }
*       ],
*       "remoteAccessSecurityGroup": "string"
*     },
*     "scalingConfig": {
*       "desiredSize": number,
*       "maxSize": number,
*       "minSize": number
*     },
*     "status": "string",
*     "subnets": [
*       "string"
*     ],
*     "tags": {
*       "string": "string"
*     },
*     "taints": [
*       {
*         "effect": "string",
*         "key": "string",
*         "value": "string"
*       }
*     ],
*     "updateConfig": {
*       "maxUnavailable": number,
*       "maxUnavailablePercentage": number
*     },
*     "version": "string"
*   }
* }

RELEASE loRest
RELEASE loAuthAws
RELEASE loJson
RELEASE loSbRequestBody
RELEASE loSbResponseBody
RELEASE loJResp