How filter is working with softlayer API in python -
i trying fetch storageid
through softlayer api using filter. giving me list of storages if applied filter method.
import softlayer import json storagename = "abc-123" client = softlayer.client() accountservice = client['softlayer_account'] objectfilterstorage = {"username": {"operation": storagename}} storageid = accountservice.getnetworkstorage(filter=objectfilterstorage) print storageid
also, how can figure out attributes needed while fetching list of particular offering?
here found attributes & took list 'objectfilterstorage'. still confused how works.
try following python script:
""" script retrieves storage identifier through name important manual pages: http://sldn.softlayer.com/reference/services/softlayer_account/getnetworkstorage http://sldn.softlayer.com/reference/datatypes/softlayer_network_storage license: http://sldn.softlayer.com/article/license author: softlayer technologies, inc. <sldn@softlayer.com> """ import softlayer # softlayer api username , key. username = 'set me' api_key = 'set me' # define username name storage storageusername = 'sl345234' # declaring api client client = softlayer.client(username=username, api_key=api_key) # define object mask additional information servers objectfilter = {"networkstorage": {"username": {"operation": storageusername}}} try: storageresult = client['softlayer_account'].getnetworkstorage(filter=objectfilter) storage in storageresult: print("storage id: %s" % storage['id']) except softlayer.softlayerapierror e: print(('error faultcode=%s, faultstring=%s' % (e.faultcode, e.faultstring)))
also, can recommend review below links clear idea how objectfilters works:
- object filters
- going further softlayer api python client - part 1
- going further softlayer api python client - part 2
i hope helps, please let me know doubt or comments it
Comments
Post a Comment