Help Center/ ModelArts/ SDK Reference/ Lite Server Lifecycle Management/ Example of Lite Server Lifecycle Management
Updated on 2025-12-04 GMT+08:00

Example of Lite Server Lifecycle Management

Lite Server lifecycle management includes Lite Server instances and supernode instances, covering the creation, startup, and status query of Lite Server resources. The service enables end-to-end lifecycle management of server instances on platforms that have Python versions later than 3.7.x and earlier than 3.10.x. This section describes how to manage Lite Servers using the Python SDK.

Example of End-to-End Lite Server Lifecycle Management Using SDK

This section describes how to use the SDK to train a model. Before using the SDK for development, you need to complete Preparations and then perform the following steps:

Preparations

The sample code in this section is implemented in ModelArts Notebook. Create and run a notebook instance first. For details, see Creating a Notebook Instance and Using JupyterLab to Develop and Debug Code Online.

To use it in other development environments, install ModelArts SDK by referring to (Optional) Installing ModelArts SDK Locally and perform session authentication.

Step 1: Creating a Lite Server Instance

from modelarts.server_mgmt import ServerManagement
from modelarts.session import Session
from modelarts.servers.server_def import Volume, ChargingInfo, Network, RootVolume, DataVolume, Server, Tag, ImageBody, BindIP

session = Session()
network = Network(
    security_group_id="150a2c76-1334-45f6-b28f-419f9b1d1742",
    subnet_id="38cf274a-98f9-4f6f-b622-5ed0e4a3db54",
    vpc_id="05982b48-a70f-43a1-a2b0-1fe36a236172")
rootvolume = RootVolume(
    root_type="SSD",
    size="200")
charginginfo = ChargingInfo(
    charging_mode="POST_PAID",
    period_num=1,
    period_type="MONTH")
server = Server(
    name="server_test",
    flavor="s7.small.1",
    image_id="e16eff65-1899-446e-baf2-0d2b6b5dd8c0",
    key_pair_name = "KeyPair-3d6a",
    network=network,
    root_volume=rootvolume,
    charging_info=charginginfo,
    arch="X86")
ServerManagement.create(session,server)

Step 2: Querying a Lite Server Instance

Query the ID of the Lite Server instance generated in Step 1: Creating a Lite Server Instance.

ServerManagement.get_server_info(session,server_id="server_id")

Step 3: Stopping a Lite Server Instance

Stop the Lite Server instance created in Step 1: Creating a Lite Server Instance.

ServerManagement.stop(session,server_id="server_id")