Skip to content

Commit c737f12

Browse files
andrew-buckleytroydai
authored andcommitted
Adds IoT Hub Basic Tier capabilities. (Azure#6320)
1 parent 70b9c27 commit c737f12

11 files changed

+2022
-1788
lines changed

azure-cli.pyproj

+1
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@
423423
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\tests\latest\test_iot_dps_commands.py" />
424424
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\tests\latest\test_sas_token_auth.py" />
425425
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\tests\latest\_test_utils.py" />
426+
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\tests\latest\__init__.py" />
426427
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\_client_factory.py" />
427428
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\_completers.py" />
428429
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\_constants.py" />

azure-cli2017.pyproj

+1
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@
424424
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\tests\latest\test_iot_dps_commands.py" />
425425
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\tests\latest\test_sas_token_auth.py" />
426426
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\tests\latest\_test_utils.py" />
427+
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\tests\latest\__init__.py" />
427428
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\_constants.py" />
428429
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\_client_factory.py" />
429430
<Compile Include="command_modules\azure-cli-iot\azure\cli\command_modules\iot\_completers.py" />

src/command_modules/azure-cli-iot/HISTORY.rst

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
Release History
44
===============
55

6+
0.1.21
7+
++++++
8+
9+
* Adds support for creating Basic Tier IoT Hubs.
10+
* Updates to Azure SDK 0.5.0
11+
612
0.1.20
713
++++++
814

src/command_modules/azure-cli-iot/azure/cli/command_modules/iot/custom.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,11 @@ def iot_hub_create(cmd, client, hub_name, resource_group_name, location=None, sk
340340
sku = IotHubSkuInfo(name=sku, capacity=unit)
341341

342342
event_hub_dic = {}
343-
event_hub_dic['events'] = EventHubProperties(1, partition_count)
344-
properties = IotHubProperties(None, None, event_hub_dic)
345-
hub_description = IotHubDescription(location, client.iot_hub_resource.config.subscription_id, resource_group_name,
346-
sku, None, None, properties)
343+
event_hub_dic['events'] = EventHubProperties(retention_time_in_days=1, partition_count=partition_count)
344+
properties = IotHubProperties(event_hub_endpoints=event_hub_dic)
345+
hub_description = IotHubDescription(location=location,
346+
sku=sku,
347+
properties=properties)
347348
return client.iot_hub_resource.create_or_update(resource_group_name, hub_name, hub_description)
348349

349350

@@ -376,15 +377,15 @@ def iot_hub_delete(client, hub_name, resource_group_name=None):
376377

377378

378379
# pylint: disable=inconsistent-return-statements
379-
def iot_hub_show_connection_string(client, hub_name=None, resource_group_name=None, policy_name='iothubowner',
380+
def iot_hub_show_connection_string(client, hub_name, resource_group_name=None, policy_name='iothubowner',
380381
key_type=KeyType.primary.value):
381382
if hub_name is None:
382383
hubs = iot_hub_list(client, resource_group_name)
383384
if hubs is None:
384385
raise CLIError("No IoT Hub found.")
385386

386387
def conn_str_getter(h):
387-
return _get_single_hub_connection_string(client, h.name, h.resourcegroup, policy_name, key_type)
388+
return _get_single_hub_connection_string(client, h.name, h.additional_properties['resourcegroup'], policy_name, key_type)
388389
return [{'name': h.name, 'connectionString': conn_str_getter(h)} for h in hubs]
389390
else:
390391
resource_group_name = _ensure_resource_group_name(client, resource_group_name, hub_name)
@@ -438,23 +439,23 @@ def iot_hub_policy_create(client, hub_name, policy_name, permissions, resource_g
438439
rights = _convert_perms_to_access_rights(permissions)
439440
hub = iot_hub_get(client, hub_name, resource_group_name)
440441
policies = []
441-
policies.extend(iot_hub_policy_list(client, hub_name, hub.resourcegroup))
442+
policies.extend(iot_hub_policy_list(client, hub_name, hub.additional_properties['resourcegroup']))
442443
if _is_policy_existed(policies, policy_name):
443444
raise CLIError("Policy {0} already existed.".format(policy_name))
444-
policies.append(SharedAccessSignatureAuthorizationRule(policy_name, rights))
445+
policies.append(SharedAccessSignatureAuthorizationRule(key_name=policy_name, rights=rights))
445446
hub.properties.authorization_policies = policies
446-
return client.iot_hub_resource.create_or_update(hub.resourcegroup, hub_name, hub, {'IF-MATCH': hub.etag})
447+
return client.iot_hub_resource.create_or_update(hub.additional_properties['resourcegroup'], hub_name, hub, {'IF-MATCH': hub.etag})
447448

448449

449450
def iot_hub_policy_delete(client, hub_name, policy_name, resource_group_name=None):
450451
import copy
451452
hub = iot_hub_get(client, hub_name, resource_group_name)
452-
policies = iot_hub_policy_list(client, hub_name, hub.resourcegroup)
453+
policies = iot_hub_policy_list(client, hub_name, hub.additional_properties['resourcegroup'])
453454
if not _is_policy_existed(copy.deepcopy(policies), policy_name):
454455
raise CLIError("Policy {0} not found.".format(policy_name))
455456
updated_policies = [p for p in policies if p.key_name.lower() != policy_name.lower()]
456457
hub.properties.authorization_policies = updated_policies
457-
return client.iot_hub_resource.create_or_update(hub.resourcegroup, hub_name, hub, {'IF-MATCH': hub.etag})
458+
return client.iot_hub_resource.create_or_update(hub.additional_properties['resourcegroup'], hub_name, hub, {'IF-MATCH': hub.etag})
458459

459460

460461
def _is_policy_existed(policies, policy_name):
@@ -655,7 +656,7 @@ def _ensure_location(cli_ctx, resource_group_name, location):
655656

656657
def _ensure_resource_group_name(client, resource_group_name, hub_name):
657658
if resource_group_name is None:
658-
return _get_iot_hub_by_name(client, hub_name).resourcegroup
659+
return _get_iot_hub_by_name(client, hub_name).additional_properties['resourcegroup']
659660
return resource_group_name
660661

661662

0 commit comments

Comments
 (0)