文档

创建云电脑

更新时间:

本文介绍了如何通过无影云电脑Java SDK调用DescribeOfficeSites、DescribeBundlesDescribePolicyGroups查询办公网络状态、云电脑模板和策略信息,再调用CreateDesktops创建一台或者多台云电脑。

前提条件

  • Java的版本为Java 8及以上。

  • 安装SDK核心库,各产品SDK默认安装了darabonba-java-core等核心库,您也可以指定安装必要版本。

操作步骤

  1. 调用DescribeOfficeSites查询办公网络是否可用。

    当返回字段Status的值为REGISTERED表示该办公网络可用。

  2. 调用DescribeBundles查询云电脑模板的详细信息。

    当返回字段StockState的值为Sufficient表示库存充足。

  3. 调用DescribePolicyGroups查询策略的详细信息。

  4. 调用CreateDesktops创建一台云电脑。

SDK示例

您可以在OpenAPI门户调用阿里云无影云电脑的API接口,自动获取相应接口的SDK示例代码。具体操作,请参见如何自动获取SDK示例

下文以DescribeOfficeSites为例,查询杭州地域的便捷办公网络(cn-hangzhou+dir-586651****)是否可用,相关SDK示例如下:

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
/*
pom.xml
<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>aliyun-java-sdk-core</artifactId>
  <version>4.6.0</version>
</dependency>
*/

public class DescribeOfficeSites {
    public static void main(String[] args) {

        // Please ensure that the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set.
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        /** use STS Token
        DefaultProfile profile = DefaultProfile.getProfile(
            "<your-region-id>",           // The region ID
            System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),       // The AccessKey ID of the RAM account
            System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),   // The AccessKey Secret of the RAM account
            System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN"));     // STS Token
        **/

        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();

        request.setSysMethod(MethodType.POST);
        request.setSysDomain("ecd.cn-hangzhou.aliyuncs.com");
        request.setSysVersion("2020-09-30");
        request.setSysAction("DescribeOfficeSites");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("OfficeSiteType", "SIMPLE");
        request.putQueryParameter("OfficeSiteId.1", "cn-hangzhou+dir-586651****");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}

相关文档

DescribeOfficeSites - 查询办公网络的详细信息

DescribeBundles - 查询云电脑模板的详细信息

DescribePolicyGroups - 查询策略详细信息

CreateDesktops - 创建一台或多台云电脑

  • 本页导读 (0)
文档反馈