swevm / scaleio-py

ScaleIO API Bindings
Apache License 2.0
13 stars 14 forks source link

ScaleIO-py

A Python module for interacting with the EMC ScaleIO 1.3+ REST API.

Authors: Magnus Nilsson & Matt Cowger

Requirements:

Module status

Goal is to resemble the ScaleIO API (not in detail) in a Pythonic way. Atm ScaleIO-py is in early beta stage and focus will be on getting basic features become stable (especially the to/from object mapping) before adding fancy functionality.

Update 2015-06-08: Now compatible with v1.31 and v1.32

Installation

For bleeding edge users:

Supported CRUD functionality

Retrieve methods

Create

Delete

Update

Code examples

Have a look in examples directory for complete code examples.

Connect to ScaleIO API

from scaleiopy.scaleio import ScaleIO
# Logging level can be change by adjusting last parameter [DEBUG, FATAL, ERROR, CRITICAL, WARNING, INFO]. If left out of class init DEBUG is assumed
sio = ScaleIO("https://192.168.50.12/api","admin","Scaleio123",False, "ERROR)

Get a list of all attributes related to each SDC known by your ScaleIO cluster

#print all the known SDCs:
pprint(sio.sdc)

Get list of attributes related to all SDS

#print all the known SDSs:
pprint(sio.sds)

Get list of attributes related to all known Volumes

#print all the known Volumes:
pprint(sio.volumes)

Get list of attributes related to each protection domain

#print all the known Protection Domains:
pprint(sio.protection_domains)

Create a new Volume in Protection Domain

#Create a new Volume (of 8192Mb, smallest possible)
sio.create_volume_by_pd_name('testvol001', 8192, sio.get_pd_by_name('default'))

#Create Volume and Map to single SDC in one operation
sio.create_volume_by_pd_name('testvol001', 8192, sio.get_pd_by_name('default'), mapToSdc=sio.get_sdc_by_id('ce4d7e2a00000001'))

#Create Volume and Map to all SDC in one operation
sio.create_volume_by_pd_name('testvol001', 8192, sio.get_pd_by_name('default'), mapAll=True)

Map existing Volume to a SDC by its ID

# method get_sdc_by_ip('ipaddr') if you want to map an Vol to SDC using its IP address
sio.map_volume_to_sdc(sio.get_volume_by_name('testvol'), sio.get_sdc_by_id('ce4d7e2a00000001'), False)

# Map Volume to all SDCs
sio.map_volume_to_sdc(sio.get_volume_by_name('testvol'), mapAll=True)

Unmap volume from SDC

#Unmap Volume from SDC
sio.unmap_volume_from_sdc(sio.get_volume_by_name('testvol'), sio.get_sdc_by_id('ce4d7e2a00000001'))

Delete a Volume from ScaleIO cluster

#Delete Volume
sio.delete_volume(sio.get_volume_by_name('testvol'), 'ONLY_ME')

Create Snapshot of Volume

snapSpec = scaleio.SnapshotSpecification()
snapSpec.addVolume(sio.get_volume_by_name('volume_name'))
sio.create_snapshot(sio.get_system_id(), snapSpec)

Delete Snapshot

# Consistency group Id can be found by parsing result from get_volume_by_name().
sio.delete_snapshot(sio.get_system_id(), 'consistency_group_id')

Install ScaleIO using IM API

#Install cluster using 'private' IM API
#Look in examples/install-cluster-mac.py for a complete example

Get statistics data from ScaleIO

#print all statistics data:
pprint(sio.statistics)