Cogniac / cogniac-sdk-py

Python SDK for Cogniac Public API
Apache License 2.0
5 stars 6 forks source link

Add gateway support in CloudCore and local APIs. #61

Closed ah-cog closed 4 years ago

ah-cog commented 4 years ago

Changes

Next

ah-cog commented 4 years ago

Thanks for taking a look, Spence. I'm still working on it and thinking about a couple things... just a heads up. I'm hoping to wrap it up today though.

One if the questions I'm thinking about is whether network interfaces should have their own functions, or if accessing the object is sufficient for now.

On Mon, Apr 6, 2020, 10:57 AM spencer-kt notifications@github.com wrote:

@spencer-kt commented on this pull request.

In cogniac/gateway.py https://github.com/Cogniac/cogniac-sdk-py/pull/61#discussion_r404282315:

  • if not connection and not url_prefix:
  • raise Exception("A URL must be specified for either a CloudCore or EdgeFlow API.")
  • if connection and not gateway_dict:
  • raise Exception("Missing gateway object.")

This logic doesn't account for connection=None cases. Does this break if it's None?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Cogniac/cogniac-sdk-py/pull/61#pullrequestreview-388487893, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFV5QOTS4OO3TIPMJXJI73RLIJYPANCNFSM4MCO7SKA .

ah-cog commented 4 years ago

Here are some tested usage examples to get a feel for the current state of this branch:

Note: This is revised. Previous variations are in edit history.

EDGEFLOW_ID = 'my_edgeflow_id'

# Connect to Core.
cc = CogniacConnection()

# Get all tenant EdgeFlows.
edgeflows = cc.get_all_edgeflows()
pprint(edgeflows)

# Get a specific EdgeFlow object.
# Note: The EdgeFlow's `ip_address` field will be used for local EdgeFlow API requests.
edgeflow = cc.get_edgeflow(EDGEFLOW_ID)

# SDK calls to EdgeFlow APIs.
edgeflow_version = edgeflow.get_version()
print(edgeflow_version)
# media_detections = edgeflow.process_media(subject_uid=SUBJECT_UID,
#                                          filename=IMAGE_FILEPATH)

# SDK calls to Core APIs.
# edgeflow.flush_upload_queue()
# edgeflow.factory_reset()
# edgeflow.upgrade()
edgeflow.reboot()
# edgeflow.status()
ah-cog commented 4 years ago

In the above examples, CogniacEdgeFlow is both the gateway object/client (CloudCore) and a client interface to a local EdgeFlow. I'm considering separating this into two classes, EdgeFlow for the object/client interface, and a separate EdgeFlowClient for local access.

I think this may clarify the purpose and prevent overloading the single class. Any preferences on that?

amy-why commented 4 years ago

how about delete gateway? can we add it to make it easier?

wskish commented 4 years ago

Gateway is going to be deleted by itself as a side effect of factory reset. https://github.com/Cogniac/gateway/issues/166