-
Notifications
You must be signed in to change notification settings - Fork 74
Adding methods for devices and device-templates #164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e8b1a7d
Adding az cli commands for central devices
8e846f1
Adding az cli commands for central devices
fdf046d
Added ability to provision a device
26299f0
Added ability to create devices and templates
950e873
Add integration test for all device commands
e3b553b
Added device template IT
c94c08d
fixed UT errors, minor renames
1ee0c23
Removed a bad IT
02d1831
fix unused issue
1d06c69
Updated docs, code cleanup
a4b2629
Added help
d60f259
relative -> full imports, added a comment, other minor fixes
32a91a3
fixed IT
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| # coding=utf-8 | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| from knack.help_files import helps | ||
|
|
||
|
|
||
| def load_central_help(): | ||
| helps[ | ||
| "iot central" | ||
| ] = """ | ||
| type: group | ||
| short-summary: Manage Azure Central (IoTC) solutions & infrastructure | ||
| """ | ||
|
|
||
| _load_central_devices_help() | ||
| _load_central_device_templates_help() | ||
|
|
||
|
|
||
| def _load_central_devices_help(): | ||
| helps[ | ||
| "iot central app device" | ||
| ] = """ | ||
| type: group | ||
| short-summary: Manage and configure IoTC devices | ||
| """ | ||
|
|
||
| helps[ | ||
| "iot central app device create" | ||
| ] = """ | ||
| type: command | ||
| short-summary: Create a device in IoTC | ||
|
|
||
| examples: | ||
| - name: Create a device | ||
| text: > | ||
| az iot central app device create | ||
| --app-id {appid} | ||
| --device-id {deviceid} | ||
|
|
||
| - name: Create a simulated device | ||
| text: > | ||
| az iot central app device create | ||
| --app-id {appid} | ||
| --device-id {deviceid} | ||
| --instance-of {devicetemplateid} | ||
| --simulated | ||
| """ | ||
|
|
||
| helps[ | ||
| "iot central app device show" | ||
| ] = """ | ||
| type: command | ||
| short-summary: Get a device from IoTC | ||
|
|
||
| examples: | ||
| - name: Get a device | ||
| text: > | ||
| az iot central app device show | ||
| --app-id {appid} | ||
| --device-id {deviceid} | ||
| """ | ||
|
|
||
| helps[ | ||
| "iot central app device list" | ||
| ] = """ | ||
| type: command | ||
| short-summary: List all devices in IoTC | ||
|
|
||
| examples: | ||
| - name: Get a device | ||
| text: > | ||
| az iot central app device list | ||
| --app-id {appid} | ||
| """ | ||
|
|
||
| helps[ | ||
| "iot central app device delete" | ||
| ] = """ | ||
| type: command | ||
| short-summary: Delete a device from IoTC | ||
|
|
||
| examples: | ||
| - name: Get a device | ||
| text: > | ||
| az iot central app device list | ||
| --app-id {appid} | ||
| --device-id {deviceid} | ||
| """ | ||
|
|
||
|
|
||
| def _load_central_device_templates_help(): | ||
| helps[ | ||
| "iot central app device-template" | ||
| ] = """ | ||
| type: group | ||
| short-summary: Manage and configure IoTC device templates | ||
| """ | ||
|
|
||
| helps[ | ||
| "iot central app device-template create" | ||
| ] = """ | ||
| type: command | ||
| short-summary: Create a device template in IoTC | ||
|
|
||
| examples: | ||
| - name: Create a device with payload read from a file | ||
| text: > | ||
| az iot central app device create | ||
| --app-id {appid} | ||
| --content {pathtofile} | ||
| --device-template-id {devicetemplateid} | ||
|
|
||
| - name: Create a device with payload read from raw json | ||
| text: > | ||
| az iot central app device create | ||
| --app-id {appid} | ||
| --content {json} | ||
| --device-template-id {devicetemplateid} | ||
| """ | ||
|
|
||
| helps[ | ||
| "iot central app device-template show" | ||
| ] = """ | ||
| type: command | ||
| short-summary: Get a device template from IoTC | ||
|
|
||
| examples: | ||
| - name: Get a device | ||
| text: > | ||
| az iot central app device show | ||
| --app-id {appid} | ||
| --device-template-id {devicetemplateid} | ||
| """ | ||
|
|
||
| helps[ | ||
| "iot central app device-template list" | ||
| ] = """ | ||
| type: command | ||
| short-summary: List all device templates in IoTC | ||
|
|
||
| examples: | ||
| - name: Get a device | ||
| text: > | ||
| az iot central app device-template list | ||
| --app-id {appid} | ||
| """ | ||
|
|
||
| helps[ | ||
| "iot central app device-template map" | ||
| ] = """ | ||
| type: command | ||
| short-summary: Returns a mapping of device template name to device template id | ||
|
|
||
| examples: | ||
| - name: Get device template name to id mapping | ||
| text: > | ||
| az iot central app device-template map | ||
| --app-id {appid} | ||
| """ | ||
|
|
||
| helps[ | ||
| "iot central app device-template delete" | ||
| ] = """ | ||
| type: command | ||
| short-summary: Delete a device template from IoTC | ||
| long-summary: | ||
| Note: this is expected to fail | ||
| if any devices are still registered to this template. | ||
|
|
||
| examples: | ||
| - name: Get a device | ||
| text: > | ||
| az iot central app device-template list | ||
| --app-id {appid} | ||
| """ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # coding=utf-8 | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| """ | ||
| Load CLI commands | ||
| """ | ||
| from azure.cli.core.commands import CliCommandType | ||
|
|
||
| central_device_ops = CliCommandType( | ||
| operations_tmpl="azext_iot.central.commands_device#{}" | ||
| ) | ||
|
|
||
| central_device_templates_ops = CliCommandType( | ||
| operations_tmpl="azext_iot.central.commands_device_template#{}" | ||
| ) | ||
|
|
||
|
|
||
| # Dev note - think of this as the "router" and all self.command_group as the controllers | ||
| def load_central_commands(self, _): | ||
| """ | ||
| Load CLI commands | ||
| """ | ||
| with self.command_group( | ||
| "iot central app device", command_type=central_device_ops, is_preview=True, | ||
| ) as cmd_group: | ||
| cmd_group.command("list", "list_devices") | ||
| cmd_group.command("show", "get_device") | ||
| cmd_group.command("create", "create_device") | ||
| cmd_group.command("delete", "delete_device") | ||
|
|
||
| with self.command_group( | ||
| "iot central app device-template", | ||
| command_type=central_device_templates_ops, | ||
| is_preview=True, | ||
| ) as cmd_group: | ||
| cmd_group.command("list", "list_device_templates") | ||
| cmd_group.command("map", "map_device_templates") | ||
| cmd_group.command("show", "get_device_template") | ||
| cmd_group.command("create", "create_device_template") | ||
| cmd_group.command("delete", "delete_device_template") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # coding=utf-8 | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Dev note - think of this as a controller | ||
|
|
||
| from knack.util import CLIError | ||
| from .providers import CentralDeviceProvider | ||
|
This conversation was marked as resolved.
Outdated
|
||
|
|
||
|
|
||
| def list_devices(cmd, app_id: str, central_dns_suffix="azureiotcentral.com"): | ||
| provider = CentralDeviceProvider(cmd, app_id) | ||
| return provider.list_devices() | ||
|
|
||
|
|
||
| def get_device( | ||
| cmd, app_id: str, device_id: str, central_dns_suffix="azureiotcentral.com" | ||
| ): | ||
| provider = CentralDeviceProvider(cmd, app_id) | ||
| return provider.get_device(device_id) | ||
|
|
||
|
|
||
| def create_device( | ||
| cmd, | ||
| app_id: str, | ||
| device_id: str, | ||
| device_name=None, | ||
| instance_of=None, | ||
| simulated=False, | ||
| central_dns_suffix="azureiotcentral.com", | ||
| ): | ||
| if simulated and not instance_of: | ||
| raise CLIError( | ||
| "Error: if you supply --simulated you must also specify --instance-of" | ||
| ) | ||
| provider = CentralDeviceProvider(cmd, app_id) | ||
| return provider.create_device( | ||
| device_id=device_id, | ||
| device_name=device_name, | ||
| instance_of=instance_of, | ||
| simulated=simulated, | ||
| central_dns_suffix=central_dns_suffix, | ||
| ) | ||
|
|
||
|
|
||
| def delete_device( | ||
| cmd, app_id: str, device_id: str, central_dns_suffix="azureiotcentral.com" | ||
| ): | ||
| provider = CentralDeviceProvider(cmd, app_id) | ||
| return provider.delete_device(device_id) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.