-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[Packaging] Bump bundled python to 3.8.9 and remove more network SDK APIs for MSI
#17816
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
Changes from all commits
3303d96
de15ac9
1924571
1e5e047
1ddabc2
bfe62da
fc4e414
c302175
5f8ae77
0098b84
14349b7
5cec09b
c6dcf54
361d8a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| import logging | ||
| import os | ||
| import re | ||
| import shutil | ||
| import azure.mgmt.network | ||
|
|
||
| from azure.cli.core.profiles import AD_HOC_API_VERSIONS, AZURE_API_PROFILES, ResourceType | ||
|
|
||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def remove_unused_network_api_versions(): | ||
| # Hard-coded API versions | ||
| used_network_api_versions = set(AD_HOC_API_VERSIONS[ResourceType.MGMT_NETWORK].values()) | ||
|
|
||
| # API versions in profile | ||
| for _, profile in AZURE_API_PROFILES.items(): | ||
| if ResourceType.MGMT_NETWORK in profile: | ||
| used_network_api_versions.add(profile[ResourceType.MGMT_NETWORK]) | ||
|
|
||
| # Normalize API version: 2019-02-01 -> v2019_02_01 | ||
| used_network_api_vers = {f"v{api.replace('-','_')}" for api in used_network_api_versions} | ||
|
|
||
| # Network SDK has a set of versions imported in models.py. | ||
| # Let's keep them before we figure out how to remove a version in all related SDK files. | ||
| path = azure.mgmt.network.__path__[0] | ||
| model_file = os.path.join(path, 'models.py') | ||
| with open(model_file, 'r', encoding='utf-8') as f: | ||
| content = f.read() | ||
| for m in re.finditer(r'from \.(v[_\d]*)\.models import \*', content): | ||
| used_network_api_vers.add(m.group(1)) | ||
|
|
||
| _LOGGER.info('Used network API versions:') | ||
| _LOGGER.info(sorted(used_network_api_vers)) | ||
|
|
||
| all_api_vers = {d for d in os.listdir(path) if os.path.isdir(os.path.join(path, d)) and d.startswith('v')} | ||
| _LOGGER.info('All network API versions:') | ||
| _LOGGER.info(sorted(all_api_vers)) | ||
|
|
||
| remove_api_vers = sorted(all_api_vers - used_network_api_vers) | ||
| _LOGGER.info('Network API versions that will be removed:') | ||
| _LOGGER.info(remove_api_vers) | ||
|
|
||
| for ver in remove_api_vers: | ||
| shutil.rmtree(os.path.join(path, ver)) | ||
|
|
||
|
|
||
| def main(): | ||
| remove_unused_network_api_versions() | ||
|
|
||
| if __name__ == "__main__": | ||
| logging.basicConfig(level=logging.INFO) | ||
| main() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,10 +28,10 @@ def get_target_network_api(cli_ctx): | |
| necessarily latest, network API version is order to avoid having to re-record every test that uses VM create | ||
| (which there are a lot) whenever NRP bumps their API version (which is often)! | ||
| """ | ||
| from azure.cli.core.profiles import get_api_version, ResourceType | ||
| from azure.cli.core.profiles import get_api_version, ResourceType, AD_HOC_API_VERSIONS | ||
| version = get_api_version(cli_ctx, ResourceType.MGMT_NETWORK) | ||
| if cli_ctx.cloud.profile == 'latest': | ||
| version = '2018-01-01' | ||
| version = AD_HOC_API_VERSIONS[ResourceType.MGMT_NETWORK]['vm_default_target_network'] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Define a const variable? VM_DEFAULT_TARGET_NETWORK = 'vm_default_target_network'
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good suggestion, but as this is temp work, eventually this will be removed, I'll check in as it is now to catch the release. Using hardcoded api version should not be allowed or we should support more dimensions in profile definition so it's possible to use different api versions in different modules. Leave this work to profile owner. |
||
| return version | ||
|
|
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Define a const variable?
VM_DEFAULT_TARGET_NETWORK = 'vm_default_target_network'