Skip to content

Commit c10c275

Browse files
author
Sam rishi
committed
feat:client documentation
1 parent efd5ce0 commit c10c275

23 files changed

+852
-2920
lines changed

docs/api_reference.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ API Reference
1414
api_reference/dataframe
1515
api_reference/spec
1616
api_reference/file
17+
api_reference/assetmanagement
1718

1819
Indices and tables
1920
------------------
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.. _api_tag_page:
2+
3+
nisystemlink.clients.assetmanagement
4+
======================
5+
6+
.. autoclass:: nisystemlink.clients.assetmanagement.AssetManagementClient
7+
:exclude-members: __init__
8+
9+
.. automethod:: __init__
10+
.. automethod:: get_assets
11+
.. automethod:: get_asset_summary
12+
.. automethod:: get_asset_by_id
13+
.. automethod:: create_assets
14+
.. automethod:: query_assets
15+
.. automethod:: export_assets
16+
.. automethod:: update_assets
17+
.. automethod:: delete_assets
18+
.. automethod:: link_files
19+
.. automethod:: unlink_files
20+
21+
.. automodule:: nisystemlink.clients.assetmanagement.models
22+
:members:
23+
:imported-members:

docs/getting_started.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,5 +210,34 @@ Examples
210210
Get the metadata of a File using its Id and download it.
211211

212212
.. literalinclude:: ../examples/file/download_file.py
213+
:language: python
214+
:linenos:
215+
216+
217+
Asset Management API
218+
-------
219+
220+
Overview
221+
~~~~~~~~
222+
223+
The :class:`.AssetManagementClient` class is the primary entry point of the Asset Management API.
224+
225+
When constructing a :class:`.AssetManagementClient`, you can pass an
226+
:class:`.HttpConfiguration` (like one retrieved from the
227+
:class:`.HttpConfigurationManager`), or let :class:`.AssetManagementClient` use the
228+
default connection. The default connection depends on your environment.
229+
230+
With a :class:`.AssetManagementClient` object, you can:
231+
232+
* Get the list of assets, create, update, query, export and delete assets.
233+
* Link and unlink files to assets.
234+
* Query asset location history.
235+
236+
Examples
237+
~~~~~~~~
238+
239+
Create, get, update, query, export and delete assets, query asset location history, and link and unlink files.
240+
241+
.. literalinclude:: ../examples/assetmanagement/assets.py
213242
:language: python
214243
:linenos:

examples/assetmanagement/assets.py

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
# Setup the server configuration to point to your instance of SystemLink Enterprise
2+
from nisystemlink.clients.assetmanagement import AssetManagementClient
3+
from nisystemlink.clients.assetmanagement.models import (
4+
ExportAssetsRequest,
5+
QueryAssetRequest,
6+
QueryLocationHistoryRequest,
7+
)
8+
from nisystemlink.clients.assetmanagement.models._asset import (
9+
AssetBusType,
10+
AssetDiscoveryType,
11+
AssetLocation,
12+
AssetPresence,
13+
AssetPresenceWithSystemConnection,
14+
AssetType,
15+
ExternalCalibration,
16+
SelfCalibration,
17+
TemperatureSensor,
18+
)
19+
from nisystemlink.clients.assetmanagement.models._asset_create import AssetCreate
20+
from nisystemlink.clients.assetmanagement.models._asset_update import AssetUpdate
21+
from nisystemlink.clients.assetmanagement.models._export_assets import (
22+
Destination,
23+
ResponseFormat,
24+
)
25+
from nisystemlink.clients.assetmanagement.models._query_location import (
26+
Destination as LocationDestination,
27+
ResponseFormat as LocationResponseFormat,
28+
)
29+
from nisystemlink.clients.core._http_configuration import HttpConfiguration
30+
31+
32+
def create_an_asset():
33+
"""Create an example asset in your server."""
34+
assets = [
35+
AssetCreate(
36+
model_number=4000,
37+
model_name="NI PXIe-6368",
38+
serial_number="01BB877A",
39+
vendor_name="NI",
40+
vendor_number="4244",
41+
bus_type=AssetBusType.ACCESSORY,
42+
name="PCISlot2",
43+
asset_type=AssetType.DEVICE_UNDER_TEST,
44+
firmware_version="A1",
45+
hardware_version="12A",
46+
visa_resource_name="vs-3144",
47+
temperature_sensors=[TemperatureSensor(name="Sensor0", reading=25.8)],
48+
supports_self_calibration=True,
49+
supports_external_calibration=True,
50+
custom_calibration_interval=24,
51+
self_calibration=SelfCalibration(
52+
temperature_sensors=[TemperatureSensor(name="Sensor0", reading=25.8)],
53+
is_limited=False,
54+
date="2022-06-07T18:58:05.000Z",
55+
),
56+
is_n_i_asset=True,
57+
workspace="846e294a-a007-47ac-9fc2-fac07eab240e",
58+
location=AssetLocation(
59+
state=AssetPresenceWithSystemConnection(
60+
asset_presence=AssetPresence.PRESENT
61+
)
62+
),
63+
external_calibration=ExternalCalibration(
64+
temperature_sensors=[TemperatureSensor(name="Sensor0", reading=25.8)],
65+
date="2022-06-07T18:58:05.000Z",
66+
recommended_interval=10,
67+
next_recommended_date="2023-11-14T20:42:11.583Z",
68+
next_custom_due_date="2024-11-14T20:42:11.583Z",
69+
resolved_due_date="2022-06-07T18:58:05.000Z",
70+
),
71+
properties={"Key1": "Value1"},
72+
keywords=["Keyword1"],
73+
discovery_type=AssetDiscoveryType.AUTOMATIC,
74+
file_ids=["608a5684800e325b48837c2a"],
75+
supports_self_test=True,
76+
supports_reset=True,
77+
partNumber="A1234 B5",
78+
)
79+
]
80+
81+
response = client.create_assets(assets=assets)
82+
return response
83+
84+
85+
# Setup the server configuration to point to your instance of SystemLink Enterprise.
86+
server_configuration = HttpConfiguration(
87+
server_uri="https://yourserver.yourcompany.com",
88+
api_key="YourAPIKeyGeneratedFromSystemLink",
89+
)
90+
client = AssetManagementClient(configuration=server_configuration)
91+
92+
93+
# Get first 10 assets using take attribute in get all method.
94+
getAssetsResponse = client.get_assets(take=10)
95+
96+
createAssetResponse = create_an_asset()
97+
98+
# Get the created asset.
99+
getAssetResponse = client.get_asset_by_id(asset_id=createAssetResponse.assets[0].id)
100+
101+
# Get asset summary.
102+
summaryResponse = client.get_asset_summary()
103+
104+
# Query assets using id.
105+
queryRequest = QueryAssetRequest(
106+
ids=[createAssetResponse.assets[0].id],
107+
skip=0,
108+
take=1,
109+
descending=False,
110+
calibratable_only=False,
111+
)
112+
queryResponse = client.query_assets(queryRequest)
113+
114+
# Export assets report.
115+
exportRequest = ExportAssetsRequest(
116+
response_format=ResponseFormat.CSV,
117+
destination=Destination.FILE_SERVICE,
118+
file_ingestion_workspace="846e294a-a007-47ac-9fc2-fac07eab240e",
119+
)
120+
exportResponse = client.export_assets(export=exportRequest)
121+
122+
# Update the created asset.
123+
updateAssets = [
124+
AssetUpdate(
125+
model_name="Updated Model Name",
126+
model_number=4001,
127+
serial_number="01BB877A",
128+
vendor_name="NI",
129+
vendor_number="4244",
130+
bus_type=AssetBusType.ACCESSORY,
131+
name="PCISlot2",
132+
asset_type=AssetType.DEVICE_UNDER_TEST,
133+
firmware_version="A1",
134+
hardware_version="12A",
135+
visa_resource_name="vs-3144",
136+
temperature_sensors=[TemperatureSensor(name="Sensor0", reading=25.8)],
137+
supports_self_calibration=True,
138+
supports_external_calibration=True,
139+
custom_calibration_interval=24,
140+
self_calibration=SelfCalibration(
141+
temperature_sensors=[TemperatureSensor(name="Sensor0", reading=25.8)],
142+
is_limited=False,
143+
date="2022-06-07T18:58:05.000Z",
144+
),
145+
is_n_i_asset=True,
146+
id=createAssetResponse.assets[0].id,
147+
workspace="846e294a-a007-47ac-9fc2-fac07eab240e",
148+
location=AssetLocation(
149+
state=AssetPresenceWithSystemConnection(
150+
asset_presence=AssetPresence.PRESENT
151+
)
152+
),
153+
external_calibration=ExternalCalibration(
154+
temperature_sensors=[TemperatureSensor(name="Sensor0", reading=25.8)],
155+
date="2022-06-07T18:58:05.000Z",
156+
recommended_interval=10,
157+
next_recommended_date="2023-11-14T20:42:11.583Z",
158+
next_custom_due_date="2024-11-14T20:42:11.583Z",
159+
resolved_due_date="2022-06-07T18:58:05.000Z",
160+
),
161+
properties={"Key1": "Value1"},
162+
keywords=["Keyword1"],
163+
file_ids=["608a5684800e325b48837c2a"],
164+
supports_self_test=True,
165+
supports_reset=True,
166+
partNumber="A1234 B5",
167+
)
168+
]
169+
updatedResponse = client.update_assets(assets=updateAssets)
170+
171+
# Query asset location history of the created asset.
172+
queryLocationRequest = QueryLocationHistoryRequest(
173+
response_format=LocationResponseFormat.JSON,
174+
destination=LocationDestination.FILE_SERVICE,
175+
)
176+
queryLocationResponse = client.query_location(
177+
query=queryLocationRequest, asset_id=createAssetResponse.assets[0].id
178+
)
179+
180+
# Link files to the created asset.
181+
if exportResponse.file_id:
182+
fileIds = [exportResponse.file_id]
183+
linkFilesResponse = client.link_files(
184+
fileIds=fileIds, asset_id=createAssetResponse.assets[0].id
185+
)
186+
187+
# Unlink a file from the created asset.
188+
client.unlink_files(asset_id=createAssetResponse.assets[0].id, file_id=fileIds[0])
189+
190+
# Delete the created asset.
191+
client.delete_assets(ids=[createAssetResponse.assets[0].id])
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
from nisystemlink.clients.assetManagement._asset_management_client import AssetManagementClient
1+
from nisystemlink.clients.assetmanagement._asset_management_client import (
2+
AssetManagementClient,
3+
)
4+
5+
# flake8: noqa

0 commit comments

Comments
 (0)