ODA Command Line Interface (CLI)

The ODA Command Line Interface package provides the user with a simple interface for accessing and querying different entities stored in the ODA.

Currently supported entity types (followed by the CLI abbreviation) are:

  • Scheduling Block Definitions (sbds)

  • Scheduling Block Instances (sbis)

  • Execution Blocks (ebs)

  • Projects (prjs)

Configuration

ODA CLI is installed as part of the ska-db-oda package:

$ pip install ska-db-oda --extra-index-url=https://artefact.skao.int/repository/pypi-internal/simple

The CLI assumes ODA server is running at the address specified by ODA_URL environment variable. Set the variable, for example when deployed locally with k8s:

$ export ODA_URL=http://<minikube_ip>/<kube_namespace>/oda/api/<MAJOR_VERSION>

To ensure the CLI is available, and for more help, run oda --help.

The typical use pattern is then as below, and specific examples can be seen in the following sections.

$ oda <entity abbreviation> <command> <parameters>

Commands

ODA CLI command

Parameters

Description

get

entity_id

Get entity by ID, first specifying entity type. Example: oda sbis get sbi-mvp01-20200325-00001

query

Query ODA for entity IDs. The query can be one of the following:

user

User query: Specify a name of the creator of the entity

starts_with

set starts_with to True if only wanting to match the beginning of the user

contains

set contains to True if only wanting to match the pattern of the entity_id/user

created_before

Date created query: Specify a start and/or end date for when the entity was first created

created_after

last_modified_before

Date modified query: Specify a start and/or end date for when the entity was last modified.

last_modified_after

entity_id

EntityID query: Specify a entity_id of the creater of entity, set starts_with to True if only wanting to match beginning of the entity_id or set contains to True if want to match the pattern.(False by default)

Examples

A typical use case would be to query for entities created in a certain time window or by a certain user, then to retrieve the full entity.

For example, to query all ExecutionBlocks created on a certain day

$ oda sbis query --created_after='2022-10-18 00:00' --created_before='2024-10-18 23:59'

   Query Parameters
   ---------------
   query_type = QueryType.CREATED_BETWEEN
   start = 2022-10-18 00:00:00
   end = 2024-10-18 23:59:00

   Result
   -------
   [
       {
           "interface": "https://schema.skao.int/ska-oso-pdm-sbi/0.1",
           "metadata": {
               "created_by": "DefaultUser",
               "created_on": "2023-10-07T16:28:41.314279+00:00",
               "last_modified_by": "DefaultUser",
               "last_modified_on": "2023-10-07T16:28:41.314279+00:00",
               "version": 1
           },
           "sbd_ref": "sbd-mvp01-20220923-00003",
           "sbd_version": 1,
           "sbi_id": "sbi-mvp01-20220923-00003",
           "subarray_id": 3,
           "telescope": "ska_mid"
       },
       {
           "interface": "https://schema.skao.int/ska-oso-pdm-sbi/0.1",
           "metadata": {
               "created_by": "DefaultUser",
               "created_on": "2023-10-03T18:26:50.416261+00:00",
               "last_modified_by": "DefaultUser",
               "last_modified_on": "2023-10-03T18:26:50.416261+00:00",
               "version": 1
           },
           "sbd_ref": "sbi-mvp01-20220923-00002",
           "sbd_version": 1,
           "sbi_id": "sbi-mvp01-20220923-00002",
           "subarray_id": 3,
           "telescope": "ska_mid"
       },
       {
           "activities": [
               {
                   "activity_ref": "test activity",
                   "executed_at": "2022-09-23T15:43:53.971548+00:00",
                   "runtime_args": [
                       {
                           "function_args": {
                               "kwargs": {
                                   "foo": "bar"
                               }
                           },
                           "function_name": "test_fn"
                       }
                   ]
               }
           ],
           "eb_ref": "eb-mvp01-20220923-00001",
           "interface": "https://schema.skao.int/ska-oso-pdm-sbi/0.1",
           "metadata": {
               "created_by": "DefaultUser",
               "created_on": "2023-10-18T17:02:53.611151+00:00",
               "last_modified_by": "DefaultUser",
               "last_modified_on": "2023-10-18T17:02:53.611151+00:00",
               "version": 1
           },
           "sbd_ref": "sbd-mvp01-20220923-00001",
           "sbd_version": 1,
           "sbi_id": "sbi-mvp01-20220923-00001",
           "subarray_id": 3,
           "telescope": "ska_mid"
       }
   ]

Then fetch the full ExecutionBlock for one of the IDs.

$ oda ebs get eb-t0001-20231018-00004

   {
       "interface": "https://schema.skao.int/ska-oso-pdm-eb/0.1",
       "eb_id": "eb-t0001-20231018-00004",
       "metadata": {
           "version": 1,
           "created_by": "DefaultUser",
           "created_on": "2023-10-18T08:36:46.710630+00:00",
           "last_modified_by": "DefaultUser",
           "last_modified_on": "2023-10-18T08:36:46.710630+00:00"
       },
       "telescope": "ska_mid",
       "sbd_ref": "sbd-mvp01-20220923-00001",
       "sbd_version": 1,
       "sbi_ref": "sbi-mvp01-20220923-00001",
       "request_responses": [
           {
             "request": "ska_oso_scripting.functions.devicecontrol.release_all_resources",
             "request_args": "{'args': None, 'kwargs': {'subarray_id': '1'}}",
             "status": "OK",
             "response": {
               "result": "this is a result"
             },
             "request_sent_at": "2022-09-23T15:43:53.971548+00:00",
             "response_received_at": "2022-09-23T15:43:53.971548+00:00"
           },
           {
             "request": "ska_oso_scripting.functions.devicecontrol.scan",
             "status": "ERROR",
             "error": {
               "detail": "this is an error"
             },
             "request_sent_at": "2022-09-23T15:43:53.971548+00:00"
           }
         ]
   }

Another example, to query SBInstances by user

$ oda sbis query -user='DefaultUser' --starts-with

    Query Parameters
    ---------------
    user = DefaultUser
    match_type = MatchType.STARTS_WITH

    Result
    -------
    [
      {
          "interface": "https://schema.skao.int/ska-oso-pdm-sbi/0.1",
          "metadata": {
              "created_by": "DefaultUser",
              "created_on": "2023-10-07T16:28:41.314279+00:00",
              "last_modified_by": "DefaultUser",
              "last_modified_on": "2023-10-07T16:28:41.314279+00:00",
              "version": 1
          },
          "sbd_ref": "sbd-mvp01-20220923-00003",
          "sbd_version": 1,
          "sbi_id": "sbi-mvp01-20220923-00003",
          "subarray_id": 3,
          "telescope": "ska_mid"
      },
      {
          "interface": "https://schema.skao.int/ska-oso-pdm-sbi/0.1",
          "metadata": {
              "created_by": "DefaultUser",
              "created_on": "2023-10-03T18:26:50.416261+00:00",
              "last_modified_by": "DefaultUser",
              "last_modified_on": "2023-10-03T18:26:50.416261+00:00",
              "version": 1
          },
          "sbd_ref": "sbi-mvp01-20220923-00002",
          "sbd_version": 1,
          "sbi_id": "sbi-mvp01-20220923-00002",
          "subarray_id": 3,
          "telescope": "ska_mid"
      },
      {
          "activities": [
              {
                  "activity_ref": "test activity",
                  "executed_at": "2022-09-23T15:43:53.971548+00:00",
                  "runtime_args": [
                      {
                          "function_args": {
                              "kwargs": {
                                  "foo": "bar"
                              }
                          },
                          "function_name": "test_fn"
                      }
                  ]
              }
          ],
          "eb_ref": "eb-mvp01-20220923-00001",
          "interface": "https://schema.skao.int/ska-oso-pdm-sbi/0.1",
          "metadata": {
              "created_by": "DefaultUser",
              "created_on": "2023-10-18T17:02:53.611151+00:00",
              "last_modified_by": "DefaultUser",
              "last_modified_on": "2023-10-18T17:02:53.611151+00:00",
              "version": 1
          },
          "sbd_ref": "sbd-mvp01-20220923-00001",
          "sbd_version": 1,
          "sbi_id": "sbi-mvp01-20220923-00001",
          "subarray_id": 3,
          "telescope": "ska_mid"
      }
  ]

  $ oda sbis query --entity_id='sbi' --contains

    Query Parameters
    ---------------
    entity_id = sbi
    match_type = MatchType.CONTAINS

    Result
    -------
    [
      {
          "interface": "https://schema.skao.int/ska-oso-pdm-sbi/0.1",
          "metadata": {
              "created_by": "DefaultUser",
              "created_on": "2023-10-07T16:28:41.314279+00:00",
              "last_modified_by": "DefaultUser",
              "last_modified_on": "2023-10-07T16:28:41.314279+00:00",
              "version": 1
          },
          "sbd_ref": "sbd-mvp01-20220923-00003",
          "sbd_version": 1,
          "sbi_id": "sbi-mvp01-20220923-00003",
          "subarray_id": 3,
          "telescope": "ska_mid"
      },
      {
          "interface": "https://schema.skao.int/ska-oso-pdm-sbi/0.1",
          "metadata": {
              "created_by": "DefaultUser",
              "created_on": "2023-10-03T18:26:50.416261+00:00",
              "last_modified_by": "DefaultUser",
              "last_modified_on": "2023-10-03T18:26:50.416261+00:00",
              "version": 1
          },
          "sbd_ref": "sbi-mvp01-20220923-00002",
          "sbd_version": 1,
          "sbi_id": "sbi-mvp01-20220923-00002",
          "subarray_id": 3,
          "telescope": "ska_mid"
      },
      {
          "activities": [
              {
                  "activity_ref": "test activity",
                  "executed_at": "2022-09-23T15:43:53.971548+00:00",
                  "runtime_args": [
                      {
                          "function_args": {
                              "kwargs": {
                                  "foo": "bar"
                              }
                          },
                          "function_name": "test_fn"
                      }
                  ]
              }
          ],
          "eb_ref": "eb-mvp01-20220923-00001",
          "interface": "https://schema.skao.int/ska-oso-pdm-sbi/0.1",
          "metadata": {
              "created_by": "DefaultUser",
              "created_on": "2023-10-18T17:02:53.611151+00:00",
              "last_modified_by": "DefaultUser",
              "last_modified_on": "2023-10-18T17:02:53.611151+00:00",
              "version": 1
          },
          "sbd_ref": "sbd-mvp01-20220923-00001",
          "sbd_version": 1,
          "sbi_id": "sbi-mvp01-20220923-00001",
          "subarray_id": 3,
          "telescope": "ska_mid"
      }
  ]