• 文档
  • 控制台
  • 登录
  • 立即注册
    目前不支持用户自主注册,如需注册账号,请联系400-080-1100
专有网络VPC API参考手册
最近更新时间:2023-04-16 17:00:00

2 安全组管理

2.1 CreateSecurityGroup

调用 CreateSecurityGroup 接口创建一个安全组。

2.1.1 使用说明

POST http://{endpoint}/vpc/v1.0/securitygroups

调用该接口创建安全组时,会根据 TemplateType 的值不同,分别创建包含对应规则的安全组。

2.1.2 请求参数

1.png

2.1.3 返回数据

2.png

3.png

2.1.4 示例

1. 请求示例

POST http://{endpoint}/vpc/v1.0/securitygroups 

{

    "SecurityGroupName": "openapi-sg",

    "Description": "test",

    "TemplateType": 1,

     "RegionId": "local"

}

2. 正常返回示例

{

     "RequestId": "b37aa3d0-1135-46bb-acb4-6b290f90ea77",

     "SecurityGroupId": "sg-0v2ergfh7***",

    "SecurityGroupName": "openapi-sg",

    "Description": "test",

     "TenantId": "1100000000011",

     "Port": "",

     "ZoneId": "",

     "RegionId": "local",

    "CreatedAt": "2022-04-29 17:59:30",

     "UpdatedAt": "2022-04-29 17:59:30"

}


2.2 DeleteSecurityGroup

调用 DeleteSecurityGroup 接口删除一个安全组。

2.2.1 使用说明

DELETE http://{endpoint}/vpc/v1.0/securitygroups/{security_group_id}

调用该接口删除安全组时,请先释放安全组绑定的实例。


2.2.2 请求参数

1.png

2.2.3 返回数据

2.png

2.2.4 示例

1. 请求示例

DELETE http://{endpoint}/vpc/v1.0/securitygroups/{security_group_id}

2. 正常返回示例

{

    "RequestId": "2e28fa30-651b-41c5-b03c-efbd391c2d8d"

}


2.3 GetSecurityGroupDetail

调用 GetSecurityGroupDetail 接口查询安全组详情。

2.3.1 使用说明

GET http://{endpoint}/vpc/v1.0/securitygroups/{security_group_id}

2.3.2 请求参数

1.png

2.3.3 返回数据

2.png

2.3.4 示例

1. 请求示例

GET http://{endpoint}/vpc/v1.0/securitygroups/{security_group_id}

2. 正常返回示例

{

    "RequestId": "a64d3c0a-1dab-4dbe-ad48-ca5c1db01d93",

     "SecurityGroupId": "sg-kbr4bkpv7v",

     "SecurityGroupName": "cecloud-sg-JJJJJ",

     "Description": "ceshi",

     "TenantId": "110000000001001",

    "Port": "",

    "ZoneId": "",

     "RegionId": "pre019",

    "CreatedAt": "2022-04-29 17:59:30",

    "UpdatedAt": "2022-04-29 17:59:30"

}


2.4 ModifySecurityGroup

调用 ModifySecurityGroup 接口修改安全组属性。

2.4.1 使用说明

PUT http://{endpoint}/vpc/v1.0/securitygroups/{security_group_id}

2.4.2 请求参数

1.png

2.4.3 返回数据

2.png

2.4.4 示例

1. 请求示例

PUT http://{endpoint}/vpc/v1.0/securitygroups/{security_group_id}

{

    "SecurityGroupName": "openapi-sg-new",

     "Description": "test"

}

2. 正常返回示例

{

     "RequestId": "a5717c5e-72ce-43d9-8e26-8f9db8d48935",

     "Id": "sg-kbr4bkpv7v",

    "SecurityGroupName": "cecloud-sg-new",

     "Description": "test",

     "TenantId": "110000000001001",

     "Port": "",

     "ZoneId": "",

     "RegionId": "pre019",

     "CreatedAt": "2022-04-29 17:59:30",

    "UpdatedAt": "2022-04-29 16:19:10"

}


2.5 GetSecurityGroupList

调用 GetSecurityGroupList 接口查询已创建的安全组列表。

2.5.1 使用说明

GET http://{Endpoint}/vpc/v1.0/securitygroups?PageNumber=1&PageSize=10

2.5.2 请求参数

1.png

2.5.3 返回数据

2.png

3.png

4.png

2.5.4 示例

1. 请求示例(多个过滤参数使用&连接)

GET http://{Endpoint}/vpc/v1.0/securitygroups?PageNumber=1&PageSize=10

2. 正常返回示例

{

    "PageNumber": 1,

    "PageSize": 10,

    "RequestId": "b98a70e5-a0b1-4bbf-bddd-28994fb38435",

    "SecurityGroups": [

        {

            "SecurityGroupId": "sg-3reu1e5xo2",

             "SecurityGroupName": "cecloud-sg-KKKKK",

             "RegionId": "pre019",

            "Description": "ceshi",

            "TenantId": "110000000001001",

             "RuleNum": 0,

            "VmNum": 1,

            "ZoneId": ""

      },

      {

        "SecurityGroupId": "sg-4aqyeolsqq5p",

         "SecurityGroupName": "sys_default",

         "RegionId": "pre019",

        "Description": "",

        "TenantId": "110000000001001",

        "RuleNum": 2,

         "VmNum": 0,

         "ZoneId": ""

     }

],

"TotalCount": 2

}


2.6 CreateSecurityGroupRule

调用 CreateSecurityGroupRule 接口创建安全组规则。

2.6.1 使用说明

POST http://{endpoint}/vpc/v1.0/securitygrouprules

2.6.2 请求参数

1.png

2.png

3.png

4.png

5.png

6.png

2.6.3 返回数据

1.png

2.png

2.6.4 示例

1. 请求示例

POST http://{endpoint}/vpc/v1.0/securitygrouprules

{

    "SecurityGroupId": "sg-pus8q85nck",

    "Description": "test",

    "Direction": "ingress",

    "EthernetType": "IPv4",

     "IpProtocol": "tcp",

     "PortRangeMin": 3,

     "PortRangeMax": 7,

    "SourceCidrIp": "0.0.0.0/0",

    "Policy": "allow",

     "Priority": 1,

    "RegionId": "local"

}

2. 正常返回示例

{

    "RequestId": "04ae8460-3603-49ba-bd85-4fb8149d0cc8",

     "SecurityGroupRuleId": "sgr-l5adg8bvahwj",

     "Description": "测试创建规则",

     "SecurityGroupId": "sg-jsv2j3fq8c",

    "Direction": "ingress",

    "EthernetType": "IPv4",

    "IpProtocol": "tcp",

    "PortRangeMin": 3,

    "PortRangeMax": 7,

    "TenantId": "110000000001001",

    "Policy": "allow",

    "Priority": 1,

     "RegionId": "pre019",

    "SourceCidrIp": "0.0.0.0/0",

    “RemoteGroupId”:””,

    "CreatedAt": "2022-04-29 17:59:30",

    "UpdatedAt": "2022-04-29 17:59:30"

}


2.7 DeleteSecurityGroupRule

调用 DeleteSecurityGroupRule 接口删除安全组规则。

2.7.1 使用说明

DELETE http://{endpoint}/vpc/v1.0/securitygrouprules/{security_group_rule_id}

2.7.2 请求参数

1.png

2.7.3 返回数据

2.png

2.7.4 示例

1. 请求示例

DELETE http://{endpoint}/vpc/v1.0/securitygrouprules/{security_group_rule_id}

2. 正常返回示例

{

     "RequestId": "6652d162-8491-4cd0-a21a-9a488f4c8af4"

}


2.8 GetSecurityGroupRuleDetail

调用 GetSecurityGroupRuleDetail 接口查询安全组规则详情。

2.8.1 使用说明

GET http://{endpoint}/vpc/v1.0/securitygrouprules/{security_group_rule_id}

2.8.2 请求参数

1.png

2.8.3 返回数据

2.png

3.png

2.8.4 示例

1. 请求示例

GET http://{endpoint}/vpc/v1.0/securitygrouprules/{security_group_rule_id}

2. 正常返回示例

{

     "RequestId": "819afcf9-8192-4160-8a1e-aabfdb8877ca",

     "SecurityGroupRuleId": "sgr-u9xtnkn6w5",

    "Description": "允许安全组内的云服务器彼此通信",

     "SecurityGroupId": "sg-uth9nopzju",

     "Direction": "ingress",

     "EthernetType": null,

     "IpProtocol": "all",

     "PortRangeMin": null,

     "PortRangeMax": null,

     "TenantId": "110000000001001",

     "Policy": "allow",

     "Priority": 1,

     "RegionId": "pre019",

    "SourceCidrIp": "0.0.0.0/0",

    “RemoteGroupId”:””,

     "CreatedAt": "2022-04-29 17:59:30",

     "UpdatedAt": "2022-04-29 17:59:30"

}


2.9 GetSecurityGroupRuleList

调用 GetSecurityGroupRuleList 接口查询安全组规则列表。

2.9.1 使用说明

GET http://{Endpoint}/vpc/v1.0/securitygrouprules?PageNumber=1&PageSize=10

2.9.2 请求参数

1.png

1.png

2.9.3 返回数据

3.png

4.png

2.9.4 示例

1. 请求示例(多个过滤参数使用&连接)

GET http://{Endpoint}/vpc/v1.0/securitygrouprules?PageNumber=1&PageSize=10

{

    "PageSize": 10,

     "PageNumber": 1,

    "SecurityGroupId": "sg-pus8q85nck"

}

2. 正常返回示例

{

     "PageNumber": 1,

    "PageSize": 5,

    "RequestId": "57baa2c0-8a49-4fe6-98b0-a53478c05ea6",

     "SecurityGroupRules": [

        {

            "SecurityGroupRuleId": "sgr-06bdnq2v7z",

            "Description": null,

            "SecurityGroupId": "sg-c0shy04egk",

            "Direction": "ingress",

            "EthernetType": null,

            "IpProtocol": "tcp",

            "PortRangeMin": 443,

            "PortRangeMax": 443,

            "TenantId": "110000000001001",

            "Policy": "allow",

             "Priority": 1,

            "RegionId": "pre019",

            "SourceCidrIp": "0.0.0.0/0",

            “RemoteGroupId”:””,

            "CreatedAt": "2022-04-29 17:59:30",

             "UpdatedAt": "2022-04-29 17:59:30"

        },

        {

             "RequestId": "",

            "SecurityGroupRuleId": "sgr-06yxtaijxn",

            "Description": "允许安全组内的云服务器彼此通信",

            "SecurityGroupId": "sg-lc8az7qkpy",

            "Direction": "ingress",

            "EthernetType": null,

            "IpProtocol": "all",

            "PortRangeMin": null,

            "PortRangeMax": null,

            "TenantId": "110000000001001",

            "Policy": "allow",

            "Priority": 1,

            "RegionId": "pre019",

            "SourceCidrIp": "0.0.0.0/0",

            “RemoteGroupId”:””,

            "CreatedAt": "2022-05-11 14:29:46",

            "UpdatedAt": "2022-05-11 14:29:46"

        }

    ],

     "TotalCount": 2

}


2.10 ModifySecurityGroupRule

调用 ModifySecurityGroupRule 接口修改安全组规则属性。

2.10.1 使用说明

PUT http://{endpoint}/vpc/v1.0/securitygrouprules/{security_group_rule_id}

2.10.2 请求参数

1.png

2.png

2.10.3 返回数据

3.png

4.png

2.10.4 示例

1. 请求示例

PUT http://{endpoint}/vpc/v1.0/securitygrouprules/{security_group_rule_id}

{

    "PortRangeMin": 13,

    "PortRangeMax": 17,

     "Policy": "drop"

}

2. 正常返回示例

{

    "RequestId": "7f72a5f2-54b0-4588-86b1-53ba23473a4c",

     "SecurityGroupRuleId": "sgr-l56m3uxu5c",

    "Description": "测试修改规则",

    "SecurityGroupId": "sg-uth9nopzju",

     "Direction": "egress",

     "EthernetType": null,

     "IpProtocol": "all",

     "PortRangeMin": 3,

    "PortRangeMax": 7,

     "TenantId": "110000000001001",

     "Policy": "allow",

    "Priority": 1,

     "RegionId": "pre019",

    "SourceCidrIp": "0.0.0.0/0",

  “RemoteGroupId”:””,

    "CreatedAt": "2022-05-11 14:29:46",

    "UpdatedAt": "2022-05-11 14:29:46"

}


2.11 AttachInstance

调用 AttachInstance 接口绑定虚机。

2.11.1 使用说明

PUT http://{endpoint}/vpc/v1.0/securitygroups/attach/{security_group_id}

2.11.2 请求参数

1.png

2.11.3 返回数据

2.png

2.11.4 示例

1. 请求示例

PUT http://{endpoint}/vpc/v1.0/securitygroups/attach/{security_group_id}

{

    "Action": "attachVmInstance",

    "InstanceUid": "ecs-xxx"

}

2. 正常返回示例

{

     "RequestId": "6652d162-8491-4cd0-a21a-9a488f4c8af4"

}


2.12 DetachVmInstance

调用 DetachVmInstance 接口解绑虚机。

2.12.1 使用说明

PUT http://{endpoint}/vpc/v1.0/securitygroups/detach/{security_group_id}

2.12.2 请求参数

1.png

2.12.3 返回数据

2.png

2.12.4 示例

1. 请求示例

PUT http://{endpoint}/vpc/v1.0/securitygroups/detach/{security_group_id}

{

         "Action": "detachVmInstance",

         "InstanceUid": " ecs-xxx "

}

37

2. 正常返回示例

{

       "RequestId": "6652d162-8491-4cd0-a21a-9a488f4c8af4"

2.13 错误码

1.png

2.png

意见反馈

文档内容是否对您有帮助?

如您有其他疑问,您也可以通过在线客服来与我们联系探讨 在线客服

联系我们
回到顶部