Skip to main content

Python

 """
  =================================================================================================================
  Copyright (C) 2012-2023 StorONE
  ​
  Use of this script is subject to the following terms and conditions:
  ​
  StorONE grants to Buyer a nonexclusive, nontransferable, worldwide license under StorONE's copyrights to: 
  (i) use, copy, modify the reference design Script for Buyer's own development and maintenance purposes; 
  (ii) use, copy, distribute and sublicense the reference Script to Buyer resellers and end-users.
  ​
  THE SCRIPT IS PROVIDED "AS IS" AND POSSIBLY WITH FAULTS.  UNLESS EXPRESSLY AGREED OTHERWISE, STORONE AND ITS 
  SUPPLIERS AND LICENSORS DISCLAIM ANY AND ALL WARRANTIES AND GUARANTEES, EXPRESS, IMPLIED OR OTHERWISE, INCLUDING 
  BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, OR FITNESS FOR A PARTICULAR PURPOSE. 
  StorONE does not warrant or assume responsibility for the accuracy or completeness of any information, text, 
  graphics, links or other items contained within the Script.  Buyer assumes all liability, financial or otherwise, 
  associated with Buyer's use or disposition of this script.
  =================================================================================================================
  """
  
  import requests,json

  # Replace credentials and StorONE node address with values for your environment.
  # The StorONE system uses a self-signed certificate by default, so you can
  # either set the URL to use http:// or set verify=False in the post or get method.
  # Setting verify=False generates a warning in the output, so this example uses http://.

  s1_username = "storoneadm"
  s1_password = "St0r1R0x!"
  s1_host_or_ip = "s1-n1.example.com"

  s1_api_url = f"http://{s1_host_or_ip}"
  s1_login_endpoint = "/login"
  s1_app_vol_list_endpoint = "/applications/volumes/list"
  login_headers = {"accept": "application/json",
                  "Content-Type": "application/json"}
  login_body = {"username": s1_username, "password": s1_password}
  login_resp = ''

  try:
      # The StorONE system uses a self-signed certificate by default, so you
      # can either set the URL to use http:// or set verify=False in the
      # requests.post or requests.get method. Setting verify=False generates a
      # warning in the output, so this example uses http://.
      login_resp = requests.post(
          f"{s1_api_url}{s1_login_endpoint}", headers=login_headers, data = json.dumps(login_body))
  except Exception as e:
      print(f"Failed to connect to {s1_host_or_ip}: {e}")
      exit()

  if login_resp.status_code == 200:
      s1_session_token = login_resp.json()['SessionToken']
  else:
      print(f"Login failed. Received HTTP status code {login_resp.status_code}.")
      exit()

  session_headers = {"accept": "application/json",
                    "Authorization": str(s1_session_token)}

  volume_list_resp = requests.get(
      f"{s1_api_url}{s1_app_vol_list_endpoint}", headers=session_headers)

  if volume_list_resp.status_code == 200:
      app_vol_list = volume_list_resp.json()['Result']['Data']
      for application in app_vol_list:
          print(f"Application: {application['Application']}")
          print("Volumes:", end=" ")
          for volume in application['Volumes']:
              print (volume['Volume'], end=" ")
          print()
  else:
      print(f"Request failed. Received HTTP status code {login_resp.status_code}.")   
      exit()
  

I think the basic example here is a good one, but we should also include logic to handle MFA when it is set