Updated on 2025-02-14 GMT+08:00

Creating a Scheduled Start/Stop Policy

Function

This API is used to create a scheduled start/stop policy.

URI

POST /v1/{project_id}/cae/timer-rules

Table 1 Path parameter

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. See Obtaining a Project ID.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token.

Maximum characters: 16,384

X-Enterprise-Project-ID

No

String

Enterprise project ID.

  • When an environment is created, it will be bound with an enterprise project ID.
  • Enter 0 or up to 36 characters in UUID format with hyphens (-).
  • If this parameter is not specified or set to 0, resources in the default enterprise project are queried.
NOTE:

For more information about enterprise projects and how to obtain enterprise project IDs, see Enterprise Management User Guide.

X-Environment-ID

Yes

String

Environment ID.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

api_version

No

String

API version. Fixed value: v1.

Enumerated value:

  • v1

kind

No

String

API type. Fixed value: TimerRule.

Enumerated value:

  • TimerRule

spec

No

UpdateTimerRuleDetails object

Start/stop policy specifications.

Table 4 UpdateTimerRuleDetails

Parameter

Mandatory

Type

Description

name

Yes

String

Name of a scheduled start/stop policy.

type

Yes

String

Policy type. Options: stop and start.

status

Yes

String

Policy status. Options: on and off.

apps

No

Array of AppInfo objects

Applications to which the scheduled start/stop policy applies. This parameter is mandatory only when effective_range is set to application.

components

No

Array of ComponentInfo objects

Components to which the scheduled start/stop policy applies. This parameter is mandatory only when effective_range is set to component.

cron

Yes

String

Cron expression.

effective_range

Yes

String

Scope to which a policy applies. Options: component, application, and environment.

effective_policy

Yes

String

Trigger mode. Options: onetime and periodic.

Table 5 AppInfo

Parameter

Mandatory

Type

Description

app_id

No

String

Application ID.

app_name

No

String

Application name.

Table 6 ComponentInfo

Parameter

Mandatory

Type

Description

component_id

No

String

Component ID.

component_name

No

String

Component name.

Response Parameters

Status code: 200

Table 7 Response body parameters

Parameter

Type

Description

api_version

String

API version. Fixed value: v1.

Enumerated value:

  • v1

kind

String

API type. Fixed value: TimerRule.

Enumerated value:

  • TimerRule

items

Array of TimerRuleDetails objects

List of start/stop policies.

Table 8 TimerRuleDetails

Parameter

Type

Description

id

String

ID of a scheduled start/stop policy. This parameter is ignored during policy creation.

name

String

Name of a scheduled start/stop policy.

type

String

Policy type. Options: stop and start.

status

String

Policy status. Options: on and off.

env_id

String

Environment ID.

apps

Array of AppInfo objects

Applications to which the scheduled start/stop policy applies. This parameter is mandatory only when effective_range is set to application.

components

Array of ComponentInfo objects

Components to which the scheduled start/stop policy applies. This parameter is mandatory only when effective_range is set to component.

component_number

Integer

Number of components to which a scheduled start/stop policy applies. This parameter is ignored during policy creation.

cron

String

Cron expression.

effective_range

String

Scope to which a policy applies. Options: component, application, and environment.

effective_policy

String

Trigger mode. Options: onetime and periodic.

last_execution_status

String

Status of the last execution. Options: abnormal, normal, and executing. This parameter is ignored during policy creation.

Table 9 AppInfo

Parameter

Type

Description

app_id

String

Application ID.

app_name

String

Application name.

Table 10 ComponentInfo

Parameter

Type

Description

component_id

String

Component ID.

component_name

String

Component name.

Example Request

Create a scheduled start/stop policy: Set name to test-2, type to start, effective_range to environment, and effective_policy to onetime.

POST https://{endpoint}/v1/{project_id}/cae/timer-rules

{
  "api_version" : "v1",
  "kind" : "TimerRule",
  "spec" : {
    "name" : "test-2",
    "type" : "start",
    "cron" : "0 55 16 22 2 ? 2023",
    "status" : "on",
    "env_id" : "c41a8e9f-5447-406a-8783-85885f3870a3",
    "effective_range" : "environment",
    "effective_policy" : "onetime"
  }
}

Example Response

Status code: 200

The request is successful.

{
  "api_version": "v1",
  "kind": "TimerRule",
  "items": [
    {
      "id": "string",
      "name": "string",
      "type": "start",
      "env_id": "string",
      "cron": "0 16 17 31 1 ? 2023",
      "component_number": 2,
      "status": "off",
      "last_execution_status": "normal",
      "effective_range": "application",
      "effective_policy": "onetime",
      "apps": [
        {
          "app_id": "string",
          "app_name": "string"
        }
      ]
  ]
}

Status Code

Status Code

Description

200

The request is successful.

Error Code

For details, see Error Codes.