Chilkat Online Tools

DescribeVirtualInterfaces Swift3 Example

AWS Direct Connect

func chilkatTest() {
    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    let rest = CkoRest()!
    var success: Bool

    let authAws = CkoAuthAws()!
    authAws.accessKey = "AWS_ACCESS_KEY"
    authAws.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.)
    authAws.region = "us-west-2"
    authAws.serviceName = "directconnect"
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.setAuthAws(authAws)

    // URL: https://directconnect.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.connect("directconnect.us-west-2.amazonaws.com", port: 443, tls: true, autoReconnect: true)
    if success != true {
        print("ConnectFailReason: \(rest.connectFailReason.intValue)")
        print("\(rest.lastErrorText!)")
        return
    }

    // 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

    let json = CkoJsonObject()!
    json.update("connectionId", value: "string")
    json.update("virtualInterfaceId", value: "string")

    // The JSON request body created by the above code:

    // {
    //   "connectionId": "string",
    //   "virtualInterfaceId": "string"
    // }

    rest.addHeader("Content-Type", value: "application/x-amz-json-1.1")
    rest.addHeader("X-Amz-Target", value: "OvertureService.DescribeVirtualInterfaces")

    let sbRequestBody = CkoStringBuilder()!
    json.emitSb(sbRequestBody)
    let sbResponseBody = CkoStringBuilder()!
    success = rest.fullRequestSb("POST", uriPath: "/", requestBody: sbRequestBody, responseBody: sbResponseBody)
    if success != true {
        print("\(rest.lastErrorText!)")
        return
    }

    var respStatusCode: Int = rest.responseStatusCode.intValue
    print("response status code = \(respStatusCode)")
    if respStatusCode != 200 {
        print("Response Header:")
        print("\(rest.responseHeader!)")
        print("Response Body:")
        print("\(sbResponseBody.getAsString()!)")
        return
    }

    let jResp = CkoJsonObject()!
    jResp.loadSb(sbResponseBody)

    // 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

    var addressFamily: String?
    var amazonAddress: String?
    var amazonSideAsn: Int
    var asn: Int
    var authKey: String?
    var awsDeviceV2: String?
    var awsLogicalDeviceId: String?
    var connectionId: String?
    var customerAddress: String?
    var customerRouterConfig: String?
    var directConnectGatewayId: String?
    var jumboFrameCapable: Int
    var location: String?
    var mtu: Int
    var ownerAccount: String?
    var region: String?
    var siteLinkEnabled: Int
    var virtualGatewayId: String?
    var virtualInterfaceId: String?
    var virtualInterfaceName: String?
    var virtualInterfaceState: String?
    var virtualInterfaceType: String?
    var vlan: Int
    var j: Int
    var count_j: Int
    var bgpPeerId: String?
    var bgpPeerState: String?
    var bgpStatus: String?
    var cidr: String?
    var key: String?
    var value: String?

    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "virtualInterfaces").intValue
    while i < count_i {
        jResp.i = i
        addressFamily = jResp.string(of: "virtualInterfaces[i].addressFamily")
        amazonAddress = jResp.string(of: "virtualInterfaces[i].amazonAddress")
        amazonSideAsn = jResp.int(of: "virtualInterfaces[i].amazonSideAsn").intValue
        asn = jResp.int(of: "virtualInterfaces[i].asn").intValue
        authKey = jResp.string(of: "virtualInterfaces[i].authKey")
        awsDeviceV2 = jResp.string(of: "virtualInterfaces[i].awsDeviceV2")
        awsLogicalDeviceId = jResp.string(of: "virtualInterfaces[i].awsLogicalDeviceId")
        connectionId = jResp.string(of: "virtualInterfaces[i].connectionId")
        customerAddress = jResp.string(of: "virtualInterfaces[i].customerAddress")
        customerRouterConfig = jResp.string(of: "virtualInterfaces[i].customerRouterConfig")
        directConnectGatewayId = jResp.string(of: "virtualInterfaces[i].directConnectGatewayId")
        jumboFrameCapable = jResp.int(of: "virtualInterfaces[i].jumboFrameCapable").intValue
        location = jResp.string(of: "virtualInterfaces[i].location")
        mtu = jResp.int(of: "virtualInterfaces[i].mtu").intValue
        ownerAccount = jResp.string(of: "virtualInterfaces[i].ownerAccount")
        region = jResp.string(of: "virtualInterfaces[i].region")
        siteLinkEnabled = jResp.int(of: "virtualInterfaces[i].siteLinkEnabled").intValue
        virtualGatewayId = jResp.string(of: "virtualInterfaces[i].virtualGatewayId")
        virtualInterfaceId = jResp.string(of: "virtualInterfaces[i].virtualInterfaceId")
        virtualInterfaceName = jResp.string(of: "virtualInterfaces[i].virtualInterfaceName")
        virtualInterfaceState = jResp.string(of: "virtualInterfaces[i].virtualInterfaceState")
        virtualInterfaceType = jResp.string(of: "virtualInterfaces[i].virtualInterfaceType")
        vlan = jResp.int(of: "virtualInterfaces[i].vlan").intValue
        j = 0
        count_j = jResp.size(ofArray: "virtualInterfaces[i].bgpPeers").intValue
        while j < count_j {
            jResp.j = j
            addressFamily = jResp.string(of: "virtualInterfaces[i].bgpPeers[j].addressFamily")
            amazonAddress = jResp.string(of: "virtualInterfaces[i].bgpPeers[j].amazonAddress")
            asn = jResp.int(of: "virtualInterfaces[i].bgpPeers[j].asn").intValue
            authKey = jResp.string(of: "virtualInterfaces[i].bgpPeers[j].authKey")
            awsDeviceV2 = jResp.string(of: "virtualInterfaces[i].bgpPeers[j].awsDeviceV2")
            awsLogicalDeviceId = jResp.string(of: "virtualInterfaces[i].bgpPeers[j].awsLogicalDeviceId")
            bgpPeerId = jResp.string(of: "virtualInterfaces[i].bgpPeers[j].bgpPeerId")
            bgpPeerState = jResp.string(of: "virtualInterfaces[i].bgpPeers[j].bgpPeerState")
            bgpStatus = jResp.string(of: "virtualInterfaces[i].bgpPeers[j].bgpStatus")
            customerAddress = jResp.string(of: "virtualInterfaces[i].bgpPeers[j].customerAddress")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "virtualInterfaces[i].routeFilterPrefixes").intValue
        while j < count_j {
            jResp.j = j
            cidr = jResp.string(of: "virtualInterfaces[i].routeFilterPrefixes[j].cidr")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "virtualInterfaces[i].tags").intValue
        while j < count_j {
            jResp.j = j
            key = jResp.string(of: "virtualInterfaces[i].tags[j].key")
            value = jResp.string(of: "virtualInterfaces[i].tags[j].value")
            j = j + 1
        }

        i = i + 1
    }

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

    // {
    //   "virtualInterfaces": [
    //     {
    //       "addressFamily": "string",
    //       "amazonAddress": "string",
    //       "amazonSideAsn": number,
    //       "asn": number,
    //       "authKey": "string",
    //       "awsDeviceV2": "string",
    //       "awsLogicalDeviceId": "string",
    //       "bgpPeers": [
    //         {
    //           "addressFamily": "string",
    //           "amazonAddress": "string",
    //           "asn": number,
    //           "authKey": "string",
    //           "awsDeviceV2": "string",
    //           "awsLogicalDeviceId": "string",
    //           "bgpPeerId": "string",
    //           "bgpPeerState": "string",
    //           "bgpStatus": "string",
    //           "customerAddress": "string"
    //         }
    //       ],
    //       "connectionId": "string",
    //       "customerAddress": "string",
    //       "customerRouterConfig": "string",
    //       "directConnectGatewayId": "string",
    //       "jumboFrameCapable": boolean,
    //       "location": "string",
    //       "mtu": number,
    //       "ownerAccount": "string",
    //       "region": "string",
    //       "routeFilterPrefixes": [
    //         {
    //           "cidr": "string"
    //         }
    //       ],
    //       "siteLinkEnabled": boolean,
    //       "tags": [
    //         {
    //           "key": "string",
    //           "value": "string"
    //         }
    //       ],
    //       "virtualGatewayId": "string",
    //       "virtualInterfaceId": "string",
    //       "virtualInterfaceName": "string",
    //       "virtualInterfaceState": "string",
    //       "virtualInterfaceType": "string",
    //       "vlan": number
    //     }
    //   ]
    // }

}