首页 > 编程语言 >【Azure Compute Gallery】使用 Python 代码从 Azure Compute Gallery 复制 Image-Version

【Azure Compute Gallery】使用 Python 代码从 Azure Compute Gallery 复制 Image-Version

时间:2024-01-23 21:02:20浏览次数:27  
标签:Compute name image gallery azure mgmt Azure compute Gallery

问题描述

Azure Compute Gallery 可以帮助围绕 Azure 资源(例如映像和应用程序)生成结构和组织,并且支持全局复制。

【Azure Compute Gallery】使用 Python 代码从 Azure Compute Gallery 复制 Image-Version_Image

如果想通过Python代码实现 Image-Version从一个Azure Compute Gallery复制到另一个中,如何实现呢?

 

问题解答

示例Python代码:

import os
from msrestazure.azure_cloud import AZURE_CHINA_CLOUD as CLOUD
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
from azure.mgmt.compute.models import GalleryImageVersion, GalleryImageVersionStorageProfile, GalleryImageVersionPublishingProfile, GalleryArtifactVersionSource, TargetRegion

credential = DefaultAzureCredential(authority=CLOUD.endpoints.active_directory)
SUBSCRIPTION_ID = "{subscriptionId}"

client = ComputeManagementClient(credential, subscription_id=SUBSCRIPTION_ID,
        base_url = CLOUD.endpoints.resource_manager,
        credential_scopes = [CLOUD.endpoints.resource_manager + "/.default"]
    )

//设置源 Image Version的Resource ID ...
source = GalleryArtifactVersionSource(id=" /subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/galleries/{galleryName}/images/{imageDefinitionName}/versions/{versionName}")
storageprofile = GalleryImageVersionStorageProfile(source=source)

//设置目标region
targetregion = TargetRegion(name="{region}")
publishingprofile = GalleryImageVersionPublishingProfile(target_regions=[targetregion], replica_count=1, exclude_from_latest=True)

imageversion = GalleryImageVersion(location="{region}", publishing_profile=publishingprofile, storage_profile=storageprofile)

image_creation = client.gallery_image_versions.begin_create_or_update(resource_group_name
="{resourceGroup}", gallery_name="{galleryName}", gallery_image_name="{imageDefinitionName}", gallery_image_version_name="{versionName}", gallery_image_version=imageversion)

// 创建目标 Image Version
image_creation.wait()

注意: {subscriptionId} , {galleryName},{resourceGroup},{region},{imageDefinitionName},{versionName} 均需要替换为对应的真实值。

 

 

参考资料

Python对Gallery Images Version操作的Python class GalleryImageVersionsOperations :  https://learn.microsoft.com/en-us/python/api/azure-mgmt-compute/azure.mgmt.compute.v2021_07_01.operations.galleryimageversionsoperations?view=azure-python

使用ComputeManagementClient class的gallery_image_version属性来初始化 : https://learn.microsoft.com/en-us/python/api/azure-mgmt-compute/azure.mgmt.compute.v2021_07_01.computemanagementclient?view=azure-python

 

 

 

/END/


当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!

标签:Compute,name,image,gallery,azure,mgmt,Azure,compute,Gallery
From: https://blog.51cto.com/u_13773780/9385984

相关文章

  • Microsoft 365:如何在Azure AD中注册Application并授权相关Graph API
    51CTOBlog地址:https://blog.51cto.com/u_13969817在使用Powershell连接GraphAPI之前,首先管理员要在AzureAD中新建Application,并授权APIPermission和Credentials,本文将给大家做细节介绍:·      在AzureAD中注册Application·      授权GraphAPIPermission· ......
  • 【Azure Compute Gallery】使用 Python 代码从 Azure Compute Gallery 复制 Image-Ver
    问题描述AzureComputeGallery可以帮助围绕Azure资源(例如映像和应用程序)生成结构和组织,并且支持全局复制。如果想通过Python代码实现Image-Version从一个AzureComputeGallery复制到另一个中,如何实现呢? 问题解答示例Python代码:importosfrommsrestazure.azure_cl......
  • 如何为Azure Kubernetes Services启用Internal Loadbalancer
    如何为AzureKubernetesServices启用InternalLoadbalancer熟悉AzureKubernetesServices(AKS)的小伙伴都知道,默认情况下,当我们创建AzureKubernetesServices群集时,创建的都是Public的AKS群集,也就是可以提供Internet访问的AKS群集。PublicAKS群集会默认附带一个Public类型的Load......
  • 【Azure Redis】PHPRedis遇见SSL Connection Timeout问题
    问题描述PHPRedis客户端遇见使用SSLConnectiontimeout,遇见问题后,切换回去Non-SSL没有出现问题。但是切换回SSL后,还是偶尔遇见Connectiontimeout问题。目前timeout设置时间为5秒,并且为例重用连接,启用了持久化redis.pconnect.pooling_enabled为1.是否有办法来缓解Timeout问题呢?......
  • 将 .NET 8应用 以 dotnet publish 创建容器镜像并结合 Github Actions 部署到 Azure
    介绍.NET8无需DockerFile即可为.NET应用创建docker映像的新方法,我将使用dotnetpublish将.NET应用容器化,在本文中,我将分享我如何为.NET8的项目创建一个简单的ci/cd的经验。它包括2个主题:创建用于生成.NET应用并将其发布到Azure的GitHub工作流如何使用do......
  • 将.NET Core项目部署到Azure WebJob - Azure SDK
    前提条件已经完成了前四篇文章中的所有步骤。安装了Microsoft.Azure.WebJobs和Microsoft.Azure.WebJobs.Extensions包。创建WebJob在你的项目中,创建一个新的类:SayHelloWebJob。在SayHelloWebJob类中,添加以下代码:usingMicrosoft.Azure.WebJobs;usingSystem;publiccla......
  • 将.NET Core项目部署到Azure WebJob - CRON
    前提条件已经完成了前三篇文章中的所有步骤。学习CRON表达式CRON表达式是一种强大的工具,可以用来描述时间表。你可以使用CRON表达式来配置你的WebJob在特定的时间运行。我推荐你访问这个网站来学习CRON表达式:https://www.baeldung.com/cron-expressions创建settings.job文件......
  • 将.NET Core项目部署到Azure App Service
    步骤1:创建ASP.NETCoreWeb应用首先,确保你已经安装了.NETCoreSDK。dotnetnewwebapp-nAzureSampleAppcdAzureSampleApp这将创建一个新的ASP.NETCoreWeb应用,并将目录更改为新创建的应用目录。步骤2:一个简单的首页编辑Pages/Index.cshtml文件,添加一些内容来展......
  • 【Azure Function】在Function执行中遇见Timeout错误
    问题描述在Function执行中遇见Timeout错误: Microsoft.Azure.WebJobs.Host.FunctionTimeoutException/Timeoutvalueof00:30:00wasexceededbyfunction/Functions.TimerTrigger_UdeskContact    asyncMicrosoft.Azure.WebJobs.Host.Executors.FunctionExecutor.TryHandl......
  • 【Azure Function】在Function执行中遇见Timeout错误
    问题描述在Function执行中遇见Timeout错误: Microsoft.Azure.WebJobs.Host.FunctionTimeoutException/Timeoutvalueof00:30:00wasexceededbyfunction/Functions.TimerTrigger_UdeskContact    asyncMicrosoft.Azure.WebJobs.Host.Executors.FunctionExecutor.TryHa......