{"id":27,"date":"2014-12-28T07:40:00","date_gmt":"2014-12-28T06:40:00","guid":{"rendered":""},"modified":"2017-11-13T18:31:33","modified_gmt":"2017-11-13T17:31:33","slug":"sample-code-using-the-oracle-zfs-storage-appliance-rest-api-from-python","status":"publish","type":"post","link":"https:\/\/ilmarkerm.eu\/blog\/2014\/12\/sample-code-using-the-oracle-zfs-storage-appliance-rest-api-from-python\/","title":{"rendered":"Sample code: Using the Oracle ZFS Storage Appliance REST API from Python"},"content":{"rendered":"<p>Most (all?) of the Oracle ZFS Storage Appliance (ZS3-4 in my case) management functions are also exposed through REST API so it is possible to script and automate the storage management tasks. No proprietary clients or GUI needed, just need to write a simple script that can send some REST commands over HTTPS to the appliance and parse the JSON output.<\/p>\n<p>I had a task of automating test database refresh from production and part of that workflow is also cloning and attaching LUNs from ZFSSA. I did not find any sample code to access ZFSSA online, so here am I publishing my code. It is a Python script that makes a use of a few ZFSSA REST API calls and publishes them as <a href=\"http:\/\/www.fabfile.org\/\">Fabric<\/a> tasks.<\/p>\n<p>This script exposes four tasks:<\/p>\n<ul>\n<li><strong>clone<\/strong> &#8211; Creates a new clone from replication<\/li>\n<li><strong>attach_stage1<\/strong> &#8211; Attaches all LUNs in a project to a single target server<\/li>\n<li><strong>attach_stage2<\/strong> &#8211; Attaches all LUNs in a project to multiple target servers<\/li>\n<li><strong>drop<\/strong> &#8211; Deletes a project<\/li>\n<\/ul>\n<p><script src=\"https:\/\/gist.github.com\/ilmarkerm\/6947221d848fa31a247b305662d81ae2.js\"><\/script><\/p>\n<p>ZFSSA REST API works fine if each LUN has only a single initiator group, but when assigning LUN to multiple initiator groups (to be used in a RAC setup), I observed the following errors (they must be ZFSSA REST API bugs):<\/p>\n<ul>\n<li>When modifying LUN to be part of multiple initiator groups (PUT request to \/api\/storage\/v1\/pools\/<em>poolname<\/em>\/projects\/<em>projectname<\/em>\/luns\/<em>lunname<\/em>), then the API responds with  (argument numbers may be different): <strong>{&#8220;fault&#8221;: {&#8220;message&#8221;: &#8220;invalid input argument (assignednumber: invalid literal for int() with base 10: &#8216;0,0,0&#8217;)&#8221;, &#8220;code&#8221;: 400, &#8220;name&#8221;: &#8220;ERR_INVALID_ARG&#8221;}}<\/strong>. Nevertheless, ZFS GUI confirms that the operation was completed successfully. This script just ignores the returned error message, when assigning LUN to multiple initiator groups.<\/li>\n<li>If any LUN in the project has multiple initiator groups defined, then API call to get the list of LUNs (GET request to \/api\/storage\/v1\/pools\/<em>poolname<\/em>\/projects\/<em>projectname<\/em>\/luns) in a project returns an error immediately: <strong>{&#8220;luns&#8221;:[{&#8220;fault&#8221;: {&#8220;message&#8221;: &#8220;internal error&#8221;, &#8220;code&#8221;: 500, &#8220;name&#8221;: &#8220;ERR_INTERNAL&#8221;}}]}<\/strong>. This script cannot reattach the LUNs in this case, since getting the list of LUNs fails.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Most (all?) of the Oracle ZFS Storage Appliance (ZS3-4 in my case) management functions are also exposed through REST API so it is possible to script and automate the storage management tasks. No proprietary clients or GUI needed, just need to write a simple script that can send some REST commands over HTTPS to the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[4,6,7],"class_list":["post-27","post","type-post","status-publish","format-standard","hentry","category-blog-entry","tag-oracle","tag-python","tag-zfssa"],"_links":{"self":[{"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/posts\/27","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/comments?post=27"}],"version-history":[{"count":8,"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/posts\/27\/revisions"}],"predecessor-version":[{"id":401,"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/posts\/27\/revisions\/401"}],"wp:attachment":[{"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/media?parent=27"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/categories?post=27"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ilmarkerm.eu\/blog\/wp-json\/wp\/v2\/tags?post=27"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}