Search in sources :

Example 6 with DescribeInstancesRequest

use of com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest in project tencentcloud-sdk-java-intl-en by TencentCloud.

the class DescribeInstances method main.

public static void main(String[] args) {
    try {
        Credential cred = new Credential("your-secret-id", "your-secret-key");
        HttpProfile httpProfile = new HttpProfile();
        httpProfile.setReqMethod("GET");
        httpProfile.setConnTimeout(30);
        httpProfile.setEndpoint("cvm.ap-shanghai.tencentcloudapi.com");
        ClientProfile clientProfile = new ClientProfile();
        clientProfile.setSignMethod("HmacSHA256");
        clientProfile.setHttpProfile(httpProfile);
        CvmClient client = new CvmClient(cred, "ap-shanghai", clientProfile);
        DescribeInstancesRequest req = new DescribeInstancesRequest();
        Filter respFilter = new Filter();
        respFilter.setName("zone");
        respFilter.setValues(new String[] { "ap-shanghai-1", "ap-shanghai-2" });
        req.setFilters(new Filter[] { respFilter });
        DescribeInstancesResponse resp = client.DescribeInstances(req);
        System.out.println(DescribeInstancesResponse.toJsonString(resp));
        System.out.println(resp.getTotalCount());
    } catch (TencentCloudSDKException e) {
        System.out.println(e.toString());
    }
}
Also used : Credential(com.tencentcloudapi.common.Credential) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) ClientProfile(com.tencentcloudapi.common.profile.ClientProfile) Filter(com.tencentcloudapi.cvm.v20170312.models.Filter) HttpProfile(com.tencentcloudapi.common.profile.HttpProfile) CvmClient(com.tencentcloudapi.cvm.v20170312.CvmClient) DescribeInstancesRequest(com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest) DescribeInstancesResponse(com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesResponse)

Example 7 with DescribeInstancesRequest

use of com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest in project tencentcloud-sdk-java by TencentCloud.

the class CredentialManager method main.

public static void main(String[] args) {
    try {
        // 通过凭证提供链得到一个认证对象
        Credential cred = new DefaultCredentialsProvider().getCredentials();
        // 实例化要请求产品(以cvm为例)的client对象,依次传入Credential、地域
        CvmClient client = new CvmClient(cred, "ap-guangzhou");
        // 实例化一个cvm实例信息查询请求对象,每个接口都会对应一个request对象。
        DescribeInstancesRequest req = new DescribeInstancesRequest();
        // 通过client对象调用DescribeInstances方法发起请求。注意请求方法名与请求对象是对应的
        // 返回的resp是一个DescribeInstancesResponse类的实例,与请求对象对应
        DescribeInstancesResponse resp = client.DescribeInstances(req);
        // 输出json格式的字符串回包
        System.out.println(DescribeInstancesResponse.toJsonString(resp));
    } catch (TencentCloudSDKException e) {
        System.out.println(e.toString());
    }
}
Also used : Credential(com.tencentcloudapi.common.Credential) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) CvmClient(com.tencentcloudapi.cvm.v20170312.CvmClient) DefaultCredentialsProvider(com.tencentcloudapi.common.provider.DefaultCredentialsProvider) DescribeInstancesRequest(com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest) DescribeInstancesResponse(com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesResponse)

Example 8 with DescribeInstancesRequest

use of com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest in project tencentcloud-sdk-java by TencentCloud.

the class SignatureTest method testGetHmacSHA256.

@Test
public void testGetHmacSHA256() {
    Credential cred = new Credential(System.getenv("TENCENTCLOUD_SECRET_ID"), System.getenv("TENCENTCLOUD_SECRET_KEY"));
    HttpProfile httpProfile = new HttpProfile();
    ClientProfile clientProfile = new ClientProfile();
    clientProfile.setHttpProfile(httpProfile);
    clientProfile.setSignMethod("HmacSHA256");
    httpProfile.setReqMethod("GET");
    CvmClient client = new CvmClient(cred, "ap-guangzhou", clientProfile);
    DescribeInstancesRequest req = new DescribeInstancesRequest();
    try {
        DescribeInstancesResponse resp = client.DescribeInstances(req);
        Assert.assertTrue(resp.getTotalCount() >= 0);
    } catch (TencentCloudSDKException e) {
        fail(e.toString());
    }
}
Also used : Credential(com.tencentcloudapi.common.Credential) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) ClientProfile(com.tencentcloudapi.common.profile.ClientProfile) HttpProfile(com.tencentcloudapi.common.profile.HttpProfile) CvmClient(com.tencentcloudapi.cvm.v20170312.CvmClient) DescribeInstancesRequest(com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest) DescribeInstancesResponse(com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesResponse) Test(org.junit.Test)

Example 9 with DescribeInstancesRequest

use of com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest in project tencentcloud-sdk-java by TencentCloud.

the class SignatureTest method testPostHmacSHA1.

@Test
public void testPostHmacSHA1() {
    Credential cred = new Credential(System.getenv("TENCENTCLOUD_SECRET_ID"), System.getenv("TENCENTCLOUD_SECRET_KEY"));
    HttpProfile httpProfile = new HttpProfile();
    ClientProfile clientProfile = new ClientProfile();
    clientProfile.setHttpProfile(httpProfile);
    clientProfile.setSignMethod("HmacSHA1");
    httpProfile.setReqMethod("POST");
    CvmClient client = new CvmClient(cred, "ap-guangzhou", clientProfile);
    DescribeInstancesRequest req = new DescribeInstancesRequest();
    try {
        DescribeInstancesResponse resp = client.DescribeInstances(req);
        Assert.assertTrue(resp.getTotalCount() >= 0);
    } catch (TencentCloudSDKException e) {
        fail(e.toString());
    }
}
Also used : Credential(com.tencentcloudapi.common.Credential) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) ClientProfile(com.tencentcloudapi.common.profile.ClientProfile) HttpProfile(com.tencentcloudapi.common.profile.HttpProfile) CvmClient(com.tencentcloudapi.cvm.v20170312.CvmClient) DescribeInstancesRequest(com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest) DescribeInstancesResponse(com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesResponse) Test(org.junit.Test)

Example 10 with DescribeInstancesRequest

use of com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest in project tencentcloud-sdk-java by TencentCloud.

the class SignatureTest method testPostHmacSHA256.

@Test
public void testPostHmacSHA256() {
    Credential cred = new Credential(System.getenv("TENCENTCLOUD_SECRET_ID"), System.getenv("TENCENTCLOUD_SECRET_KEY"));
    HttpProfile httpProfile = new HttpProfile();
    ClientProfile clientProfile = new ClientProfile();
    clientProfile.setHttpProfile(httpProfile);
    clientProfile.setSignMethod("HmacSHA256");
    httpProfile.setReqMethod("POST");
    CvmClient client = new CvmClient(cred, "ap-guangzhou", clientProfile);
    DescribeInstancesRequest req = new DescribeInstancesRequest();
    try {
        DescribeInstancesResponse resp = client.DescribeInstances(req);
        Assert.assertTrue(resp.getTotalCount() >= 0);
    } catch (TencentCloudSDKException e) {
        fail(e.toString());
    }
}
Also used : Credential(com.tencentcloudapi.common.Credential) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) ClientProfile(com.tencentcloudapi.common.profile.ClientProfile) HttpProfile(com.tencentcloudapi.common.profile.HttpProfile) CvmClient(com.tencentcloudapi.cvm.v20170312.CvmClient) DescribeInstancesRequest(com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest) DescribeInstancesResponse(com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesResponse) Test(org.junit.Test)

Aggregations

Credential (com.tencentcloudapi.common.Credential)12 TencentCloudSDKException (com.tencentcloudapi.common.exception.TencentCloudSDKException)12 DescribeInstancesRequest (com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest)12 CvmClient (com.tencentcloudapi.cvm.v20170312.CvmClient)10 DescribeInstancesResponse (com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesResponse)10 ClientProfile (com.tencentcloudapi.common.profile.ClientProfile)8 HttpProfile (com.tencentcloudapi.common.profile.HttpProfile)8 Test (org.junit.Test)6 CommonClient (com.tencentcloudapi.common.CommonClient)2 Filter (com.tencentcloudapi.cvm.v20170312.models.Filter)2 DefaultCredentialsProvider (com.tencentcloudapi.common.provider.DefaultCredentialsProvider)1