diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 66f026834e8..435dbbae79f 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -124,9 +124,11 @@ /src/ssh/ @rlrossiter @danybeam @arrownj -/src/k8sconfiguration/ @NarayanThiru +/src/k8sconfiguration/ @NarayanThiru @jonathan-innis -/src/k8s-configuration/ @NarayanThiru +/src/k8s-configuration/ @NarayanThiru @jonathan-innis + +/src/k8s-extension/ @NarayanThiru @jonathan-innis /src/log-analytics-solution/ @zhoxing-ms diff --git a/src/k8s-extension/HISTORY.rst b/src/k8s-extension/HISTORY.rst new file mode 100644 index 00000000000..54c1e375f6f --- /dev/null +++ b/src/k8s-extension/HISTORY.rst @@ -0,0 +1,35 @@ +.. :changelog: + +Release History +=============== + +0.2.0 +++++++++++++++++++ + +* Refactor for clear separation of extension-type specific customizations +* OpenServiceMesh customization. +* Fix clusterType of Microsoft.ResourceConnector resource +* Update clusterType validation to allow 'appliances' +* Update identity creation to use the appropriate parent resource's type and api-version +* Throw error if cluster type is not one of the 3 supported types +* Rename azuremonitor-containers extension type to microsoft.azuremonitor.containers +* Move CLI errors to non-deprecated error types +* Remove support for update + +0.1.3 +++++++++++++++++++ + +* Customization for microsoft.openservicemesh + +0.1.2 +++++++++++++++++++ + +* Add support for Arc Appliance cluster type + +0.1.1 +++++++++++++++++++ +* Add support for microsoft-azure-defender extension type + +0.1.0 +++++++++++++++++++ +* Initial release. diff --git a/src/k8s-extension/README.rst b/src/k8s-extension/README.rst new file mode 100644 index 00000000000..5d4694e14cb --- /dev/null +++ b/src/k8s-extension/README.rst @@ -0,0 +1,59 @@ +Microsoft Azure CLI 'k8s-extension' Extension +============================================= + +This package is for the 'k8s-extension' extension. +i.e. 'az k8s-extension' + +### How to use ### +Install this extension using the below CLI command +``` +az extension add --name k8s-extension +``` + +### Included Features +#### Kubernetes Extensions: +Kubernetes Extensions: [more info](https://docs.microsoft.com/en-us/azure/kubernetessconfiguration/)\ +*Examples:* + +##### Create a KubernetesExtension +``` +az k8s-extension create \ + --resource-group groupName \ + --cluster-name clusterName \ + --cluster-type clusterType \ + --name extensionName \ + --extension-type extensionType \ + --scope scopeType \ + --release-train releaseTrain \ + --version versionNumber \ + --auto-upgrade-minor-version autoUpgrade \ + --configuration-settings exampleSetting=exampleValue \ +``` + +##### Get a KubernetesExtension +``` +az k8s-extension show \ + --resource-group groupName \ + --cluster-name clusterName \ + --cluster-type clusterType \ + --name extensionName +``` + +##### Delete a KubernetesExtension +``` +az k8s-extension delete \ + --resource-group groupName \ + --cluster-name clusterName \ + --cluster-type clusterType \ + --name extensionName +``` + +##### List all KubernetesExtension of a cluster +``` +az k8s-extension list \ + --resource-group groupName \ + --cluster-name clusterName \ + --cluster-type clusterType +``` + +If you have issues, please give feedback by opening an issue at https://github.com/Azure/azure-cli-extensions/issues. \ No newline at end of file diff --git a/src/k8s-extension/azext_k8s_extension/__init__.py b/src/k8s-extension/azext_k8s_extension/__init__.py new file mode 100644 index 00000000000..e2301227d45 --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/__init__.py @@ -0,0 +1,32 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +from azure.cli.core import AzCommandsLoader + +from azext_k8s_extension._help import helps # pylint: disable=unused-import + + +class K8sExtensionCommandsLoader(AzCommandsLoader): + + def __init__(self, cli_ctx=None): + from azure.cli.core.commands import CliCommandType + from azext_k8s_extension._client_factory import cf_k8s_extension + k8s_extension_custom = CliCommandType( + operations_tmpl='azext_k8s_extension.custom#{}', + client_factory=cf_k8s_extension) + super(K8sExtensionCommandsLoader, self).__init__(cli_ctx=cli_ctx, + custom_command_type=k8s_extension_custom) + + def load_command_table(self, args): + from azext_k8s_extension.commands import load_command_table + load_command_table(self, args) + return self.command_table + + def load_arguments(self, command): + from azext_k8s_extension._params import load_arguments + load_arguments(self, command) + + +COMMAND_LOADER_CLS = K8sExtensionCommandsLoader diff --git a/src/k8s-extension/azext_k8s_extension/_client_factory.py b/src/k8s-extension/azext_k8s_extension/_client_factory.py new file mode 100644 index 00000000000..1a9a10c2615 --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/_client_factory.py @@ -0,0 +1,31 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +from azure.cli.core.commands.client_factory import get_mgmt_service_client +from azure.cli.core.profiles import ResourceType + + +def cf_k8s_extension(cli_ctx, *_): + from azext_k8s_extension.vendored_sdks import SourceControlConfigurationClient + return get_mgmt_service_client(cli_ctx, SourceControlConfigurationClient) + + +def cf_k8s_extension_operation(cli_ctx, _): + return cf_k8s_extension(cli_ctx).extensions + + +def cf_resource_groups(cli_ctx, subscription_id=None): + return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES, + subscription_id=subscription_id).resource_groups + + +def cf_resources(cli_ctx, subscription_id=None): + return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES, + subscription_id=subscription_id).resources + + +def cf_log_analytics(cli_ctx, subscription_id=None): + from azure.mgmt.loganalytics import LogAnalyticsManagementClient # pylint: disable=no-name-in-module + return get_mgmt_service_client(cli_ctx, LogAnalyticsManagementClient, subscription_id=subscription_id) diff --git a/src/k8s-extension/azext_k8s_extension/_consts.py b/src/k8s-extension/azext_k8s_extension/_consts.py new file mode 100644 index 00000000000..d0fdaf7775f --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/_consts.py @@ -0,0 +1,8 @@ +# coding=utf-8 +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +EXTENSION_NAME = 'k8s-extension' +VERSION = "0.2.0" diff --git a/src/k8s-extension/azext_k8s_extension/_format.py b/src/k8s-extension/azext_k8s_extension/_format.py new file mode 100644 index 00000000000..ef96f7cf88f --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/_format.py @@ -0,0 +1,24 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +from collections import OrderedDict + + +def k8s_extension_list_table_format(results): + return [__get_table_row(result) for result in results] + + +def k8s_extension_show_table_format(result): + return __get_table_row(result) + + +def __get_table_row(result): + return OrderedDict([ + ('name', result['name']), + ('extensionType', result['extensionType']), + ('version', result['version']), + ('installState', result['installState']), + ('lastModifiedTime', result['lastModifiedTime']) + ]) diff --git a/src/k8s-extension/azext_k8s_extension/_help.py b/src/k8s-extension/azext_k8s_extension/_help.py new file mode 100644 index 00000000000..64e4be612ea --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/_help.py @@ -0,0 +1,39 @@ +# coding=utf-8 +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +from knack.help_files import helps # pylint: disable=unused-import +import azext_k8s_extension._consts as consts + + +helps[f'{consts.EXTENSION_NAME}'] = """ + type: group + short-summary: Commands to manage K8s-extensions. +""" + +helps[f'{consts.EXTENSION_NAME} create'] = """ + type: command + short-summary: Create a K8s-extension. +""" + +helps[f'{consts.EXTENSION_NAME} list'] = """ + type: command + short-summary: List K8s-extensions. +""" + +helps[f'{consts.EXTENSION_NAME} delete'] = """ + type: command + short-summary: Delete a K8s-extension. +""" + +helps[f'{consts.EXTENSION_NAME} show'] = """ + type: command + short-summary: Show details of a K8s-extension. +""" + +helps[f'{consts.EXTENSION_NAME} update'] = """ + type: command + short-summary: Update a K8s-extension. +""" diff --git a/src/k8s-extension/azext_k8s_extension/_params.py b/src/k8s-extension/azext_k8s_extension/_params.py new file mode 100644 index 00000000000..3bbc6056a2e --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/_params.py @@ -0,0 +1,75 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +from azure.cli.core.commands.parameters import ( + get_enum_type, + get_three_state_flag, + tags_type +) +from azure.cli.core.commands.validators import get_default_location_from_resource_group +import azext_k8s_extension._consts as consts + +from azext_k8s_extension.action import ( + AddConfigurationSettings, + AddConfigurationProtectedSettings +) + + +def load_arguments(self, _): + with self.argument_context(consts.EXTENSION_NAME) as c: + c.argument('tags', tags_type) + c.argument('location', + validator=get_default_location_from_resource_group) + c.argument('name', + options_list=['--name', '-n'], + help='Name of the extension instance') + c.argument('extension_type', + help='Name of the extension type.') + c.argument('cluster_name', + options_list=['--cluster-name', '-c'], + help='Name of the Kubernetes cluster') + c.argument('cluster_type', + arg_type=get_enum_type(['connectedClusters', 'managedClusters', 'appliances']), + help='Specify Arc clusters or AKS managed clusters or Arc appliances.') + c.argument('scope', + arg_type=get_enum_type(['cluster', 'namespace']), + help='Specify the extension scope.') + c.argument('auto_upgrade_minor_version', + arg_group="Version", + options_list=['--auto-upgrade-minor-version', '--auto-upgrade'], + arg_type=get_three_state_flag(), + help='Automatically upgrade minor version of the extension instance.') + c.argument('version', + arg_group="Version", + help='Specify the version to install for the extension instance if' + ' --auto-upgrade-minor-version is not enabled.') + c.argument('release_train', + arg_group="Version", + help='Specify the release train for the extension type.') + c.argument('configuration_settings', + arg_group="Configuration", + options_list=['--configuration-settings', '--config'], + action=AddConfigurationSettings, + nargs='+', + help='Configuration Settings as key=value pair. Repeat parameter for each setting') + c.argument('configuration_protected_settings', + arg_group="Configuration", + options_list=['--configuration-protected-settings', '--config-protected'], + action=AddConfigurationProtectedSettings, + nargs='+', + help='Configuration Protected Settings as key=value pair. Repeat parameter for each setting') + c.argument('configuration_settings_file', + arg_group="Configuration", + options_list=['--configuration-settings-file', '--config-file'], + help='JSON file path for configuration-settings') + c.argument('configuration_protected_settings_file', + arg_group="Configuration", + options_list=['--configuration-protected-settings-file', '--config-protected-file'], + help='JSON file path for configuration-protected-settings') + c.argument('release_namespace', + help='Specify the namespace to install the extension release.') + c.argument('target_namespace', + help='Specify the target namespace to install to for the extension instance. This' + ' parameter is required if extension scope is set to \'namespace\'') diff --git a/src/k8s-extension/azext_k8s_extension/action.py b/src/k8s-extension/azext_k8s_extension/action.py new file mode 100644 index 00000000000..4afbbbcd611 --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/action.py @@ -0,0 +1,37 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +import argparse +from azure.cli.core.azclierror import ArgumentUsageError + + +# pylint: disable=protected-access, too-few-public-methods +class AddConfigurationSettings(argparse._AppendAction): + + def __call__(self, parser, namespace, values, option_string=None): + settings = {} + for item in values: + try: + key, value = item.split('=', 1) + settings[key] = value + except ValueError: + raise ArgumentUsageError('Usage error: {} configuration_setting_key=configuration_setting_value'. + format(option_string)) + super(AddConfigurationSettings, self).__call__(parser, namespace, settings, option_string) + + +# pylint: disable=protected-access, too-few-public-methods +class AddConfigurationProtectedSettings(argparse._AppendAction): + + def __call__(self, parser, namespace, values, option_string=None): + prot_settings = {} + for item in values: + try: + key, value = item.split('=', 1) + prot_settings[key] = value + except ValueError: + raise ArgumentUsageError('Usage error: {} configuration_protected_setting_key=' + 'configuration_protected_setting_value'.format(option_string)) + super(AddConfigurationProtectedSettings, self).__call__(parser, namespace, prot_settings, option_string) diff --git a/src/k8s-extension/azext_k8s_extension/azext_metadata.json b/src/k8s-extension/azext_k8s_extension/azext_metadata.json new file mode 100644 index 00000000000..cf7b8927a07 --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/azext_metadata.json @@ -0,0 +1,4 @@ +{ + "azext.isPreview": true, + "azext.minCliCoreVersion": "2.15.0" +} diff --git a/src/k8s-extension/azext_k8s_extension/commands.py b/src/k8s-extension/azext_k8s_extension/commands.py new file mode 100644 index 00000000000..931662814c0 --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/commands.py @@ -0,0 +1,26 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +# pylint: disable=line-too-long +from azure.cli.core.commands import CliCommandType +from azext_k8s_extension._client_factory import (cf_k8s_extension, cf_k8s_extension_operation) +from azext_k8s_extension._format import k8s_extension_list_table_format, k8s_extension_show_table_format +import azext_k8s_extension._consts as consts + + +def load_command_table(self, _): + + k8s_extension_sdk = CliCommandType( + operations_tmpl='azext_k8s_extension.vendored_sdks.operations#K8sExtensionsOperations.{}', + client_factory=cf_k8s_extension) + + with self.command_group(consts.EXTENSION_NAME, k8s_extension_sdk, client_factory=cf_k8s_extension_operation, + is_preview=True) \ + as g: + g.custom_command('create', 'create_k8s_extension') + g.custom_command('update', 'update_k8s_extension') + g.custom_command('delete', 'delete_k8s_extension', confirmation=True) + g.custom_command('list', 'list_k8s_extension', table_transformer=k8s_extension_list_table_format) + g.custom_show_command('show', 'show_k8s_extension', table_transformer=k8s_extension_show_table_format) diff --git a/src/k8s-extension/azext_k8s_extension/custom.py b/src/k8s-extension/azext_k8s_extension/custom.py new file mode 100644 index 00000000000..ba9dbfce501 --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/custom.py @@ -0,0 +1,279 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +# pylint: disable=unused-argument,too-many-locals + +import json +from knack.log import get_logger + +from msrestazure.azure_exceptions import CloudError + +from azure.cli.core.azclierror import ResourceNotFoundError, MutuallyExclusiveArgumentError, \ + InvalidArgumentValueError, CommandNotFoundError, RequiredArgumentMissingError +from azure.cli.core.commands.client_factory import get_subscription_id +from azext_k8s_extension.vendored_sdks.models import ConfigurationIdentity +from azext_k8s_extension.vendored_sdks.models import ErrorResponseException +from azext_k8s_extension.vendored_sdks.models import Scope + +from azext_k8s_extension.partner_extensions.ContainerInsights import ContainerInsights +from azext_k8s_extension.partner_extensions.AzureDefender import AzureDefender +from azext_k8s_extension.partner_extensions.Cassandra import Cassandra +from azext_k8s_extension.partner_extensions.DefaultExtension import DefaultExtension +import azext_k8s_extension._consts as consts + +from ._client_factory import cf_resources + +logger = get_logger(__name__) + + +# A factory method to return the correct extension class based off of the extension name +def ExtensionFactory(extension_name): + extension_map = { + 'microsoft.azuremonitor.containers': ContainerInsights, + 'microsoft.azuredefender.kubernetes': AzureDefender, + 'cassandradatacentersoperator': Cassandra + } + + # Return the extension if we find it in the map, else return the default + return extension_map.get(extension_name, DefaultExtension)() + + +def show_k8s_extension(client, resource_group_name, cluster_name, name, cluster_type): + """Get an existing K8s Extension. + + """ + # Determine ClusterRP + cluster_rp = __get_cluster_rp(cluster_type) + + try: + extension = client.get(resource_group_name, + cluster_rp, cluster_type, cluster_name, name) + return extension + except ErrorResponseException as ex: + # Customize the error message for resources not found + if ex.response.status_code == 404: + # If Cluster not found + if ex.message.__contains__("(ResourceNotFound)"): + message = "{0} Verify that the cluster-type is correct and the resource exists.".format( + ex.message) + # If Configuration not found + elif ex.message.__contains__("Operation returned an invalid status code 'Not Found'"): + message = "(ExtensionNotFound) The Resource {0}/{1}/{2}/Microsoft.KubernetesConfiguration/" \ + "extensions/{3} could not be found!".format( + cluster_rp, cluster_type, cluster_name, name) + else: + message = ex.message + raise ResourceNotFoundError(message) + + +def create_k8s_extension(cmd, client, resource_group_name, cluster_name, name, cluster_type, + extension_type, scope=None, auto_upgrade_minor_version=None, release_train=None, + version=None, target_namespace=None, release_namespace=None, configuration_settings=None, + configuration_protected_settings=None, configuration_settings_file=None, + configuration_protected_settings_file=None, tags=None): + """Create a new Extension Instance. + + """ + extension_type_lower = extension_type.lower() + + # Determine ClusterRP + cluster_rp = __get_cluster_rp(cluster_type) + + # Configuration Settings & Configuration Protected Settings + if configuration_settings is not None and configuration_settings_file is not None: + raise MutuallyExclusiveArgumentError( + 'Error! Both configuration-settings and configuration-settings-file cannot be provided.' + ) + + if configuration_protected_settings is not None and configuration_protected_settings_file is not None: + raise MutuallyExclusiveArgumentError( + 'Error! Both configuration-protected-settings and configuration-protected-settings-file ' + 'cannot be provided.' + ) + + config_settings = {} + config_protected_settings = {} + # Get Configuration Settings from file + if configuration_settings_file is not None: + config_settings = __get_config_settings_from_file(configuration_settings_file) + + if configuration_settings is not None: + for dicts in configuration_settings: + for key, value in dicts.items(): + config_settings[key] = value + + # Get Configuration Protected Settings from file + if configuration_protected_settings_file is not None: + config_protected_settings = __get_config_settings_from_file(configuration_protected_settings_file) + + if configuration_protected_settings is not None: + for dicts in configuration_protected_settings: + for key, value in dicts.items(): + config_protected_settings[key] = value + + # Identity is not created by default. Extension type must specify if identity is required. + create_identity = False + extension_instance = None + + # Scope & Namespace validation - common to all extension-types + __validate_scope_and_namespace(scope, release_namespace, target_namespace) + + # Give Partners a chance to their extensionType specific validations and to set value over-rides. + + # Get the extension class based on the extension name + extension_class = ExtensionFactory(extension_type_lower) + extension_instance, name, create_identity = extension_class.Create( + cmd, client, resource_group_name, cluster_name, name, cluster_type, extension_type_lower, scope, + auto_upgrade_minor_version, release_train, version, target_namespace, release_namespace, config_settings, + config_protected_settings, configuration_settings_file, configuration_protected_settings_file) + + # Common validations + __validate_version_and_auto_upgrade(extension_instance.version, extension_instance.auto_upgrade_minor_version) + __validate_scope_after_customization(extension_instance.scope) + + # Create identity, if required + if create_identity: + extension_instance.identity, extension_instance.location = \ + __create_identity(cmd, resource_group_name, cluster_name, cluster_type, cluster_rp) + + # Try to create the resource + return client.create(resource_group_name, cluster_rp, cluster_type, cluster_name, name, extension_instance) + + +def list_k8s_extension(client, resource_group_name, cluster_name, cluster_type): + cluster_rp = __get_cluster_rp(cluster_type) + return client.list(resource_group_name, cluster_rp, cluster_type, cluster_name) + + +def update_k8s_extension(client, resource_group_name, cluster_type, cluster_name, name, + auto_upgrade_minor_version='', release_train='', version='', tags=None): + + """Patch an existing Extension Instance. + + """ + + # TODO: Remove this after we eventually get PATCH implemented for update and uncomment + raise CommandNotFoundError( + f"\"{consts.EXTENSION_NAME} update\" currently is not available. " + f"Use \"{consts.EXTENSION_NAME} create\" to update a previously created extension instance." + ) + + # # Ensure some values are provided for update + # if auto_upgrade_minor_version is None and release_train is None and version is None: + # message = "Error! No values provided for update. Provide new value(s) for one or more of these properties:" \ + # " auto-upgrade-minor-version, release-train or version." + # raise RequiredArgumentMissingError(message) + + # # Determine ClusterRP + # cluster_rp = __get_cluster_rp(cluster_type) + + # # Get the existing extensionInstance + # extension = client.get(resource_group_name, cluster_rp, cluster_type, cluster_name, name) + + # extension_type_lower = extension.extension_type.lower() + + # # Get the extension class based on the extension name + # extension_class = ExtensionFactory(extension_type_lower) + # upd_extension = extension_class.Update(extension, auto_upgrade_minor_version, release_train, version) + + # __validate_version_and_auto_upgrade(version, auto_upgrade_minor_version) + + # upd_extension = ExtensionInstanceUpdate(auto_upgrade_minor_version=auto_upgrade_minor_version, + # release_train=release_train, version=version) + + # return client.update(resource_group_name, cluster_rp, cluster_type, cluster_name, name, upd_extension) + + +def delete_k8s_extension(client, resource_group_name, cluster_name, name, cluster_type): + """Delete an existing Kubernetes Extension. + + """ + # Determine ClusterRP + cluster_rp = __get_cluster_rp(cluster_type) + return client.delete(resource_group_name, cluster_rp, cluster_type, cluster_name, name) + + +def __create_identity(cmd, resource_group_name, cluster_name, cluster_type, cluster_rp): + subscription_id = get_subscription_id(cmd.cli_ctx) + resources = cf_resources(cmd.cli_ctx, subscription_id) + + cluster_resource_id = '/subscriptions/{0}/resourceGroups/{1}/providers/{2}/{3}/{4}'.format(subscription_id, + resource_group_name, + cluster_rp, + cluster_type, + cluster_name) + + if cluster_rp == 'Microsoft.Kubernetes': + parent_api_version = '2020-01-01-preview' + elif cluster_rp == 'Microsoft.ResourceConnector': + parent_api_version = '2020-09-15-privatepreview' + elif cluster_rp == 'Microsoft.ContainerService': + parent_api_version = '2017-07-01' + else: + raise InvalidArgumentValueError( + "Error! Cluster type '{}' is not supported for extension identity".format(cluster_type) + ) + + try: + resource = resources.get_by_id(cluster_resource_id, parent_api_version) + location = str(resource.location.lower()) + except CloudError as ex: + raise ex + identity_type = "SystemAssigned" + + return ConfigurationIdentity(type=identity_type), location + + +def __get_cluster_rp(cluster_type): + rp = "" + if cluster_type.lower() == 'connectedclusters': + rp = 'Microsoft.Kubernetes' + elif cluster_type.lower() == 'appliances': + rp = 'Microsoft.ResourceConnector' + elif cluster_type.lower() == '': + rp = 'Microsoft.ContainerService' + else: + raise InvalidArgumentValueError("Error! Cluster type '{}' is not supported".format(cluster_type)) + return rp + + +def __validate_scope_and_namespace(scope, release_namespace, target_namespace): + if scope == 'cluster': + if target_namespace is not None: + message = "When --scope is 'cluster', --target-namespace must not be given." + raise MutuallyExclusiveArgumentError(message) + else: + if release_namespace is not None: + message = "When --scope is 'namespace', --release-namespace must not be given." + raise MutuallyExclusiveArgumentError(message) + + +def __validate_scope_after_customization(scope_obj: Scope): + if scope_obj is not None and scope_obj.namespace is not None and scope_obj.namespace.target_namespace is None: + message = "When --scope is 'namespace', --target-namespace must be given." + raise RequiredArgumentMissingError(message) + + +def __validate_version_and_auto_upgrade(version, auto_upgrade_minor_version): + if version is not None: + if auto_upgrade_minor_version: + message = "To pin to specific version, auto-upgrade-minor-version must be set to 'false'." + raise MutuallyExclusiveArgumentError(message) + + auto_upgrade_minor_version = False + + +def __get_config_settings_from_file(file_path): + try: + config_file = open(file_path,) + settings = json.load(config_file) + except ValueError: + raise Exception("File {} is not a valid JSON file".format(file_path)) + + files = len(settings) + if files == 0: + raise Exception("File {} is empty".format(file_path)) + + return settings diff --git a/src/k8s-extension/azext_k8s_extension/partner_extensions/AzureDefender.py b/src/k8s-extension/azext_k8s_extension/partner_extensions/AzureDefender.py new file mode 100644 index 00000000000..dcd2853affc --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/partner_extensions/AzureDefender.py @@ -0,0 +1,71 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +# pylint: disable=unused-argument + +from knack.log import get_logger + +from azext_k8s_extension.vendored_sdks.models import ExtensionInstance +from azext_k8s_extension.vendored_sdks.models import ExtensionInstanceUpdate +from azext_k8s_extension.vendored_sdks.models import ScopeCluster +from azext_k8s_extension.vendored_sdks.models import Scope + +from azext_k8s_extension.partner_extensions.PartnerExtensionModel import PartnerExtensionModel +from azext_k8s_extension.partner_extensions.ContainerInsights import _get_container_insights_settings + +logger = get_logger(__name__) + + +class AzureDefender(PartnerExtensionModel): + def Create(self, cmd, client, resource_group_name, cluster_name, name, cluster_type, extension_type, + scope, auto_upgrade_minor_version, release_train, version, target_namespace, + release_namespace, configuration_settings, configuration_protected_settings, + configuration_settings_file, configuration_protected_settings_file): + + """ExtensionType 'microsoft.azuredefender.kubernetes' specific validations & defaults for Create + Must create and return a valid 'ExtensionInstance' object. + + """ + # NOTE-1: Replace default scope creation with your customization! + ext_scope = None + # Hardcoding name, release_namespace and scope since ci only supports one instance and cluster scope + # and platform doesnt have support yet extension specific constraints like this + name = extension_type.lower() + release_namespace = "azuredefender" + # Scope is always cluster + scope_cluster = ScopeCluster(release_namespace=release_namespace) + ext_scope = Scope(cluster=scope_cluster, namespace=None) + + is_ci_extension_type = False + + logger.warning('Ignoring name, release-namespace and scope parameters since %s ' + 'only supports cluster scope and single instance of this extension', extension_type) + + _get_container_insights_settings(cmd, resource_group_name, cluster_name, configuration_settings, + configuration_protected_settings, is_ci_extension_type) + + # NOTE-2: Return a valid ExtensionInstance object, Instance name and flag for Identity + create_identity = True + extension_instance = ExtensionInstance( + extension_type=extension_type, + auto_upgrade_minor_version=auto_upgrade_minor_version, + release_train=release_train, + version=version, + scope=ext_scope, + configuration_settings=configuration_settings, + configuration_protected_settings=configuration_protected_settings + ) + return extension_instance, name, create_identity + + def Update(self, extension, auto_upgrade_minor_version, release_train, version): + """ExtensionType 'microsoft.azuredefender.kubernetes' specific validations & defaults for Update + Must create and return a valid 'ExtensionInstanceUpdate' object. + + """ + return ExtensionInstanceUpdate( + auto_upgrade_minor_version=auto_upgrade_minor_version, + release_train=release_train, + version=version + ) diff --git a/src/k8s-extension/azext_k8s_extension/partner_extensions/Cassandra.py b/src/k8s-extension/azext_k8s_extension/partner_extensions/Cassandra.py new file mode 100644 index 00000000000..2a609ce125a --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/partner_extensions/Cassandra.py @@ -0,0 +1,57 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +# pylint: disable=unused-argument + +from azext_k8s_extension.vendored_sdks.models import ExtensionInstance +from azext_k8s_extension.vendored_sdks.models import ExtensionInstanceUpdate +from azext_k8s_extension.vendored_sdks.models import ScopeCluster +from azext_k8s_extension.vendored_sdks.models import ScopeNamespace +from azext_k8s_extension.vendored_sdks.models import Scope + +from azext_k8s_extension.partner_extensions.PartnerExtensionModel import PartnerExtensionModel + + +class Cassandra(PartnerExtensionModel): + def Create(self, cmd, client, resource_group_name, cluster_name, name, cluster_type, extension_type, + scope, auto_upgrade_minor_version, release_train, version, target_namespace, + release_namespace, configuration_settings, configuration_protected_settings, + configuration_settings_file, configuration_protected_settings_file): + + """Default validations & defaults for Create + Must create and return a valid 'ExtensionInstance' object. + + """ + ext_scope = None + if scope is not None: + if scope.lower() == 'cluster': + scope_cluster = ScopeCluster(release_namespace=release_namespace) + ext_scope = Scope(cluster=scope_cluster, namespace=None) + elif scope.lower() == 'namespace': + scope_namespace = ScopeNamespace(target_namespace=target_namespace) + ext_scope = Scope(namespace=scope_namespace, cluster=None) + + create_identity = True + extension_instance = ExtensionInstance( + extension_type=extension_type, + auto_upgrade_minor_version=auto_upgrade_minor_version, + release_train=release_train, + version=version, + scope=ext_scope, + configuration_settings=configuration_settings, + configuration_protected_settings=configuration_protected_settings, + ) + return extension_instance, name, create_identity + + def Update(self, extension, auto_upgrade_minor_version, release_train, version): + """Default validations & defaults for Update + Must create and return a valid 'ExtensionInstanceUpdate' object. + + """ + return ExtensionInstanceUpdate( + auto_upgrade_minor_version=auto_upgrade_minor_version, + release_train=release_train, + version=version + ) diff --git a/src/k8s-extension/azext_k8s_extension/partner_extensions/ContainerInsights.py b/src/k8s-extension/azext_k8s_extension/partner_extensions/ContainerInsights.py new file mode 100644 index 00000000000..8c678b34915 --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/partner_extensions/ContainerInsights.py @@ -0,0 +1,458 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +# pylint: disable=unused-argument + +import datetime +import json + +from knack.log import get_logger + +from azure.cli.core.azclierror import InvalidArgumentValueError +from azure.cli.core.commands import LongRunningOperation +from azure.cli.core.commands.client_factory import get_mgmt_service_client, get_subscription_id +from azure.cli.core.util import sdk_no_wait +from msrestazure.azure_exceptions import CloudError +from msrestazure.tools import parse_resource_id, is_valid_resource_id + +from azext_k8s_extension.vendored_sdks.models import ExtensionInstance +from azext_k8s_extension.vendored_sdks.models import ExtensionInstanceUpdate +from azext_k8s_extension.vendored_sdks.models import ScopeCluster +from azext_k8s_extension.vendored_sdks.models import Scope + +from azext_k8s_extension.partner_extensions.PartnerExtensionModel import PartnerExtensionModel + +from azext_k8s_extension._client_factory import ( + cf_resources, cf_resource_groups, cf_log_analytics) + +logger = get_logger(__name__) + + +class ContainerInsights(PartnerExtensionModel): + def Create(self, cmd, client, resource_group_name, cluster_name, name, cluster_type, extension_type, + scope, auto_upgrade_minor_version, release_train, version, target_namespace, + release_namespace, configuration_settings, configuration_protected_settings, + configuration_settings_file, configuration_protected_settings_file): + + """ExtensionType 'microsoft.azuremonitor.containers' specific validations & defaults for Create + Must create and return a valid 'ExtensionInstance' object. + + """ + # NOTE-1: Replace default scope creation with your customization! + ext_scope = None + # Hardcoding name, release_namespace and scope since container-insights only supports one instance and cluster + # scope and platform doesnt have support yet extension specific constraints like this + name = 'azuremonitor-containers' + release_namespace = 'azuremonitor-containers' + # Scope is always cluster + scope_cluster = ScopeCluster(release_namespace=release_namespace) + ext_scope = Scope(cluster=scope_cluster, namespace=None) + + is_ci_extension_type = True + + logger.warning('Ignoring name, release-namespace and scope parameters since %s ' + 'only supports cluster scope and single instance of this extension', extension_type) + + _get_container_insights_settings(cmd, resource_group_name, cluster_name, configuration_settings, + configuration_protected_settings, is_ci_extension_type) + + # NOTE-2: Return a valid ExtensionInstance object, Instance name and flag for Identity + create_identity = True + extension_instance = ExtensionInstance( + extension_type=extension_type, + auto_upgrade_minor_version=auto_upgrade_minor_version, + release_train=release_train, + version=version, + scope=ext_scope, + configuration_settings=configuration_settings, + configuration_protected_settings=configuration_protected_settings + ) + return extension_instance, name, create_identity + + def Update(self, extension, auto_upgrade_minor_version, release_train, version): + """ExtensionType 'microsoft.azuremonitor.containers' specific validations & defaults for Update + Must create and return a valid 'ExtensionInstanceUpdate' object. + + """ + return ExtensionInstanceUpdate( + auto_upgrade_minor_version=auto_upgrade_minor_version, + release_train=release_train, + version=version + ) + + +# Custom Validation Logic for Container Insights + +def _invoke_deployment(cmd, resource_group_name, deployment_name, template, parameters, validate, no_wait, + subscription_id=None): + from azure.cli.core.profiles import ResourceType + deployment_properties = cmd.get_models('DeploymentProperties', resource_type=ResourceType.MGMT_RESOURCE_RESOURCES) + properties = deployment_properties(template=template, parameters=parameters, mode='incremental') + smc = get_mgmt_service_client(cmd.cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES, + subscription_id=subscription_id).deployments + if validate: + logger.info('==== BEGIN TEMPLATE ====') + logger.info(json.dumps(template, indent=2)) + logger.info('==== END TEMPLATE ====') + + if cmd.supported_api_version(min_api='2019-10-01', resource_type=ResourceType.MGMT_RESOURCE_RESOURCES): + deployment_temp = cmd.get_models('Deployment', resource_type=ResourceType.MGMT_RESOURCE_RESOURCES) + deployment = deployment_temp(properties=properties) + + if validate: + validation_poller = smc.validate(resource_group_name, deployment_name, deployment) + return LongRunningOperation(cmd.cli_ctx)(validation_poller) + return sdk_no_wait(no_wait, smc.create_or_update, resource_group_name, deployment_name, deployment) + + if validate: + return smc.validate(resource_group_name, deployment_name, properties) + return sdk_no_wait(no_wait, smc.create_or_update, resource_group_name, deployment_name, properties) + + +def _ensure_default_log_analytics_workspace_for_monitoring(cmd, subscription_id, + cluster_resource_group_name, cluster_name): + # mapping for azure public cloud + # log analytics workspaces cannot be created in WCUS region due to capacity limits + # so mapped to EUS per discussion with log analytics team + # pylint: disable=too-many-locals,too-many-statements + + azurecloud_location_to_oms_region_code_map = { + "australiasoutheast": "ASE", + "australiaeast": "EAU", + "australiacentral": "CAU", + "canadacentral": "CCA", + "centralindia": "CIN", + "centralus": "CUS", + "eastasia": "EA", + "eastus": "EUS", + "eastus2": "EUS2", + "eastus2euap": "EAP", + "francecentral": "PAR", + "japaneast": "EJP", + "koreacentral": "SE", + "northeurope": "NEU", + "southcentralus": "SCUS", + "southeastasia": "SEA", + "uksouth": "SUK", + "usgovvirginia": "USGV", + "westcentralus": "EUS", + "westeurope": "WEU", + "westus": "WUS", + "westus2": "WUS2" + } + azurecloud_region_to_oms_region_map = { + "australiacentral": "australiacentral", + "australiacentral2": "australiacentral", + "australiaeast": "australiaeast", + "australiasoutheast": "australiasoutheast", + "brazilsouth": "southcentralus", + "canadacentral": "canadacentral", + "canadaeast": "canadacentral", + "centralus": "centralus", + "centralindia": "centralindia", + "eastasia": "eastasia", + "eastus": "eastus", + "eastus2": "eastus2", + "francecentral": "francecentral", + "francesouth": "francecentral", + "japaneast": "japaneast", + "japanwest": "japaneast", + "koreacentral": "koreacentral", + "koreasouth": "koreacentral", + "northcentralus": "eastus", + "northeurope": "northeurope", + "southafricanorth": "westeurope", + "southafricawest": "westeurope", + "southcentralus": "southcentralus", + "southeastasia": "southeastasia", + "southindia": "centralindia", + "uksouth": "uksouth", + "ukwest": "uksouth", + "westcentralus": "eastus", + "westeurope": "westeurope", + "westindia": "centralindia", + "westus": "westus", + "westus2": "westus2" + } + + # mapping for azure china cloud + # currently log analytics supported only China East 2 region + azurechina_location_to_oms_region_code_map = { + "chinaeast": "EAST2", + "chinaeast2": "EAST2", + "chinanorth": "EAST2", + "chinanorth2": "EAST2" + } + azurechina_region_to_oms_region_map = { + "chinaeast": "chinaeast2", + "chinaeast2": "chinaeast2", + "chinanorth": "chinaeast2", + "chinanorth2": "chinaeast2" + } + + # mapping for azure us governmner cloud + azurefairfax_location_to_oms_region_code_map = { + "usgovvirginia": "USGV" + } + azurefairfax_region_to_oms_region_map = { + "usgovvirginia": "usgovvirginia" + } + + cluster_location = '' + resources = cf_resources(cmd.cli_ctx, subscription_id) + + cluster_resource_id = '/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Kubernetes' \ + '/connectedClusters/{2}'.format(subscription_id, cluster_resource_group_name, cluster_name) + try: + resource = resources.get_by_id(cluster_resource_id, '2020-01-01-preview') + cluster_location = resource.location.lower() + except CloudError as ex: + raise ex + + cloud_name = cmd.cli_ctx.cloud.name.lower() + workspace_region = "eastus" + workspace_region_code = "EUS" + + # sanity check that locations and clouds match. + if ((cloud_name == 'azurecloud' and azurechina_region_to_oms_region_map.get(cluster_location, False)) or + (cloud_name == 'azurecloud' and azurefairfax_region_to_oms_region_map.get(cluster_location, False))): + raise InvalidArgumentValueError( + 'Wrong cloud (azurecloud) setting for region {}, please use "az cloud set ..."' + .format(cluster_location) + ) + + if ((cloud_name == 'azurechinacloud' and azurecloud_region_to_oms_region_map.get(cluster_location, False)) or + (cloud_name == 'azurechinacloud' and azurefairfax_region_to_oms_region_map.get(cluster_location, False))): + raise InvalidArgumentValueError( + 'Wrong cloud (azurechinacloud) setting for region {}, please use "az cloud set ..."' + .format(cluster_location) + ) + + if ((cloud_name == 'azureusgovernment' and azurecloud_region_to_oms_region_map.get(cluster_location, False)) or + (cloud_name == 'azureusgovernment' and azurechina_region_to_oms_region_map.get(cluster_location, False))): + raise InvalidArgumentValueError( + 'Wrong cloud (azureusgovernment) setting for region {}, please use "az cloud set ..."' + .format(cluster_location) + ) + + if cloud_name == 'azurecloud': + workspace_region = azurecloud_region_to_oms_region_map.get(cluster_location, "eastus") + workspace_region_code = azurecloud_location_to_oms_region_code_map.get(workspace_region, "EUS") + elif cloud_name == 'azurechinacloud': + workspace_region = azurechina_region_to_oms_region_map.get(cluster_location, "chinaeast2") + workspace_region_code = azurechina_location_to_oms_region_code_map.get(workspace_region, "EAST2") + elif cloud_name == 'azureusgovernment': + workspace_region = azurefairfax_region_to_oms_region_map.get(cluster_location, "usgovvirginia") + workspace_region_code = azurefairfax_location_to_oms_region_code_map.get(workspace_region, "USGV") + else: + logger.error("AKS Monitoring addon not supported in cloud : %s", cloud_name) + + default_workspace_resource_group = 'DefaultResourceGroup-' + workspace_region_code + default_workspace_name = 'DefaultWorkspace-{0}-{1}'.format(subscription_id, workspace_region_code) + default_workspace_resource_id = '/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.OperationalInsights' \ + '/workspaces/{2}'.format(subscription_id, default_workspace_resource_group, default_workspace_name) + resource_groups = cf_resource_groups(cmd.cli_ctx, subscription_id) + + # check if default RG exists + if resource_groups.check_existence(default_workspace_resource_group): + try: + resource = resources.get_by_id(default_workspace_resource_id, '2015-11-01-preview') + return resource.id + except CloudError as ex: + if ex.status_code != 404: + raise ex + else: + resource_groups.create_or_update(default_workspace_resource_group, { + 'location': workspace_region}) + + default_workspace_params = { + 'location': workspace_region, + 'properties': { + 'sku': { + 'name': 'standalone' + } + } + } + async_poller = resources.create_or_update_by_id(default_workspace_resource_id, '2015-11-01-preview', + default_workspace_params) + + ws_resource_id = '' + while True: + result = async_poller.result(15) + if async_poller.done(): + ws_resource_id = result.id + break + + return ws_resource_id + + +def _ensure_container_insights_for_monitoring(cmd, workspace_resource_id): + # extract subscription ID and resource group from workspace_resource_id URL + parsed = parse_resource_id(workspace_resource_id) + subscription_id, resource_group = parsed["subscription"], parsed["resource_group"] + + resources = cf_resources(cmd.cli_ctx, subscription_id) + try: + resource = resources.get_by_id(workspace_resource_id, '2015-11-01-preview') + location = resource.location + except CloudError as ex: + raise ex + + unix_time_in_millis = int( + (datetime.datetime.utcnow() - datetime.datetime.utcfromtimestamp(0)).total_seconds() * 1000.0) + + solution_deployment_name = 'ContainerInsights-{}'.format(unix_time_in_millis) + + # pylint: disable=line-too-long + template = { + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "workspaceResourceId": { + "type": "string", + "metadata": { + "description": "Azure Monitor Log Analytics Resource ID" + } + }, + "workspaceRegion": { + "type": "string", + "metadata": { + "description": "Azure Monitor Log Analytics workspace region" + } + }, + "solutionDeploymentName": { + "type": "string", + "metadata": { + "description": "Name of the solution deployment" + } + } + }, + "resources": [ + { + "type": "Microsoft.Resources/deployments", + "name": "[parameters('solutionDeploymentName')]", + "apiVersion": "2017-05-10", + "subscriptionId": "[split(parameters('workspaceResourceId'),'/')[2]]", + "resourceGroup": "[split(parameters('workspaceResourceId'),'/')[4]]", + "properties": { + "mode": "Incremental", + "template": { + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": {}, + "variables": {}, + "resources": [ + { + "apiVersion": "2015-11-01-preview", + "type": "Microsoft.OperationsManagement/solutions", + "location": "[parameters('workspaceRegion')]", + "name": "[Concat('ContainerInsights', '(', split(parameters('workspaceResourceId'),'/')" + "[8], ')')]", + "properties": { + "workspaceResourceId": "[parameters('workspaceResourceId')]" + }, + "plan": { + "name": "[Concat('ContainerInsights', '(', split(parameters('workspaceResourceId')," + "'/')[8], ')')]", + "product": "[Concat('OMSGallery/', 'ContainerInsights')]", + "promotionCode": "", + "publisher": "Microsoft" + } + } + ] + }, + "parameters": {} + } + } + ] + } + + params = { + "workspaceResourceId": { + "value": workspace_resource_id + }, + "workspaceRegion": { + "value": location + }, + "solutionDeploymentName": { + "value": solution_deployment_name + } + } + + deployment_name = 'arc-k8s-monitoring-{}'.format(unix_time_in_millis) + # publish the Container Insights solution to the Log Analytics workspace + return _invoke_deployment(cmd, resource_group, deployment_name, template, params, + validate=False, no_wait=False, subscription_id=subscription_id) + + +def _get_container_insights_settings(cmd, cluster_resource_group_name, cluster_name, configuration_settings, + configuration_protected_settings, is_ci_extension_type): + + subscription_id = get_subscription_id(cmd.cli_ctx) + workspace_resource_id = '' + + if configuration_settings is not None: + if 'loganalyticsworkspaceresourceid' in configuration_settings: + configuration_settings['logAnalyticsWorkspaceResourceID'] = \ + configuration_settings.pop('loganalyticsworkspaceresourceid') + + if 'logAnalyticsWorkspaceResourceID' in configuration_settings: + workspace_resource_id = configuration_settings['logAnalyticsWorkspaceResourceID'] + + workspace_resource_id = workspace_resource_id.strip() + + if configuration_protected_settings is not None: + if 'proxyEndpoint' in configuration_protected_settings: + # current supported format for proxy endpoint is http(s)://:@: + # do some basic validation since the ci agent does the complete validation + proxy = configuration_protected_settings['proxyEndpoint'].strip().lower() + proxy_parts = proxy.split('://') + if (not proxy) or (not proxy.startswith('http://') and not proxy.startswith('https://')) or \ + (len(proxy_parts) != 2): + raise InvalidArgumentValueError( + 'proxyEndpoint url should in this format http(s)://:@:' + ) + logger.info("successfully validated proxyEndpoint url hence passing proxy endpoint to extension") + configuration_protected_settings['omsagent.proxy'] = configuration_protected_settings['proxyEndpoint'] + + if not workspace_resource_id: + workspace_resource_id = _ensure_default_log_analytics_workspace_for_monitoring( + cmd, subscription_id, cluster_resource_group_name, cluster_name) + else: + if not is_valid_resource_id(workspace_resource_id): + raise InvalidArgumentValueError('{} is not a valid Azure resource ID.'.format(workspace_resource_id)) + + if is_ci_extension_type: + _ensure_container_insights_for_monitoring(cmd, workspace_resource_id).result() + + # extract subscription ID and resource group from workspace_resource_id URL + parsed = parse_resource_id(workspace_resource_id) + workspace_sub_id, workspace_rg_name, workspace_name = \ + parsed["subscription"], parsed["resource_group"], parsed["name"] + + log_analytics_client = cf_log_analytics(cmd.cli_ctx, workspace_sub_id) + log_analytics_workspace = log_analytics_client.workspaces.get(workspace_rg_name, workspace_name) + if not log_analytics_workspace: + raise InvalidArgumentValueError( + 'Fails to retrieve workspace by {}'.format(workspace_name)) + + shared_keys = log_analytics_client.shared_keys.get_shared_keys( + workspace_rg_name, workspace_name) + if not shared_keys: + raise InvalidArgumentValueError('Fails to retrieve shared key for workspace {}'.format( + log_analytics_workspace)) + configuration_protected_settings['omsagent.secret.wsid'] = log_analytics_workspace.customer_id + configuration_settings['logAnalyticsWorkspaceResourceID'] = workspace_resource_id + configuration_protected_settings['omsagent.secret.key'] = shared_keys.primary_shared_key + # set the domain for the ci agent for non azure public clouds + cloud_name = cmd.cli_ctx.cloud.name + if cloud_name.lower() == 'azurechinacloud': + configuration_settings['omsagent.domain'] = 'opinsights.azure.cn' + elif cloud_name.lower() == 'azureusgovernment': + configuration_settings['omsagent.domain'] = 'opinsights.azure.us' + elif cloud_name.lower() == 'usnat': + configuration_settings['omsagent.domain'] = 'opinsights.azure.eaglex.ic.gov' + elif cloud_name.lower() == 'ussec': + configuration_settings['omsagent.domain'] = 'opinsights.azure.microsoft.scloud' diff --git a/src/k8s-extension/azext_k8s_extension/partner_extensions/DefaultExtension.py b/src/k8s-extension/azext_k8s_extension/partner_extensions/DefaultExtension.py new file mode 100644 index 00000000000..9a69199f838 --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/partner_extensions/DefaultExtension.py @@ -0,0 +1,57 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +# pylint: disable=unused-argument + +from azext_k8s_extension.vendored_sdks.models import ExtensionInstance +from azext_k8s_extension.vendored_sdks.models import ExtensionInstanceUpdate +from azext_k8s_extension.vendored_sdks.models import ScopeCluster +from azext_k8s_extension.vendored_sdks.models import ScopeNamespace +from azext_k8s_extension.vendored_sdks.models import Scope + +from azext_k8s_extension.partner_extensions.PartnerExtensionModel import PartnerExtensionModel + + +class DefaultExtension(PartnerExtensionModel): + def Create(self, cmd, client, resource_group_name, cluster_name, name, cluster_type, extension_type, + scope, auto_upgrade_minor_version, release_train, version, target_namespace, + release_namespace, configuration_settings, configuration_protected_settings, + configuration_settings_file, configuration_protected_settings_file): + + """Default validations & defaults for Create + Must create and return a valid 'ExtensionInstance' object. + + """ + ext_scope = None + if scope is not None: + if scope.lower() == 'cluster': + scope_cluster = ScopeCluster(release_namespace=release_namespace) + ext_scope = Scope(cluster=scope_cluster, namespace=None) + elif scope.lower() == 'namespace': + scope_namespace = ScopeNamespace(target_namespace=target_namespace) + ext_scope = Scope(namespace=scope_namespace, cluster=None) + + create_identity = False + extension_instance = ExtensionInstance( + extension_type=extension_type, + auto_upgrade_minor_version=auto_upgrade_minor_version, + release_train=release_train, + version=version, + scope=ext_scope, + configuration_settings=configuration_settings, + configuration_protected_settings=configuration_protected_settings + ) + return extension_instance, name, create_identity + + def Update(self, extension, auto_upgrade_minor_version, release_train, version): + """Default validations & defaults for Update + Must create and return a valid 'ExtensionInstanceUpdate' object. + + """ + return ExtensionInstanceUpdate( + auto_upgrade_minor_version=auto_upgrade_minor_version, + release_train=release_train, + version=version + ) diff --git a/src/k8s-extension/azext_k8s_extension/partner_extensions/PartnerExtensionModel.py b/src/k8s-extension/azext_k8s_extension/partner_extensions/PartnerExtensionModel.py new file mode 100644 index 00000000000..96c489644e7 --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/partner_extensions/PartnerExtensionModel.py @@ -0,0 +1,23 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +from abc import ABC, abstractmethod +from azext_k8s_extension.vendored_sdks.models import ExtensionInstance +from azext_k8s_extension.vendored_sdks.models import ExtensionInstanceUpdate + + +class PartnerExtensionModel(ABC): + @abstractmethod + def Create(self, cmd, client, resource_group_name: str, cluster_name: str, name: str, cluster_type: str, + extension_type: str, scope: str, auto_upgrade_minor_version: bool, release_train: str, version: str, + target_namespace: str, release_namespace: str, configuration_settings: dict, + configuration_protected_settings: dict, configuration_settings_file: str, + configuration_protected_settings_file: str) -> ExtensionInstance: + pass + + @abstractmethod + def Update(self, extension: ExtensionInstance, auto_upgrade_minor_version: bool, + release_train: str, version: str) -> ExtensionInstanceUpdate: + pass diff --git a/src/k8s-extension/azext_k8s_extension/partner_extensions/__init__.py b/src/k8s-extension/azext_k8s_extension/partner_extensions/__init__.py new file mode 100644 index 00000000000..9ccaff6c1b8 --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/partner_extensions/__init__.py @@ -0,0 +1,5 @@ +# ----------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# ----------------------------------------------------------------------------- diff --git a/src/k8s-extension/azext_k8s_extension/tests/__init__.py b/src/k8s-extension/azext_k8s_extension/tests/__init__.py new file mode 100644 index 00000000000..99c0f28cd71 --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/tests/__init__.py @@ -0,0 +1,5 @@ +# ----------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# ----------------------------------------------------------------------------- diff --git a/src/k8s-extension/azext_k8s_extension/tests/latest/__init__.py b/src/k8s-extension/azext_k8s_extension/tests/latest/__init__.py new file mode 100644 index 00000000000..99c0f28cd71 --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/tests/latest/__init__.py @@ -0,0 +1,5 @@ +# ----------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# ----------------------------------------------------------------------------- diff --git a/src/k8s-extension/azext_k8s_extension/tests/latest/recordings/test_k8s_extension.yaml b/src/k8s-extension/azext_k8s_extension/tests/latest/recordings/test_k8s_extension.yaml new file mode 100644 index 00000000000..127b21ac873 --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/tests/latest/recordings/test_k8s_extension.yaml @@ -0,0 +1,270 @@ +interactions: +- request: + body: '{"properties": {"extensionType": "microsoft.openservicemesh", "autoUpgradeMinorVersion": + false, "releaseTrain": "staging", "version": "0.1.0", "scope": {"cluster": {}}, + "configurationSettings": {}, "configurationProtectedSettings": {}}, "location": + ""}' + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - k8s-extension create + Connection: + - keep-alive + Content-Length: + - '252' + Content-Type: + - application/json; charset=utf-8 + ParameterSetName: + - -g -n -c --cluster-type --extension-type --release-train --version + User-Agent: + - python/3.9.0 (Windows-10-10.0.19041-SP0) msrest/0.6.21 msrest_azure/0.6.4 + azure-mgmt-kubernetesconfiguration/0.1.0 Azure-SDK-For-Python AZURECLI/2.19.1 + accept-language: + - en-US + method: PUT + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/nanthirg0923/providers/Microsoft.Kubernetes/connectedClusters/nanthicluster0923/providers/Microsoft.KubernetesConfiguration/extensions/openservice-mesh?api-version=2020-07-01-preview + response: + body: + string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/nanthirg0923/providers/Microsoft.Kubernetes/connectedClusters/nanthicluster0923/providers/Microsoft.KubernetesConfiguration/extensions/openservice-mesh","name":"openservice-mesh","type":"Microsoft.KubernetesConfiguration/extensions","properties":{"configurationSettings":{},"statuses":[],"extensionType":"microsoft.openservicemesh","autoUpgradeMinorVersion":false,"releaseTrain":"staging","version":"0.1.0","scope":{"cluster":{"releaseNamespace":"arc-osm-system"}},"installState":"Pending","lastStatusTime":null,"errorInfo":{},"creationTime":"2021-03-08T23:14:12.4010326+00:00","lastModifiedTime":"2021-03-08T23:14:12.4010327+00:00"}}' + headers: + api-supported-versions: + - 2020-07-01-Preview + cache-control: + - no-cache + content-length: + - '708' + content-type: + - application/json; charset=utf-8 + date: + - Mon, 08 Mar 2021 23:14:11 GMT + expires: + - '-1' + pragma: + - no-cache + server: + - openresty/1.15.8.2 + strict-transport-security: + - max-age=31536000; includeSubDomains + transfer-encoding: + - chunked + vary: + - Accept-Encoding,Accept-Encoding + x-content-type-options: + - nosniff + x-ms-ratelimit-remaining-subscription-writes: + - '1199' + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - k8s-extension list + Connection: + - keep-alive + ParameterSetName: + - -c -g --cluster-type + User-Agent: + - python/3.9.0 (Windows-10-10.0.19041-SP0) msrest/0.6.21 msrest_azure/0.6.4 + azure-mgmt-kubernetesconfiguration/0.1.0 Azure-SDK-For-Python AZURECLI/2.19.1 + accept-language: + - en-US + method: GET + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/nanthirg0923/providers/Microsoft.Kubernetes/connectedClusters/nanthicluster0923/providers/Microsoft.KubernetesConfiguration/extensions?api-version=2020-07-01-preview + response: + body: + string: '{"value":[{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/nanthirg0923/providers/Microsoft.Kubernetes/connectedClusters/nanthicluster0923/providers/Microsoft.KubernetesConfiguration/extensions/openservice-mesh","name":"openservice-mesh","type":"Microsoft.KubernetesConfiguration/extensions","properties":{"extensionType":"microsoft.openservicemesh","autoUpgradeMinorVersion":false,"releaseTrain":"staging","version":"0.1.0","scope":{"cluster":{"releaseNamespace":"arc-osm-system"}},"installState":"Pending","lastStatusTime":null,"errorInfo":{},"creationTime":"2021-03-08T23:14:12.4010326+00:00","lastModifiedTime":"2021-03-08T23:14:12.4010327+00:00"}},{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/nanthirg0923/providers/Microsoft.Kubernetes/connectedClusters/nanthicluster0923/providers/Microsoft.KubernetesConfiguration/extensions/hci22jan21","name":"hci22jan21","type":"Microsoft.KubernetesConfiguration/extensions","properties":{"extensionType":"microsoft.azstackhci.operator","autoUpgradeMinorVersion":true,"releaseTrain":"stable","version":"1.0.0","scope":{"cluster":{"releaseNamespace":null}},"installState":"Pending","lastStatusTime":null,"errorInfo":{},"creationTime":"2021-01-22T20:49:34.3336157+00:00","lastModifiedTime":"2021-01-22T20:49:34.3336249+00:00"}}],"nextLink":null}' + headers: + api-supported-versions: + - 2020-07-01-Preview + cache-control: + - no-cache + content-length: + - '1341' + content-type: + - application/json; charset=utf-8 + date: + - Mon, 08 Mar 2021 23:14:13 GMT + expires: + - '-1' + pragma: + - no-cache + server: + - openresty/1.15.8.2 + strict-transport-security: + - max-age=31536000; includeSubDomains + transfer-encoding: + - chunked + vary: + - Accept-Encoding,Accept-Encoding + x-content-type-options: + - nosniff + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - k8s-extension show + Connection: + - keep-alive + ParameterSetName: + - -c -g -n --cluster-type + User-Agent: + - python/3.9.0 (Windows-10-10.0.19041-SP0) msrest/0.6.21 msrest_azure/0.6.4 + azure-mgmt-kubernetesconfiguration/0.1.0 Azure-SDK-For-Python AZURECLI/2.19.1 + accept-language: + - en-US + method: GET + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/nanthirg0923/providers/Microsoft.Kubernetes/connectedClusters/nanthicluster0923/providers/Microsoft.KubernetesConfiguration/extensions/openservice-mesh?api-version=2020-07-01-preview + response: + body: + string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/nanthirg0923/providers/Microsoft.Kubernetes/connectedClusters/nanthicluster0923/providers/Microsoft.KubernetesConfiguration/extensions/openservice-mesh","name":"openservice-mesh","type":"Microsoft.KubernetesConfiguration/extensions","properties":{"configurationSettings":{},"statuses":[],"extensionType":"microsoft.openservicemesh","autoUpgradeMinorVersion":false,"releaseTrain":"staging","version":"0.1.0","scope":{"cluster":{"releaseNamespace":"arc-osm-system"}},"installState":"Pending","lastStatusTime":null,"errorInfo":{},"creationTime":"2021-03-08T23:14:12.4010326+00:00","lastModifiedTime":"2021-03-08T23:14:12.4010327+00:00"}}' + headers: + api-supported-versions: + - 2020-07-01-Preview + cache-control: + - no-cache + content-length: + - '708' + content-type: + - application/json; charset=utf-8 + date: + - Mon, 08 Mar 2021 23:14:14 GMT + expires: + - '-1' + pragma: + - no-cache + server: + - openresty/1.15.8.2 + strict-transport-security: + - max-age=31536000; includeSubDomains + transfer-encoding: + - chunked + vary: + - Accept-Encoding,Accept-Encoding + x-content-type-options: + - nosniff + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - k8s-extension delete + Connection: + - keep-alive + Content-Length: + - '0' + ParameterSetName: + - -g -c -n --cluster-type -y + User-Agent: + - python/3.9.0 (Windows-10-10.0.19041-SP0) msrest/0.6.21 msrest_azure/0.6.4 + azure-mgmt-kubernetesconfiguration/0.1.0 Azure-SDK-For-Python AZURECLI/2.19.1 + accept-language: + - en-US + method: DELETE + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/nanthirg0923/providers/Microsoft.Kubernetes/connectedClusters/nanthicluster0923/providers/Microsoft.KubernetesConfiguration/extensions/openservice-mesh?api-version=2020-07-01-preview + response: + body: + string: '{"content":null,"statusCode":200,"headers":[],"version":"1.1","reasonPhrase":"OK","trailingHeaders":[],"requestMessage":null,"isSuccessStatusCode":true}' + headers: + api-supported-versions: + - 2020-07-01-Preview + cache-control: + - no-cache + content-length: + - '152' + content-type: + - application/json; charset=utf-8 + date: + - Mon, 08 Mar 2021 23:14:14 GMT + expires: + - '-1' + pragma: + - no-cache + server: + - openresty/1.15.8.2 + strict-transport-security: + - max-age=31536000; includeSubDomains + transfer-encoding: + - chunked + vary: + - Accept-Encoding + x-content-type-options: + - nosniff + x-ms-ratelimit-remaining-subscription-deletes: + - '14999' + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - k8s-extension list + Connection: + - keep-alive + ParameterSetName: + - -c -g --cluster-type + User-Agent: + - python/3.9.0 (Windows-10-10.0.19041-SP0) msrest/0.6.21 msrest_azure/0.6.4 + azure-mgmt-kubernetesconfiguration/0.1.0 Azure-SDK-For-Python AZURECLI/2.19.1 + accept-language: + - en-US + method: GET + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/nanthirg0923/providers/Microsoft.Kubernetes/connectedClusters/nanthicluster0923/providers/Microsoft.KubernetesConfiguration/extensions?api-version=2020-07-01-preview + response: + body: + string: '{"value":[{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/nanthirg0923/providers/Microsoft.Kubernetes/connectedClusters/nanthicluster0923/providers/Microsoft.KubernetesConfiguration/extensions/hci22jan21","name":"hci22jan21","type":"Microsoft.KubernetesConfiguration/extensions","properties":{"extensionType":"microsoft.azstackhci.operator","autoUpgradeMinorVersion":true,"releaseTrain":"stable","version":"1.0.0","scope":{"cluster":{"releaseNamespace":null}},"installState":"Pending","lastStatusTime":null,"errorInfo":{},"creationTime":"2021-01-22T20:49:34.3336157+00:00","lastModifiedTime":"2021-01-22T20:49:34.3336249+00:00"}}],"nextLink":null}' + headers: + api-supported-versions: + - 2020-07-01-Preview + cache-control: + - no-cache + content-length: + - '673' + content-type: + - application/json; charset=utf-8 + date: + - Mon, 08 Mar 2021 23:14:16 GMT + expires: + - '-1' + pragma: + - no-cache + server: + - openresty/1.15.8.2 + strict-transport-security: + - max-age=31536000; includeSubDomains + transfer-encoding: + - chunked + vary: + - Accept-Encoding,Accept-Encoding + x-content-type-options: + - nosniff + status: + code: 200 + message: OK +version: 1 diff --git a/src/k8s-extension/azext_k8s_extension/tests/latest/test_k8s_extension_scenario.py b/src/k8s-extension/azext_k8s_extension/tests/latest/test_k8s_extension_scenario.py new file mode 100644 index 00000000000..0e53c9e6691 --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/tests/latest/test_k8s_extension_scenario.py @@ -0,0 +1,67 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +import os +import unittest + +from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer, record_only) + + +TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..')) + + +class K8sExtensionScenarioTest(ScenarioTest): + @record_only() + @ResourceGroupPreparer(name_prefix='cli_test_k8s_extension') + def test_k8s_extension(self): + resource_type = 'microsoft.openservicemesh' + self.kwargs.update({ + 'name': 'openservice-mesh', + 'rg': 'nanthirg0923', + 'cluster_name': 'nanthicluster0923', + 'cluster_type': 'connectedClusters', + 'extension_type': resource_type, + 'release_train': 'staging', + 'version': '0.1.0' + }) + + self.cmd('k8s-extension create -g {rg} -n {name} -c {cluster_name} --cluster-type {cluster_type} --extension-type {extension_type} --release-train {release_train} --version {version}', checks=[ + self.check('name', '{name}'), + self.check('releaseTrain', '{release_train}'), + self.check('version', '{version}'), + self.check('resourceGroup', '{rg}'), + self.check('extensionType', '{extension_type}') + ]) + + # Update is disabled for now + # self.cmd('k8s-extension update -g {rg} -n {name} --tags foo=boo', checks=[ + # self.check('tags.foo', 'boo') + # ]) + + installed_exts = self.cmd('k8s-extension list -c {cluster_name} -g {rg} --cluster-type {cluster_type}').get_output_in_json() + found_extension = False + for item in installed_exts: + if item['extensionType'] == resource_type: + found_extension = True + break + self.assertTrue(found_extension) + + self.cmd('k8s-extension show -c {cluster_name} -g {rg} -n {name} --cluster-type {cluster_type}', checks=[ + self.check('name', '{name}'), + self.check('releaseTrain', '{release_train}'), + self.check('version', '{version}'), + self.check('resourceGroup', '{rg}'), + self.check('extensionType', '{extension_type}') + ]) + + self.cmd('k8s-extension delete -g {rg} -c {cluster_name} -n {name} --cluster-type {cluster_type} -y') + + installed_exts = self.cmd('k8s-extension list -c {cluster_name} -g {rg} --cluster-type {cluster_type}').get_output_in_json() + found_extension = False + for item in installed_exts: + if item['extensionType'] == resource_type: + found_extension = True + break + self.assertFalse(found_extension) diff --git a/src/k8s-extension/azext_k8s_extension/vendored_sdks/__init__.py b/src/k8s-extension/azext_k8s_extension/vendored_sdks/__init__.py new file mode 100644 index 00000000000..874177b4d34 --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/vendored_sdks/__init__.py @@ -0,0 +1,19 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from ._configuration import SourceControlConfigurationClientConfiguration +from ._source_control_configuration_client import SourceControlConfigurationClient +__all__ = ['SourceControlConfigurationClient', 'SourceControlConfigurationClientConfiguration'] + +from .version import VERSION + +__version__ = VERSION + diff --git a/src/k8s-extension/azext_k8s_extension/vendored_sdks/_configuration.py b/src/k8s-extension/azext_k8s_extension/vendored_sdks/_configuration.py new file mode 100644 index 00000000000..5043ed69594 --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/vendored_sdks/_configuration.py @@ -0,0 +1,49 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- +from msrestazure import AzureConfiguration + +from .version import VERSION + + +class SourceControlConfigurationClientConfiguration(AzureConfiguration): + """Configuration for SourceControlConfigurationClient + Note that all parameters used to create this instance are saved as instance + attributes. + + :param credentials: Credentials needed for the client to connect to Azure. + :type credentials: :mod:`A msrestazure Credentials + object` + :param subscription_id: The Azure subscription ID. This is a + GUID-formatted string (e.g. 00000000-0000-0000-0000-000000000000) + :type subscription_id: str + :param str base_url: Service URL + """ + + def __init__( + self, credentials, subscription_id, base_url=None): + + if credentials is None: + raise ValueError("Parameter 'credentials' must not be None.") + if subscription_id is None: + raise ValueError("Parameter 'subscription_id' must not be None.") + if not base_url: + base_url = 'https://management.azure.com' + + super(SourceControlConfigurationClientConfiguration, self).__init__(base_url) + + # Starting Autorest.Python 4.0.64, make connection pool activated by default + self.keep_alive = True + + self.add_user_agent('azure-mgmt-kubernetesconfiguration/{}'.format(VERSION)) + self.add_user_agent('Azure-SDK-For-Python') + + self.credentials = credentials + self.subscription_id = subscription_id diff --git a/src/k8s-extension/azext_k8s_extension/vendored_sdks/_source_control_configuration_client.py b/src/k8s-extension/azext_k8s_extension/vendored_sdks/_source_control_configuration_client.py new file mode 100644 index 00000000000..a77176d8cb1 --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/vendored_sdks/_source_control_configuration_client.py @@ -0,0 +1,60 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from msrest.service_client import SDKClient +from msrest import Serializer, Deserializer + +from ._configuration import SourceControlConfigurationClientConfiguration +from .operations import SourceControlConfigurationsOperations +from .operations import Operations +from .operations import ExtensionsOperations +from . import models + + +class SourceControlConfigurationClient(SDKClient): + """KubernetesConfiguration Client + + :ivar config: Configuration for client. + :vartype config: SourceControlConfigurationClientConfiguration + + :ivar source_control_configurations: SourceControlConfigurations operations + :vartype source_control_configurations: azure.mgmt.kubernetesconfiguration.operations.SourceControlConfigurationsOperations + :ivar operations: Operations operations + :vartype operations: azure.mgmt.kubernetesconfiguration.operations.Operations + :ivar extensions: Extensions operations + :vartype extensions: azure.mgmt.kubernetesconfiguration.operations.ExtensionsOperations + + :param credentials: Credentials needed for the client to connect to Azure. + :type credentials: :mod:`A msrestazure Credentials + object` + :param subscription_id: The Azure subscription ID. This is a + GUID-formatted string (e.g. 00000000-0000-0000-0000-000000000000) + :type subscription_id: str + :param str base_url: Service URL + """ + + def __init__( + self, credentials, subscription_id, base_url=None): + + self.config = SourceControlConfigurationClientConfiguration(credentials, subscription_id, base_url) + super(SourceControlConfigurationClient, self).__init__(self.config.credentials, self.config) + + client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)} + self.api_version = '2020-07-01-preview' + self._serialize = Serializer(client_models) + self._deserialize = Deserializer(client_models) + + self.source_control_configurations = SourceControlConfigurationsOperations( + self._client, self.config, self._serialize, self._deserialize) + self.operations = Operations( + self._client, self.config, self._serialize, self._deserialize) + self.extensions = ExtensionsOperations( + self._client, self.config, self._serialize, self._deserialize) diff --git a/src/k8s-extension/azext_k8s_extension/vendored_sdks/models/__init__.py b/src/k8s-extension/azext_k8s_extension/vendored_sdks/models/__init__.py new file mode 100644 index 00000000000..e74cb56832b --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/vendored_sdks/models/__init__.py @@ -0,0 +1,94 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +try: + from ._models_py3 import ComplianceStatus + from ._models_py3 import ConfigurationIdentity + from ._models_py3 import ErrorDefinition + from ._models_py3 import ErrorResponse, ErrorResponseException + from ._models_py3 import ExtensionInstance + from ._models_py3 import ExtensionInstanceUpdate + from ._models_py3 import ExtensionStatus + from ._models_py3 import HelmOperatorProperties + from ._models_py3 import ProxyResource + from ._models_py3 import Resource + from ._models_py3 import ResourceProviderOperation + from ._models_py3 import ResourceProviderOperationDisplay + from ._models_py3 import Result + from ._models_py3 import Scope + from ._models_py3 import ScopeCluster + from ._models_py3 import ScopeNamespace + from ._models_py3 import SourceControlConfiguration + from ._models_py3 import SystemData +except (SyntaxError, ImportError): + from ._models import ComplianceStatus + from ._models import ConfigurationIdentity + from ._models import ErrorDefinition + from ._models import ErrorResponse, ErrorResponseException + from ._models import ExtensionInstance + from ._models import ExtensionInstanceUpdate + from ._models import ExtensionStatus + from ._models import HelmOperatorProperties + from ._models import ProxyResource + from ._models import Resource + from ._models import ResourceProviderOperation + from ._models import ResourceProviderOperationDisplay + from ._models import Result + from ._models import Scope + from ._models import ScopeCluster + from ._models import ScopeNamespace + from ._models import SourceControlConfiguration + from ._models import SystemData +from ._paged_models import ExtensionInstancePaged +from ._paged_models import ResourceProviderOperationPaged +from ._paged_models import SourceControlConfigurationPaged +from ._source_control_configuration_client_enums import ( + ComplianceStateType, + MessageLevelType, + OperatorType, + OperatorScopeType, + ProvisioningStateType, + InstallStateType, + LevelType, + ResourceIdentityType, +) + +__all__ = [ + 'ComplianceStatus', + 'ConfigurationIdentity', + 'ErrorDefinition', + 'ErrorResponse', 'ErrorResponseException', + 'ExtensionInstance', + 'ExtensionInstanceUpdate', + 'ExtensionStatus', + 'HelmOperatorProperties', + 'ProxyResource', + 'Resource', + 'ResourceProviderOperation', + 'ResourceProviderOperationDisplay', + 'Result', + 'Scope', + 'ScopeCluster', + 'ScopeNamespace', + 'SourceControlConfiguration', + 'SystemData', + 'SourceControlConfigurationPaged', + 'ResourceProviderOperationPaged', + 'ExtensionInstancePaged', + 'ComplianceStateType', + 'MessageLevelType', + 'OperatorType', + 'OperatorScopeType', + 'ProvisioningStateType', + 'InstallStateType', + 'LevelType', + 'ResourceIdentityType', +] diff --git a/src/k8s-extension/azext_k8s_extension/vendored_sdks/models/_models.py b/src/k8s-extension/azext_k8s_extension/vendored_sdks/models/_models.py new file mode 100644 index 00000000000..f74ea5d809e --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/vendored_sdks/models/_models.py @@ -0,0 +1,726 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model +from msrest.exceptions import HttpOperationError + + +class CloudError(Model): + """CloudError. + """ + + _attribute_map = { + } + + +class ComplianceStatus(Model): + """Compliance Status details. + + Variables are only populated by the server, and will be ignored when + sending a request. + + :ivar compliance_state: The compliance state of the configuration. + Possible values include: 'Pending', 'Compliant', 'Noncompliant', + 'Installed', 'Failed' + :vartype compliance_state: str or + ~azure.mgmt.kubernetesconfiguration.models.ComplianceStateType + :param last_config_applied: Datetime the configuration was last applied. + :type last_config_applied: datetime + :param message: Message from when the configuration was applied. + :type message: str + :param message_level: Level of the message. Possible values include: + 'Error', 'Warning', 'Information' + :type message_level: str or + ~azure.mgmt.kubernetesconfiguration.models.MessageLevelType + """ + + _validation = { + 'compliance_state': {'readonly': True}, + } + + _attribute_map = { + 'compliance_state': {'key': 'complianceState', 'type': 'str'}, + 'last_config_applied': {'key': 'lastConfigApplied', 'type': 'iso-8601'}, + 'message': {'key': 'message', 'type': 'str'}, + 'message_level': {'key': 'messageLevel', 'type': 'str'}, + } + + def __init__(self, **kwargs): + super(ComplianceStatus, self).__init__(**kwargs) + self.compliance_state = None + self.last_config_applied = kwargs.get('last_config_applied', None) + self.message = kwargs.get('message', None) + self.message_level = kwargs.get('message_level', None) + + +class ConfigurationIdentity(Model): + """Identity for the managed cluster. + + Variables are only populated by the server, and will be ignored when + sending a request. + + :ivar principal_id: The principal id of the system assigned identity which + is used by the configuration. + :vartype principal_id: str + :ivar tenant_id: The tenant id of the system assigned identity which is + used by the configuration. + :vartype tenant_id: str + :param type: The type of identity used for the configuration. Type + 'SystemAssigned' will use an implicitly created identity. Type 'None' will + not use Managed Identity for the configuration. Possible values include: + 'SystemAssigned', 'None' + :type type: str or + ~azure.mgmt.kubernetesconfiguration.models.ResourceIdentityType + """ + + _validation = { + 'principal_id': {'readonly': True}, + 'tenant_id': {'readonly': True}, + } + + _attribute_map = { + 'principal_id': {'key': 'principalId', 'type': 'str'}, + 'tenant_id': {'key': 'tenantId', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'ResourceIdentityType'}, + } + + def __init__(self, **kwargs): + super(ConfigurationIdentity, self).__init__(**kwargs) + self.principal_id = None + self.tenant_id = None + self.type = kwargs.get('type', None) + + +class ErrorDefinition(Model): + """Error definition. + + All required parameters must be populated in order to send to Azure. + + :param code: Required. Service specific error code which serves as the + substatus for the HTTP error code. + :type code: str + :param message: Required. Description of the error. + :type message: str + """ + + _validation = { + 'code': {'required': True}, + 'message': {'required': True}, + } + + _attribute_map = { + 'code': {'key': 'code', 'type': 'str'}, + 'message': {'key': 'message', 'type': 'str'}, + } + + def __init__(self, **kwargs): + super(ErrorDefinition, self).__init__(**kwargs) + self.code = kwargs.get('code', None) + self.message = kwargs.get('message', None) + + +class ErrorResponse(Model): + """Error response. + + :param error: Error definition. + :type error: ~azure.mgmt.kubernetesconfiguration.models.ErrorDefinition + """ + + _attribute_map = { + 'error': {'key': 'error', 'type': 'ErrorDefinition'}, + } + + def __init__(self, **kwargs): + super(ErrorResponse, self).__init__(**kwargs) + self.error = kwargs.get('error', None) + + +class ErrorResponseException(HttpOperationError): + """Server responsed with exception of type: 'ErrorResponse'. + + :param deserialize: A deserializer + :param response: Server response to be deserialized. + """ + + def __init__(self, deserialize, response, *args): + + super(ErrorResponseException, self).__init__(deserialize, response, 'ErrorResponse', *args) + + +class Resource(Model): + """The Resource model definition. + + Variables are only populated by the server, and will be ignored when + sending a request. + + :ivar id: Resource Id + :vartype id: str + :ivar name: Resource name + :vartype name: str + :ivar type: Resource type + :vartype type: str + :param system_data: Top level metadata + https://github.com/Azure/azure-resource-manager-rpc/blob/master/v1.0/common-api-contracts.md#system-metadata-for-all-azure-resources + :type system_data: ~azure.mgmt.kubernetesconfiguration.models.SystemData + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + } + + def __init__(self, **kwargs): + super(Resource, self).__init__(**kwargs) + self.id = None + self.name = None + self.type = None + self.system_data = kwargs.get('system_data', None) + + +class ProxyResource(Resource): + """ARM proxy resource. + + Variables are only populated by the server, and will be ignored when + sending a request. + + :ivar id: Resource Id + :vartype id: str + :ivar name: Resource name + :vartype name: str + :ivar type: Resource type + :vartype type: str + :param system_data: Top level metadata + https://github.com/Azure/azure-resource-manager-rpc/blob/master/v1.0/common-api-contracts.md#system-metadata-for-all-azure-resources + :type system_data: ~azure.mgmt.kubernetesconfiguration.models.SystemData + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + } + + def __init__(self, **kwargs): + super(ProxyResource, self).__init__(**kwargs) + + +class ExtensionInstance(ProxyResource): + """The Extension Instance object. + + Variables are only populated by the server, and will be ignored when + sending a request. + + :ivar id: Resource Id + :vartype id: str + :ivar name: Resource name + :vartype name: str + :ivar type: Resource type + :vartype type: str + :param location: Location of resource type + :type location: str + :param system_data: Top level metadata + https://github.com/Azure/azure-resource-manager-rpc/blob/master/v1.0/common-api-contracts.md#system-metadata-for-all-azure-resources + :type system_data: ~azure.mgmt.kubernetesconfiguration.models.SystemData + :param extension_type: Type of the Extension, of which this resource is an + instance of. It must be one of the Extension Types registered with + Microsoft.KubernetesConfiguration by the Extension publisher. + :type extension_type: str + :param auto_upgrade_minor_version: Flag to note if this instance + participates in auto upgrade of minor version, or not. + :type auto_upgrade_minor_version: bool + :param release_train: ReleaseTrain this extension instance participates in + for auto-upgrade (e.g. Stable, Preview, etc.) - only if + autoUpgradeMinorVersion is 'true'. + :type release_train: str + :param version: Version of the extension for this extension instance, if + it is 'pinned' to a specific version. autoUpgradeMinorVersion must be + 'false'. + :type version: str + :param scope: Scope at which the extension instance is installed. + :type scope: ~azure.mgmt.kubernetesconfiguration.models.Scope + :param configuration_settings: Configuration settings, as name-value pairs + for configuring this instance of the extension. + :type configuration_settings: dict[str, str] + :param configuration_protected_settings: Configuration settings that are + sensitive, as name-value pairs for configuring this instance of the + extension. + :type configuration_protected_settings: dict[str, str] + :param install_state: Status of installation of this instance of the + extension. Possible values include: 'Pending', 'Installed', 'Failed' + :type install_state: str or + ~azure.mgmt.kubernetesconfiguration.models.InstallStateType + :param statuses: Status from this instance of the extension. + :type statuses: + list[~azure.mgmt.kubernetesconfiguration.models.ExtensionStatus] + :ivar creation_time: DateLiteral (per ISO8601) noting the time the + resource was created by the client (user). + :vartype creation_time: str + :ivar last_modified_time: DateLiteral (per ISO8601) noting the time the + resource was modified by the client (user). + :vartype last_modified_time: str + :ivar last_status_time: DateLiteral (per ISO8601) noting the time of last + status from the agent. + :vartype last_status_time: str + :ivar error_info: Error information from the Agent - e.g. errors during + installation. + :vartype error_info: + ~azure.mgmt.kubernetesconfiguration.models.ErrorDefinition + :param identity: The identity of the configuration. + :type identity: + ~azure.mgmt.kubernetesconfiguration.models.ConfigurationIdentity + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'creation_time': {'readonly': True}, + 'last_modified_time': {'readonly': True}, + 'last_status_time': {'readonly': True}, + 'error_info': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'location': {'key': 'location', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'identity': {'key': 'identity', 'type': 'ConfigurationIdentity'}, + 'extension_type': {'key': 'properties.extensionType', 'type': 'str'}, + 'auto_upgrade_minor_version': {'key': 'properties.autoUpgradeMinorVersion', 'type': 'bool'}, + 'release_train': {'key': 'properties.releaseTrain', 'type': 'str'}, + 'version': {'key': 'properties.version', 'type': 'str'}, + 'scope': {'key': 'properties.scope', 'type': 'Scope'}, + 'configuration_settings': {'key': 'properties.configurationSettings', 'type': '{str}'}, + 'configuration_protected_settings': {'key': 'properties.configurationProtectedSettings', 'type': '{str}'}, + 'install_state': {'key': 'properties.installState', 'type': 'str'}, + 'statuses': {'key': 'properties.statuses', 'type': '[ExtensionStatus]'}, + 'creation_time': {'key': 'properties.creationTime', 'type': 'str'}, + 'last_modified_time': {'key': 'properties.lastModifiedTime', 'type': 'str'}, + 'last_status_time': {'key': 'properties.lastStatusTime', 'type': 'str'}, + 'error_info': {'key': 'properties.errorInfo', 'type': 'ErrorDefinition'}, + } + + def __init__(self, **kwargs): + super(ExtensionInstance, self).__init__(**kwargs) + self.location = kwargs.get('location', None) + self.extension_type = kwargs.get('extension_type', None) + self.auto_upgrade_minor_version = kwargs.get('auto_upgrade_minor_version', None) + self.release_train = kwargs.get('release_train', None) + self.version = kwargs.get('version', None) + self.scope = kwargs.get('scope', None) + self.configuration_settings = kwargs.get('configuration_settings', None) + self.configuration_protected_settings = kwargs.get('configuration_protected_settings', None) + self.install_state = kwargs.get('install_state', None) + self.statuses = kwargs.get('statuses', None) + self.creation_time = None + self.last_modified_time = None + self.last_status_time = None + self.error_info = None + self.identity = kwargs.get('identity', None) + + +class ExtensionInstanceUpdate(Model): + """Update Extension Instance request object. + + :param auto_upgrade_minor_version: Flag to note if this instance + participates in Extension Lifecycle Management or not. + :type auto_upgrade_minor_version: bool + :param release_train: ReleaseTrain this extension instance participates in + for auto-upgrade (e.g. Stable, Preview, etc.) - only if + autoUpgradeMinorVersion is 'true'. + :type release_train: str + :param version: Version number of extension, to 'pin' to a specific + version. autoUpgradeMinorVersion must be 'false'. + :type version: str + """ + + _attribute_map = { + 'auto_upgrade_minor_version': {'key': 'properties.autoUpgradeMinorVersion', 'type': 'bool'}, + 'release_train': {'key': 'properties.releaseTrain', 'type': 'str'}, + 'version': {'key': 'properties.version', 'type': 'str'}, + } + + def __init__(self, **kwargs): + super(ExtensionInstanceUpdate, self).__init__(**kwargs) + self.auto_upgrade_minor_version = kwargs.get('auto_upgrade_minor_version', None) + self.release_train = kwargs.get('release_train', None) + self.version = kwargs.get('version', None) + + +class ExtensionStatus(Model): + """Status from this instance of the extension. + + :param code: Status code provided by the Extension + :type code: str + :param display_status: Short description of status of this instance of the + extension. + :type display_status: str + :param level: Level of the status. Possible values include: 'Error', + 'Warning', 'Information'. Default value: "Information" . + :type level: str or ~azure.mgmt.kubernetesconfiguration.models.LevelType + :param message: Detailed message of the status from the Extension + instance. + :type message: str + :param time: DateLiteral (per ISO8601) noting the time of installation + status. + :type time: str + """ + + _attribute_map = { + 'code': {'key': 'code', 'type': 'str'}, + 'display_status': {'key': 'displayStatus', 'type': 'str'}, + 'level': {'key': 'level', 'type': 'str'}, + 'message': {'key': 'message', 'type': 'str'}, + 'time': {'key': 'time', 'type': 'str'}, + } + + def __init__(self, **kwargs): + super(ExtensionStatus, self).__init__(**kwargs) + self.code = kwargs.get('code', None) + self.display_status = kwargs.get('display_status', None) + self.level = kwargs.get('level', "Information") + self.message = kwargs.get('message', None) + self.time = kwargs.get('time', None) + + +class HelmOperatorProperties(Model): + """Properties for Helm operator. + + :param chart_version: Version of the operator Helm chart. + :type chart_version: str + :param chart_values: Values override for the operator Helm chart. + :type chart_values: str + """ + + _attribute_map = { + 'chart_version': {'key': 'chartVersion', 'type': 'str'}, + 'chart_values': {'key': 'chartValues', 'type': 'str'}, + } + + def __init__(self, **kwargs): + super(HelmOperatorProperties, self).__init__(**kwargs) + self.chart_version = kwargs.get('chart_version', None) + self.chart_values = kwargs.get('chart_values', None) + + +class ResourceProviderOperation(Model): + """Supported operation of this resource provider. + + Variables are only populated by the server, and will be ignored when + sending a request. + + :param name: Operation name, in format of + {provider}/{resource}/{operation} + :type name: str + :param display: Display metadata associated with the operation. + :type display: + ~azure.mgmt.kubernetesconfiguration.models.ResourceProviderOperationDisplay + :ivar is_data_action: The flag that indicates whether the operation + applies to data plane. + :vartype is_data_action: bool + """ + + _validation = { + 'is_data_action': {'readonly': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'display': {'key': 'display', 'type': 'ResourceProviderOperationDisplay'}, + 'is_data_action': {'key': 'isDataAction', 'type': 'bool'}, + } + + def __init__(self, **kwargs): + super(ResourceProviderOperation, self).__init__(**kwargs) + self.name = kwargs.get('name', None) + self.display = kwargs.get('display', None) + self.is_data_action = None + + +class ResourceProviderOperationDisplay(Model): + """Display metadata associated with the operation. + + :param provider: Resource provider: Microsoft KubernetesConfiguration. + :type provider: str + :param resource: Resource on which the operation is performed. + :type resource: str + :param operation: Type of operation: get, read, delete, etc. + :type operation: str + :param description: Description of this operation. + :type description: str + """ + + _attribute_map = { + 'provider': {'key': 'provider', 'type': 'str'}, + 'resource': {'key': 'resource', 'type': 'str'}, + 'operation': {'key': 'operation', 'type': 'str'}, + 'description': {'key': 'description', 'type': 'str'}, + } + + def __init__(self, **kwargs): + super(ResourceProviderOperationDisplay, self).__init__(**kwargs) + self.provider = kwargs.get('provider', None) + self.resource = kwargs.get('resource', None) + self.operation = kwargs.get('operation', None) + self.description = kwargs.get('description', None) + + +class Result(Model): + """Sample result definition. + + :param sample_property: Sample property of type string + :type sample_property: str + """ + + _attribute_map = { + 'sample_property': {'key': 'sampleProperty', 'type': 'str'}, + } + + def __init__(self, **kwargs): + super(Result, self).__init__(**kwargs) + self.sample_property = kwargs.get('sample_property', None) + + +class Scope(Model): + """Scope of the extensionInstance. It can be either Cluster or Namespace; but + not both. + + :param cluster: Specifies that the scope of the extensionInstance is + Cluster + :type cluster: ~azure.mgmt.kubernetesconfiguration.models.ScopeCluster + :param namespace: Specifies that the scope of the extensionInstance is + Namespace + :type namespace: ~azure.mgmt.kubernetesconfiguration.models.ScopeNamespace + """ + + _attribute_map = { + 'cluster': {'key': 'cluster', 'type': 'ScopeCluster'}, + 'namespace': {'key': 'namespace', 'type': 'ScopeNamespace'}, + } + + def __init__(self, **kwargs): + super(Scope, self).__init__(**kwargs) + self.cluster = kwargs.get('cluster', None) + self.namespace = kwargs.get('namespace', None) + + +class ScopeCluster(Model): + """Specifies that the scope of the extensionInstance is Cluster. + + :param release_namespace: Namespace where the extension Release must be + placed, for a Cluster scoped extensionInstance. If this namespace does + not exist, it will be created + :type release_namespace: str + """ + + _attribute_map = { + 'release_namespace': {'key': 'releaseNamespace', 'type': 'str'}, + } + + def __init__(self, **kwargs): + super(ScopeCluster, self).__init__(**kwargs) + self.release_namespace = kwargs.get('release_namespace', None) + + +class ScopeNamespace(Model): + """Specifies that the scope of the extensionInstance is Namespace. + + :param target_namespace: Namespace where the extensionInstance will be + created for an Namespace scoped extensionInstance. If this namespace does + not exist, it will be created + :type target_namespace: str + """ + + _attribute_map = { + 'target_namespace': {'key': 'targetNamespace', 'type': 'str'}, + } + + def __init__(self, **kwargs): + super(ScopeNamespace, self).__init__(**kwargs) + self.target_namespace = kwargs.get('target_namespace', None) + + +class SourceControlConfiguration(ProxyResource): + """The SourceControl Configuration object returned in Get & Put response. + + Variables are only populated by the server, and will be ignored when + sending a request. + + :ivar id: Resource Id + :vartype id: str + :ivar name: Resource name + :vartype name: str + :ivar type: Resource type + :vartype type: str + :param system_data: Top level metadata + https://github.com/Azure/azure-resource-manager-rpc/blob/master/v1.0/common-api-contracts.md#system-metadata-for-all-azure-resources + :type system_data: ~azure.mgmt.kubernetesconfiguration.models.SystemData + :param repository_url: Url of the SourceControl Repository. + :type repository_url: str + :param operator_namespace: The namespace to which this operator is + installed to. Maximum of 253 lower case alphanumeric characters, hyphen + and period only. Default value: "default" . + :type operator_namespace: str + :param operator_instance_name: Instance name of the operator - identifying + the specific configuration. + :type operator_instance_name: str + :param operator_type: Type of the operator. Possible values include: + 'Flux' + :type operator_type: str or + ~azure.mgmt.kubernetesconfiguration.models.OperatorType + :param operator_params: Any Parameters for the Operator instance in string + format. + :type operator_params: str + :param configuration_protected_settings: Name-value pairs of protected + configuration settings for the configuration + :type configuration_protected_settings: dict[str, str] + :param operator_scope: Scope at which the operator will be installed. + Possible values include: 'cluster', 'namespace'. Default value: "cluster" + . + :type operator_scope: str or + ~azure.mgmt.kubernetesconfiguration.models.OperatorScopeType + :ivar repository_public_key: Public Key associated with this SourceControl + configuration (either generated within the cluster or provided by the + user). + :vartype repository_public_key: str + :param ssh_known_hosts_contents: Base64-encoded known_hosts contents + containing public SSH keys required to access private Git instances + :type ssh_known_hosts_contents: str + :param enable_helm_operator: Option to enable Helm Operator for this git + configuration. + :type enable_helm_operator: bool + :param helm_operator_properties: Properties for Helm operator. + :type helm_operator_properties: + ~azure.mgmt.kubernetesconfiguration.models.HelmOperatorProperties + :ivar provisioning_state: The provisioning state of the resource provider. + Possible values include: 'Accepted', 'Deleting', 'Running', 'Succeeded', + 'Failed' + :vartype provisioning_state: str or + ~azure.mgmt.kubernetesconfiguration.models.ProvisioningStateType + :ivar compliance_status: Compliance Status of the Configuration + :vartype compliance_status: + ~azure.mgmt.kubernetesconfiguration.models.ComplianceStatus + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'repository_public_key': {'readonly': True}, + 'provisioning_state': {'readonly': True}, + 'compliance_status': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'repository_url': {'key': 'properties.repositoryUrl', 'type': 'str'}, + 'operator_namespace': {'key': 'properties.operatorNamespace', 'type': 'str'}, + 'operator_instance_name': {'key': 'properties.operatorInstanceName', 'type': 'str'}, + 'operator_type': {'key': 'properties.operatorType', 'type': 'str'}, + 'operator_params': {'key': 'properties.operatorParams', 'type': 'str'}, + 'configuration_protected_settings': {'key': 'properties.configurationProtectedSettings', 'type': '{str}'}, + 'operator_scope': {'key': 'properties.operatorScope', 'type': 'str'}, + 'repository_public_key': {'key': 'properties.repositoryPublicKey', 'type': 'str'}, + 'ssh_known_hosts_contents': {'key': 'properties.sshKnownHostsContents', 'type': 'str'}, + 'enable_helm_operator': {'key': 'properties.enableHelmOperator', 'type': 'bool'}, + 'helm_operator_properties': {'key': 'properties.helmOperatorProperties', 'type': 'HelmOperatorProperties'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'compliance_status': {'key': 'properties.complianceStatus', 'type': 'ComplianceStatus'}, + } + + def __init__(self, **kwargs): + super(SourceControlConfiguration, self).__init__(**kwargs) + self.repository_url = kwargs.get('repository_url', None) + self.operator_namespace = kwargs.get('operator_namespace', "default") + self.operator_instance_name = kwargs.get('operator_instance_name', None) + self.operator_type = kwargs.get('operator_type', None) + self.operator_params = kwargs.get('operator_params', None) + self.configuration_protected_settings = kwargs.get('configuration_protected_settings', None) + self.operator_scope = kwargs.get('operator_scope', "cluster") + self.repository_public_key = None + self.ssh_known_hosts_contents = kwargs.get('ssh_known_hosts_contents', None) + self.enable_helm_operator = kwargs.get('enable_helm_operator', None) + self.helm_operator_properties = kwargs.get('helm_operator_properties', None) + self.provisioning_state = None + self.compliance_status = None + + +class SystemData(Model): + """Top level metadata + https://github.com/Azure/azure-resource-manager-rpc/blob/master/v1.0/common-api-contracts.md#system-metadata-for-all-azure-resources. + + Variables are only populated by the server, and will be ignored when + sending a request. + + :ivar created_by: A string identifier for the identity that created the + resource + :vartype created_by: str + :ivar created_by_type: The type of identity that created the resource: + user, application, managedIdentity, key + :vartype created_by_type: str + :ivar created_at: The timestamp of resource creation (UTC) + :vartype created_at: datetime + :ivar last_modified_by: A string identifier for the identity that last + modified the resource + :vartype last_modified_by: str + :ivar last_modified_by_type: The type of identity that last modified the + resource: user, application, managedIdentity, key + :vartype last_modified_by_type: str + :ivar last_modified_at: The timestamp of resource last modification (UTC) + :vartype last_modified_at: datetime + """ + + _validation = { + 'created_by': {'readonly': True}, + 'created_by_type': {'readonly': True}, + 'created_at': {'readonly': True}, + 'last_modified_by': {'readonly': True}, + 'last_modified_by_type': {'readonly': True}, + 'last_modified_at': {'readonly': True}, + } + + _attribute_map = { + 'created_by': {'key': 'createdBy', 'type': 'str'}, + 'created_by_type': {'key': 'createdByType', 'type': 'str'}, + 'created_at': {'key': 'createdAt', 'type': 'iso-8601'}, + 'last_modified_by': {'key': 'lastModifiedBy', 'type': 'str'}, + 'last_modified_by_type': {'key': 'lastModifiedByType', 'type': 'str'}, + 'last_modified_at': {'key': 'lastModifiedAt', 'type': 'iso-8601'}, + } + + def __init__(self, **kwargs): + super(SystemData, self).__init__(**kwargs) + self.created_by = None + self.created_by_type = None + self.created_at = None + self.last_modified_by = None + self.last_modified_by_type = None + self.last_modified_at = None diff --git a/src/k8s-extension/azext_k8s_extension/vendored_sdks/models/_models_py3.py b/src/k8s-extension/azext_k8s_extension/vendored_sdks/models/_models_py3.py new file mode 100644 index 00000000000..57f42c85edd --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/vendored_sdks/models/_models_py3.py @@ -0,0 +1,726 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model +from msrest.exceptions import HttpOperationError + + +class CloudError(Model): + """CloudError. + """ + + _attribute_map = { + } + + +class ComplianceStatus(Model): + """Compliance Status details. + + Variables are only populated by the server, and will be ignored when + sending a request. + + :ivar compliance_state: The compliance state of the configuration. + Possible values include: 'Pending', 'Compliant', 'Noncompliant', + 'Installed', 'Failed' + :vartype compliance_state: str or + ~azure.mgmt.kubernetesconfiguration.models.ComplianceStateType + :param last_config_applied: Datetime the configuration was last applied. + :type last_config_applied: datetime + :param message: Message from when the configuration was applied. + :type message: str + :param message_level: Level of the message. Possible values include: + 'Error', 'Warning', 'Information' + :type message_level: str or + ~azure.mgmt.kubernetesconfiguration.models.MessageLevelType + """ + + _validation = { + 'compliance_state': {'readonly': True}, + } + + _attribute_map = { + 'compliance_state': {'key': 'complianceState', 'type': 'str'}, + 'last_config_applied': {'key': 'lastConfigApplied', 'type': 'iso-8601'}, + 'message': {'key': 'message', 'type': 'str'}, + 'message_level': {'key': 'messageLevel', 'type': 'str'}, + } + + def __init__(self, *, last_config_applied=None, message: str=None, message_level=None, **kwargs) -> None: + super(ComplianceStatus, self).__init__(**kwargs) + self.compliance_state = None + self.last_config_applied = last_config_applied + self.message = message + self.message_level = message_level + + +class ConfigurationIdentity(Model): + """Identity for the managed cluster. + + Variables are only populated by the server, and will be ignored when + sending a request. + + :ivar principal_id: The principal id of the system assigned identity which + is used by the configuration. + :vartype principal_id: str + :ivar tenant_id: The tenant id of the system assigned identity which is + used by the configuration. + :vartype tenant_id: str + :param type: The type of identity used for the configuration. Type + 'SystemAssigned' will use an implicitly created identity. Type 'None' will + not use Managed Identity for the configuration. Possible values include: + 'SystemAssigned', 'None' + :type type: str or + ~azure.mgmt.kubernetesconfiguration.models.ResourceIdentityType + """ + + _validation = { + 'principal_id': {'readonly': True}, + 'tenant_id': {'readonly': True}, + } + + _attribute_map = { + 'principal_id': {'key': 'principalId', 'type': 'str'}, + 'tenant_id': {'key': 'tenantId', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'ResourceIdentityType'}, + } + + def __init__(self, *, type=None, **kwargs) -> None: + super(ConfigurationIdentity, self).__init__(**kwargs) + self.principal_id = None + self.tenant_id = None + self.type = type + + +class ErrorDefinition(Model): + """Error definition. + + All required parameters must be populated in order to send to Azure. + + :param code: Required. Service specific error code which serves as the + substatus for the HTTP error code. + :type code: str + :param message: Required. Description of the error. + :type message: str + """ + + _validation = { + 'code': {'required': True}, + 'message': {'required': True}, + } + + _attribute_map = { + 'code': {'key': 'code', 'type': 'str'}, + 'message': {'key': 'message', 'type': 'str'}, + } + + def __init__(self, *, code: str, message: str, **kwargs) -> None: + super(ErrorDefinition, self).__init__(**kwargs) + self.code = code + self.message = message + + +class ErrorResponse(Model): + """Error response. + + :param error: Error definition. + :type error: ~azure.mgmt.kubernetesconfiguration.models.ErrorDefinition + """ + + _attribute_map = { + 'error': {'key': 'error', 'type': 'ErrorDefinition'}, + } + + def __init__(self, *, error=None, **kwargs) -> None: + super(ErrorResponse, self).__init__(**kwargs) + self.error = error + + +class ErrorResponseException(HttpOperationError): + """Server responsed with exception of type: 'ErrorResponse'. + + :param deserialize: A deserializer + :param response: Server response to be deserialized. + """ + + def __init__(self, deserialize, response, *args): + + super(ErrorResponseException, self).__init__(deserialize, response, 'ErrorResponse', *args) + + +class Resource(Model): + """The Resource model definition. + + Variables are only populated by the server, and will be ignored when + sending a request. + + :ivar id: Resource Id + :vartype id: str + :ivar name: Resource name + :vartype name: str + :ivar type: Resource type + :vartype type: str + :param system_data: Top level metadata + https://github.com/Azure/azure-resource-manager-rpc/blob/master/v1.0/common-api-contracts.md#system-metadata-for-all-azure-resources + :type system_data: ~azure.mgmt.kubernetesconfiguration.models.SystemData + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + } + + def __init__(self, *, system_data=None, **kwargs) -> None: + super(Resource, self).__init__(**kwargs) + self.id = None + self.name = None + self.type = None + self.system_data = system_data + + +class ProxyResource(Resource): + """ARM proxy resource. + + Variables are only populated by the server, and will be ignored when + sending a request. + + :ivar id: Resource Id + :vartype id: str + :ivar name: Resource name + :vartype name: str + :ivar type: Resource type + :vartype type: str + :param system_data: Top level metadata + https://github.com/Azure/azure-resource-manager-rpc/blob/master/v1.0/common-api-contracts.md#system-metadata-for-all-azure-resources + :type system_data: ~azure.mgmt.kubernetesconfiguration.models.SystemData + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + } + + def __init__(self, *, system_data=None, **kwargs) -> None: + super(ProxyResource, self).__init__(system_data=system_data, **kwargs) + + +class ExtensionInstance(ProxyResource): + """The Extension Instance object. + + Variables are only populated by the server, and will be ignored when + sending a request. + + :ivar id: Resource Id + :vartype id: str + :ivar name: Resource name + :vartype name: str + :ivar type: Resource type + :vartype type: str + :param location: Location of resource type + :type location: str + :param system_data: Top level metadata + https://github.com/Azure/azure-resource-manager-rpc/blob/master/v1.0/common-api-contracts.md#system-metadata-for-all-azure-resources + :type system_data: ~azure.mgmt.kubernetesconfiguration.models.SystemData + :param extension_type: Type of the Extension, of which this resource is an + instance of. It must be one of the Extension Types registered with + Microsoft.KubernetesConfiguration by the Extension publisher. + :type extension_type: str + :param auto_upgrade_minor_version: Flag to note if this instance + participates in auto upgrade of minor version, or not. + :type auto_upgrade_minor_version: bool + :param release_train: ReleaseTrain this extension instance participates in + for auto-upgrade (e.g. Stable, Preview, etc.) - only if + autoUpgradeMinorVersion is 'true'. + :type release_train: str + :param version: Version of the extension for this extension instance, if + it is 'pinned' to a specific version. autoUpgradeMinorVersion must be + 'false'. + :type version: str + :param scope: Scope at which the extension instance is installed. + :type scope: ~azure.mgmt.kubernetesconfiguration.models.Scope + :param configuration_settings: Configuration settings, as name-value pairs + for configuring this instance of the extension. + :type configuration_settings: dict[str, str] + :param configuration_protected_settings: Configuration settings that are + sensitive, as name-value pairs for configuring this instance of the + extension. + :type configuration_protected_settings: dict[str, str] + :param install_state: Status of installation of this instance of the + extension. Possible values include: 'Pending', 'Installed', 'Failed' + :type install_state: str or + ~azure.mgmt.kubernetesconfiguration.models.InstallStateType + :param statuses: Status from this instance of the extension. + :type statuses: + list[~azure.mgmt.kubernetesconfiguration.models.ExtensionStatus] + :ivar creation_time: DateLiteral (per ISO8601) noting the time the + resource was created by the client (user). + :vartype creation_time: str + :ivar last_modified_time: DateLiteral (per ISO8601) noting the time the + resource was modified by the client (user). + :vartype last_modified_time: str + :ivar last_status_time: DateLiteral (per ISO8601) noting the time of last + status from the agent. + :vartype last_status_time: str + :ivar error_info: Error information from the Agent - e.g. errors during + installation. + :vartype error_info: + ~azure.mgmt.kubernetesconfiguration.models.ErrorDefinition + :param identity: The identity of the configuration. + :type identity: + ~azure.mgmt.kubernetesconfiguration.models.ConfigurationIdentity + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'creation_time': {'readonly': True}, + 'last_modified_time': {'readonly': True}, + 'last_status_time': {'readonly': True}, + 'error_info': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'location': {'key': 'location', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'identity': {'key': 'identity', 'type': 'ConfigurationIdentity'}, + 'extension_type': {'key': 'properties.extensionType', 'type': 'str'}, + 'auto_upgrade_minor_version': {'key': 'properties.autoUpgradeMinorVersion', 'type': 'bool'}, + 'release_train': {'key': 'properties.releaseTrain', 'type': 'str'}, + 'version': {'key': 'properties.version', 'type': 'str'}, + 'scope': {'key': 'properties.scope', 'type': 'Scope'}, + 'configuration_settings': {'key': 'properties.configurationSettings', 'type': '{str}'}, + 'configuration_protected_settings': {'key': 'properties.configurationProtectedSettings', 'type': '{str}'}, + 'install_state': {'key': 'properties.installState', 'type': 'str'}, + 'statuses': {'key': 'properties.statuses', 'type': '[ExtensionStatus]'}, + 'creation_time': {'key': 'properties.creationTime', 'type': 'str'}, + 'last_modified_time': {'key': 'properties.lastModifiedTime', 'type': 'str'}, + 'last_status_time': {'key': 'properties.lastStatusTime', 'type': 'str'}, + 'error_info': {'key': 'properties.errorInfo', 'type': 'ErrorDefinition'} + } + + def __init__(self, *, system_data=None, location: str=None, extension_type: str=None, auto_upgrade_minor_version: bool=None, release_train: str=None, version: str=None, scope=None, configuration_settings=None, configuration_protected_settings=None, install_state=None, statuses=None, identity=None, **kwargs) -> None: + super(ExtensionInstance, self).__init__(system_data=system_data, **kwargs) + self.location = location + self.extension_type = extension_type + self.auto_upgrade_minor_version = auto_upgrade_minor_version + self.release_train = release_train + self.version = version + self.scope = scope + self.configuration_settings = configuration_settings + self.configuration_protected_settings = configuration_protected_settings + self.install_state = install_state + self.statuses = statuses + self.creation_time = None + self.last_modified_time = None + self.last_status_time = None + self.error_info = None + self.identity = identity + + +class ExtensionInstanceUpdate(Model): + """Update Extension Instance request object. + + :param auto_upgrade_minor_version: Flag to note if this instance + participates in Extension Lifecycle Management or not. + :type auto_upgrade_minor_version: bool + :param release_train: ReleaseTrain this extension instance participates in + for auto-upgrade (e.g. Stable, Preview, etc.) - only if + autoUpgradeMinorVersion is 'true'. + :type release_train: str + :param version: Version number of extension, to 'pin' to a specific + version. autoUpgradeMinorVersion must be 'false'. + :type version: str + """ + + _attribute_map = { + 'auto_upgrade_minor_version': {'key': 'properties.autoUpgradeMinorVersion', 'type': 'bool'}, + 'release_train': {'key': 'properties.releaseTrain', 'type': 'str'}, + 'version': {'key': 'properties.version', 'type': 'str'}, + } + + def __init__(self, *, auto_upgrade_minor_version: bool=None, release_train: str=None, version: str=None, **kwargs) -> None: + super(ExtensionInstanceUpdate, self).__init__(**kwargs) + self.auto_upgrade_minor_version = auto_upgrade_minor_version + self.release_train = release_train + self.version = version + + +class ExtensionStatus(Model): + """Status from this instance of the extension. + + :param code: Status code provided by the Extension + :type code: str + :param display_status: Short description of status of this instance of the + extension. + :type display_status: str + :param level: Level of the status. Possible values include: 'Error', + 'Warning', 'Information'. Default value: "Information" . + :type level: str or ~azure.mgmt.kubernetesconfiguration.models.LevelType + :param message: Detailed message of the status from the Extension + instance. + :type message: str + :param time: DateLiteral (per ISO8601) noting the time of installation + status. + :type time: str + """ + + _attribute_map = { + 'code': {'key': 'code', 'type': 'str'}, + 'display_status': {'key': 'displayStatus', 'type': 'str'}, + 'level': {'key': 'level', 'type': 'str'}, + 'message': {'key': 'message', 'type': 'str'}, + 'time': {'key': 'time', 'type': 'str'}, + } + + def __init__(self, *, code: str=None, display_status: str=None, level="Information", message: str=None, time: str=None, **kwargs) -> None: + super(ExtensionStatus, self).__init__(**kwargs) + self.code = code + self.display_status = display_status + self.level = level + self.message = message + self.time = time + + +class HelmOperatorProperties(Model): + """Properties for Helm operator. + + :param chart_version: Version of the operator Helm chart. + :type chart_version: str + :param chart_values: Values override for the operator Helm chart. + :type chart_values: str + """ + + _attribute_map = { + 'chart_version': {'key': 'chartVersion', 'type': 'str'}, + 'chart_values': {'key': 'chartValues', 'type': 'str'}, + } + + def __init__(self, *, chart_version: str=None, chart_values: str=None, **kwargs) -> None: + super(HelmOperatorProperties, self).__init__(**kwargs) + self.chart_version = chart_version + self.chart_values = chart_values + + +class ResourceProviderOperation(Model): + """Supported operation of this resource provider. + + Variables are only populated by the server, and will be ignored when + sending a request. + + :param name: Operation name, in format of + {provider}/{resource}/{operation} + :type name: str + :param display: Display metadata associated with the operation. + :type display: + ~azure.mgmt.kubernetesconfiguration.models.ResourceProviderOperationDisplay + :ivar is_data_action: The flag that indicates whether the operation + applies to data plane. + :vartype is_data_action: bool + """ + + _validation = { + 'is_data_action': {'readonly': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'display': {'key': 'display', 'type': 'ResourceProviderOperationDisplay'}, + 'is_data_action': {'key': 'isDataAction', 'type': 'bool'}, + } + + def __init__(self, *, name: str=None, display=None, **kwargs) -> None: + super(ResourceProviderOperation, self).__init__(**kwargs) + self.name = name + self.display = display + self.is_data_action = None + + +class ResourceProviderOperationDisplay(Model): + """Display metadata associated with the operation. + + :param provider: Resource provider: Microsoft KubernetesConfiguration. + :type provider: str + :param resource: Resource on which the operation is performed. + :type resource: str + :param operation: Type of operation: get, read, delete, etc. + :type operation: str + :param description: Description of this operation. + :type description: str + """ + + _attribute_map = { + 'provider': {'key': 'provider', 'type': 'str'}, + 'resource': {'key': 'resource', 'type': 'str'}, + 'operation': {'key': 'operation', 'type': 'str'}, + 'description': {'key': 'description', 'type': 'str'}, + } + + def __init__(self, *, provider: str=None, resource: str=None, operation: str=None, description: str=None, **kwargs) -> None: + super(ResourceProviderOperationDisplay, self).__init__(**kwargs) + self.provider = provider + self.resource = resource + self.operation = operation + self.description = description + + +class Result(Model): + """Sample result definition. + + :param sample_property: Sample property of type string + :type sample_property: str + """ + + _attribute_map = { + 'sample_property': {'key': 'sampleProperty', 'type': 'str'}, + } + + def __init__(self, *, sample_property: str=None, **kwargs) -> None: + super(Result, self).__init__(**kwargs) + self.sample_property = sample_property + + +class Scope(Model): + """Scope of the extensionInstance. It can be either Cluster or Namespace; but + not both. + + :param cluster: Specifies that the scope of the extensionInstance is + Cluster + :type cluster: ~azure.mgmt.kubernetesconfiguration.models.ScopeCluster + :param namespace: Specifies that the scope of the extensionInstance is + Namespace + :type namespace: ~azure.mgmt.kubernetesconfiguration.models.ScopeNamespace + """ + + _attribute_map = { + 'cluster': {'key': 'cluster', 'type': 'ScopeCluster'}, + 'namespace': {'key': 'namespace', 'type': 'ScopeNamespace'}, + } + + def __init__(self, *, cluster=None, namespace=None, **kwargs) -> None: + super(Scope, self).__init__(**kwargs) + self.cluster = cluster + self.namespace = namespace + + +class ScopeCluster(Model): + """Specifies that the scope of the extensionInstance is Cluster. + + :param release_namespace: Namespace where the extension Release must be + placed, for a Cluster scoped extensionInstance. If this namespace does + not exist, it will be created + :type release_namespace: str + """ + + _attribute_map = { + 'release_namespace': {'key': 'releaseNamespace', 'type': 'str'}, + } + + def __init__(self, *, release_namespace: str=None, **kwargs) -> None: + super(ScopeCluster, self).__init__(**kwargs) + self.release_namespace = release_namespace + + +class ScopeNamespace(Model): + """Specifies that the scope of the extensionInstance is Namespace. + + :param target_namespace: Namespace where the extensionInstance will be + created for an Namespace scoped extensionInstance. If this namespace does + not exist, it will be created + :type target_namespace: str + """ + + _attribute_map = { + 'target_namespace': {'key': 'targetNamespace', 'type': 'str'}, + } + + def __init__(self, *, target_namespace: str=None, **kwargs) -> None: + super(ScopeNamespace, self).__init__(**kwargs) + self.target_namespace = target_namespace + + +class SourceControlConfiguration(ProxyResource): + """The SourceControl Configuration object returned in Get & Put response. + + Variables are only populated by the server, and will be ignored when + sending a request. + + :ivar id: Resource Id + :vartype id: str + :ivar name: Resource name + :vartype name: str + :ivar type: Resource type + :vartype type: str + :param system_data: Top level metadata + https://github.com/Azure/azure-resource-manager-rpc/blob/master/v1.0/common-api-contracts.md#system-metadata-for-all-azure-resources + :type system_data: ~azure.mgmt.kubernetesconfiguration.models.SystemData + :param repository_url: Url of the SourceControl Repository. + :type repository_url: str + :param operator_namespace: The namespace to which this operator is + installed to. Maximum of 253 lower case alphanumeric characters, hyphen + and period only. Default value: "default" . + :type operator_namespace: str + :param operator_instance_name: Instance name of the operator - identifying + the specific configuration. + :type operator_instance_name: str + :param operator_type: Type of the operator. Possible values include: + 'Flux' + :type operator_type: str or + ~azure.mgmt.kubernetesconfiguration.models.OperatorType + :param operator_params: Any Parameters for the Operator instance in string + format. + :type operator_params: str + :param configuration_protected_settings: Name-value pairs of protected + configuration settings for the configuration + :type configuration_protected_settings: dict[str, str] + :param operator_scope: Scope at which the operator will be installed. + Possible values include: 'cluster', 'namespace'. Default value: "cluster" + . + :type operator_scope: str or + ~azure.mgmt.kubernetesconfiguration.models.OperatorScopeType + :ivar repository_public_key: Public Key associated with this SourceControl + configuration (either generated within the cluster or provided by the + user). + :vartype repository_public_key: str + :param ssh_known_hosts_contents: Base64-encoded known_hosts contents + containing public SSH keys required to access private Git instances + :type ssh_known_hosts_contents: str + :param enable_helm_operator: Option to enable Helm Operator for this git + configuration. + :type enable_helm_operator: bool + :param helm_operator_properties: Properties for Helm operator. + :type helm_operator_properties: + ~azure.mgmt.kubernetesconfiguration.models.HelmOperatorProperties + :ivar provisioning_state: The provisioning state of the resource provider. + Possible values include: 'Accepted', 'Deleting', 'Running', 'Succeeded', + 'Failed' + :vartype provisioning_state: str or + ~azure.mgmt.kubernetesconfiguration.models.ProvisioningStateType + :ivar compliance_status: Compliance Status of the Configuration + :vartype compliance_status: + ~azure.mgmt.kubernetesconfiguration.models.ComplianceStatus + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'repository_public_key': {'readonly': True}, + 'provisioning_state': {'readonly': True}, + 'compliance_status': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'repository_url': {'key': 'properties.repositoryUrl', 'type': 'str'}, + 'operator_namespace': {'key': 'properties.operatorNamespace', 'type': 'str'}, + 'operator_instance_name': {'key': 'properties.operatorInstanceName', 'type': 'str'}, + 'operator_type': {'key': 'properties.operatorType', 'type': 'str'}, + 'operator_params': {'key': 'properties.operatorParams', 'type': 'str'}, + 'configuration_protected_settings': {'key': 'properties.configurationProtectedSettings', 'type': '{str}'}, + 'operator_scope': {'key': 'properties.operatorScope', 'type': 'str'}, + 'repository_public_key': {'key': 'properties.repositoryPublicKey', 'type': 'str'}, + 'ssh_known_hosts_contents': {'key': 'properties.sshKnownHostsContents', 'type': 'str'}, + 'enable_helm_operator': {'key': 'properties.enableHelmOperator', 'type': 'bool'}, + 'helm_operator_properties': {'key': 'properties.helmOperatorProperties', 'type': 'HelmOperatorProperties'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'compliance_status': {'key': 'properties.complianceStatus', 'type': 'ComplianceStatus'}, + } + + def __init__(self, *, system_data=None, repository_url: str=None, operator_namespace: str="default", operator_instance_name: str=None, operator_type=None, operator_params: str=None, configuration_protected_settings=None, operator_scope="cluster", ssh_known_hosts_contents: str=None, enable_helm_operator: bool=None, helm_operator_properties=None, **kwargs) -> None: + super(SourceControlConfiguration, self).__init__(system_data=system_data, **kwargs) + self.repository_url = repository_url + self.operator_namespace = operator_namespace + self.operator_instance_name = operator_instance_name + self.operator_type = operator_type + self.operator_params = operator_params + self.configuration_protected_settings = configuration_protected_settings + self.operator_scope = operator_scope + self.repository_public_key = None + self.ssh_known_hosts_contents = ssh_known_hosts_contents + self.enable_helm_operator = enable_helm_operator + self.helm_operator_properties = helm_operator_properties + self.provisioning_state = None + self.compliance_status = None + + +class SystemData(Model): + """Top level metadata + https://github.com/Azure/azure-resource-manager-rpc/blob/master/v1.0/common-api-contracts.md#system-metadata-for-all-azure-resources. + + Variables are only populated by the server, and will be ignored when + sending a request. + + :ivar created_by: A string identifier for the identity that created the + resource + :vartype created_by: str + :ivar created_by_type: The type of identity that created the resource: + user, application, managedIdentity, key + :vartype created_by_type: str + :ivar created_at: The timestamp of resource creation (UTC) + :vartype created_at: datetime + :ivar last_modified_by: A string identifier for the identity that last + modified the resource + :vartype last_modified_by: str + :ivar last_modified_by_type: The type of identity that last modified the + resource: user, application, managedIdentity, key + :vartype last_modified_by_type: str + :ivar last_modified_at: The timestamp of resource last modification (UTC) + :vartype last_modified_at: datetime + """ + + _validation = { + 'created_by': {'readonly': True}, + 'created_by_type': {'readonly': True}, + 'created_at': {'readonly': True}, + 'last_modified_by': {'readonly': True}, + 'last_modified_by_type': {'readonly': True}, + 'last_modified_at': {'readonly': True}, + } + + _attribute_map = { + 'created_by': {'key': 'createdBy', 'type': 'str'}, + 'created_by_type': {'key': 'createdByType', 'type': 'str'}, + 'created_at': {'key': 'createdAt', 'type': 'iso-8601'}, + 'last_modified_by': {'key': 'lastModifiedBy', 'type': 'str'}, + 'last_modified_by_type': {'key': 'lastModifiedByType', 'type': 'str'}, + 'last_modified_at': {'key': 'lastModifiedAt', 'type': 'iso-8601'}, + } + + def __init__(self, **kwargs) -> None: + super(SystemData, self).__init__(**kwargs) + self.created_by = None + self.created_by_type = None + self.created_at = None + self.last_modified_by = None + self.last_modified_by_type = None + self.last_modified_at = None diff --git a/src/k8s-extension/azext_k8s_extension/vendored_sdks/models/_paged_models.py b/src/k8s-extension/azext_k8s_extension/vendored_sdks/models/_paged_models.py new file mode 100644 index 00000000000..c545286fe54 --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/vendored_sdks/models/_paged_models.py @@ -0,0 +1,53 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from msrest.paging import Paged + + +class SourceControlConfigurationPaged(Paged): + """ + A paging container for iterating over a list of :class:`SourceControlConfiguration ` object + """ + + _attribute_map = { + 'next_link': {'key': 'nextLink', 'type': 'str'}, + 'current_page': {'key': 'value', 'type': '[SourceControlConfiguration]'} + } + + def __init__(self, *args, **kwargs): + + super(SourceControlConfigurationPaged, self).__init__(*args, **kwargs) +class ResourceProviderOperationPaged(Paged): + """ + A paging container for iterating over a list of :class:`ResourceProviderOperation ` object + """ + + _attribute_map = { + 'next_link': {'key': 'nextLink', 'type': 'str'}, + 'current_page': {'key': 'value', 'type': '[ResourceProviderOperation]'} + } + + def __init__(self, *args, **kwargs): + + super(ResourceProviderOperationPaged, self).__init__(*args, **kwargs) +class ExtensionInstancePaged(Paged): + """ + A paging container for iterating over a list of :class:`ExtensionInstance ` object + """ + + _attribute_map = { + 'next_link': {'key': 'nextLink', 'type': 'str'}, + 'current_page': {'key': 'value', 'type': '[ExtensionInstance]'} + } + + def __init__(self, *args, **kwargs): + + super(ExtensionInstancePaged, self).__init__(*args, **kwargs) diff --git a/src/k8s-extension/azext_k8s_extension/vendored_sdks/models/_source_control_configuration_client_enums.py b/src/k8s-extension/azext_k8s_extension/vendored_sdks/models/_source_control_configuration_client_enums.py new file mode 100644 index 00000000000..7be14a4b085 --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/vendored_sdks/models/_source_control_configuration_client_enums.py @@ -0,0 +1,68 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from enum import Enum + + +class ComplianceStateType(str, Enum): + + pending = "Pending" + compliant = "Compliant" + noncompliant = "Noncompliant" + installed = "Installed" + failed = "Failed" + + +class MessageLevelType(str, Enum): + + error = "Error" + warning = "Warning" + information = "Information" + + +class OperatorType(str, Enum): + + flux = "Flux" + + +class OperatorScopeType(str, Enum): + + cluster = "cluster" + namespace = "namespace" + + +class ProvisioningStateType(str, Enum): + + accepted = "Accepted" + deleting = "Deleting" + running = "Running" + succeeded = "Succeeded" + failed = "Failed" + + +class InstallStateType(str, Enum): + + pending = "Pending" + installed = "Installed" + failed = "Failed" + + +class LevelType(str, Enum): + + error = "Error" + warning = "Warning" + information = "Information" + + +class ResourceIdentityType(str, Enum): + + system_assigned = "SystemAssigned" + none = "None" diff --git a/src/k8s-extension/azext_k8s_extension/vendored_sdks/operations/__init__.py b/src/k8s-extension/azext_k8s_extension/vendored_sdks/operations/__init__.py new file mode 100644 index 00000000000..6be16d2582d --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/vendored_sdks/operations/__init__.py @@ -0,0 +1,20 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from ._source_control_configurations_operations import SourceControlConfigurationsOperations +from ._operations import Operations +from ._extensions_operations import ExtensionsOperations + +__all__ = [ + 'SourceControlConfigurationsOperations', + 'Operations', + 'ExtensionsOperations', +] diff --git a/src/k8s-extension/azext_k8s_extension/vendored_sdks/operations/_extensions_operations.py b/src/k8s-extension/azext_k8s_extension/vendored_sdks/operations/_extensions_operations.py new file mode 100644 index 00000000000..e99f3328816 --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/vendored_sdks/operations/_extensions_operations.py @@ -0,0 +1,431 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +import uuid +from msrest.pipeline import ClientRawResponse + +from .. import models + + +class ExtensionsOperations(object): + """ExtensionsOperations operations. + + You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute. + + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + :ivar api_version: The API version to be used with the HTTP request. Constant value: "2020-07-01-preview". + """ + + models = models + + def __init__(self, client, config, serializer, deserializer): + + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self.api_version = "2020-07-01-preview" + + self.config = config + + def create( + self, resource_group_name, cluster_rp, cluster_resource_name, cluster_name, extension_instance_name, extension_instance, custom_headers=None, raw=False, **operation_config): + """Create a new Kubernetes Cluster Extension Instance. + + :param resource_group_name: The name of the resource group. + :type resource_group_name: str + :param cluster_rp: The Kubernetes cluster RP - either + Microsoft.ContainerService (for AKS clusters) or Microsoft.Kubernetes + (for OnPrem K8S clusters). Possible values include: + 'Microsoft.ContainerService', 'Microsoft.Kubernetes' + :type cluster_rp: str + :param cluster_resource_name: The Kubernetes cluster resource name - + either managedClusters (for AKS clusters) or connectedClusters (for + OnPrem K8S clusters). Possible values include: 'managedClusters', + 'connectedClusters' + :type cluster_resource_name: str + :param cluster_name: The name of the kubernetes cluster. + :type cluster_name: str + :param extension_instance_name: Name of an instance of the Extension. + :type extension_instance_name: str + :param extension_instance: Properties necessary to Create an Extension + Instance. + :type extension_instance: + ~azure.mgmt.kubernetesconfiguration.models.ExtensionInstance + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :param operation_config: :ref:`Operation configuration + overrides`. + :return: ExtensionInstance or ClientRawResponse if raw=true + :rtype: ~azure.mgmt.kubernetesconfiguration.models.ExtensionInstance + or ~msrest.pipeline.ClientRawResponse + :raises: + :class:`ErrorResponseException` + """ + # Construct URL + url = self.create.metadata['url'] + path_format_arguments = { + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'clusterRp': self._serialize.url("cluster_rp", cluster_rp, 'str'), + 'clusterResourceName': self._serialize.url("cluster_resource_name", cluster_resource_name, 'str'), + 'clusterName': self._serialize.url("cluster_name", cluster_name, 'str'), + 'extensionInstanceName': self._serialize.url("extension_instance_name", extension_instance_name, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + + # Construct headers + header_parameters = {} + header_parameters['Accept'] = 'application/json' + header_parameters['Content-Type'] = 'application/json; charset=utf-8' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct body + body_content = self._serialize.body(extension_instance, 'ExtensionInstance') + + # Construct and send request + request = self._client.put(url, query_parameters, header_parameters, body_content) + response = self._client.send(request, stream=False, **operation_config) + + if response.status_code not in [200]: + raise models.ErrorResponseException(self._deserialize, response) + + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize('ExtensionInstance', response) + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + return client_raw_response + + return deserialized + create.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{clusterRp}/{clusterResourceName}/{clusterName}/providers/Microsoft.KubernetesConfiguration/extensions/{extensionInstanceName}'} + + def get( + self, resource_group_name, cluster_rp, cluster_resource_name, cluster_name, extension_instance_name, custom_headers=None, raw=False, **operation_config): + """Gets details of the Kubernetes Cluster Extension Instance. + + :param resource_group_name: The name of the resource group. + :type resource_group_name: str + :param cluster_rp: The Kubernetes cluster RP - either + Microsoft.ContainerService (for AKS clusters) or Microsoft.Kubernetes + (for OnPrem K8S clusters). Possible values include: + 'Microsoft.ContainerService', 'Microsoft.Kubernetes' + :type cluster_rp: str + :param cluster_resource_name: The Kubernetes cluster resource name - + either managedClusters (for AKS clusters) or connectedClusters (for + OnPrem K8S clusters). Possible values include: 'managedClusters', + 'connectedClusters' + :type cluster_resource_name: str + :param cluster_name: The name of the kubernetes cluster. + :type cluster_name: str + :param extension_instance_name: Name of an instance of the Extension. + :type extension_instance_name: str + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :param operation_config: :ref:`Operation configuration + overrides`. + :return: ExtensionInstance or ClientRawResponse if raw=true + :rtype: ~azure.mgmt.kubernetesconfiguration.models.ExtensionInstance + or ~msrest.pipeline.ClientRawResponse + :raises: + :class:`ErrorResponseException` + """ + # Construct URL + url = self.get.metadata['url'] + path_format_arguments = { + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'clusterRp': self._serialize.url("cluster_rp", cluster_rp, 'str'), + 'clusterResourceName': self._serialize.url("cluster_resource_name", cluster_resource_name, 'str'), + 'clusterName': self._serialize.url("cluster_name", cluster_name, 'str'), + 'extensionInstanceName': self._serialize.url("extension_instance_name", extension_instance_name, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + + # Construct headers + header_parameters = {} + header_parameters['Accept'] = 'application/json' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct and send request + request = self._client.get(url, query_parameters, header_parameters) + response = self._client.send(request, stream=False, **operation_config) + + if response.status_code not in [200]: + raise models.ErrorResponseException(self._deserialize, response) + + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize('ExtensionInstance', response) + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + return client_raw_response + + return deserialized + get.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{clusterRp}/{clusterResourceName}/{clusterName}/providers/Microsoft.KubernetesConfiguration/extensions/{extensionInstanceName}'} + + def update( + self, resource_group_name, cluster_rp, cluster_resource_name, cluster_name, extension_instance_name, extension_instance, custom_headers=None, raw=False, **operation_config): + """Update an existing Kubernetes Cluster Extension Instance. + + :param resource_group_name: The name of the resource group. + :type resource_group_name: str + :param cluster_rp: The Kubernetes cluster RP - either + Microsoft.ContainerService (for AKS clusters) or Microsoft.Kubernetes + (for OnPrem K8S clusters). Possible values include: + 'Microsoft.ContainerService', 'Microsoft.Kubernetes' + :type cluster_rp: str + :param cluster_resource_name: The Kubernetes cluster resource name - + either managedClusters (for AKS clusters) or connectedClusters (for + OnPrem K8S clusters). Possible values include: 'managedClusters', + 'connectedClusters' + :type cluster_resource_name: str + :param cluster_name: The name of the kubernetes cluster. + :type cluster_name: str + :param extension_instance_name: Name of an instance of the Extension. + :type extension_instance_name: str + :param extension_instance: Properties to Update in the Extension + Instance. + :type extension_instance: + ~azure.mgmt.kubernetesconfiguration.models.ExtensionInstanceUpdate + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :param operation_config: :ref:`Operation configuration + overrides`. + :return: ExtensionInstance or ClientRawResponse if raw=true + :rtype: ~azure.mgmt.kubernetesconfiguration.models.ExtensionInstance + or ~msrest.pipeline.ClientRawResponse + :raises: + :class:`ErrorResponseException` + """ + # Construct URL + url = self.update.metadata['url'] + path_format_arguments = { + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'clusterRp': self._serialize.url("cluster_rp", cluster_rp, 'str'), + 'clusterResourceName': self._serialize.url("cluster_resource_name", cluster_resource_name, 'str'), + 'clusterName': self._serialize.url("cluster_name", cluster_name, 'str'), + 'extensionInstanceName': self._serialize.url("extension_instance_name", extension_instance_name, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + + # Construct headers + header_parameters = {} + header_parameters['Accept'] = 'application/json' + header_parameters['Content-Type'] = 'application/json; charset=utf-8' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct body + body_content = self._serialize.body(extension_instance, 'ExtensionInstanceUpdate') + + # Construct and send request + request = self._client.patch(url, query_parameters, header_parameters, body_content) + response = self._client.send(request, stream=False, **operation_config) + + if response.status_code not in [200]: + raise models.ErrorResponseException(self._deserialize, response) + + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize('ExtensionInstance', response) + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + return client_raw_response + + return deserialized + update.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{clusterRp}/{clusterResourceName}/{clusterName}/providers/Microsoft.KubernetesConfiguration/extensions/{extensionInstanceName}'} + + def delete( + self, resource_group_name, cluster_rp, cluster_resource_name, cluster_name, extension_instance_name, custom_headers=None, raw=False, **operation_config): + """Delete a Kubernetes Cluster Extension Instance. This will cause the + Agent to Uninstall the extension instance from the cluster. + + :param resource_group_name: The name of the resource group. + :type resource_group_name: str + :param cluster_rp: The Kubernetes cluster RP - either + Microsoft.ContainerService (for AKS clusters) or Microsoft.Kubernetes + (for OnPrem K8S clusters). Possible values include: + 'Microsoft.ContainerService', 'Microsoft.Kubernetes' + :type cluster_rp: str + :param cluster_resource_name: The Kubernetes cluster resource name - + either managedClusters (for AKS clusters) or connectedClusters (for + OnPrem K8S clusters). Possible values include: 'managedClusters', + 'connectedClusters' + :type cluster_resource_name: str + :param cluster_name: The name of the kubernetes cluster. + :type cluster_name: str + :param extension_instance_name: Name of an instance of the Extension. + :type extension_instance_name: str + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :param operation_config: :ref:`Operation configuration + overrides`. + :return: None or ClientRawResponse if raw=true + :rtype: None or ~msrest.pipeline.ClientRawResponse + :raises: + :class:`ErrorResponseException` + """ + # Construct URL + url = self.delete.metadata['url'] + path_format_arguments = { + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'clusterRp': self._serialize.url("cluster_rp", cluster_rp, 'str'), + 'clusterResourceName': self._serialize.url("cluster_resource_name", cluster_resource_name, 'str'), + 'clusterName': self._serialize.url("cluster_name", cluster_name, 'str'), + 'extensionInstanceName': self._serialize.url("extension_instance_name", extension_instance_name, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + + # Construct headers + header_parameters = {} + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct and send request + request = self._client.delete(url, query_parameters, header_parameters) + response = self._client.send(request, stream=False, **operation_config) + + if response.status_code not in [200, 204]: + raise models.ErrorResponseException(self._deserialize, response) + + if raw: + client_raw_response = ClientRawResponse(None, response) + return client_raw_response + delete.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{clusterRp}/{clusterResourceName}/{clusterName}/providers/Microsoft.KubernetesConfiguration/extensions/{extensionInstanceName}'} + + def list( + self, resource_group_name, cluster_rp, cluster_resource_name, cluster_name, custom_headers=None, raw=False, **operation_config): + """List all Source Control Configurations. + + :param resource_group_name: The name of the resource group. + :type resource_group_name: str + :param cluster_rp: The Kubernetes cluster RP - either + Microsoft.ContainerService (for AKS clusters) or Microsoft.Kubernetes + (for OnPrem K8S clusters). Possible values include: + 'Microsoft.ContainerService', 'Microsoft.Kubernetes' + :type cluster_rp: str + :param cluster_resource_name: The Kubernetes cluster resource name - + either managedClusters (for AKS clusters) or connectedClusters (for + OnPrem K8S clusters). Possible values include: 'managedClusters', + 'connectedClusters' + :type cluster_resource_name: str + :param cluster_name: The name of the kubernetes cluster. + :type cluster_name: str + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :param operation_config: :ref:`Operation configuration + overrides`. + :return: An iterator like instance of ExtensionInstance + :rtype: + ~azure.mgmt.kubernetesconfiguration.models.ExtensionInstancePaged[~azure.mgmt.kubernetesconfiguration.models.ExtensionInstance] + :raises: + :class:`ErrorResponseException` + """ + def prepare_request(next_link=None): + if not next_link: + # Construct URL + url = self.list.metadata['url'] + path_format_arguments = { + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'clusterRp': self._serialize.url("cluster_rp", cluster_rp, 'str'), + 'clusterResourceName': self._serialize.url("cluster_resource_name", cluster_resource_name, 'str'), + 'clusterName': self._serialize.url("cluster_name", cluster_name, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + + else: + url = next_link + query_parameters = {} + + # Construct headers + header_parameters = {} + header_parameters['Accept'] = 'application/json' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct and send request + request = self._client.get(url, query_parameters, header_parameters) + return request + + def internal_paging(next_link=None): + request = prepare_request(next_link) + + response = self._client.send(request, stream=False, **operation_config) + + if response.status_code not in [200]: + raise models.ErrorResponseException(self._deserialize, response) + + return response + + # Deserialize response + header_dict = None + if raw: + header_dict = {} + deserialized = models.ExtensionInstancePaged(internal_paging, self._deserialize.dependencies, header_dict) + + return deserialized + list.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{clusterRp}/{clusterResourceName}/{clusterName}/providers/Microsoft.KubernetesConfiguration/extensions'} diff --git a/src/k8s-extension/azext_k8s_extension/vendored_sdks/operations/_operations.py b/src/k8s-extension/azext_k8s_extension/vendored_sdks/operations/_operations.py new file mode 100644 index 00000000000..245a93c8294 --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/vendored_sdks/operations/_operations.py @@ -0,0 +1,101 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +import uuid +from msrest.pipeline import ClientRawResponse + +from .. import models + + +class Operations(object): + """Operations operations. + + You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute. + + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + :ivar api_version: The API version to be used with the HTTP request. Constant value: "2020-07-01-preview". + """ + + models = models + + def __init__(self, client, config, serializer, deserializer): + + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self.api_version = "2020-07-01-preview" + + self.config = config + + def list( + self, custom_headers=None, raw=False, **operation_config): + """List all the available operations the KubernetesConfiguration resource + provider supports. + + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :param operation_config: :ref:`Operation configuration + overrides`. + :return: An iterator like instance of ResourceProviderOperation + :rtype: + ~azure.mgmt.kubernetesconfiguration.models.ResourceProviderOperationPaged[~azure.mgmt.kubernetesconfiguration.models.ResourceProviderOperation] + :raises: + :class:`ErrorResponseException` + """ + def prepare_request(next_link=None): + if not next_link: + # Construct URL + url = self.list.metadata['url'] + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + + else: + url = next_link + query_parameters = {} + + # Construct headers + header_parameters = {} + header_parameters['Accept'] = 'application/json' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct and send request + request = self._client.get(url, query_parameters, header_parameters) + return request + + def internal_paging(next_link=None): + request = prepare_request(next_link) + + response = self._client.send(request, stream=False, **operation_config) + + if response.status_code not in [200]: + raise models.ErrorResponseException(self._deserialize, response) + + return response + + # Deserialize response + header_dict = None + if raw: + header_dict = {} + deserialized = models.ResourceProviderOperationPaged(internal_paging, self._deserialize.dependencies, header_dict) + + return deserialized + list.metadata = {'url': '/providers/Microsoft.KubernetesConfiguration/operations'} diff --git a/src/k8s-extension/azext_k8s_extension/vendored_sdks/operations/_source_control_configurations_operations.py b/src/k8s-extension/azext_k8s_extension/vendored_sdks/operations/_source_control_configurations_operations.py new file mode 100644 index 00000000000..83a49e32146 --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/vendored_sdks/operations/_source_control_configurations_operations.py @@ -0,0 +1,386 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +import uuid +from msrest.pipeline import ClientRawResponse +from msrest.polling import LROPoller, NoPolling +from msrestazure.polling.arm_polling import ARMPolling + +from .. import models + + +class SourceControlConfigurationsOperations(object): + """SourceControlConfigurationsOperations operations. + + You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute. + + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + :ivar api_version: The API version to be used with the HTTP request. Constant value: "2020-07-01-preview". + """ + + models = models + + def __init__(self, client, config, serializer, deserializer): + + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self.api_version = "2020-07-01-preview" + + self.config = config + + def get( + self, resource_group_name, cluster_rp, cluster_resource_name, cluster_name, source_control_configuration_name, custom_headers=None, raw=False, **operation_config): + """Gets details of the Source Control Configuration. + + :param resource_group_name: The name of the resource group. + :type resource_group_name: str + :param cluster_rp: The Kubernetes cluster RP - either + Microsoft.ContainerService (for AKS clusters) or Microsoft.Kubernetes + (for OnPrem K8S clusters). Possible values include: + 'Microsoft.ContainerService', 'Microsoft.Kubernetes' + :type cluster_rp: str + :param cluster_resource_name: The Kubernetes cluster resource name - + either managedClusters (for AKS clusters) or connectedClusters (for + OnPrem K8S clusters). Possible values include: 'managedClusters', + 'connectedClusters' + :type cluster_resource_name: str + :param cluster_name: The name of the kubernetes cluster. + :type cluster_name: str + :param source_control_configuration_name: Name of the Source Control + Configuration. + :type source_control_configuration_name: str + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :param operation_config: :ref:`Operation configuration + overrides`. + :return: SourceControlConfiguration or ClientRawResponse if raw=true + :rtype: + ~azure.mgmt.kubernetesconfiguration.models.SourceControlConfiguration + or ~msrest.pipeline.ClientRawResponse + :raises: + :class:`ErrorResponseException` + """ + # Construct URL + url = self.get.metadata['url'] + path_format_arguments = { + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'clusterRp': self._serialize.url("cluster_rp", cluster_rp, 'str'), + 'clusterResourceName': self._serialize.url("cluster_resource_name", cluster_resource_name, 'str'), + 'clusterName': self._serialize.url("cluster_name", cluster_name, 'str'), + 'sourceControlConfigurationName': self._serialize.url("source_control_configuration_name", source_control_configuration_name, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + + # Construct headers + header_parameters = {} + header_parameters['Accept'] = 'application/json' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct and send request + request = self._client.get(url, query_parameters, header_parameters) + response = self._client.send(request, stream=False, **operation_config) + + if response.status_code not in [200]: + raise models.ErrorResponseException(self._deserialize, response) + + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize('SourceControlConfiguration', response) + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + return client_raw_response + + return deserialized + get.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{clusterRp}/{clusterResourceName}/{clusterName}/providers/Microsoft.KubernetesConfiguration/sourceControlConfigurations/{sourceControlConfigurationName}'} + + def create_or_update( + self, resource_group_name, cluster_rp, cluster_resource_name, cluster_name, source_control_configuration_name, source_control_configuration, custom_headers=None, raw=False, **operation_config): + """Create a new Kubernetes Source Control Configuration. + + :param resource_group_name: The name of the resource group. + :type resource_group_name: str + :param cluster_rp: The Kubernetes cluster RP - either + Microsoft.ContainerService (for AKS clusters) or Microsoft.Kubernetes + (for OnPrem K8S clusters). Possible values include: + 'Microsoft.ContainerService', 'Microsoft.Kubernetes' + :type cluster_rp: str + :param cluster_resource_name: The Kubernetes cluster resource name - + either managedClusters (for AKS clusters) or connectedClusters (for + OnPrem K8S clusters). Possible values include: 'managedClusters', + 'connectedClusters' + :type cluster_resource_name: str + :param cluster_name: The name of the kubernetes cluster. + :type cluster_name: str + :param source_control_configuration_name: Name of the Source Control + Configuration. + :type source_control_configuration_name: str + :param source_control_configuration: Properties necessary to Create + KubernetesConfiguration. + :type source_control_configuration: + ~azure.mgmt.kubernetesconfiguration.models.SourceControlConfiguration + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :param operation_config: :ref:`Operation configuration + overrides`. + :return: SourceControlConfiguration or ClientRawResponse if raw=true + :rtype: + ~azure.mgmt.kubernetesconfiguration.models.SourceControlConfiguration + or ~msrest.pipeline.ClientRawResponse + :raises: + :class:`ErrorResponseException` + """ + # Construct URL + url = self.create_or_update.metadata['url'] + path_format_arguments = { + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'clusterRp': self._serialize.url("cluster_rp", cluster_rp, 'str'), + 'clusterResourceName': self._serialize.url("cluster_resource_name", cluster_resource_name, 'str'), + 'clusterName': self._serialize.url("cluster_name", cluster_name, 'str'), + 'sourceControlConfigurationName': self._serialize.url("source_control_configuration_name", source_control_configuration_name, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + + # Construct headers + header_parameters = {} + header_parameters['Accept'] = 'application/json' + header_parameters['Content-Type'] = 'application/json; charset=utf-8' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct body + body_content = self._serialize.body(source_control_configuration, 'SourceControlConfiguration') + + # Construct and send request + request = self._client.put(url, query_parameters, header_parameters, body_content) + response = self._client.send(request, stream=False, **operation_config) + + if response.status_code not in [200, 201]: + raise models.ErrorResponseException(self._deserialize, response) + + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize('SourceControlConfiguration', response) + if response.status_code == 201: + deserialized = self._deserialize('SourceControlConfiguration', response) + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + return client_raw_response + + return deserialized + create_or_update.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{clusterRp}/{clusterResourceName}/{clusterName}/providers/Microsoft.KubernetesConfiguration/sourceControlConfigurations/{sourceControlConfigurationName}'} + + + def _delete_initial( + self, resource_group_name, cluster_rp, cluster_resource_name, cluster_name, source_control_configuration_name, custom_headers=None, raw=False, **operation_config): + # Construct URL + url = self.delete.metadata['url'] + path_format_arguments = { + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'clusterRp': self._serialize.url("cluster_rp", cluster_rp, 'str'), + 'clusterResourceName': self._serialize.url("cluster_resource_name", cluster_resource_name, 'str'), + 'clusterName': self._serialize.url("cluster_name", cluster_name, 'str'), + 'sourceControlConfigurationName': self._serialize.url("source_control_configuration_name", source_control_configuration_name, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + + # Construct headers + header_parameters = {} + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct and send request + request = self._client.delete(url, query_parameters, header_parameters) + response = self._client.send(request, stream=False, **operation_config) + + if response.status_code not in [200, 204]: + raise models.ErrorResponseException(self._deserialize, response) + + if raw: + client_raw_response = ClientRawResponse(None, response) + return client_raw_response + + def delete( + self, resource_group_name, cluster_rp, cluster_resource_name, cluster_name, source_control_configuration_name, custom_headers=None, raw=False, polling=True, **operation_config): + """This will delete the YAML file used to set up the Source control + configuration, thus stopping future sync from the source repo. + + :param resource_group_name: The name of the resource group. + :type resource_group_name: str + :param cluster_rp: The Kubernetes cluster RP - either + Microsoft.ContainerService (for AKS clusters) or Microsoft.Kubernetes + (for OnPrem K8S clusters). Possible values include: + 'Microsoft.ContainerService', 'Microsoft.Kubernetes' + :type cluster_rp: str + :param cluster_resource_name: The Kubernetes cluster resource name - + either managedClusters (for AKS clusters) or connectedClusters (for + OnPrem K8S clusters). Possible values include: 'managedClusters', + 'connectedClusters' + :type cluster_resource_name: str + :param cluster_name: The name of the kubernetes cluster. + :type cluster_name: str + :param source_control_configuration_name: Name of the Source Control + Configuration. + :type source_control_configuration_name: str + :param dict custom_headers: headers that will be added to the request + :param bool raw: The poller return type is ClientRawResponse, the + direct response alongside the deserialized response + :param polling: True for ARMPolling, False for no polling, or a + polling object for personal polling strategy + :return: An instance of LROPoller that returns None or + ClientRawResponse if raw==True + :rtype: ~msrestazure.azure_operation.AzureOperationPoller[None] or + ~msrestazure.azure_operation.AzureOperationPoller[~msrest.pipeline.ClientRawResponse[None]] + :raises: + :class:`ErrorResponseException` + """ + raw_result = self._delete_initial( + resource_group_name=resource_group_name, + cluster_rp=cluster_rp, + cluster_resource_name=cluster_resource_name, + cluster_name=cluster_name, + source_control_configuration_name=source_control_configuration_name, + custom_headers=custom_headers, + raw=True, + **operation_config + ) + + def get_long_running_output(response): + if raw: + client_raw_response = ClientRawResponse(None, response) + return client_raw_response + + lro_delay = operation_config.get( + 'long_running_operation_timeout', + self.config.long_running_operation_timeout) + if polling is True: polling_method = ARMPolling(lro_delay, **operation_config) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + delete.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{clusterRp}/{clusterResourceName}/{clusterName}/providers/Microsoft.KubernetesConfiguration/sourceControlConfigurations/{sourceControlConfigurationName}'} + + def list( + self, resource_group_name, cluster_rp, cluster_resource_name, cluster_name, custom_headers=None, raw=False, **operation_config): + """List all Source Control Configurations. + + :param resource_group_name: The name of the resource group. + :type resource_group_name: str + :param cluster_rp: The Kubernetes cluster RP - either + Microsoft.ContainerService (for AKS clusters) or Microsoft.Kubernetes + (for OnPrem K8S clusters). Possible values include: + 'Microsoft.ContainerService', 'Microsoft.Kubernetes' + :type cluster_rp: str + :param cluster_resource_name: The Kubernetes cluster resource name - + either managedClusters (for AKS clusters) or connectedClusters (for + OnPrem K8S clusters). Possible values include: 'managedClusters', + 'connectedClusters' + :type cluster_resource_name: str + :param cluster_name: The name of the kubernetes cluster. + :type cluster_name: str + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :param operation_config: :ref:`Operation configuration + overrides`. + :return: An iterator like instance of SourceControlConfiguration + :rtype: + ~azure.mgmt.kubernetesconfiguration.models.SourceControlConfigurationPaged[~azure.mgmt.kubernetesconfiguration.models.SourceControlConfiguration] + :raises: + :class:`ErrorResponseException` + """ + def prepare_request(next_link=None): + if not next_link: + # Construct URL + url = self.list.metadata['url'] + path_format_arguments = { + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'clusterRp': self._serialize.url("cluster_rp", cluster_rp, 'str'), + 'clusterResourceName': self._serialize.url("cluster_resource_name", cluster_resource_name, 'str'), + 'clusterName': self._serialize.url("cluster_name", cluster_name, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') + + else: + url = next_link + query_parameters = {} + + # Construct headers + header_parameters = {} + header_parameters['Accept'] = 'application/json' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct and send request + request = self._client.get(url, query_parameters, header_parameters) + return request + + def internal_paging(next_link=None): + request = prepare_request(next_link) + + response = self._client.send(request, stream=False, **operation_config) + + if response.status_code not in [200]: + raise models.ErrorResponseException(self._deserialize, response) + + return response + + # Deserialize response + header_dict = None + if raw: + header_dict = {} + deserialized = models.SourceControlConfigurationPaged(internal_paging, self._deserialize.dependencies, header_dict) + + return deserialized + list.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{clusterRp}/{clusterResourceName}/{clusterName}/providers/Microsoft.KubernetesConfiguration/sourceControlConfigurations'} diff --git a/src/k8s-extension/azext_k8s_extension/vendored_sdks/version.py b/src/k8s-extension/azext_k8s_extension/vendored_sdks/version.py new file mode 100644 index 00000000000..3e682bbd5fb --- /dev/null +++ b/src/k8s-extension/azext_k8s_extension/vendored_sdks/version.py @@ -0,0 +1,13 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +VERSION = "0.3.0" + diff --git a/src/k8s-extension/setup.py b/src/k8s-extension/setup.py new file mode 100644 index 00000000000..d3d491fd48c --- /dev/null +++ b/src/k8s-extension/setup.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python + +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + + +from codecs import open +from setuptools import setup, find_packages +import azext_k8s_extension._consts as consts +try: + from azure_bdist_wheel import cmdclass +except ImportError: + from distutils import log as logger + logger.warn("Wheel is not available, disabling bdist_wheel hook") + +# The full list of classifiers is available at +# https://pypi.python.org/pypi?%3Aaction=list_classifiers +CLASSIFIERS = [ + 'Development Status :: 4 - Beta', + 'Intended Audience :: Developers', + 'Intended Audience :: System Administrators', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'License :: OSI Approved :: MIT License', +] + +# TODO: Add any additional SDK dependencies here +DEPENDENCIES = [] + +with open('README.rst', 'r', encoding='utf-8') as f: + README = f.read() +with open('HISTORY.rst', 'r', encoding='utf-8') as f: + HISTORY = f.read() + +setup( + name=consts.EXTENSION_NAME, + version=consts.VERSION, + description='Microsoft Azure Command-Line Tools K8s-extension Extension', + # TODO: Update author and email, if applicable + author='Microsoft Corporation', + author_email='azpycli@microsoft.com', + # TODO: consider pointing directly to your source code instead of the generic repo + url='https://github.com/Azure/azure-cli-extensions', + long_description=README + '\n\n' + HISTORY, + license='MIT', + classifiers=CLASSIFIERS, + packages=find_packages(), + install_requires=DEPENDENCIES, + package_data={'azext_k8s_extension': ['azext_metadata.json']}, +)