All Products
Search
Document Center

CloudOps Orchestration Service:Public Templates

Last Updated:Dec 27, 2023

CloudOps Orchestration Service (OOS) provides various public templates specific to different scenarios. The following tables list the currently supported templates and the sample code.

Handle multiple O&M tasks at a time

Template

Description

Sample code

ACS-ECS-StartInstancesByInstanceIds

Starts the ECS instances that have the specified IDs at the same time. When this template is executed, the StartInstance operation is called to start the ECS instances. Only ECS instances in the Stopped status can be started. Required parameter: instanceIds.

YAML

ACS-ECS-StopInstancesByInstanceIds

Stops the ECS instances that have the specified IDs at the same time. When this template is executed, the StopInstance operation is called to stop the ECS instances. Only ECS instances in the Running status can be stopped. Required parameter: instanceIds.

YAML

ACS-ECS-RebootInstancesByInstanceIds

Restarts the ECS instances that have the specified IDs at the same time. When this template is executed, the RebootInstance operation is called to restart the ECS instances. Only ECS instances in the Running status can be restarted. Required parameter: instanceIds.

YAML

ACS-ECS-ScheduleToUpgradeInternetBandwidthByInstanceIds

Temporarily upgrades the bandwidth for the ECS instances that have the specified IDs at the specified point in time. When this template is executed, the ModifyInstanceNetworkSpec operation is called to temporarily upgrade the bandwidth for the ECS instances that have the specified IDs at the specified point in time. Required parameters: cron, endDate, instanceIds, maxBandwidthIn, maxBandwidthOut, startTime, and endTime.

YAML

ACS-ECS-BulkyUpgradeInternetBandwidthByInstanceIds

Temporarily upgrades the bandwidth for the ECS instances that have the specified IDs at the same time. When this template is executed, the ModifyInstanceNetworkSpec operation is called to temporarily upgrade the bandwidth for the ECS instances that have the specified IDs. Required parameters: instanceIds, maxBandwidthIn, maxBandwidthOut, startTime, and endTime.

YAML

ACS-ECS-BulkyDeletePrepaidInstanceByInstanceIds

Releases the subscription-based ECS instances that have the specified IDs at the same time. Required parameter: instanceIds.

YAML

ACS-ECS-BulkyRunCommandByTag

Runs a command in the Cloud Assistant client on multiple ECS instances that are specified by instance tags. Required parameters: tagKey, tagValue, commandContent, and commandType.

YAML

ACS-ECS-BulkyTagInstanceByRunCommandResultAndInstanceIds

Creates a tag and attaches it to the specified ECS instances based on the results returned by running a command in the Cloud Assistant client. Required parameters: instanceIds, tagKey, and commandContent.

YAML

ACS-ECS-BulkyTagInstanceByOSTypeAndInstanceIds

Creates a tag and attaches it to the specified ECS instances based on the operating system types of the instances. Required parameters: instanceIds and tagKey.

YAML

ACS-ECS-BulkyTagInstanceByLinuxKernelVersionAndInstanceIds

Creates a tag and attaches it to the specified ECS instances based on the Linux kernel versions of the instances. Required parameters: instanceIds and tagKey.

YAML

Update images

To ensure secure running of the ECS instances, you may need to deploy patches or upgrade the components that the ECS instances depend on. Generally, the operations start from updating the source image and end in generating a new image for testing and production. Before updating an image, you need to use the source image to create an instance. After the update completes, the instance must be released. The update process is complicated. Therefore, OOS provides you with the ACS-ECS-UpdateImage template to process such update requests conveniently.

Template

Description

Sample code

ACS-ECS-UpdateImage

Automatically updates an ECS image based on the following logic: Create an ECS instance from the source image, run a command in the Cloud Assistant client to create an ECS image from this instance, and then release the instance. Required parameters: sourceImageId, instanceType, securityGroupId, vSwitchId, commandContent, commandType, and targetImageName.

YAML

Manage approval requests

Template

Description

Sample code

ACS-ECS-DeleteInstancesWithApprovalByInstanceIds

Releases the ECS instances that have been approved through DingTalk at the same time. Required parameters: instanceIds and accessToken.

YAML

ACS-ECS-BuyCostlyInstancesWithApproval

Creates ECS instances with a DingTalk approval. When this template is executed, OOS sends an approval notification to the specified DingTalk contact or group and creates ECS instances with the approval by the contact or group. Required parameters: accessToken, imageId, instanceType, securityGroupId, vSwitchId, and amount.

YAML

Manage scheduled tasks

Template

Description

Sample code

ACS-ECS-ScheduleToStopInstancesByTag

Stops the ECS instances that have the specified tag at the specified point in time. When this template is executed, the StopInstance operation is called to stop the ECS instances that have the specified tag at the specified point in time. Only ECS instances in the Running status can be stopped. Required parameters: cron, endDate, tagKey, and tagValue.

YAML

ACS-ECS-ScheduleToStartInstancesByTag

Starts the ECS instances that have the specified tag at the specified point in time. When this template is executed, the StartInstance operation is called to start the ECS instances that have the specified tag at the specified point in time. Only ECS instances in the Stopped status can be started. Required parameters: cron, endDate, tagKey, and tagValue.

YAML

ACS-ECS-ScheduleToRebootInstancesByTag

Restarts the ECS instances that have the specified tag at the specified point in time. When this template is executed, the RebootInstance operation is called to restart the ECS instances that have the specified tag at the specified point in time. Only ECS instances in the Running status can be restarted. Required parameters: cron, endDate, tagKey, and tagValue.

YAML

ACS-ECS-ScheduleToUpgradeInternetBandwidthByInstanceIds

Temporarily upgrades the bandwidth for the ECS instances that have the specified IDs at the specified point in time. When this template is executed, the ModifyInstanceNetworkSpec operation is called to temporarily upgrade the bandwidth for the ECS instances that have the specified IDs at the specified point in time. Required parameters: cron, endDate, instanceIds, maxBandwidthIn, maxBandwidthOut, startTime, and endTime.

YAML

Manage O&M tasks based on tags

Template

Description

Sample code

ACS-ECS-ScheduleToStopInstancesByTag

Stops the ECS instances that have the specified tag at the specified point in time. When this template is executed, the StopInstance operation is called to stop the ECS instances that have the specified tag at the specified point in time. Only ECS instances in the Running status can be stopped. Required parameters: cron, endDate, tagKey, and tagValue.

YAML

ACS-ECS-RebootInstancesByTag

Restarts the ECS instances that have the specified tags at the same time. When this template is executed, the RebootInstance operation is called to restart the ECS instances that have the specified tag. Only ECS instances in the Running status can be restarted. Required parameters: tagKey and tagValue.

YAML

ACS-ECS-StartInstancesByTag

Starts the ECS instances that have the specified tags at the same time. When this template is executed, the StartInstance operation is called to start the ECS instances that have the specified tag. Only ECS instances in the Stopped status can be started. Required parameters: tagKey and tagValue.

YAML

Manage standardized O&M tasks

Template

Description

Sample code

ACS-ECS-TagInstanceByRunCommandResult

Runs a command in the Cloud Assistant client on the specified ECS instance, creates a tag, and attaches the tag to the instance based on the command output. Required parameters: instanceId, tagKey, and commandContent.

YAML

ACS-ECS-TagInstanceByLinuxKernelVersion

Creates a tag and attaches it to the specified ECS instance based on the Linux kernel version of the instance. Required parameters: instanceId and tagKey.

YAML

ACS-ECS-TagInstanceByOSType

Creates a tag and attaches it to the specified ECS instance based on the operating system type of the instance. Required parameters: instanceId and tagKey.

YAML

Manage cross-region O&M tasks

Template

Description

Sample code

ACS-ECS-CloneInstancesAcrossAZ

Duplicates multiple ECS instances with the same specifications across zones at a time. Procedure: Obtain the specifications of the ECS instances to be duplicated and create the images of the instances. After the images are created, use the images to create ECS instances with the same specifications as the duplicated ones, and then run the instances in the target zone. Required parameters: instanceIds, regionId, targetZoneId, targetSecurityGroupId, and targetVSwitchId.

YAML

ACS-ECS-CloneInstancesAcrossRegion

Duplicates multiple ECS instances across regions at a time. Procedure: Create the images of the ECS instances to be duplicated. After the images are created, duplicate the images to the target region, create ECS instances based on the images, and then run the instances in the target zone of the target region. Required parameters: instanceIds, regionId, targetRegionId, targetZoneId, targetInstanceType, targetSecurityGroupId, and targetVSwitchId.

YAML

Replicate files from ECS instances to OSS buckets

You can use the osscmd tool to replicate log files from ECS instances to OSS buckets or store the output of jstack to a file in an OSS bucket for problem analysis when a process is stuck. The manual operation is complicated. In this case, you can use the following template to process the request.

Template (JSON format):

{
    "FormatVersion": "OOS-2019-06-01",
    "Description": "Tag ECS Instance by the RunCommand invocation result.",
    "Parameters": {
        "InstanceId": {
            "Type": "String",
            "Description": "the Instance Id to operate in linux.",
            "MinLength": 1,
            "MaxLength": 30
        },
        "SrcUrl": {
            "Type": "String",
            "Description": "command content to run in linux ecs."
        },
        "DestUrl": {
            "Type": "String",
            "Description": "command content to run in linux ecs."
        },
        "InstanceAssumeRole": {
            "Type": "String",
            "Description": ""
        },
        "OOSAssumeRole": {
            "Type": "String",
            "Description": "oos assume this role to execution task.",
            "Default": "OOSServiceRole"
        }
    },
    "RamRole": "{{OOSAssumeRole}}",
    "Tasks": [{
            "Name": "checkInstanceReady",
            "Action": "ACS::CheckFor",
            "Description": "describe instances",
            "Properties": {
                "API": "DescribeInstances",
                "Service": "ECS",
                "PropertySelector": "Instances.Instance[].Status",
                "DesiredValues": [
                    "Running"
                ],
                "Parameters": {
                    "InstanceIds": ["{{ InstanceId }}"]
                }
            }
        },
        {
            "Name": "runCommand",
            "Action": "ACS::ECS::RunCommand",
            "Description": "",
            "Properties": {
                "commandContent": {
                  "Fn::Join": [ "\n", [
                        "test -e oos || mkdir oos;",
                        "cd oos;",
                        "test -e ossutil64 || wget https://oos-public.oss-{{ACS::RegionId}}-internal.aliyuncs.com/x64/ossutil64 && chmod 755 ossutil64",
                        "test -e jq || wget https://oos-public.oss-{{ACS::RegionId}}-internal.aliyuncs.com/x64/jq && chmod 755 jq",
                        "stsToken=`curl http://100.100.100.200/latest/meta-data/Ram/security-credentials/{{InstanceAssumeRole}}`",
                        "accessKeyId=`echo $stsToken |./jq .AccessKeyId | awk -F'\"' '{print $2}'` ;",
                        "accessKeySecret=`echo $stsToken | ./jq .AccessKeySecret | awk -F'\"' '{print $2}'` ;",
                        "securityToken=`echo $stsToken | ./jq .SecurityToken | awk -F'\"' '{print $2}'` ;",
                        "endpoint=https://oss-{{ACS::RegionId}}-internal.aliyuncs.com;",
                        "./ossutil64 -i $accessKeyId -k $accessKeySecret -t $securityToken -e $endpoint cp {{SrcUrl}} {{DestUrl}}" 
                    ]
                  ]
                },

                "commandType": "RunShellScript",
                "instanceId": "{{InstanceId}}"
            },
            "Outputs": {
                "CommandOutput":{
                    "Type": "String",
                    "ValueSelector": "InvocationResult[].Output"
                }
            }
        }
    ],
    "Outputs": {}
}

Attach tags to ECS instances

O&M is difficult where there are a large number of instances. Sometimes, you need to use several accounts to manage the instances in different departments or of different purposes. In this case, we recommend that you manage instances based on tags.

You can attach tags to instances based on scenarios. For example, instances are grouped for different environments, including the development and testing, staging, and production environments. The O&M operations for these instances are isolated. You can attach tags to distinguish these instances. For example, you can attach the tag of which the key is env and the value is test to the instances in the development and testing environment, and add the tag of which the key is env and the value is product to the instances in the production environment.

You can also attach tags to instances based on the kernel version and operating system type. For example, you can group instances based on the operating system type, such as Linux and Window. You can obtain the kernel version by running the uname -r command. The following template is used to attach tags to instances based on the operating system type:

Template (JSON format):

{
  "FormatVersion": "OOS-2019-06-01",
  "Description": "tag instance by os type",
  "Parameters": {
    "InstanceId": {
      "Type": "String",
      "Description": "the InstanceId to tag",
      "MinLength": 1,
      "MaxLength": 30
    },
    "TagKey": {
      "Type": "String",
      "Description": "the tag key you specified"
    },
    "OOSAssumeRole": {
      "Type": "String",
      "Description": "The RAM role to be assumed by OOS.",
      "Default": "OOSServiceRole"
    }
  },
  "RamRole": "{{OOSAssumeRole}}",
  "Tasks": [
    {
      "Name": "queryInstanceOsType",
      "Action": "ACS::ExecuteApi",
      "Description": "",
      "Properties": {
        "API": "DescribeInstances",
        "Service": "ECS",
        "Parameters": {
          "InstanceIds": [
            "{{ InstanceId }}"
          ]
        }
      },
      "Outputs": {
        "OsType": {
          "ValueSelector": "Instances.Instance[].OSType",
          "Type": "String"
        }
      }
    },
    {
      "Name": "tagResources",
      "Action": "ACS::ExecuteApi",
      "Description": "Tag Resources.",
      "Properties": {
        "API": "TagResources",
        "Service": "ECS",
        "Parameters": {
          "ResourceType": "Instance",
          "ResourceIds": [
            "{{ InstanceId }}"
          ],
          "Tags": [
            {
              "Key": "{{ TagKey }}",
              "Value": "{{ queryInstanceOsType.OsType }}"
            }
          ]
        }
      }
    }
  ],
  "Outputs": {
    "OsType": {
      "Type": "String",
      "Value": "{{ queryInstanceOsType.OsType}}"
    }
  }
}

Add instances to Log Service machine groups

Before multiple instances are resized, you need to configure Log Service for the instances. After a Logstore is created, you can add the instances to a Log Service machine group. You can use the following template to add the instance to the Logstore instance group.

Template (JSON format):

{
  "FormatVersion": "OOS-2019-06-01",
  "Description": "Install Logtail agent on the ECS Instance.",
  "Parameters": {
    "InstanceId": {
      "Type": "String",
      "Description": "the Instance Id to install ilogtail",
      "AllowedPattern": "i-[A-Za-z0-9]*",
      "MinLength": 1,
      "MaxLength": 30
    },
    "LogTailUserDefinedId": {
      "Type": "String",
      "Description": "the user defined Id write to /etc/ilogtail/user_defined_id",
      "AllowedPattern": "[A-Za-z0-9\\-_]*",
      "MinLength": 1,
      "MaxLength": 30
    },
    "OOSAssumeRole": {
      "Type": "String",
      "Description": "The RAM role to be assumed by OOS.",
      "Default": "OOSServiceRole"
    }
  },
  "RamRole": "{{OOSAssumeRole}}",
  "Tasks": [
    {
      "Name": "checkInstanceReady",
      "Action": "ACS::CheckFor",
      "Description": "describe instances.",
      "Properties": {
        "API": "DescribeInstances",
        "Service": "ECS",
        "PropertySelector": "Instances.Instance[].Status",
        "DesiredValues": [
          "Running"
        ],
        "Parameters": {
          "InstanceIds": [
            "{{ InstanceId }}"
          ]
        }
      },
      "Outputs": {
        "InstanceIds": {
          "ValueSelector": "InstanceIdSets.InstanceIdSet[]",
          "Type": "List"
        }
      }
    },
    {
      "Name": "createCommand",
      "Action": "ACS::ExecuteApi",
      "Description": "create the command to install logtail agent.",
      "Properties": {
        "API": "CreateCommand",
        "Service": "ECS",
        "Parameters": {
          "CommandContent": {
            "Fn::Base64Encode": "wget http://logtail-release-{{ACS::RegionId}}.oss-{{ACS::RegionId}}-internal.aliyuncs.com/linux64/logtail.sh -O logtail.sh; chmod 755 logtail.sh; ./logtail.sh install {{ACS::RegionId}}; echo {{ LogTailUserDefinedId }} > /etc/ilogtail/user_defined_id"
          },
          "Name": "oos-{{ACS::TemplateName}}",
          "Type": "RunShellScript"
        }
      },
      "Outputs": {
        "CommandId": {
          "Type": "String",
          "ValueSelector": "CommandId"
        }
      }
    },
    {
      "Name": "invokeCommand",
      "Action": "ACS::ExecuteApi",
      "Description": "invoke the command to install ilogtail",
      "Properties": {
        "Service": "ECS",
        "API": "InvokeCommand",
        "Parameters": {
          "CommandId": "{{ createCommand.CommandId }}",
          "InstanceIds": [
            "{{ InstanceId }}"
          ]
        }
      },
      "Outputs": {
        "InvokeId": {
          "Type": "String",
          "ValueSelector": "InvokeId"
        }
      }
    },
    {
      "Name": "untilInvocationDone",
      "Action": "ACS::WaitFor",
      "Description": "until invocation ready",
      "MaxAttempts": 5,
      "Properties": {
        "Service": "ECS",
        "API": "DescribeInvocations",
        "Parameters": {
          "InvokeId": "{{  invokeCommand.InvokeId }}"
        },
        "DesiredValues": [
          "Finished"
        ],
        "PropertySelector": "Invocations.Invocation[].InvokeStatus"
      }
    },
    {
      "Name": "describeInvocationResult",
      "Action": "ACS::ExecuteApi",
      "Description": "get the command invocation result",
      "Properties": {
        "Service": "Ecs",
        "API": "DescribeInvocationResults",
        "Parameters": {
          "InvokeId": "{{ invokeCommand.InvokeId }}"
        }
      },
      "Outputs": {
        "InvocationResult": {
          "Type": "String",
          "ValueSelector": "Invocation.InvocationResults.InvocationResult[].Output"
        },
        "ExitCode": {
          "Type": "Number",
          "ValueSelector": "Invocation.InvocationResults.InvocationResult[].ExitCode"
        }
      }
    },
    {
      "Name": "deleteCommand",
      "Action": "ACS::ExecuteAPI",
      "Description": "clean up the install ilogtail command",
      "Properties": {
        "Service": "ECS",
        "Risk": "Normal",
        "API": "DeleteCommand",
        "Parameters": {
          "CommandId": "{{ createCommand.CommandId }}"
        }
      }
    }
  ],
  "Outputs": {
    "InvocationResult": {
      "Type": "String",
      "Value": {
        "Fn::Base64Decode": "{{ describeInvocationResult.InvocationResult }}"
      }
    },
    "ExitCode": {
      "Type": "String",
      "Value": "{{ describeInvocationResult.ExitCode }}"
    }
  }
}