Skip to content

Commit

Permalink
feat: update asset and asset endpoint profile api to GA versions (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
vilit1 authored Nov 5, 2024
1 parent f10f548 commit 6432daa
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 111 deletions.
1 change: 0 additions & 1 deletion azext_edge/edge/commands_asset_endpoint_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def query_asset_endpoint_profiles(
asset_endpoint_profile_name=asset_endpoint_profile_name,
auth_mode=auth_mode,
custom_query=custom_query,
discovered=False,
endpoint_profile_type=endpoint_profile_type,
instance_name=instance_name,
instance_resource_group=instance_resource_group,
Expand Down
5 changes: 1 addition & 4 deletions azext_edge/edge/commands_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,9 @@ def delete_asset(
# TODO: add in once GA
def list_assets(
cmd,
# discovered: bool = False, # TODO: discovered
resource_group_name: str = None,
) -> List[dict]:
return Assets(cmd).list(discovered=False, resource_group_name=resource_group_name)
return Assets(cmd).list(resource_group_name=resource_group_name)


def query_assets(
Expand All @@ -114,7 +113,6 @@ def query_assets(
default_topic_retain: Optional[str] = None,
description: Optional[str] = None,
disabled: Optional[bool] = None,
# discovered: Optional[bool] = None, # TODO: discovered
display_name: Optional[str] = None,
documentation_uri: Optional[str] = None,
endpoint_profile: Optional[str] = None,
Expand All @@ -138,7 +136,6 @@ def query_assets(
default_topic_retain=default_topic_retain,
description=description,
display_name=display_name,
discovered=False,
disabled=disabled,
documentation_uri=documentation_uri,
endpoint_profile=endpoint_profile,
Expand Down
13 changes: 0 additions & 13 deletions azext_edge/edge/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,12 +612,6 @@ def load_iotops_arguments(self, _):
help="Disable an asset.",
arg_type=get_three_state_flag(),
)
context.argument(
"discovered",
options_list=["--discovered"],
help="Flag to determine if an asset was discovered on the cluster.",
arg_type=get_three_state_flag(),
)
context.argument(
"documentation_uri",
options_list=["--documentation-uri", "--du"],
Expand Down Expand Up @@ -945,13 +939,6 @@ def load_iotops_arguments(self, _):
help="Instance subscription id. If not provided, asset endpoint profile subscription id will be used.",
deprecate_info=context.deprecate(hide=True),
)
context.argument(
"discovered",
options_list=["--discovered"],
help="Flag to determine if an asset endpoint profile was discovered on the cluster.",
arg_group="Additional Info",
arg_type=get_three_state_flag(),
)
context.argument(
"target_address",
options_list=["--target-address", "--ta"],
Expand Down
2 changes: 1 addition & 1 deletion azext_edge/edge/providers/edge_api/deviceregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ class DeviceRegistryResourceKinds(ListableEnum):


DEVICEREGISTRY_API_V1 = EdgeResourceApi(
group="deviceregistry.microsoft.com", version="v1beta2", moniker="deviceregistry"
group="deviceregistry.microsoft.com", version="v1", moniker="deviceregistry"
)
4 changes: 2 additions & 2 deletions azext_edge/edge/providers/orchestration/work.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from rich.table import Table

from ...util.az_client import (
REGISTRY_API_VERSION,
REGISTRY_PREVIEW_API_VERSION,
get_resource_client,
parse_resource_id,
wait_for_terminal_state,
Expand Down Expand Up @@ -341,7 +341,7 @@ def _do_work(self): # noqa: C901
# Ensure schema registry exists.
self.resource_client.resources.get_by_id(
resource_id=self._targets.schema_registry_resource_id,
api_version=REGISTRY_API_VERSION,
api_version=REGISTRY_PREVIEW_API_VERSION,
)
if not self._extension_map:
self._extension_map = self._resource_map.connected_cluster.get_extensions_by_type(
Expand Down
40 changes: 8 additions & 32 deletions azext_edge/edge/providers/rpsaas/adr/asset_endpoint_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import json
from rich.console import Console
from typing import TYPE_CHECKING, Dict, Iterable, Optional, Union
from typing import TYPE_CHECKING, Dict, Iterable, Optional

from knack.log import get_logger

Expand All @@ -22,32 +22,29 @@
REMOVED_CERT_REF_MSG,
REMOVED_USERPASS_REF_MSG,
)
from ....util.az_client import get_registry_mgmt_client, wait_for_terminal_state
from ....util.az_client import get_registry_mgmt_client, wait_for_terminal_state, REGISTRY_API_VERSION
from ....util.queryable import Queryable
from ....common import AEPAuthModes, AEPTypes

if TYPE_CHECKING:
from ....vendor.clients.deviceregistrymgmt.operations import (
DiscoveredAssetEndpointProfilesOperations as DAEPOperations,
AssetEndpointProfilesOperations as AEPOperations
)

console = Console()
logger = get_logger(__name__)
AEP_RESOURCE_TYPE = "Microsoft.DeviceRegistry/assetEndpointProfiles"
DISCOVERED_AEP_RESOURCE_TYPE = "Microsoft.DeviceRegistry/discoveredAssetEndpointProfiless"


# TODO: soul searching to see if I should combine with assets class
class AssetEndpointProfiles(Queryable):
def __init__(self, cmd):
super().__init__(cmd=cmd)
self.deviceregistry_mgmt_client = get_registry_mgmt_client(
subscription_id=self.default_subscription_id
subscription_id=self.default_subscription_id,
api_version=REGISTRY_API_VERSION
)
self.ops: "AEPOperations" = self.deviceregistry_mgmt_client.asset_endpoint_profiles
self.discovered_ops: "DAEPOperations" = self.deviceregistry_mgmt_client.discovered_asset_endpoint_profiles
self.update_ops: Optional[Union["AEPOperations", "DAEPOperations"]] = None

def create(
self,
Expand All @@ -63,7 +60,6 @@ def create(
password_reference: Optional[str] = None,
username_reference: Optional[str] = None,
tags: Optional[Dict[str, str]] = None,
discovered: bool = False, # for easy discovered debugging
**additional_configuration
):
from .helpers import get_extended_location
Expand Down Expand Up @@ -93,12 +89,6 @@ def create(
password_reference=password_reference,
certificate_reference=certificate_reference,
)
# discovered
if discovered:
self.ops = self.discovered_ops
properties.pop("authentication", None)
properties["version"] = 1
properties["discoveryId"] = "discoveryid1"

aep_body = {
"extendedLocation": extended_location,
Expand All @@ -122,7 +112,7 @@ def delete(self, asset_endpoint_profile_name: str, resource_group_name: str, **k
check_cluster=True
)
with console.status(f"Deleting {asset_endpoint_profile_name}..."):
poller = self.update_ops.begin_delete(
poller = self.ops.begin_delete(
resource_group_name,
asset_endpoint_profile_name,
)
Expand All @@ -134,18 +124,13 @@ def show(
asset_endpoint = self.ops.get(
resource_group_name=resource_group_name, asset_endpoint_profile_name=asset_endpoint_profile_name
)
self.update_ops = self.ops
self.ops = self.ops
if check_cluster:
from .helpers import check_cluster_connectivity
check_cluster_connectivity(self.cmd, asset_endpoint)
return asset_endpoint

def list(self, resource_group_name: Optional[str] = None, discovered: bool = False) -> Iterable[dict]:
if discovered:
if resource_group_name:
return self.discovered_ops.list_by_resource_group(resource_group_name=resource_group_name)
return self.discovered_ops.list_by_subscription()

if resource_group_name:
return self.ops.list_by_resource_group(resource_group_name=resource_group_name)
return self.ops.list_by_subscription()
Expand All @@ -156,7 +141,6 @@ def query_asset_endpoint_profiles(
asset_endpoint_profile_name: Optional[str] = None,
auth_mode: Optional[str] = None,
custom_query: Optional[str] = None,
discovered: Optional[bool] = None,
endpoint_profile_type: Optional[str] = None,
instance_name: Optional[str] = None,
instance_resource_group: Optional[str] = None,
Expand All @@ -172,15 +156,7 @@ def query_asset_endpoint_profiles(
resource_group_name=resource_group_name,
target_address=target_address
)

if discovered is not None:
resource_type = DISCOVERED_AEP_RESOURCE_TYPE if discovered else AEP_RESOURCE_TYPE
query = f"Resources | where type =~\"{resource_type}\" " + query_body
else:
# we put the query body into the each type query and then union to avoid the union result from
# becoming too big
query = f"Resources | where type =~ \"{AEP_RESOURCE_TYPE}\" {query_body} "\
f"| union (Resources | where type =~ \"{DISCOVERED_AEP_RESOURCE_TYPE}\" {query_body})"
query = f"Resources | where type =~\"{AEP_RESOURCE_TYPE}\" " + query_body

if any([instance_name, instance_resource_group]):
instance_query = "Resources | where type =~ 'microsoft.iotoperations/instances' "
Expand Down Expand Up @@ -228,7 +204,7 @@ def update(
)
# use this over update since we want to make sure we get the tags in
with console.status(f"Updating {asset_endpoint_profile_name}..."):
poller = self.update_ops.begin_create_or_replace(
poller = self.ops.begin_create_or_replace(
resource_group_name,
asset_endpoint_profile_name,
original_aep
Expand Down
Loading

0 comments on commit 6432daa

Please sign in to comment.