示例接口摘要
初始化客户端
Copied!
String user = "******";
String password = "******";
String projectId = "******";
String userDomainId = "******";
String authUrl = "******";
OSClient.OSClientV3 osclient = OSFactory.builderV3().endpoint(authUrl)
.credentials(user, password, Identifier.byId(userDomainId))
.scopeToProject(Identifier.byId(projectId)).authenticate();
创建VPC
功能介绍
创建虚拟私有云
接口实现代码示例:
Copied!
String cidr = "xxx.xxx.xxx.xxx/xx";
VpcCreate vpc = VpcCreate.builder()
.cidr(cidr)
.name("xxxxxx")
.enterpriseProjectId("")
.build();
Vpc createResp = osclient.vpc().vpcs().create(vpc);
if (null != createResp) {
System.out.println("create VPC success, id = " + createResp.getId());
} else {
System.out.println("create VPC failed");
}
查询VPC
功能介绍
查询虚拟私有云。
接口实现代码示例:
Copied!
Vpc getResp = osclient.vpc().vpcs().get(createResp.getId());
if (null != getResp) {
System.out.println("get VPC success, id = " + getResp.getId());
} else {
System.out.println("get VPC failed");
}
查询VPC列表
功能介绍
查询虚拟私有云列表。
接口实现代码示例:
Copied!
List<? extends Vpc> listResp = osclient.vpc().vpcs().list();
if (null != listResp) {
System.out.println("List all VPC success, size is = " + listResp.size());
} else {
System.out.println("get VPC failed");
}
Map<String, String> filteringParams = new HashMap<>();
filteringParams.put("limit", "5");
List<? extends Vpc> listWithFilterResp = osclient.vpc().vpcs().list(filteringParams);
if (null != listWithFilterResp) {
System.out.println("List VPC success, size is = " + listResp.size());
} else {
System.out.println("List VPC failed");
}
更新VPC
功能介绍
更新虚拟私有云。
接口实现代码示例:
Copied!
VpcUpdate vpcUpdate = VpcUpdate.builder().name("testUpdate").build();
Vpc updateResp = osclient.vpc().vpcs().update(getResp.getId(),vpcUpdate);
if (null != updateResp) {
System.out.println("Update a VPC success, id = " + updateResp.getId());
} else {
System.out.println("Update a VPC failed");
}
删除VPC
功能介绍
删除虚拟私有云。
接口实现代码示例:
Copied!
ActionResponse resp = osclient.vpc().vpcs().delete(getResp.getId());
if (resp.isSuccess()) {
System.out.println("Delete a VPC success");
} else {
System.out.println("Delete a VPC failed");
}
版本说明
本示例基于华为云SDK V2.0版本开发,高版本示例正在开发中。
功能介绍
虚拟私有云服务(Virtual Private Cloud, 以下简称VPC)。VPC为弹性云服务器构建隔离的、用户自主配置和管理的虚拟网络环境,提升用户云上资源的安全性,简化用户的网络部署。您可以使用本文档提供的API对VPC进行相关操作,如创建、查询、删除、更新等。 在调用VPC服务的API之前,请确保已经充分了解VPC服务相关概念,详细信息请参见《虚拟私有云用户指南》的产品介绍。
调用说明
VPC服务提供了REST(Representational StateTransfer)风格API,支持您通过HTTPS请求调用,调用方法请参见如何调用API。 同时VPC服务还提供多种编程语言的SDK供您使用,详情请参见SDK使用方法。
准备工作
1、获取华为云VPC开发工具包(SDK)。
2、华为云 Java SDK 支持认证方式:token认证。
3、华为云 Java SDK 支持 Java JDK 1.8 及其以上版本。
示例接口摘要
初始化客户端
String user = "******"; String password = "******"; String projectId = "******"; String userDomainId = "******"; String authUrl = "******"; OSClient.OSClientV3 osclient = OSFactory.builderV3().endpoint(authUrl) .credentials(user, password, Identifier.byId(userDomainId)) .scopeToProject(Identifier.byId(projectId)).authenticate();
创建VPC
功能介绍
创建虚拟私有云
接口实现代码示例:
// Create VPC String cidr = "xxx.xxx.xxx.xxx/xx"; VpcCreate vpc = VpcCreate.builder() .cidr(cidr) .name("xxxxxx") .enterpriseProjectId("") .build(); Vpc createResp = osclient.vpc().vpcs().create(vpc); if (null != createResp) { System.out.println("create VPC success, id = " + createResp.getId()); } else { System.out.println("create VPC failed"); }
查询VPC
功能介绍
查询虚拟私有云。
接口实现代码示例:
// Get VPC Vpc getResp = osclient.vpc().vpcs().get(createResp.getId()); if (null != getResp) { System.out.println("get VPC success, id = " + getResp.getId()); } else { System.out.println("get VPC failed"); }
查询VPC列表
功能介绍
查询虚拟私有云列表。
接口实现代码示例:
// List all VPC List<? extends Vpc> listResp = osclient.vpc().vpcs().list(); if (null != listResp) { System.out.println("List all VPC success, size is = " + listResp.size()); } else { System.out.println("get VPC failed"); } // List VPC with filter Map<String, String> filteringParams = new HashMap<>(); filteringParams.put("limit", "5"); List<? extends Vpc> listWithFilterResp = osclient.vpc().vpcs().list(filteringParams); if (null != listWithFilterResp) { System.out.println("List VPC success, size is = " + listResp.size()); } else { System.out.println("List VPC failed"); }
更新VPC
功能介绍
更新虚拟私有云。
接口实现代码示例:
//Update a VPC VpcUpdate vpcUpdate = VpcUpdate.builder().name("testUpdate").build(); Vpc updateResp = osclient.vpc().vpcs().update(getResp.getId(),vpcUpdate); if (null != updateResp) { System.out.println("Update a VPC success, id = " + updateResp.getId()); } else { System.out.println("Update a VPC failed"); }
删除VPC
功能介绍
删除虚拟私有云。
接口实现代码示例:
//Delete a VPC ActionResponse resp = osclient.vpc().vpcs().delete(getResp.getId()); if (resp.isSuccess()) { System.out.println("Delete a VPC success"); } else { System.out.println("Delete a VPC failed"); }
参考
更多信息请参考虚拟私有云VPC服务。