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

创建子网

最近更新时间2023.06.09 11:20:34

首次发布时间2023.06.09 11:20:34

本文介绍如何创建一个子网。

示例代码

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

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

import com.volcengine.vpc.VpcApi;
import com.volcengine.vpc.model.*;


public class TestCreateSubnet {
    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);

        VpcApi api = new VpcApi(apiClient);

        //创建一个子网
        CreateSubnetRequest createSubnetRequest = new CreateSubnetRequest();
        createSubnetRequest.setCidrBlock("172.XX.XX.0/24");   // 子网的网段
        createSubnetRequest.setVpcId("vpc-257gqcdfvx6n****"); // 子网所属的VPC
        createSubnetRequest.setZoneId("cn-beijing-a");        // 子网所在的可用区

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

相关文档