Python 3: OCI REST API - Set Annotation On Storage Array

In the NetApp OCI API Samples for Python (available from the OCI Operational Server WebUI > REST API documentation > API samples) there is a which can be used to set the annotation on a specific volume. With a slight modification of the Python, we get a which can be used to set the annotation on a specific storage. An example of using it>

python --url https://YOUR_OCI_SERVER --user YOUR_REST_USER --password YOUR_PASSWORD --storage STORAGE_NAME -annotation SOME_ANNOTATION --value ANNOTATION_VALUE

Image: Insight REST API documentation > API samples

The Script

Save as say ‘’.

#!/usr/bin/env python 


Set annotation for a specific storage


from __future__ import print_function

import json

from oci_rest import OciRest, configure_command_line_parser

def find_storage(oci, storage_name):

  for storage in oci.get('assets/storages'):

    if storage['name'] == storage_name:

      return storage['self']

  return None

def annotate_storage(oci, storage_url, annotation_name, annotation_value):

  return oci.put('{}/annotations'.format(storage_url), data=json.dumps(



        "rawValue": annotation_value,

        "definition": {"name": annotation_name}




if __name__ == "__main__":

  # Get the default command-line arguments (url, user, password)

  parser = configure_command_line_parser(usage='Set storage annotation')


  # Add additional arguments to configure the search criteria

  parser.add_argument('--storage', required=True, help="Storage name")

  parser.add_argument('--annotation', required=True, help="Annotation name (do NOT use label!)")

  parser.add_argument('--value', required=True, help="Annotation value to set")


  options = parser.parse_args()

  url, user, password = options.url, options.user, options.password


  with OciRest(url, user, password) as oci:

    storage_url = find_storage(oci,


    if storage_url is not None:

      new_annotation = annotate_storage(oci,





      print('Created new annotation:\n', json.dumps(new_annotation))



      print("Could not find storage {}".format(

APPENDIX: List of the 14 out-of-the-box ‘NetApp OCI API Samples for Python’

  • - print list of all storagePools with storage name and total allocatedCapacity
  • - manipulate annotation types
  • - manipulate business entities
  • - Print status report for each datasource
  • - Create OCI user
  • - print list of storage pools filtered by storage tier, and thresholds
  • - print virtual machines with dataStores on specific storage
  • - Programmatically manipulate OCI license
  • - Import datasource patch
  • - Set annotation for a specific volume
  • - Set datacenter annotation for hosts based on their connected storage annotation
  • - Set annotation for a group of volumes identified with prefix
  • - set values for LDAP configuration
  • - create, delete agents and integrations. Ingest integration data.