Skip to content

Commit

Permalink
Merge pull request #30 from swevm/0_3-beta3
Browse files Browse the repository at this point in the history
0.3 beta3
  • Loading branch information
swevm committed Jun 10, 2015
2 parents 0304b97 + 73b928f commit b52a425
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 84 deletions.
21 changes: 18 additions & 3 deletions Changelog.md
Expand Up @@ -33,7 +33,7 @@ Initial code to test integration against ScaleIO API
* IM integration to install new cluster
* Add examples

## v0.31 (WIP)
## v0.31 (beta1)
* Create Snapshot by Volume Name
* Create Snapshot by Volume Id
* Delete Snapshot
Expand All @@ -45,9 +45,24 @@ Initial code to test integration against ScaleIO API
* Delete ProtectionDomain (WIP)
* Create FaultSet (WIP)
* Delete FaultSet (WIP)
* set name functionality for FS, PD, SDC and SDS
*
* set name functionality for FS, PD, SDC and SDS

## v0.32 (beta2)
* Faultset folded into IM integration as it depend on removing SDS to change - Create Faultset can be done at install time
* Protection Domain Mgmt removed - Pushed to v0.4
* Remove and Manage Faultsets removed - Pushed to v0.4
* Better logging - Configurable at __init__

## v0.33 (beta3)
* Support for 1.32 - Create Volume
* PIP package - Install with: pip install ScaleIO-py
* Store API version to optimize code path for different versions - Not needed to be compatible with basic Mgmt for both 1.31 and 1.32 (need to be used for Metric collection)
* delete_volume() - Obey kwargs 'autoUnmap'
* map_volume_to_sdc() and unmap_volume_from_sdc() - Changed kwargs to 'enableMapAllSdcs'

## v0.34 (beta4) WIP
* Make logging consisent
* Error handling - Find a consistent way to return errors to caller (caller have to use try/catch???)

## v0.3+
* Unit Testing
Expand Down
15 changes: 0 additions & 15 deletions examples/create_map-volume.py

This file was deleted.

2 changes: 1 addition & 1 deletion examples/create_mapall-volume.py
Expand Up @@ -10,6 +10,6 @@

sio = scaleio.ScaleIO("https://" + sys.argv[1] + "/api",sys.argv[2],sys.argv[3],False,"ERROR") # HTTPS must be used as there seem to be an issue with 302 responses in Requests when using POST

sio.create_volume(sys.argv[4], sys.argv[5], sio.get_pd_by_name(sys.argv[6]), sio.get_storage_pool_by_name(sys.argv[7]), mapAll=True)
sio.create_volume(sys.argv[4], sys.argv[5], sio.get_pd_by_name(sys.argv[6]), sio.get_storage_pool_by_name(sys.argv[7]), enableMapAllSdcs=True)

pprint(sio.volumes)
3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

77 changes: 23 additions & 54 deletions scaleiopy/scaleio.py
Expand Up @@ -923,8 +923,8 @@ def get_sdc_for_volume(self, volObj):
for sdc in volObj.mapped_sdcs:
sdcList.append(sdc)
if len(sdcList) == 0:
self.logger.debug("No SDCs mapped to volume: %s-(%s)" %
(volObj.name, volObj.id))
self.logger.debug("No SDCs mapped to volume: %s-(%s)" % (volObj.name, volObj.id))
return []
# returning an empty list is
# valid for snapshots or volumes.
return sdcList
Expand Down Expand Up @@ -989,7 +989,7 @@ def get_volumes_for_vtree(self, vtreeObj):
:param vtreeObj: VTree object
Protection Domain Object
:return: list of Volumes attached to VTree
:rtyoe: ScaleIO Volume object
:rtype: ScaleIO Volume object
"""
self._check_login()
all_volumes = []
Expand Down Expand Up @@ -1112,36 +1112,7 @@ def delete_snapshot(self, systemId, snapshotGroupId):
#except:
# raise RuntimeError("delete_snapshot() - Error communicating wit ScaleIO gateway")
return response

def create_volume_by_pd_name(self, volName, volSizeInMb, pdObj, thinProvision=True, **kwargs):
# TODO: REMOVE - Replace byt create_volume()
# Check if object parameters are the correct ones, otherwise throw error
self._check_login()
if thinProvision:
volType = 'ThinProvisioned'
else:
volType = 'ThickProvisioned'
volumeDict = {'protectionDomainId': pdObj.id, 'volumeSizeInKb': str(volSizeInMb * 1024), 'name': volName, 'volumeType': volType}
response = self._do_post("{}/{}".format(self._api_url, "types/Volume/instances"), json=volumeDict)

if kwargs:
for key, value in kwargs.iteritems():
if key == 'mapAll':
if value == True:
self.map_volume_to_sdc(self.get_volume_by_name(volName), mapAll=True)
if key == 'mapToSdc':
if value:
for innerKey, innerValue in kwargs.iteritems():
if innerKey == 'mapAll':
if innerValue == True:
self.map_volume_to_sdc(self.get_volume_y_name(volName), mapAll=True)
else:
self.map_volume_to_sdc(self.get_volume_by_name(volName), value)
return response

"""
Use create_volume() instead of create_volume_by_pd_name() which doesnt make sense name wise since it take a PD object and not a name
"""
#def create_volume(self, volName, volSizeInMb, pdObj, thinProvision=True, **kwargs): # Worked in v1.31 but not in v1.32
def create_volume(self, volName, volSizeInMb, pdObj, spObj, thinProvision=True, **kwargs): #v1.32 require storagePoolId when creating a volume
# Check if object parameters are the correct ones, otherwise throw error
Expand All @@ -1156,17 +1127,16 @@ def create_volume(self, volName, volSizeInMb, pdObj, spObj, thinProvision=True,

if kwargs:
for key, value in kwargs.iteritems():
if key == 'mapAll':
if value == True:
self.map_volume_to_sdc(self.get_volume_by_name(volName), mapAll=True)
if key == 'enableMapAllSdcs' and value == True:
self.map_volume_to_sdc(self.get_volume_by_name(volName), enableMapAllSdcs=True)
if key == 'mapToSdc':
if value:
for innerKey, innerValue in kwargs.iteritems():
if innerKey == 'mapAll':
if innerKey == 'enableMapAllSdcs':
if innerValue == True:
self.map_volume_to_sdc(self.get_volume_y_name(volName), mapAll=True)
self.map_volume_to_sdc(self.get_volume_by_name(volName), enableMapAllSdcs=True)
else:
self.map_volume_to_sdc(self.get_volume_by_name(volName), value)
self.map_volume_to_sdc(self.get_volume_by_name(volName), self.get_sdc_by_name(value))
return response

def resize_volume(self, volumeObj, sizeInGb, bsize=1000):
Expand Down Expand Up @@ -1200,7 +1170,7 @@ def map_volume_to_sdc(self, volumeObj, sdcObj=None, allowMultipleMappings=False,
self._check_login()
if kwargs:
for key, value in kwargs.iteritems():
if key == 'mapAll':
if key == 'enableMapAllSdcs':
if value == True:
mapVolumeToSdcDict = {'allSdcs': 'True'}
else:
Expand All @@ -1227,16 +1197,15 @@ def unmap_volume_from_sdc(self, volObj, sdcObj=None, **kwargs):
self._check_login()
if kwargs:
for key, value in kwargs.iteritems():
if key == 'disableMapAllSdcs':
if value == True:
if self.get_volume_all_sdcs_mapped:
unmapVolumeFromSdcDict = {'allSdcs': 'False'}
if key == 'enableMapAllSdcs' and value == False:
if self.get_volume_all_sdcs_mapped(volObj): # Check if allSdc?s is True before continuing
unmapVolumeFromSdcDict = {'allSdcs': 'False'}
else:
unmapVolumeFromSdcDict = {'sdcId': sdcObj.id}
try:
response = self._do_post("{}/{}{}/{}".format(self._api_url, "instances/Volume::", volObj.id, 'action/removeMappedSdc'), json=unmapVolumeFromSdcDict)
except:
raise RuntimeError("unmap_volume_from_sdc() - Communication error with ScaleIO gateway")
raise RuntimeError("unmap_volume_from_sdc() - Cannot unmap volume")
return response

def delete_volume(self, volObj, removeMode='ONLY_ME', **kwargs):
Expand All @@ -1246,20 +1215,20 @@ def delete_volume(self, volObj, removeMode='ONLY_ME', **kwargs):
"""
if kwargs:
for key, value in kwargs.iteritems():
if key =='autoUnmap':
if key =='autoUnmap' and value ==True:
# Find all mapped SDS to this volObj
# Call unmap for all of them
if self.get_volume_all_sdcs_mapped:
if self.get_volume_all_sdcs_mapped(volObj):
try:
self.unmap_volume_from_sdc(volObj, disableMapAllSdcs=True)
self.unmap_volume_from_sdc(volObj, enableMapAllSdcs=False)
except:
raise RuntimeError("delete_volume() - Communication error with ScaleIO gateway")
else:
for sdcIdentDict in self.get_sdc_for_volume(volObj):
try:
self.unmap_volume_from_sdc(volObj, sio.get_sdc_by_id(sdcIdentDict.sdcId))
except:
raise RuntimeError("delete_volume() - Communication error with ScaleIO gateway")
raise RuntimeError("delete_volume() - enableMapAllSdcs error")
else: # All SDS not enabled so loop through all mapped SDCs of volume and remove one by one
for sdc in self.get_sdc_for_volume(volObj):
try:
self.unmap_volume_from_sdc(volObj, self.get_sdc_by_id(sdc['sdcId']))
except:
raise RuntimeError("delete_volume() - unmap_volume_from_sdc() error")
# TODO:
# Check if object parameters are the correct ones, otherwise throw error
self._check_login()
Expand Down
22 changes: 14 additions & 8 deletions setup.py
Expand Up @@ -3,24 +3,30 @@
from setuptools import find_packages
from distutils.core import setup

# requests 2.4.3 and 2.5.1 is known to work. Not sure about 2.5.1+
install_reqs =[
'requests>=2.4.3',
'requests-toolbelt==0.3.1',
'wsgiref==0.1'
]

setup(
author='Matt Cowger & Magnus Nilson',
author_email='magnus@karabas.nu,matt@cowger.us',
author='Magnus Nilsson',
author_email='magnus@karabas.nu',
name='ScaleIO-py',
description='Python interface to ScaleIO 1.3 REST API',
version="0.31",
description='Python interface to ScaleIO 1.31+ REST API',
version="0.3.3-3",
url='https://github.com/swevm/scaleio-py/',
license='Apache License',
packages=find_packages(),

classifiers=[
'Development Status :: 4 - Alpha',
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Topic :: Software Development :: Libraries',
'Topic :: Software Development :: Libraries :: Python Modules',
],
install_requires=[
open("requirements.txt").readlines(),
],
install_requires=install_reqs,
)

0 comments on commit b52a425

Please sign in to comment.