• CLI

sdk
  1. Help Center
  2. CLI
  3. Developer Guide
  4. SDK
  5. Python
  6. EVS Python SDK Demo

EVS Python SDK Demo

EVS disks are scalable virtual block storage devices designed based on the distributed architecture. You can create EVS disks online and attach them to ECSs. The method for using EVS disks is the same as that for using hard disks on physical servers. Compared with traditional hard disks, EVS disks have higher data reliability and I/O throughput capabilities. They are also easier to use. EVS disks apply to file systems, databases, and system software and applications that require block storage devices.

Creating a Volume

You can create a volume using Python OpenStack SDK based on the following code. The volume can be attached to the ECS only when the volume is in the available status.

def create_volume(conn): 
    volume = conn.block_store.create_volume( 
        name='volume_name', 
        size=1) 
    conn.block_store.wait_for_status(volume, 
                                    status='available', 
                                    failures=['error'], 
                                     interval=2, 
                                     wait=120) 

Attaching a Volume to an ECS

You can attach a volume to an ECS using Python OpenStack SDK based on the following code. The attachment operation is successful after the volume is in the in-use status.

def attach_volume_to_ecs(conn):         
    attach_attrs = { 
        'volume_id': attach_volume_id
        } 
    attachment = conn.compute.create_volume_attachment(server, 
**attach_attrs) 
    conn.block_store.wait_for_status(volume, 
                                        status='in-use', 
                                        failures=['error'], 
                                        interval=2, 
                                        wait=120)    

Detaching a Volume from an ECS

You can detach a volume from an ECS based on the following code. The detachment process takes several seconds, and the volume can be deleted only after the volume is detached.

def attach_volume_to_ecs(conn):         
    conn.compute.delete_volume_attachment(attachment,server) 
    conn.block_store.wait_for_status(volume, 
                                        status='available', 
                                        failures=['error'], 
                                        interval=2, 
                                        wait=120)