|
@@ -0,0 +1,195 @@
|
|
|
+# 华为云CLI VPC
|
|
|
+
|
|
|
+## 写在前面
|
|
|
+
|
|
|
+本实验未指明的信息均是在华为云CLI的默认配置中调用。
|
|
|
+
|
|
|
+## API概览
|
|
|
+
|
|
|
+虚拟私有云所提供的接口分为VPC接口与OpenStack原生接口。
|
|
|
+
|
|
|
+通过配合使用VPC接口和OpenStack原生接口,您可以完整的使用虚拟私有云的所有功能。同一功能既有原生OpenStack接口,还有VPC接口时,建议您优先使用VPC接口。
|
|
|
+
|
|
|
+### VPC接口说明
|
|
|
+
|
|
|
+| **类型** | **说明** |
|
|
|
+| ------------------------------------------------------------ | ------------------------------------------------------------ |
|
|
|
+| [VPC](https://support.huaweicloud.com/api-vpc/vpc_api01_0000.html) | VPC的创建、查询、更新、删除等接口。 |
|
|
|
+| [子网](https://support.huaweicloud.com/api-vpc/vpc_subnet01_0000.html) | 子网的创建、查询、更新、删除等接口。 |
|
|
|
+| [配额](https://support.huaweicloud.com/api-vpc/vpc_quota_0000.html) | 配额查询接口。 |
|
|
|
+| [私有IP](https://support.huaweicloud.com/api-vpc/vpc_privateip_0000.html) | 私有IP的申请、查询、删除等接口。 |
|
|
|
+| [安全组](https://support.huaweicloud.com/api-vpc/vpc_sg01_0000.html) | 安全组创建、查询、删除等接口。安全组规则创建、查询、删除等接口。 |
|
|
|
+| [端口](https://support.huaweicloud.com/api-vpc/vpc_port01_0000.html) | 端口创建、查询、更新、删除等接口。 |
|
|
|
+| [对等连接](https://support.huaweicloud.com/api-vpc/vpc_peering_0000.html) | 对等连接查询、创建、更新、删除等接口。接受、拒绝对等连接请求接口。 |
|
|
|
+| [VPC路由](https://support.huaweicloud.com/api-vpc/vpc_route_0000.html) | VPC路由查询、创建、删除等接口。 |
|
|
|
+| [路由表](https://support.huaweicloud.com/api-vpc/vpc_apiroutetab_0000.html) | 路由表查询、创建、删除等接口。 |
|
|
|
+| [标签管理](https://support.huaweicloud.com/api-vpc/vpc_tag_0000.html) | VPC资源标签的创建、查询、删除等接口。子网资源标签的创建、查询、删除等接口。该类型接口目前在“华北-北京一”“华北-北京四”、“华东-上海一”、“华东-上海二”、“西南-贵阳一”“华南-广州”、“中国-香港”区域开放。 |
|
|
|
+| [查询网络IP使用情况](https://support.huaweicloud.com/api-vpc/vpc_natworkip_0000.html) | 查询一个指定网络中的IP地址使用情况,包括网络中的IP总数以及已用IP总数。 |
|
|
|
+
|
|
|
+### OpenStack原生接口说明
|
|
|
+
|
|
|
+| **类型** | **说明** |
|
|
|
+| ------------------------------------------------------------ | ------------------------------------------------------------ |
|
|
|
+| [API版本信息](https://support.huaweicloud.com/api-vpc/vpc_version_0000.html) | 当前API所有可用版本的查询、分页查询。 |
|
|
|
+| [端口](https://support.huaweicloud.com/api-vpc/vpc_port02_0000.html) | 端口的查询、创建、更新、删除等接口。 |
|
|
|
+| [网络](https://support.huaweicloud.com/api-vpc/vpc_network_0000.html) | 网络的查询、创建、更新、删除等接口。 |
|
|
|
+| [子网](https://support.huaweicloud.com/api-vpc/vpc_subnet02_0000.html) | 子网的查询、创建、更新、删除等接口。 |
|
|
|
+| [路由器](https://support.huaweicloud.com/api-vpc/vpc_router_0000.html) | 路由器的查询、创建、更新、删除等接口。 |
|
|
|
+| [网络ACL](https://support.huaweicloud.com/api-vpc/vpc_firewall_0000.html) | 网络ACL的创建、更新、删除等接口。网络ACL规则的创建、更新、删除、查询等接口。网络ACL策略的创建、更新、删除、查询等接口。 |
|
|
|
+| [安全组](https://support.huaweicloud.com/api-vpc/vpc_sg02_0000.html) | 安全组创建、查询、删除、更新等接口。安全组规则创建、查询、删除等接口。 |
|
|
|
+
|
|
|
+## VPC
|
|
|
+
|
|
|
+### 查询VPC
|
|
|
+
|
|
|
+`hcloud VPC ListVpcs`命令可以用来查询VPC列表。
|
|
|
+
|
|
|
+现在华为云有V2和V3两种API版本,默认调用V3进行查询,可以通过指定API版本来选择。
|
|
|
+
|
|
|
+```shell
|
|
|
+hcloud VPC ListVpcs
|
|
|
+命令中ListVpcs有多个版本,默认使用该API最新版本v3.若需指定其他版本,请将API名修改为"ListVpcs/版本号"
|
|
|
+{
|
|
|
+ "request_id": "aabb48b0901d934435c4859408afd2e0",
|
|
|
+ "vpcs": [
|
|
|
+ {
|
|
|
+ "id": "b517649f-9465-4985-acbc-4472e1b36608",
|
|
|
+ "name": "vpc-default",
|
|
|
+ "description": "vpc-default",
|
|
|
+ "cidr": "192.168.0.0/16",
|
|
|
+ "extend_cidrs": [],
|
|
|
+ "status": "ACTIVE",
|
|
|
+ "project_id": "06c9a7702d00254f2f84c00e8a1a5bf5",
|
|
|
+ "enterprise_project_id": "0",
|
|
|
+ "tags": [],
|
|
|
+ "created_at": "2022-03-11T01:21:00Z",
|
|
|
+ "updated_at": "2022-03-11T01:21:01Z",
|
|
|
+ "cloud_resources": [
|
|
|
+ {
|
|
|
+ "resource_type": "routetable",
|
|
|
+ "resource_count": 1
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "resource_type": "virsubnet",
|
|
|
+ "resource_count": 1
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "page_info": {
|
|
|
+ "previous_marker": "b517649f-9465-4985-acbc-4472e1b36608",
|
|
|
+ "current_count": 1
|
|
|
+ }
|
|
|
+}
|
|
|
+hcloud VPC ListVpcs/v2
|
|
|
+{
|
|
|
+ "vpcs": [
|
|
|
+ {
|
|
|
+ "id": "b517649f-9465-4985-acbc-4472e1b36608",
|
|
|
+ "name": "vpc-default",
|
|
|
+ "description": "vpc-default",
|
|
|
+ "cidr": "192.168.0.0/16",
|
|
|
+ "status": "OK",
|
|
|
+ "routes": [],
|
|
|
+ "enterprise_project_id": "0"
|
|
|
+ }
|
|
|
+ ]
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+**参数解析**
|
|
|
+
|
|
|
+| 参数 | 说明 |
|
|
|
+| ----------- | ------------- |
|
|
|
+| id | VPC的ID |
|
|
|
+| name | VPC的名字 |
|
|
|
+| description | VPC的描述信息 |
|
|
|
+| cidr | VPC的网段信息 |
|
|
|
+| status | VPC的状态 |
|
|
|
+| routes | VPC的路由表 |
|
|
|
+
|
|
|
+### 创建VPC
|
|
|
+
|
|
|
+通过查询可以得知一个VPC需要的最基本的参数有:name,cidr。可以配合以下命令来创建VPC:
|
|
|
+
|
|
|
+```shell
|
|
|
+hcloud VPC CreateVpc --help
|
|
|
+
|
|
|
+HCloud CLI(Huawei Cloud CLI) Version 3.1.10 Copyright(C) 2020-2022 www.huaweicloud.com
|
|
|
+
|
|
|
+Service:
|
|
|
+ VPC
|
|
|
+
|
|
|
+Description:
|
|
|
+ 创建虚拟私有云。
|
|
|
+
|
|
|
+Method:
|
|
|
+ POST
|
|
|
+
|
|
|
+Params:
|
|
|
+ --cli-region
|
|
|
+ required string 当前可调用的区域.若命令中未输入,将使用当前配置项中的cli-region
|
|
|
+ --project_id
|
|
|
+ required string path 项目ID。若命令中未输入,将根据认证信息获取指定区域的父级项目ID,或使用当前配置项中的cli-project-id
|
|
|
+ --vpc.cidr
|
|
|
+ optional string body 功能说明:虚拟私有云下可用子网的范围。
|
|
|
+ 取值范围:
|
|
|
+ - 10.0.0.0/8 ~ 10.255.255.240/28
|
|
|
+ - 172.16.0.0/12 ~ 172.31.255.240/28
|
|
|
+ - 192.168.0.0/16 ~ 192.168.255.240/28
|
|
|
+ 约束:必须是ipv4 cidr格式,例如:192.168.0.0/16
|
|
|
+ --vpc.description
|
|
|
+ optional string body 功能说明:虚拟私有云的描述。
|
|
|
+ 取值范围:0-255个字符,不能包含“<”和“>”。
|
|
|
+ --vpc.enterprise_project_id
|
|
|
+ optional string body 功能说明:企业项目ID。创建虚拟私有云时,给虚拟私有云绑定企业项目ID。
|
|
|
+ 取值范围:最大长度36字节,带“-”连字符的UUID格式,或者是字符串“0”。“0”表示默认企业项目。
|
|
|
+ 默认值:"0"
|
|
|
+ --vpc.name
|
|
|
+ optional string body 功能说明:虚拟私有云名称。
|
|
|
+ 取值范围:0-64个字符,支持数字、字母、中文、_(下划线)、-(中划线)、.(点)
|
|
|
+ 约束:如果名称不为空,则同一个租户下的名称不能重复
|
|
|
+```
|
|
|
+
|
|
|
+**示例:**
|
|
|
+
|
|
|
+根据上面的信息来创建一个名为vpc-test,CIDR为192.168.0.0/24的VPC。
|
|
|
+
|
|
|
+```shell
|
|
|
+hcloud VPC CreateVpc --vpc.name=vpc-test --vpc.cidr=192.168.0.0/24
|
|
|
+{
|
|
|
+ "vpc": {
|
|
|
+ "id": "12fb3a3a-5e55-4fb4-a589-862d09ef59ce",
|
|
|
+ "name": "vpc-test",
|
|
|
+ "description": "",
|
|
|
+ "cidr": "192.168.0.0/24",
|
|
|
+ "status": "CREATING",
|
|
|
+ "routes": [],
|
|
|
+ "enterprise_project_id": "0"
|
|
|
+ }
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+![2022.3.15-华为云CLI-创建VPC-vps-test](images/2022.3.15-华为云CLI-创建VPC-vps-test.png)
|
|
|
+
|
|
|
+### 删除VPC
|
|
|
+
|
|
|
+使用`cloud VPC DeleteVpc`命令删除VPC。
|
|
|
+
|
|
|
+```shell
|
|
|
+hcloud VPC DeleteVpc --vpc_id=12fb3a3a-5e55-4fb4-a589-862d09ef59ce
|
|
|
+
|
|
|
+```
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+## 子网
|
|
|
+
|
|
|
+## 安全组
|
|
|
+
|
|
|
+## 对等连接
|
|
|
+
|
|
|
+## VPC路由
|
|
|
+
|
|
|
+## 路由表
|
|
|
+
|