Skip to content

Commit

Permalink
{diskpool} Refine output and add new command (#3490)
Browse files Browse the repository at this point in the history
* test pass

* refine

* test pass
  • Loading branch information
Juliehzl committed Jun 25, 2021
1 parent 0cf0381 commit bea72c8
Show file tree
Hide file tree
Showing 14 changed files with 1,710 additions and 880 deletions.
5 changes: 5 additions & 0 deletions src/diskpool/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
Release History
===============

0.1.2
++++++
* Refine table output
* Add `az disk-pool list-outbound-network-dependency-endpoint` command

0.1.1
++++++
* Fix generation issue.
Expand Down
10 changes: 10 additions & 0 deletions src/diskpool/azext_diskpool/generated/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@
az disk-pool delete --name "myDiskPool" --resource-group "myResourceGroup"
"""

helps['disk-pool list-outbound-network-dependency-endpoint'] = """
type: command
short-summary: "Gets the network endpoints of all outbound dependencies of a Disk Pool."
examples:
- name: Get Disk Pool outbound network dependencies
text: |-
az disk-pool list-outbound-network-dependency-endpoint --name "SampleAse" --resource-group \
"Sample-WestUSResourceGroup"
"""

helps['disk-pool list-skus'] = """
type: command
short-summary: "Lists available Disk Pool Skus in an Azure location."
Expand Down
5 changes: 5 additions & 0 deletions src/diskpool/azext_diskpool/generated/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ def load_arguments(self, _):
c.argument('disk_pool_name', options_list=['--name', '-n', '--disk-pool-name'], type=str, help='The name of '
'the Disk Pool.', id_part='name')

with self.argument_context('disk-pool list-outbound-network-dependency-endpoint') as c:
c.argument('resource_group_name', resource_group_name_type)
c.argument('disk_pool_name', options_list=['--name', '-n', '--disk-pool-name'], type=str, help='The name of '
'the Disk Pool.')

with self.argument_context('disk-pool list-skus') as c:
c.argument('location', arg_type=get_location_type(self.cli_ctx))

Expand Down
4 changes: 2 additions & 2 deletions src/diskpool/azext_diskpool/generated/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __call__(self, parser, namespace, values, option_string=None):

def get_action(self, values, option_string=None):
try:
value_chunk_list = [values[x:x + 1] for x in range(0, len(values), 1)]
value_chunk_list = [values[x: x + 1] for x in range(0, len(values), 1)]
value_list = []
for chunk in value_chunk_list:
id, = chunk
Expand All @@ -71,7 +71,7 @@ def __call__(self, parser, namespace, values, option_string=None):

def get_action(self, values, option_string=None):
try:
value_chunk_list = [values[x:x + 1] for x in range(0, len(values), 1)]
value_chunk_list = [values[x: x + 1] for x in range(0, len(values), 1)]
value_list = []
for chunk in value_chunk_list:
id, = chunk
Expand Down
2 changes: 2 additions & 0 deletions src/diskpool/azext_diskpool/generated/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def load_command_table(self, _):
g.custom_command('create', 'disk_pool_create', supports_no_wait=True)
g.custom_command('update', 'disk_pool_update', supports_no_wait=True)
g.custom_command('delete', 'disk_pool_delete', supports_no_wait=True, confirmation=True)
g.custom_command('list-outbound-network-dependency-endpoint', 'disk_pool_list_outbound_network_dependency_endpo'
'int')
g.custom_command('list-skus', 'disk_pool_list_skus')
g.custom_command('start', 'disk_pool_start', supports_no_wait=True)
g.custom_command('stop', 'disk_pool_stop', supports_no_wait=True)
Expand Down
7 changes: 7 additions & 0 deletions src/diskpool/azext_diskpool/generated/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ def disk_pool_delete(client,
disk_pool_name=disk_pool_name)


def disk_pool_list_outbound_network_dependency_endpoint(client,
resource_group_name,
disk_pool_name):
return client.list_outbound_network_dependencies_endpoints(resource_group_name=resource_group_name,
disk_pool_name=disk_pool_name)


def disk_pool_list_skus(client,
location):
return client.list(location=location)
Expand Down
52 changes: 51 additions & 1 deletion src/diskpool/azext_diskpool/manual/_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def _value_from_path(each_item, path):
try:
for part in path.split('.'):
obj = obj.get(part, None)
if isinstance(obj, list):
obj = _process_array(obj)
except AttributeError:
obj = None
return obj or ' '
Expand All @@ -35,8 +37,56 @@ def transform_disk_pool_list_output(result):
usable by the CLI and tools such as jpterm. """
return build_table_output(result, [
('Name', 'name'),
('Availability Zones', 'availabilityZones'),
('Resource Group', 'resourceGroup'),
('Status', 'status'),
('Location', 'location'),
('Last Modified', 'systemData.lastModifiedAt')
])


def transform_disk_pool_show_output(result):
from collections import OrderedDict

new_result = OrderedDict()
new_result['Name'] = result.pop('name')
new_result['Resource Group'] = result.pop('resourceGroup')
new_result['Status'] = result.pop('status')
new_result['Location'] = result.pop('location')
new_result['Last Modified'] = result.get('systemData').get('lastModifiedAt', None) \
if result.get('systemData') else None
return new_result


def transform_disk_pool_iscsi_target_list_output(result):
""" Transform to convert SDK output into a form that is more readily
usable by the CLI and tools such as jpterm. """
return build_table_output(result, [
('Name', 'name'),
('Acl Mode', 'aclMode'),
('Endpoints', 'endpoints'),
('Status', 'status'),
('Provisioning State', 'provisioningState'),
('Target Iqn', 'targetIqn')
])


def _process_array(array):
if array:
item = ','.join(array)
else:
item = None
return item


def transform_disk_pool_iscsi_target_show_output(result):
from collections import OrderedDict

new_result = OrderedDict()
new_result['Name'] = result.pop('name')
new_result['Acl Mode'] = result.pop('aclMode')
new_result['Endpoints'] = _process_array(result.pop('endpoints'))

new_result['Status'] = result['status']
new_result['Provisioning State'] = result['provisioningState']
new_result['Target Iqn'] = result['targetIqn']
return new_result
13 changes: 11 additions & 2 deletions src/diskpool/azext_diskpool/manual/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,22 @@

def load_command_table(self, _):

from azext_diskpool.generated._client_factory import cf_disk_pool
from azext_diskpool.generated._client_factory import cf_disk_pool, cf_iscsi_target
from azext_diskpool.manual._client_factory import cf_disk_pool_zone
diskpool_disk_pool = CliCommandType(
operations_tmpl='azext_diskpool.vendored_sdks.storagepool.operations._disk_pools_operations#DiskPoolsOperations'
'.{}',
client_factory=cf_disk_pool)
with self.command_group('disk-pool', diskpool_disk_pool, client_factory=cf_disk_pool, is_preview=True) as g:
from ._transformers import transform_disk_pool_list_output
from ._transformers import transform_disk_pool_list_output, transform_disk_pool_show_output
g.custom_command('list', 'disk_pool_list', table_transformer=transform_disk_pool_list_output)
g.custom_command('list-skus', 'disk_pool_list_skus', client_factory=cf_disk_pool_zone)
g.custom_show_command('show', 'disk_pool_show', table_transformer=transform_disk_pool_show_output)

with self.command_group('disk-pool iscsi-target', client_factory=cf_iscsi_target) as g:
from ._transformers import transform_disk_pool_iscsi_target_list_output, \
transform_disk_pool_iscsi_target_show_output
g.custom_command('list', 'disk_pool_iscsi_target_list',
table_transformer=transform_disk_pool_iscsi_target_list_output)
g.custom_show_command('show', 'disk_pool_iscsi_target_show',
table_transformer=transform_disk_pool_iscsi_target_show_output)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interactions:
ParameterSetName:
- -l
User-Agent:
- AZURECLI/2.24.0 azsdk-python-storagepoolmanagement/unknown Python/3.8.3 (Windows-10-10.0.19041-SP0)
- AZURECLI/2.24.2 azsdk-python-storagepoolmanagement/unknown Python/3.8.3 (Windows-10-10.0.19041-SP0)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.StoragePool/locations/eastus/diskPoolZones?api-version=2021-04-01-preview
response:
Expand All @@ -27,7 +27,7 @@ interactions:
content-type:
- application/json
date:
- Tue, 01 Jun 2021 10:36:03 GMT
- Thu, 10 Jun 2021 09:31:53 GMT
expires:
- '-1'
pragma:
Expand Down
Loading

0 comments on commit bea72c8

Please sign in to comment.