• CLI

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

IMS Python SDK Demo

Public Images

A public image is a widely used and standard image. Each public image contains an OS and multiple pre-installed public applications and is visible to all users.

Obtain the image ID from the console as follows:

Optionally, you can use the following code to list all the images:

def list_images(conn): 
    print("List Images:") 
    for image in conn.image.images(): 
        print(image)

Using Python OpenStack SDK to Create a Private Image

IMS supports the native OpenStack Glance v2 image API, with which you can create a private image with your image file. The supported image types are VHD, ZVHD, QCOW2, and VMDK.

The following uses the image in the QCOW2 format as an example. Image uploading takes a long time, which depends on the image size and network quality.

def upload_image(conn): 
    #upload the image 
    img =conn.image.upload_image( 
        name='name', 
        disk_format='qcow2', 
        container_format='bare', 
        properties='{"description": "cirros image"}', 
        min_disk=4, 
        data=open('cirros.img', 'rb') 
    ) 
    # wait until the image to be active status. 
    activeFlag = False 
    i = 1 
    while(i < 10): 
        status =conn.image.get_image(img.id).status  
        print status 
        if(status == 'active'): 
            activeFlag = True 
            break; 
            i = i + 1 
            sleep(60) 
        if( not activeFlag): 
            print 'Image upload failed'
Table 1 Parameter description

Parameter

Description

Example Value

diskFormat

Specifies the disk format.

qcow2

IMS supports VHD, ZVHD, QCOW2, and VMDK images.

data

Specifies the image file to be uploaded.

open('cirros.img', 'rb')

cirros.img is the name of the image file to be uploaded.