应用管理与运维平台 ServiceStage-创建并管理环境:操作步骤

时间:2025-02-12 15:02:01

操作步骤

  1. 调用创建环境API创建环境,请求示例如下:

    curl -k -H "Content-Type:application/json;charset=utf8" -H "X-Auth-Token:$Token" -X POST "https://{servicestage_endpoint}/v3/{project_id}/cas/environments" -d ' {    "name": "env-Kubernetes",    "description": "test environment",    "enterprise_project_id": "0",    "charge_mode": "provided",    "vpc_id": "081c539d-ed09-43b0-81d7-a87603e528b7",    "labels": [        {            "key": "testKey",            "value": "testValue"        }    ],    "deploy_mode": "container"}'
    返回结果:
    {    "id": "9cd33350-5d7f-46ec-ba6d-40ed793f0eb7",    "name": "env-Kubernetes",    "description": "test environment",    "creator": "test_user",    "enterprise_project_id": "0",    "vpc_id": "081c539d-ed09-43b0-81d7-a87603e528b7",    "deploy_mode": "container",    "vm_cluster_size": 50,    "labels": [        {            "key": "testKey",            "value": "testValue"        }    ],    "create_time": 1689564968283,    "update_time": 1689564968283,    "resources": []}

    记录返回结果中加粗显示的环境ID,用于替换后续示例中的{environment_id}。

  2. 调用根据环境ID修改环境资源API为环境添加资源。

    根据您已有的资源和需求,可以将和环境相同VPC下的计算、网络、中间件等多种类型的资源添加到环境中。请求示例如下:
    curl -k -H "Content-Type:application/json;charset=utf8" -H "X-Auth-Token:$Token" -X PUT "https://{servicestage_endpoint}/v3/{project_id}/cas/environments/{environment_id}/resources" -d ' {    "resources": [        {            "id": "d2917177-3436-4e53-a5bc-706c3529e0e7",            "name": "elb-pu6a",            "type": "elb"        }    ]}'
    返回结果:
    {    "resources": [        {            "id": "d2917177-3436-4e53-a5bc-706c3529e0e7",            "type": "elb",            "name": "elb-pu6a"        }    ]}

  3. 调用根据环境ID获取环境详细信息API根据环境ID查询环境详细信息,请求示例如下:

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

    返回结果:

    {    "id": "9cd33350-5d7f-46ec-ba6d-40ed793f0eb7",    "name": "env-Kubernetes",    "description": "test environment",    "creator": "test_user",    "enterprise_project_id": "0",    "vpc_id": "081c539d-ed09-43b0-81d7-a87603e528b7",    "deploy_mode": "container",    "vm_cluster_size": 50,    "labels": [        {            "key": "testKey",            "value": "testValue"        }    ],    "create_time": 1689564968283,    "update_time": 1689574181240,    "resources": [        {            "id": "d2917177-3436-4e53-a5bc-706c3529e0e7",            "type": "elb",            "name": "elb-pu6a"        }    ]}

support.huaweicloud.com/api-servicestage/servicestage_06_0013.html