Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions azext_iot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,49 @@
import azext_iot._help # noqa: F401


iothub_ops = CliCommandType(
operations_tmpl='azext_iot.operations.hub#{}'
)
iothub_ops = CliCommandType(operations_tmpl="azext_iot.operations.hub#{}")

iothub_ops_job = CliCommandType(
operations_tmpl='azext_iot.iothub.job_commands#{}'
)
iothub_ops_job = CliCommandType(operations_tmpl="azext_iot.iothub.job_commands#{}")

iothub_ops_device = CliCommandType(
operations_tmpl='azext_iot.iothub.device_commands#{}'
operations_tmpl="azext_iot.iothub.device_commands#{}"
)

iotdps_ops = CliCommandType(
operations_tmpl='azext_iot.operations.dps#{}',
client_factory=iot_service_provisioning_factory
operations_tmpl="azext_iot.operations.dps#{}",
client_factory=iot_service_provisioning_factory,
)

iotcentral_ops = CliCommandType(
operations_tmpl='azext_iot.operations.central#{}'
)
iotcentral_ops = CliCommandType(operations_tmpl="azext_iot.operations.central#{}")

iotdigitaltwin_ops = CliCommandType(
operations_tmpl='azext_iot.operations.digitaltwin#{}'
operations_tmpl="azext_iot.operations.digitaltwin#{}"
)

iotpnp_ops = CliCommandType(
operations_tmpl='azext_iot.operations.pnp#{}'
)
iotpnp_ops = CliCommandType(operations_tmpl="azext_iot.operations.pnp#{}")


class IoTExtCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
super(IoTExtCommandsLoader, self).__init__(cli_ctx=cli_ctx)

def load_command_table(self, args):
from azext_iot.commands import load_command_table
load_command_table(self, args)
from azext_iot.iothub.command_bindings import load_iothub_commands
from azext_iot.central.command_map import load_central_commands

load_command_table(self, args)
load_iothub_commands(self, args)
load_central_commands(self, args)

return self.command_table

def load_arguments(self, command):
from azext_iot._params import load_arguments
from azext_iot.central.params import load_central_arguments

load_arguments(self, command)
load_central_arguments(self, command)


COMMAND_LOADER_CLS = IoTExtCommandsLoader
Expand Down
4 changes: 4 additions & 0 deletions azext_iot/central/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from ._help import load_central_help

load_central_help()
178 changes: 178 additions & 0 deletions azext_iot/central/_help.py
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}
Comment thread
This conversation was marked as resolved.

- 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}
"""
43 changes: 43 additions & 0 deletions azext_iot/central/command_map.py
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")
51 changes: 51 additions & 0 deletions azext_iot/central/commands_device.py
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
Comment thread
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)
Loading