#include <tencentcloud/core/TencentCloud.h>
#include <tencentcloud/core/profile/HttpProfile.h>
#include <tencentcloud/core/profile/ClientProfile.h>
#include <tencentcloud/core/Credential.h>
#include <tencentcloud/core/NetworkProxy.h>
#include <tencentcloud/core/AsyncCallerContext.h>
#include <tencentcloud/cvm/v20170312/CvmClient.h>
#include <tencentcloud/cvm/v20170312/model/DescribeInstancesRequest.h>
#include <tencentcloud/cvm/v20170312/model/DescribeInstancesResponse.h>
#include <tencentcloud/cvm/v20170312/model/Instance.h>
#include <iostream>
#include <string>
using namespace TencentCloud;
using namespace TencentCloud::Cvm::V20170312;
using namespace TencentCloud::Cvm::V20170312::Model;
using namespace std;
int main()
{
TencentCloud::InitAPI();
// Use the SDK
// Instantiate an authentication object. Pass in `secretId` and `secretKey` of your Tencent Cloud account as the input parameters and keep them confidential
string secretId = "<your secret id>";
string secretKey = "<your secret key>";
Credential cred = Credential(secretId, secretKey);
// (Optional) Instantiate an HTTP option
HttpProfile httpProfile = HttpProfile();
httpProfile.SetKeepAlive(true); // Specify whether to enable the keepalive feature. The default value is false
httpProfile.SetEndpoint("cvm.ap-guangzhou.tencentcloudapi.com"); // Specify the endpoint. If you do not specify the endpoint, nearby access is enabled by default
httpProfile.SetReqTimeout(30); // Specify the request timeout value in seconds. The default value is 60s
httpProfile.SetConnectTimeout(30); // Specify the response timeout value in seconds. The default value is 60s
ClientProfile clientProfile = ClientProfile(httpProfile);
DescribeInstancesRequest req = DescribeInstancesRequest();
req.SetOffset(0);
req.SetLimit(5);
CvmClient cvm_client = CvmClient(cred, "ap-guangzhou", clientProfile);
// Set proxy
// NetworkProxy proxy = NetworkProxy(NetworkProxy::Type::HTTP, "localhost.proxy.com", 8080);
// cvm_client.SetNetworkProxy(proxy);
auto outcome = cvm_client.DescribeInstances(req);
if (!outcome.IsSuccess())
{
cout << outcome.GetError().PrintAll() << endl;
TencentCloud::ShutdownAPI();
return -1;
}
DescribeInstancesResponse rsp = outcome.GetResult();
cout<<"RequestId="<<rsp.GetRequestId()<<endl;
cout<<"TotalCount="<<rsp.GetTotalCount()<<endl;
if (rsp.InstanceSetHasBeenSet())
{
vector<Instance> instanceSet = rsp.GetInstanceSet();
for (auto itr=instanceSet.begin(); itr!=instanceSet.end(); ++itr)
{
cout<<(*itr).GetPlacement().GetZone()<<endl;
}
}
TencentCloud::ShutdownAPI();
return 0;
}
本页内容是否解决了您的问题?