def aks_upgrades_table_format(result): """Format get-upgrades results as a summary for display with "-o table".""" preview = {} def find_preview_versions(versions_bag): for upgrade in versions_bag.get('upgrades', []): if upgrade.get('isPreview', False): preview[upgrade['kubernetesVersion']] = True find_preview_versions(result.get('controlPlaneProfile', {})) find_preview_versions(result.get('agentPoolProfiles', [{}])[0]) # This expression assumes there is one node pool, and that the master and nodes upgrade in lockstep. parsed = compile_jmes("""{ name: name, resourceGroup: resourceGroup, masterVersion: controlPlaneProfile.kubernetesVersion || `unknown`, nodePoolVersion: agentPoolProfiles[0].kubernetesVersion || `unknown` | set_preview(@), upgrades: controlPlaneProfile.upgrades[].kubernetesVersion || [`None available`] | sort_versions(@) | set_preview_array(@) | join(`, `, @) }""") # use ordered dicts so headers are predictable return parsed.search( result, Options(dict_cls=OrderedDict, custom_functions=_custom_functions(preview)))
def aks_versions_table_format(result): """Format get-versions results as a summary for display with "-o table".""" # get preview orchestrator version preview = {} def find_preview_versions(): for orchestrator in result.get('orchestrators', []): if orchestrator.get('isPreview', False): preview[orchestrator['orchestratorVersion']] = True find_preview_versions() parsed = compile_jmes("""orchestrators[].{ kubernetesVersion: orchestratorVersion | set_preview(@), upgrades: upgrades[].orchestratorVersion || [`None available`] | sort_versions(@) | set_preview_array(@) | join(`, `, @) }""") # use ordered dicts so headers are predictable results = parsed.search( result, Options(dict_cls=OrderedDict, custom_functions=_custom_functions(preview))) return sorted(results, key=lambda x: version_to_tuple(x.get('kubernetesVersion')), reverse=True)
def aks_versions_table_format(result): """Format get-versions results as a summary for display with "-o table".""" # pylint: disable=import-error from jmespath import compile as compile_jmes, Options # get preview orchestrator version preview = [] for key, value in result.items(): if key == "orchestrators": for i in value: if i["isPreview"]: preview.append(i["orchestratorVersion"]) parsed = compile_jmes("""orchestrators[].{ kubernetesVersion: orchestratorVersion | set_preview(@), upgrades: upgrades[].orchestratorVersion || [`None available`] | sort_versions(@) | set_preview_array(@) | join(`, `, @) }""") # use ordered dicts so headers are predictable results = parsed.search( result, Options(dict_cls=OrderedDict, custom_functions=_custom_functions(preview))) return sorted(results, key=lambda x: version_to_tuple(x.get('kubernetesVersion')), reverse=True)
def aks_upgrades_table_format(result): """Format get-upgrades results as a summary for display with "-o table".""" # pylint: disable=import-error from jmespath import compile as compile_jmes, Options preview = [] for i, j in result.items(): if i == "controlPlaneProfile": # the reason why we choose "upgrades" obejct, since only it has the isPreview boolean. for item in j["upgrades"]: if item["isPreview"]: preview.append(item["kubernetesVersion"]) # This expression assumes there is one node pool, and that the master and nodes upgrade in lockstep. parsed = compile_jmes("""{ name: name, resourceGroup: resourceGroup, masterVersion: controlPlaneProfile.kubernetesVersion || `unknown` | set_preview(@), nodePoolVersion: agentPoolProfiles[0].kubernetesVersion || `unknown` | set_preview(@), upgrades: controlPlaneProfile.upgrades[].kubernetesVersion || [`None available`] | sort_versions(@) | set_preview_array(@) | join(`, `, @) }""") # use ordered dicts so headers are predictable return parsed.search( result, Options(dict_cls=OrderedDict, custom_functions=_custom_functions(preview)))
def _connectedk8s_list_table_format(result): parsed = compile_jmes("""{ name: name, location: location, resourceGroup: resourceGroup }""") # use ordered dicts so headers are predictable return parsed.search(result, Options(dict_cls=OrderedDict))
def _aro_table_format(result): parsed = compile_jmes("""{ name: name, location: location, resourceGroup: resourceGroup, provisioningState: provisioningState, fqdn: fqdn }""") # use ordered dicts so headers are predictable return parsed.search(result, Options(dict_cls=OrderedDict))
def aks_pod_identity_exceptions_table_format(result): """Format pod identity exceptions results as a summary for display with "-o table".""" preview = {} parsed = compile_jmes("""podIdentityProfile.userAssignedIdentityExceptions[].{ name: name, namespace: namespace, PodLabels: podLabels | pprint_labels(@) }""") # use ordered dicts so headers are predictable return parsed.search(result, Options(dict_cls=OrderedDict, custom_functions=_custom_functions(preview)))
def aks_versions_table_format(result): """Format get-versions results as a summary for display with "-o table".""" from jmespath import compile as compile_jmes, Options parsed = compile_jmes("""orchestrators[].{ kubernetesVersion: orchestratorVersion, upgrades: upgrades[].orchestratorVersion || [`None available`] | sort_versions(@) | join(`, `, @) }""") # use ordered dicts so headers are predictable results = parsed.search(result, Options(dict_cls=OrderedDict, custom_functions=_custom_functions())) return sorted(results, key=lambda x: version_to_tuple(x.get('kubernetesVersion')), reverse=True)
def _osa_table_format(result): parsed = compile_jmes("""{ name: name, location: location, resourceGroup: resourceGroup, openShiftVersion: openShiftVersion, provisioningState: provisioningState, publicHostname: publicHostname }""") # use ordered dicts so headers are predictable return parsed.search(result, Options(dict_cls=OrderedDict))
def aks_pod_identities_table_format(result): """Format pod identities results as a summary for display with "-o table".""" preview = {} parsed = compile_jmes("""podIdentityProfile.userAssignedIdentities[].{ name: name, namespace: namespace, provisioningState: provisioningState identity: identity.resourceId }""") # use ordered dicts so headers are predictable return parsed.search(result, Options(dict_cls=OrderedDict, custom_functions=_custom_functions(preview)))
def _aks_table_format(result): parsed = compile_jmes("""{ name: name, location: location, resourceGroup: resourceGroup, kubernetesVersion: kubernetesVersion, currentKubernetesVersion: currentKubernetesVersion, provisioningState: provisioningState, fqdn: fqdn || privateFqdn }""") # use ordered dicts so headers are predictable return parsed.search(result, Options(dict_cls=OrderedDict))
def parser(entry): config = "" for k, v in entry["config"].items(): config += k + "=" + v + ";" entry["config"] = config parsed = compile_jmes("""{ name: name, api_key: api_key, config: config, identity: identity }""") return parsed.search(entry, Options(dict_cls=OrderedDict))
def _aks_snapshot_table_format(result): parsed = compile_jmes("""{ name: name, location: location, resourceGroup: resourceGroup, nodeImageVersion: nodeImageVersion, kubernetesVersion: kubernetesVersion, osType: osType, enableFIPS: enableFIPS }""") # use ordered dicts so headers are predictable return parsed.search(result, Options(dict_cls=OrderedDict))
def _aks_agentpool_table_format(result): parsed = compile_jmes("""{ name: name, osType: osType, kubernetesVersion: kubernetesVersion, vmSize: vmSize, osDiskSizeGB: osDiskSizeGB, count: count, maxPods: maxPods, provisioningState: provisioningState }""") # use ordered dicts so headers are predictable return parsed.search(result, Options(dict_cls=OrderedDict))
def _osa_table_format(result): from jmespath import compile as compile_jmes, Options parsed = compile_jmes("""{ name: name, location: location, resourceGroup: resourceGroup, openShiftVersion: openShiftVersion, provisioningState: provisioningState, fqdn: fqdn }""") # use ordered dicts so headers are predictable return parsed.search(result, Options(dict_cls=OrderedDict))
def aks_upgrades_table_format(result): """Format get-upgrades results as a summary for display with "-o table".""" from jmespath import compile as compile_jmes, Options # This expression assumes there is one node pool, and that the master and nodes upgrade in lockstep. parsed = compile_jmes("""{ name: name, resourceGroup: resourceGroup, masterVersion: controlPlaneProfile.kubernetesVersion || `unknown`, nodePoolVersion: agentPoolProfiles[0].kubernetesVersion || `unknown`, upgrades: controlPlaneProfile.upgrades || [`None available`] | sort_versions(@) | join(`, `, @) }""") # use ordered dicts so headers are predictable return parsed.search(result, Options(dict_cls=OrderedDict, custom_functions=_custom_functions()))
def _aks_table_format(result): # pylint: disable=import-error from jmespath import compile as compile_jmes, Options parsed = compile_jmes("""{ name: name, location: location, resourceGroup: resourceGroup, kubernetesVersion: kubernetesVersion, provisioningState: provisioningState, fqdn: fqdn }""") # use ordered dicts so headers are predictable return parsed.search(result, Options(dict_cls=OrderedDict))
def _aks_snapshot_table_format(result): parsed = compile_jmes("""{ name: name, location: location, resourceGroup: resourceGroup, sku: managedClusterPropertiesReadOnly.sku.tier, enableRbac: managedClusterPropertiesReadOnly.enableRbac, kubernetesVersion: managedClusterPropertiesReadOnly.kubernetesVersion, networkPlugin: managedClusterPropertiesReadOnly.networkProfile.networkPlugin, networkPolicy: managedClusterPropertiesReadOnly.networkProfile.networkPolicy, networkMode: managedClusterPropertiesReadOnly.networkProfile.networkMode, loadBalancerSku: managedClusterPropertiesReadOnly.networkProfile.loadBalancerSku }""") # use ordered dicts so headers are predictable return parsed.search(result, Options(dict_cls=OrderedDict))
def _amc_node_status_table_format(result): result['tokensDisplay'] = 'N/A' if result['tokens'] is not None and result['tokens']: result['tokensDisplay'] = result['tokens'][0] + ",..." parsed = compile_jmes("""{ Datacenter:datacenter, Status:status, State:state, Address:address, Rack:rack, Tokens:tokensDisplay, HostId: hostId, Load:load, Owns:owns }""") # use ordered dicts so headers are predictable return parsed.search(result, Options(dict_cls=OrderedDict))
def format_table(obj): result = obj.result try: if obj.table_transformer and not obj.is_query_active: if isinstance(obj.table_transformer, str): from jmespath import compile as compile_jmes, Options result = compile_jmes(obj.table_transformer).search(result, Options(OrderedDict)) else: result = obj.table_transformer(result) result_list = result if isinstance(result, list) else [result] should_sort_keys = not obj.is_query_active and not obj.table_transformer to = TableOutput(should_sort_keys) return to.dump(result_list) except: logger.debug(traceback.format_exc()) raise CLIError("Table output unavailable. " "Use the --query option to specify an appropriate query. " "Use --debug for more info.")
def format_table(obj): result = obj.result try: if obj.table_transformer and not obj.is_query_active: if isinstance(obj.table_transformer, str): from jmespath import compile as compile_jmes, Options result = compile_jmes(obj.table_transformer).search(result, Options(OrderedDict)) else: result = obj.table_transformer(result) result_list = result if isinstance(result, list) else [result] should_sort_keys = not obj.is_query_active and not obj.table_transformer to = _TableOutput(should_sort_keys) return to.dump(result_list) except: logger.debug(traceback.format_exc()) raise CLIError("Table output unavailable. " "Use the --query option to specify an appropriate query. " "Use --debug for more info.")
def aks_versions_table_format(result): """Format get-versions results as a summary for display with "-o table".""" # pylint: disable=import-error from jmespath import compile as compile_jmes, Options # get preview orchestrator version preview = [] for key, value in result.items(): if key == "orchestrators": for i in value: if i["isPreview"]: preview.append(i["orchestratorVersion"]) parsed = compile_jmes("""orchestrators[].{ kubernetesVersion: orchestratorVersion | set_preview(@), upgrades: upgrades[].orchestratorVersion || [`None available`] | sort_versions(@) | set_preview_array(@) | join(`, `, @) }""") # use ordered dicts so headers are predictable results = parsed.search(result, Options(dict_cls=OrderedDict, custom_functions=_custom_functions(preview))) return sorted(results, key=lambda x: version_to_tuple(x.get('kubernetesVersion')), reverse=True)
def aks_upgrades_table_format(result): """Format get-upgrades results as a summary for display with "-o table".""" # pylint: disable=import-error from jmespath import compile as compile_jmes, Options preview = [] for i, j in result.items(): if i == "controlPlaneProfile": # the reason why we choose "upgrades" obejct, since only it has the isPreview boolean. for item in j["upgrades"]: if item["isPreview"]: preview.append(item["kubernetesVersion"]) # This expression assumes there is one node pool, and that the master and nodes upgrade in lockstep. parsed = compile_jmes("""{ name: name, resourceGroup: resourceGroup, masterVersion: controlPlaneProfile.kubernetesVersion || `unknown` | set_preview(@), nodePoolVersion: agentPoolProfiles[0].kubernetesVersion || `unknown` | set_preview(@), upgrades: controlPlaneProfile.upgrades[].kubernetesVersion || [`None available`] | sort_versions(@) | set_preview_array(@) | join(`, `, @) }""") # use ordered dicts so headers are predictable return parsed.search(result, Options(dict_cls=OrderedDict, custom_functions=_custom_functions(preview)))
def parser(entry): parsed = compile_jmes("""{ name: name, enabled: enabled }""") return parsed.search(entry, Options(dict_cls=OrderedDict))
def parser(entry): parsed = compile_jmes("""{ name: name, description: description }""") return parsed.search(entry, Options(dict_cls=OrderedDict))