文档首页 > > API参考> 应用示例> 环境管理

环境管理

分享
更新时间:2020/06/09 GMT+08:00

场景描述

本章节指导用户通过API实现环境管理。API的调用方法请参见如何调用API

流程介绍

  1. 创建环境,添加基础资源
  2. 为环境添加其他需要的资源
  3. 根据环境ID查询环境

前提条件

  • 获取IAM的token,调用Token认证,并将token值设置为环境变量:export Token={token}。
  • 获取ServiceStage的endpoint,参考地区和终端节点,以下示例中以{servicestage_endpoint}代替。

操作步骤

  1. 创建环境,添加基础资源。

    调用创建环境接口,请求示例如下。

    curl -k -H "Content-Type:application/json" -H "X-Auth-Token:$Token" -X POST "https://{servicestage_endpoint}/v2/{project_id}/cas/environments" -d '{
        "name": "dev-env", 
        "description": "develop environment", 
        "enterprise_project_id": "0", 
        "charge_mode": "provided", 
        "vpc_id": "b9b8f9ad-1a2e-403d-83f1-cb71a3c06df8", 
        "base_resources": [
            {
                "id": "b6862a62-d916-11e9-bdf1-0255ac101fd9", 
                "type": "cce"
            }
        ]
    }'

    返回结果:

    {
        "id": "ea011e01-2eb5-453f-87bf-874e4a855abe", 
        "name": "dev-env", 
        "alias": null, 
        "description": "develop environment", 
        "project_id": "bf8523d898b64e4eb956e3be3555ca16", 
        "enterprise_project_id": "0", 
        "charge_mode": "provided", 
        "vpc_id": "b9b8f9ad-1a2e-403d-83f1-cb71a3c06df8", 
        "base_resources": [
            {
                "id": "b6862a62-d916-11e9-bdf1-0255ac101fd9", 
                "type": "cce"
            }
        ],  
        "creator": "xxx", 
        "create_time": 1578984198394, 
        "update_time": 1578984198394
    }

    得到的id,后续示例中以{environment_id}代替。

  2. 为环境添加其他需要的资源。

    调用修改环境资源接口。根据自己已有的资源和需求,可以将和环境相同vpc下的ecs,cce,elb,cse,eip等多种类型的资源添加到环境中。请求示例如下。

    curl -k -H "Content-Type:application/json" -H "X-Auth-Token:$Token" -X PATCH "https://{servicestage_endpoint}/v2/{project_id}/cas/environments/{environment_id}/resources" -d '{
        "add_optional_resources": [{
            "id": "default",
            "type": "cse"
        }]
    }'
    返回结果:
    {
        "id": "ea011e01-2eb5-453f-87bf-874e4a855abe", 
        "name": "dev-env", 
        "alias": null, 
        "description": "develop environment", 
        "project_id": "bf8523d898b64e4eb956e3be3555ca16", 
        "enterprise_project_id": "0", 
        "charge_mode": "provided", 
        "vpc_id": "b9b8f9ad-1a2e-403d-83f1-cb71a3c06df8", 
        "base_resources": [
            {
                "id": "b6862a62-d916-11e9-bdf1-0255ac101fd9", 
                "type": "cce"
            }
        ],
        "optional_resources": [
            {
                "id": "default", 
                "type": "cse"
            }
        ], 
        "creator": "xxx", 
        "create_time": 1578984198394, 
        "update_time": 1578984198394
    }

  3. 根据环境ID查询环境。

    调用根据环境ID获取环境详细信息接口,去查询环境。请求示例如下。

    curl -k -H "Content-Type:application/json" -H "X-Auth-Token:$Token" -X GET "https://{servicestage_endpoint}/v2/{project_id}/cas/environments/{environment_id}"

    返回结果:

    {
        "id": "ea011e01-2eb5-453f-87bf-874e4a855abe", 
        "name": "dev-env", 
        "alias": null, 
        "description": "develop environment", 
        "project_id": "bf8523d898b64e4eb956e3be3555ca16", 
        "enterprise_project_id": "0", 
        "charge_mode": "provided", 
        "vpc_id": "b9b8f9ad-1a2e-403d-83f1-cb71a3c06df8", 
        "base_resources": [
            {
                "id": "b6862a62-d916-11e9-bdf1-0255ac101fd9", 
                "type": "cce"
            }
        ],
        "optional_resources": [
            {
                "id": "default", 
                "type": "cse"
            }
        ], 
        "creator": "xxx", 
        "create_time": 1578984198394, 
        "update_time": 1578984198394
    }

分享:

    相关文档

    相关产品

文档是否有解决您的问题?

提交成功!

非常感谢您的反馈,我们会继续努力做到更好!

反馈提交失败,请稍后再试!

*必选

请至少选择或填写一项反馈信息

字符长度不能超过200

提交反馈 取消

如您有其它疑问,您也可以通过华为云社区问答频道来与我们联系探讨

智能客服提问云社区提问