|
| 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]) |
0 commit comments