Executing a Script
When managing a large number of cloud resources, COC's script management feature lets you automate repetitive tasks like delivering configurations, updating patches, and checking system status. You can create standardized scripts and deploy them across multiple servers, containers, or cloud hosts quickly with just a few clicks. This automatic management mode not only greatly reduces the time spent on manual operations on each device, but also eliminates manual input errors and omissions. During script execution, O&M personnel can view the execution progress, success or failure status, and detailed logs of each resource on the console in real time. This helps locate and rectify faults promptly, ensuring stable and efficient O&M.
Precautions
Ensure that you have the resource permissions of the component to which the target VM belongs when executing a script.
Constraints
- A maximum of 999 instances can be selected for a task.
- A maximum of four script tasks can be executed on a single server per second. If the execution rate exceeds the threshold, the tasks are queued for execution.
- A single script task can output a maximum of 1 MB logs. Excess logs cannot be displayed.
- If the script input parameter is referenced from Parameter Center, ensure that the parameters referenced from Parameter Center and the target instance are in the same region.
Executing a Custom Script
Once a custom script is configured, you can confirm the target resource and start a script execution. The system automatically delivers the script to the specified resource and executes it.
- Log in to COC.
- In the navigation pane, choose Resource O&M > Automated O&M.
- In the Routine O&M area, click Script Management. The script management page is displayed.
- On the Custom Scripts tab page, locate the script you want to execute and click Execute in the Operation column.
- Set Script Input Parameters.
The parameter names and default values have been preset when the custom script is created. When the script is executed, you can manually set the input parameter values or select values from the parameter center.
- You can manually specify new script parameters and their values.
- You can also reference preset parameters and values from the Parameter Center. Note: You need to select the regions where the parameters are located, parameter names, and parameter association modes. Figure 1 Manually specifying script parameters
Figure 2 Selecting script parameters from the parameter center
- Set Executed By and Timeout Interval.
- Executed By: root is used by default. It is the user who executes the script on a target instance node.
- Timeout Interval: 300 is used by default. It indicates the timeout interval for executing the script on a single target instance.
- Click Add and select an instance by referring to Table 1.
Table 1 Parameters for selecting an instance Parameter
Description
Selection Method
Select an instance selection method.
Manual Selection: Manually select one or more instances based on settings of Enterprise Project, View Type, Resource Type, Region, and Target Instance.
Enterprise Project
Select an enterprise project from the drop-down list. You can choose All.
View Type
Select a view type.
- CloudCMDB resources: Select an instance by resource type.
- CloudCMDB application groups: Select an instance by application group.
Resource Type
Resource type of the target instance.
The value can be ECS, BMS, FlexusL, or On-premises IDCs.
Region
Select a region from the drop-down list.
Target Instance
Set filter criteria in the filter box and select the displayed instances.
When selecting the target instance, ensure that parameters referenced from parameter center and those set on target instances do not belong to different regions.
- Set Batch Policy.
Select Automatic, Manual, or No Batch.
Table 2 Batch policy parameters Parameter
Description
Automatic
The selected instances on which you want to perform operations are automatically divided into multiple batches based on the default rule.
Manual
You can manually create multiple batches and add instances to each batch as required.
No Batch
All instances on which you want to perform operations are in the same batch.
If you select multiple target instances and set Batch Policy to Automatic or Manual, you can set the batch execution rule. You can select Pause for 1st batch, Pause after all batches, or Continue all.
- If you select Pause for the 1st batch, you need to click Continue to execute the next batch after the first batch is executed.
- If you select Pause after all batches, you need to click Continue after each batch is executed.
- If you select Continue all, the system automatically executes the next batch after each batch is executed.
- If you select Customize, you can determine whether to start or continue with the next batch after each batch is executed.
For example, if you have selected multiple target instances and want to execute them in a custom number of batches, select Manual, set Batches to 3, and set the execution rule to Pause for the 1st batch. Then, select the corresponding batch and click Add.
After the first batch of instances are executed, the execution is suspended. You can check whether the execution result meets the expectation. If the execution result is correct, click Continue to execute the next batch of instances. After the second batch of instances is executed, the third batch of instances will be automatically executed without manual confirmation.
Figure 3 Setting a batch policy
- Set Suspension Policy.
When a fault occurs in the target service, the invocation is suspended. After the fault is rectified, the service communication is restored, ensuring fault isolation and self-protection.
- You can set a target execution success rate. If the number of failed servers reaches the threshold derived from this success rate, the service ticket is flagged as abnormal and execution stops immediately.
- The success rate ranges from 0 to 100 with precision to one decimal point.
- Click OK. In the confirmation drawer, confirm the execution information, and click OK to execute the service ticket.
The service ticket details page is displayed. You can view the details by referring to Viewing the Execution Records of a Script Service Ticket.
Executing a Public Script
Public scripts are predefined scripts. You can clean disks, reset passwords, start or stop OSs with this function. You can only read and execute public scripts.
- Log in to COC.
- In the navigation pane, choose Resource O&M > Automated O&M.
- In the Routine O&M area, click Script Management. The script management page is displayed.
- Click Common Scripts in the upper left corner to switch to the public script tab page.
- Locate the script you want to execute and click Execute in the Operation column.
- Set Script Input Parameters.
Script Input Parameters: The parameters are preset in public scripts and cannot be modified. The script input parameter values can be set manually or selected from the parameter center. Currently, selecting parameters from the parameter center cannot be used to clean up disks.
- You can manually specify new script parameters and their values.
- You can also reference preset parameters and values from the Parameter Center. Note: You need to select the regions where the parameters are located, parameter names, and parameter association modes. Figure 4 Manually specifying script parameters
Figure 5 Selecting script parameters from the parameter center
Table 3 Parameter association modes Parameter Association Mode
Description
Use the latest parameter value in the corresponding environment
This parameter is used during script execution. The value is the latest parameter value obtained from the corresponding region in the parameter center in real time.
- Set Executed By and Timeout Interval.
- Executed By: root is used by default. It is the user who executes the script on a target instance node.
- Timeout Interval: 300 is used by default. It indicates the timeout interval for executing the script on a single target instance.
- Click Add and select the target instances to be executed.
Table 4 Parameters for selecting an instance Parameter
Description
Selection Method
Select an instance selection method.
- Manual Selection: Manually select one or more instances based on settings of Enterprise Project, View Type, Resource Type, Region, and Target Instance.
Enterprise Project
Select an enterprise project from the drop-down list. You can choose All.
View Type
Select a view type.
- CloudCMDB resources: Select an instance by resource type.
- CloudCMDB application groups: Select an instance by application group.
Resource Type
Resource type of the target instance.
The value can be ECS, BMS, FlexusL, or On-premises IDCs.
Region
Select a region from the drop-down list.
Target Instance
Set filter criteria in the filter box and select the displayed instances.
When selecting the target instance, ensure that parameters referenced from parameter center and those set on target instances do not belong to different regions.
- Set Batch Policy.
Select Automatic, Manual, or No Batch.
Table 5 Batch policy parameters Parameter
Description
Automatic
The selected instances on which you want to perform operations are automatically divided into multiple batches based on the default rule.
Manual
You can manually create multiple batches and add instances to each batch as required.
No Batch
All instances on which you want to perform operations are in the same batch.
If you select multiple target instances and set Batch Policy to Automatic or Manual, you can set the batch execution rule. You can select Pause for 1st batch, Pause after all batches, or Continue all.
- If you select Pause for the 1st batch, you need to click Continue to execute the next batch after the first batch is executed.
- If you select Pause after all batches, you need to click Continue after each batch is executed.
- If you select Continue all, the system automatically executes the next batch after each batch is executed.
- If you select Customize, you can determine whether to start or continue with the next batch after each batch is executed.
For example, if you have selected multiple target instances and want to execute them in a custom number of batches, select Manual, set Batches to 3, and set the execution rule to Pause for the 1st batch. Then, select the corresponding batch and click Add.
After the first batch of instances are executed, the execution is suspended. You can check whether the execution result meets the expectation. If the execution result is correct, click Continue to execute the next batch of instances. After the second batch of instances is executed, the third batch of instances will be automatically executed without manual confirmation.
Figure 6 Setting a batch policy
- Set Suspension Policy.
When a fault occurs in the target service, the invocation is suspended. After the fault is rectified, the service communication is restored, ensuring fault isolation and self-protection.
- You can set a target execution success rate. If the number of failed servers reaches the threshold derived from this success rate, the service ticket is flagged as abnormal and execution stops immediately.
- The success rate ranges from 0 to 100 with precision to one decimal point.
- Click OK. In the confirmation drawer, confirm the execution information, and click OK to execute the service ticket.
The service ticket details page is displayed. You can view the details by referring to Viewing the Execution Records of a Script Service Ticket.
Viewing the Execution Records of a Script Service Ticket
After a script is executed, a script service ticket record is generated to record the script execution results. To monitor and record the execution objects and results of the script, you can use the script service ticket function.
- Log in to COC.
- In the navigation pane on the left, choose Task Management > Execution Records. The task execution records page is displayed.
- Click Script Tickets. The Script Tickets tab page is displayed.
- Click the script name to go to the service ticket details page.
On the service ticket details page, you can view the basic information and execution information about the service ticket.
- Perform the following operations based on the service ticket status:
- If the script ticket status is Abnormal, click Forcibly End in the upper right corner to end the service ticket.
- If the service ticket status is Executing, click Pause or Forcibly End in the upper right corner to pause or end the service ticket.
- If the service ticket status is Paused, click Continue or Forcibly End in the upper right corner to continue or end the service ticket.
Helpful Links
- Custom and public scripts can be executed periodically. For details, see Scheduled O&M.
- The COC script management feature enables the standardized, online modification of ECS hostnames. For details, see Changing the ECS Hostname Using a Script.
- You can use COC to create, review, modify, execute, and delete scripts, and manage tags by calling APIs. For details, see Script Management.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot