You need to enable JavaScript to run this app.
导航

导入自定义镜像

最近更新时间2023.05.24 14:24:44

首次发布时间2023.05.24 14:24:44

本文介绍如何导入自定义镜像到火山引擎。

示例代码

/**
* Example Code generated by Beijing Volcanoengine Technology.
*/
package com.volcengine.ecs.examples;

import com.volcengine.ApiClient;
import com.volcengine.ApiException;
import com.volcengine.sign.Credentials;

import com.volcengine.ecs.EcsApi;
import com.volcengine.ecs.model.*;


public class TestImportImage {
    public static void main(String[] args) throws Exception {
        //设置您的ak
        String ak = "Your AK";
        //设置您的sk
        String sk = "Your SK";
        //设置您要访问的地域
        String region = "Your Region";

				//初始化apiclient
        ApiClient apiClient = new ApiClient()
                .setCredentials(Credentials.getCredentials(ak, sk))
                .setRegion(region);

        EcsApi api = new EcsApi(apiClient);

        //导入自定义镜像
        ImportImageRequest importImageRequest = new ImportImageRequest();
        importImageRequest.setArchitecture("amd64");//镜像的架构类型
        importImageRequest.setImageName("image-1");//镜像的名称
        importImageRequest.setOsType("Linux");//操作系统类型
        importImageRequest.setPlatform("CentOS");//镜像操作系统的发行版本
        importImageRequest.setPlatformVersion("7.6");//镜像的发行版本
        importImageRequest.setUrl("xxx");//自定义镜像在TOS存储桶的Url链接

        // 发起请求并处理返回或异常
        try {
            ImportImageResponse response = api.importImage(importImageRequest);
            System.out.println(response);
        } catch (ApiException e) {
            System.out.println(e.getResponseBody());
        }
    }
}

相关文档