Help Center > > Best Practices> Periodically Shutting Down Huawei Public Cloud VMs

Periodically Shutting Down Huawei Public Cloud VMs

Updated at: Jul 27, 2019 GMT+08:00

Introduction

If you forget to shut down your test or development servers on the public cloud after work, a great resource waste will be caused. You can call HUAWEI CLOUD's Elastic Cloud Server (ECS) API through FunctionGraph to periodically shut down the servers.

Periodically shuts down virtual machines (VMs) by calling ECS API to save resources.

Preparation

To call the ECS API, you need to build a FunctionGraph function based on OpenStack. Download the Python SDK of OpenStack. For more information, see SDK Developer Guide.

Building a Program

Download the function program package provided in this example to build a program for periodically shutting down your public cloud VMs.

  1. Creating a Function
    Create a function by uploading the example code according to Figure 1. For details, see Creating a Function.
    Figure 1 Creating Functions
  2. Setting Environment Variables

    On the Configuration tab page of the preceding function, set environment variables to pass the bucket address, bucket name, and object name, as shown in Table 1.

    Table 1 Environment variables

    Environment Variable

    Description

    region

    Required. For example, cn-north-1.

    domain

    Required. For example, myhuaweicloud.com.

    projectId

    Required

    ak

    Required if no agency is specified.

    sk

    Required if no agency is specified.

    whiteLists

    Whitelist, in which VM names are separated with commas.

    Set the environment variables ( Figure 2) by following the procedure in Environment Variables.
    Figure 2 Setting environment variables
  3. Adding a Dependency
    On the Code tab page, click Add, select openstacksdk-1.0.6, and click OK. Figure 3 shows the Add Dependency dialog box.
    Figure 3 Adding a dependency

    For more information, see Configuring Dependencies for a Function.

Adding an Event Source

Create a timer trigger and set the trigger parameters according to Figure 4.
Figure 4 Creating a timer trigger

Did you find this page helpful?

Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel