Skip to content

Commit

Permalink
add onvif
Browse files Browse the repository at this point in the history
  • Loading branch information
vilit1 committed Dec 11, 2024
1 parent 65aee3b commit 040bb2f
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 39 deletions.
21 changes: 20 additions & 1 deletion azext_edge/edge/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ def load_iotops_help():
- name: Create an asset endpoint with username-password user authentication using the given instance in a different resource group but same subscription. The additional
configuration is provided as an inline json.
text: >
az iot ops asset endpoint create opcua --name myprofile -g myresourcegroup --instance myinstance
az iot ops asset endpoint create custom --name myprofile -g myresourcegroup --instance myinstance
--instance-resource-group myinstanceresourcegroup
--target-address http://rest-server-service.azure-iot-operations.svc.cluster.local:80 --endpoint-type rest-thermostat
--username-ref rest-server-auth-creds/username --password-ref rest-server-auth-creds/password
Expand All @@ -1051,6 +1051,25 @@ def load_iotops_help():
--additional-configuration '{"hello": "world"}'
"""

helps[
"iot ops asset endpoint create onvif"
] = """
type: command
short-summary: Create an asset endpoint profile with an Onvif connector.
long-summary: For more information on how to create an Onvif connector, please see aka.ms/onvif-quickstart
examples:
- name: Create an asset endpoint with anonymous user authentication using the given instance in the same resource group.
text: >
az iot ops asset endpoint create onvif --name myprofile -g myresourcegroup --instance myinstance
--target-address http://onvif-rtsp-simulator:8000
- name: Create an asset endpoint with username-password user authentication using the given instance in a different resource group but same subscription.
text: >
az iot ops asset endpoint create onvif --name myprofile -g myresourcegroup --instance myinstance
--instance-resource-group myinstanceresourcegroup
--target-address http://onvif-rtsp-simulator:8000
--username-ref rest-server-auth-creds/username --password-ref rest-server-auth-creds/password
"""

helps[
"iot ops asset endpoint create opcua"
] = """
Expand Down
1 change: 1 addition & 0 deletions azext_edge/edge/command_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def load_iotops_commands(self, _):
command_type=aep_resource_ops,
) as cmd_group:
cmd_group.command("custom", "create_custom_asset_endpoint_profile")
cmd_group.command("onvif", "create_onvif_asset_endpoint_profile", is_preview=True)
cmd_group.command("opcua", "create_opcua_asset_endpoint_profile")

with self.command_group(
Expand Down
102 changes: 67 additions & 35 deletions azext_edge/edge/commands_asset_endpoint_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,73 @@
logger = get_logger(__name__)


def create_custom_asset_endpoint_profile(
cmd,
asset_endpoint_profile_name: str,
endpoint_profile_type: str,
instance_name: str,
resource_group_name: str,
target_address: str,
certificate_reference: Optional[str] = None,
instance_resource_group: Optional[str] = None,
instance_subscription: Optional[str] = None,
location: Optional[str] = None,
password_reference: Optional[str] = None,
username_reference: Optional[str] = None,
tags: Optional[Dict[str, str]] = None,
additional_configuration: Optional[str] = None,
**kwargs
) -> dict:
return AssetEndpointProfiles(cmd).create(
asset_endpoint_profile_name=asset_endpoint_profile_name,
endpoint_profile_type=endpoint_profile_type,
instance_name=instance_name,
resource_group_name=resource_group_name,
target_address=target_address,
certificate_reference=certificate_reference,
instance_resource_group=instance_resource_group,
instance_subscription=instance_subscription,
location=location,
password_reference=password_reference,
username_reference=username_reference,
tags=tags,
additional_configuration=additional_configuration,
**kwargs
)


def create_onvif_asset_endpoint_profile(
cmd,
asset_endpoint_profile_name: str,
instance_name: str,
resource_group_name: str,
target_address: str,
certificate_reference: Optional[str] = None,
instance_resource_group: Optional[str] = None,
instance_subscription: Optional[str] = None,
location: Optional[str] = None,
password_reference: Optional[str] = None,
username_reference: Optional[str] = None,
tags: Optional[Dict[str, str]] = None,
**kwargs
) -> dict:
return AssetEndpointProfiles(cmd).create(
asset_endpoint_profile_name=asset_endpoint_profile_name,
endpoint_profile_type=AEPTypes.onvif.value,
instance_name=instance_name,
resource_group_name=resource_group_name,
target_address=target_address,
certificate_reference=certificate_reference,
instance_resource_group=instance_resource_group,
instance_subscription=instance_subscription,
location=location,
password_reference=password_reference,
username_reference=username_reference,
tags=tags,
**kwargs
)


def create_opcua_asset_endpoint_profile(
cmd,
asset_endpoint_profile_name: str,
Expand Down Expand Up @@ -76,41 +143,6 @@ def create_opcua_asset_endpoint_profile(
)


def create_custom_asset_endpoint_profile(
cmd,
asset_endpoint_profile_name: str,
endpoint_profile_type: str,
instance_name: str,
resource_group_name: str,
target_address: str,
certificate_reference: Optional[str] = None,
instance_resource_group: Optional[str] = None,
instance_subscription: Optional[str] = None,
location: Optional[str] = None,
password_reference: Optional[str] = None,
username_reference: Optional[str] = None,
tags: Optional[Dict[str, str]] = None,
additional_configuration: Optional[str] = None,
**kwargs
) -> dict:
return AssetEndpointProfiles(cmd).create(
asset_endpoint_profile_name=asset_endpoint_profile_name,
endpoint_profile_type=endpoint_profile_type,
instance_name=instance_name,
resource_group_name=resource_group_name,
target_address=target_address,
certificate_reference=certificate_reference,
instance_resource_group=instance_resource_group,
instance_subscription=instance_subscription,
location=location,
password_reference=password_reference,
username_reference=username_reference,
tags=tags,
additional_configuration=additional_configuration,
**kwargs
)


def delete_asset_endpoint_profile(
cmd,
asset_endpoint_profile_name: str,
Expand Down
2 changes: 1 addition & 1 deletion azext_edge/edge/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ class AEPAuthModes(Enum):
class AEPTypes(ListableEnum):
"""Asset Endpoint Profile (connector) Types"""

# TODO: ensure this is the final enum
opcua = "Microsoft.OpcUa"
onvif = "Microsoft.Onvif"


class TopicRetain(Enum):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_asset_endpoint_lifecycle(require_init, tracked_resources, tracked_files
password = generate_random_string()
address = f"opc.tcp://{generate_random_string()}:5000"
userpass_endpoint = run(
f"az iot ops asset endpoint create opcua -n {userpass_name} -g {rg} --instance {instance} "
f"az iot ops asset endpoint create onvif -n {userpass_name} -g {rg} --instance {instance} "
f"--ta {address} --username-ref {username} --password-ref {password}"
)
tracked_resources.append(userpass_endpoint["id"])
Expand All @@ -102,7 +102,7 @@ def test_asset_endpoint_lifecycle(require_init, tracked_resources, tracked_files
target_address=address,
username_reference=username,
password_reference=password,
endpoint_type="Microsoft.OpcUa",
endpoint_type="Microsoft.Onvif",
)

cert_name = "test-endpoint-" + generate_random_string(force_lower=True)[:4]
Expand Down

0 comments on commit 040bb2f

Please sign in to comment.