зеркало из https://github.com/Azure/ARO-RP.git
Added AZ command to list install version by location with optional table formatter
This commit is contained in:
Родитель
e5453d7718
Коммит
226e60c8cc
|
@ -32,3 +32,4 @@ gomock_reflect_*
|
|||
.idea*
|
||||
/hack/hive-config/crds
|
||||
/hack/hive-config/hive-deployment.yaml
|
||||
cmd/aro/__debug_bin
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
import urllib3
|
||||
|
||||
from azext_aro.custom import rp_mode_development
|
||||
from azext_aro.vendored_sdks.azure.mgmt.redhatopenshift.v2022_04_01 import AzureRedHatOpenShiftClient
|
||||
from azext_aro.vendored_sdks.azure.mgmt.redhatopenshift.v2022_09_04 import AzureRedHatOpenShiftClient
|
||||
from azure.cli.core.commands.client_factory import get_mgmt_service_client
|
||||
|
||||
|
||||
|
@ -21,6 +21,6 @@ def cf_aro(cli_ctx, *_):
|
|||
|
||||
client = get_mgmt_service_client(cli_ctx,
|
||||
AzureRedHatOpenShiftClient,
|
||||
**opt_args).open_shift_clusters
|
||||
**opt_args)
|
||||
|
||||
return client
|
||||
|
|
|
@ -23,3 +23,11 @@ def aro_show_table_format(result):
|
|||
WorkerCount=sum(wp['count'] or 0 for wp in worker_profiles),
|
||||
URL=result['consoleProfile']['url'],
|
||||
)
|
||||
|
||||
def aro_version_table_format(result):
|
||||
return [aro_build_version_table(r) for r in result]
|
||||
|
||||
def aro_build_version_table(result):
|
||||
return collections.OrderedDict(
|
||||
Version=result
|
||||
)
|
|
@ -5,12 +5,13 @@ from azure.cli.core.commands import CliCommandType
|
|||
from azext_aro._client_factory import cf_aro
|
||||
from azext_aro._format import aro_show_table_format
|
||||
from azext_aro._format import aro_list_table_format
|
||||
from azext_aro._format import aro_version_table_format
|
||||
from azext_aro._help import helps # pylint: disable=unused-import
|
||||
|
||||
|
||||
def load_command_table(self, _):
|
||||
aro_sdk = CliCommandType(
|
||||
operations_tmpl='azext_aro.vendored_sdks.azure.mgmt.redhatopenshift.v2022_04_01.operations#OpenShiftClustersOperations.{}', # pylint: disable=line-too-long
|
||||
operations_tmpl='azext_aro.vendored_sdks.azure.mgmt.redhatopenshift.v2022_09_04.operations#OpenShiftClustersOperations.{}', # pylint: disable=line-too-long
|
||||
client_factory=cf_aro)
|
||||
|
||||
with self.command_group('aro', aro_sdk, client_factory=cf_aro) as g:
|
||||
|
@ -23,3 +24,5 @@ def load_command_table(self, _):
|
|||
|
||||
g.custom_command('list-credentials', 'aro_list_credentials')
|
||||
g.custom_command('get-admin-kubeconfig', 'aro_list_admin_credentials')
|
||||
|
||||
g.custom_command('list-install-versions', 'aro_list_install_versions', table_transformer=aro_version_table_format)
|
|
@ -5,7 +5,7 @@ import random
|
|||
import os
|
||||
from base64 import b64decode
|
||||
|
||||
import azext_aro.vendored_sdks.azure.mgmt.redhatopenshift.v2022_04_01.models as openshiftcluster
|
||||
import azext_aro.vendored_sdks.azure.mgmt.redhatopenshift.v2022_09_04.models as openshiftcluster
|
||||
|
||||
from azure.cli.command_modules.role import GraphError
|
||||
from azure.cli.core.commands.client_factory import get_mgmt_service_client
|
||||
|
@ -146,7 +146,7 @@ def aro_create(cmd, # pylint: disable=too-many-locals
|
|||
sp_obj_ids = [client_sp_id, rp_client_sp_id]
|
||||
ensure_resource_permissions(cmd.cli_ctx, oc, True, sp_obj_ids)
|
||||
|
||||
return sdk_no_wait(no_wait, client.begin_create_or_update,
|
||||
return sdk_no_wait(no_wait, client.open_shift_clusters.begin_create_or_update,
|
||||
resource_group_name=resource_group_name,
|
||||
resource_name=resource_name,
|
||||
parameters=oc)
|
||||
|
@ -157,7 +157,7 @@ def aro_delete(cmd, client, resource_group_name, resource_name, no_wait=False):
|
|||
rp_client_sp_id = None
|
||||
|
||||
try:
|
||||
oc = client.get(resource_group_name, resource_name)
|
||||
oc = client.open_shift_clusters.get(resource_group_name, resource_name)
|
||||
except CloudError as e:
|
||||
if e.status_code == 404:
|
||||
raise ResourceNotFoundError(e.message) from e
|
||||
|
@ -180,23 +180,23 @@ def aro_delete(cmd, client, resource_group_name, resource_name, no_wait=False):
|
|||
if rp_client_sp_id:
|
||||
ensure_resource_permissions(cmd.cli_ctx, oc, False, [rp_client_sp_id])
|
||||
|
||||
return sdk_no_wait(no_wait, client.begin_delete,
|
||||
return sdk_no_wait(no_wait, client.open_shift_clusters.begin_delete,
|
||||
resource_group_name=resource_group_name,
|
||||
resource_name=resource_name)
|
||||
|
||||
|
||||
def aro_list(client, resource_group_name=None):
|
||||
if resource_group_name:
|
||||
return client.list_by_resource_group(resource_group_name)
|
||||
return client.list()
|
||||
return client.open_shift_clusters.list_by_resource_group(resource_group_name)
|
||||
return client.open_shift_clusters.list()
|
||||
|
||||
|
||||
def aro_show(client, resource_group_name, resource_name):
|
||||
return client.get(resource_group_name, resource_name)
|
||||
return client.open_shift_clusters.get(resource_group_name, resource_name)
|
||||
|
||||
|
||||
def aro_list_credentials(client, resource_group_name, resource_name):
|
||||
return client.list_credentials(resource_group_name, resource_name)
|
||||
return client.open_shift_clusters.list_credentials(resource_group_name, resource_name)
|
||||
|
||||
|
||||
def aro_list_admin_credentials(cmd, client, resource_group_name, resource_name, file="kubeconfig"):
|
||||
|
@ -210,7 +210,7 @@ def aro_list_admin_credentials(cmd, client, resource_group_name, resource_name,
|
|||
if feature.properties.state not in accepted_states:
|
||||
logger.warning("This operation requires the Microsoft.RedHatOpenShift/AdminKubeconfig feature to be registered")
|
||||
logger.warning("To register run: az feature register --namespace Microsoft.RedHatOpenShift -n AdminKubeconfig")
|
||||
query_result = client.list_admin_credentials(resource_group_name, resource_name)
|
||||
query_result = client.open_shift_clusters.list_admin_credentials(resource_group_name, resource_name)
|
||||
file_mode = "x"
|
||||
yaml_data = b64decode(query_result.kubeconfig).decode('UTF-8')
|
||||
try:
|
||||
|
@ -221,6 +221,10 @@ def aro_list_admin_credentials(cmd, client, resource_group_name, resource_name,
|
|||
logger.info("Kubeconfig written to file: %s", file)
|
||||
|
||||
|
||||
def aro_list_install_versions(client, location):
|
||||
return client.list.install_versions(location)
|
||||
|
||||
|
||||
def aro_update(cmd,
|
||||
client,
|
||||
resource_group_name,
|
||||
|
@ -230,7 +234,7 @@ def aro_update(cmd,
|
|||
client_secret=None,
|
||||
no_wait=False):
|
||||
# if we can't read cluster spec, we will not be able to do much. Fail.
|
||||
oc = client.get(resource_group_name, resource_name)
|
||||
oc = client.open_shift_clusters.get(resource_group_name, resource_name)
|
||||
|
||||
ocUpdate = openshiftcluster.OpenShiftClusterUpdate()
|
||||
|
||||
|
@ -246,7 +250,7 @@ def aro_update(cmd,
|
|||
if client_id is not None:
|
||||
ocUpdate.service_principal_profile.client_id = client_id
|
||||
|
||||
return sdk_no_wait(no_wait, client.begin_update,
|
||||
return sdk_no_wait(no_wait, client.open_shift_clusters.begin_update,
|
||||
resource_group_name=resource_group_name,
|
||||
resource_name=resource_name,
|
||||
parameters=ocUpdate)
|
||||
|
|
Загрузка…
Ссылка в новой задаче