-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Enable NFS Azure file Storage for managed environment #7155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wangzelin007
merged 3 commits into
Azure:main
from
LaylaLiu-gmail:user/layliu/Enablenfsazurefile
Feb 4, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
src/containerapp/azext_containerapp/containerapp_env_storage_decorator.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # 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 import AzCliCommand | ||
| from azure.cli.command_modules.containerapp.base_resource import BaseResource | ||
| from azure.cli.core.azclierror import RequiredArgumentMissingError, ValidationError | ||
| from knack.log import get_logger | ||
| from typing import Any, Dict | ||
|
|
||
| from ._client_factory import handle_raw_exception | ||
| from ._models import AzureFileProperties, NfsAzureFileProperties, ManagedEnvironmentStorageProperties | ||
| from ._constants import AZURE_FILE_STORAGE_TYPE, NFS_AZURE_FILE_STORAGE_TYPE | ||
| logger = get_logger(__name__) | ||
|
|
||
|
|
||
| class ContainerappEnvStorageDecorator(BaseResource): | ||
|
|
||
| def __init__(self, cmd: AzCliCommand, client: Any, raw_parameters: Dict, models: str): | ||
| super().__init__(cmd, client, raw_parameters, models) | ||
| self.managed_environment_storage_def = ManagedEnvironmentStorageProperties | ||
| self.storage_type = self.get_argument_storage_type() | ||
| self.azure_file_account_name = self.get_argument_azure_file_account_name() | ||
| self.azure_file_share_name = self.get_argument_azure_file_share_name() | ||
| self.azure_file_account_key = self.get_argument_azure_file_account_key() | ||
| self.server = self.get_argument_server() | ||
| self.access_mode = self.get_argument_access_mode() | ||
|
|
||
| def get_argument_storage_name(self): | ||
| return self.get_param("storage_name") | ||
|
|
||
| def get_argument_storage_type(self): | ||
| return self.get_param("storage_type") | ||
|
|
||
| def get_argument_azure_file_account_name(self): | ||
| return self.get_param("azure_file_account_name") | ||
|
|
||
| def get_argument_azure_file_share_name(self): | ||
| return self.get_param("azure_file_share_name") | ||
|
|
||
| def get_argument_azure_file_account_key(self): | ||
| return self.get_param("azure_file_account_key") | ||
|
|
||
| def get_argument_server(self): | ||
| return self.get_param("server") | ||
|
|
||
| def get_argument_access_mode(self): | ||
| return self.get_param("access_mode") | ||
|
|
||
| def construct_payload(self): | ||
| if not self.storage_type or self.storage_type.lower() == AZURE_FILE_STORAGE_TYPE.lower(): | ||
| storage_def = AzureFileProperties | ||
| storage_def["accountKey"] = self.azure_file_account_key | ||
| storage_def["accountName"] = self.azure_file_account_name | ||
| storage_def["shareName"] = self.azure_file_share_name | ||
| storage_def["accessMode"] = self.access_mode | ||
|
|
||
| self.managed_environment_storage_def["properties"] = {} | ||
| self.managed_environment_storage_def["properties"]["azureFile"] = storage_def | ||
| elif self.storage_type.lower() == NFS_AZURE_FILE_STORAGE_TYPE.lower(): | ||
| storage_def = NfsAzureFileProperties | ||
| storage_def["server"] = self.server | ||
| storage_def["shareName"] = self.azure_file_share_name | ||
| storage_def["accessMode"] = self.access_mode | ||
| self.managed_environment_storage_def["properties"] = {} | ||
| self.managed_environment_storage_def["properties"]["nfsAzureFile"] = storage_def | ||
|
|
||
| def validate_arguments(self): | ||
| import json | ||
| if not self.storage_type or self.storage_type.lower() == AZURE_FILE_STORAGE_TYPE: | ||
| if len(self.azure_file_share_name) == 0 or len(self.azure_file_account_name) == 0 or len( | ||
| self.azure_file_account_key) == 0 or len(self.access_mode) == 0: | ||
| raise RequiredArgumentMissingError( | ||
| "--azure-file-share-name/--file-share/-f, --azure-file-account-key/--storage-account-key/-k, and --access-mode must be provided for AzureFile storage type") | ||
| if len(self.azure_file_share_name) < 3: | ||
| raise ValidationError("File share name with --azure-file-share-name/--file-share/-f must be longer than 2 characters.") | ||
| if len(self.azure_file_account_name) < 3: | ||
| raise ValidationError("Account name with --azure-file-account-name/--account-name/-a must be longer than 2 characters.") | ||
| elif self.storage_type.lower() == NFS_AZURE_FILE_STORAGE_TYPE: | ||
| if len(self.server) == 0 or len(self.access_mode) == 0 or len(self.azure_file_share_name) == 0: | ||
| raise RequiredArgumentMissingError( | ||
| "--server, --file-share/-f and --access-mode must be provided for NfsAzureFile storage type") | ||
| if len(self.server) < 3: | ||
| raise ValidationError("Server with --server must be longer than 2 characters.") | ||
|
|
||
| try: | ||
| r = self.client.show(cmd=self.cmd, resource_group_name=self.get_argument_resource_group_name(), | ||
| env_name=self.get_argument_name(), name=self.get_argument_storage_name()) | ||
| if r: | ||
| logger.warning( | ||
| 'Only AzureFile account keys can be updated. In order to change the AzureFile share name or account' | ||
| ' name or NfsAzureFile server, please delete this storage and create a new one.') | ||
| except Exception as e: | ||
| string_err = str(e) | ||
| if "ManagedEnvironmentStorageNotFound" in string_err: | ||
| pass | ||
| else: | ||
| handle_raw_exception(e) | ||
|
|
||
| def create_or_update(self): | ||
| try: | ||
| return self.client.create_or_update(cmd=self.cmd, | ||
| resource_group_name=self.get_argument_resource_group_name(), | ||
| env_name=self.get_argument_name(), | ||
| name=self.get_argument_storage_name(), | ||
| storage_envelope=self.managed_environment_storage_def) | ||
| except Exception as e: | ||
| handle_raw_exception(e) | ||
|
|
||
| def show(self): | ||
| try: | ||
| return self.client.show(cmd=self.cmd, | ||
| resource_group_name=self.get_argument_resource_group_name(), | ||
| env_name=self.get_argument_name(), | ||
| name=self.get_argument_storage_name()) | ||
| except Exception as e: | ||
| handle_raw_exception(e) | ||
|
|
||
| def list(self): | ||
| try: | ||
| return self.client.list(cmd=self.cmd, | ||
| resource_group_name=self.get_argument_resource_group_name(), | ||
| env_name=self.get_argument_name()) | ||
| except Exception as e: | ||
| handle_raw_exception(e) | ||
|
|
||
| def delete(self): | ||
| try: | ||
| return self.client.delete(cmd=self.cmd, | ||
| resource_group_name=self.get_argument_resource_group_name(), | ||
| env_name=self.get_argument_name(), | ||
| name=self.get_argument_storage_name()) | ||
| except Exception as e: | ||
| handle_raw_exception(e) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.