{"id":1107,"date":"2017-04-30T09:22:57","date_gmt":"2017-04-30T14:22:57","guid":{"rendered":"http:\/\/blog.ls-al.com\/?p=1107"},"modified":"2017-04-30T09:22:57","modified_gmt":"2017-04-30T14:22:57","slug":"zfssa-list-replication-actions-status","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/zfssa-list-replication-actions-status\/","title":{"rendered":"ZFSSA List Replication Actions Status"},"content":{"rendered":"

Using the ZFS appliance REST API to take a quick look at all replication actions and check on progress of long running jobs.<\/p>\n

\r\n# python zfssa_status_replication_v1.0.py\r\n\r\nList Replicated Project Snapshots -- PST Run Date 2017-04-30 06:42:59.386738\r\ndate                       target project    pool      bytes_sent      estimated_size  estimated_time_left average_throughput\r\n2017-04-30 07:20:04.232975 zfs2   EBSPRD     POOL1     6.78G           21.3G           01:00:35            4MB\/s\r\n2017-04-30 06:42:59.386738 zfs3   EBSPRD     POOL2     0               0               00:00:00            0B\/s           \r\n<snip>\r\n<\/pre>\n
\r\n# cat zfssa_status_replication_v1.0.py \r\n#!\/usr\/bin\/env python\r\n\r\n# Version 1.0\r\nimport sys\r\nimport requests, json, os\r\nimport datetime\r\n\r\nrequests.packages.urllib3.disable_warnings()\r\ndt = datetime.datetime.now()\r\n\r\n# ZFSSA API URL\r\nurl = "https:\/\/zfs1:215"\r\n\r\n# ZFSSA authentication credentials, it reads username and password from environment variables ZFSUSER and ZFSPASSWORD\r\n#zfsauth = (os.getenv('ZFSUSER'), os.getenv('ZFSPASSWORD'))\r\nzfsauth = ('ROuser','password')\r\n\r\njsonheader={'Content-Type': 'application\/json'}\r\n\r\ndef list_replication_actions_status():\r\n  r = requests.get("%s\/api\/storage\/v1\/replication\/actions" % (url), auth=zfsauth, verify=False, headers=jsonheader)\r\n  if r.status_code != 200:\r\n    print("Error getting actions %s %s" % (r.status_code, r.text))\r\n  else:\r\n   j = json.loads(r.text)\r\n   #print j\r\n   for action in j["actions"]:\r\n     #print action\r\n     print("{} {:15} {:10} {:15} ".format(dt, action["target"], action["project"], action["pool"])),\r\n     show_one_replication_action(action["id"])\r\n\r\ndef show_one_replication_action(id):\r\n  r = requests.get("%s\/api\/storage\/v1\/replication\/actions\/%s" % (url,id), auth=zfsauth, verify=False, headers=jsonheader)\r\n  if r.status_code != 200:\r\n    print("Error getting status %s %s" % (r.status_code, r.text))\r\n  else:\r\n   j = json.loads(r.text)\r\n   #print j\r\n   print("{:15} {:15} {:19} {:15}".format(j["action"]["bytes_sent"], j["action"]["estimated_size"], j["action"]["estimated_time_left"], j["action"]["average_throughput"]))\r\n\r\nprint ("\\nList Replicated Project Snapshots -- PST Run Date %s" % dt)\r\nprint('{:26} {:15} {:10} {:16} {:15} {:15} {:16} {}').format('date','target','project','pool','bytes_sent','estimated_size','estimated_time_left','average_throughput')\r\nlist_replication_actions_status()\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

Using the ZFS appliance REST API to take a quick look at all replication actions and check on progress of<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[],"class_list":["post-1107","post","type-post","status-publish","format-standard","hentry","category-zfs"],"_links":{"self":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1107","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/comments?post=1107"}],"version-history":[{"count":0,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1107\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/media?parent=1107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/categories?post=1107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/tags?post=1107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}