问题描述

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

如果想通过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/

【Azure Compute Gallery】使用 Python 代码从 Azure Compute Gallery 复制 Image-Version的更多相关文章

  1. 【Azure 环境】【Azure Developer】使用Python代码获取Azure 中的资源的Metrics定义及数据

    问题描述 使用Python SDK来获取Azure上的各种资源的Metrics的名称以及Metrics Data的示例 问题解答 通过 azure-monitor-query ,可以创建一个 metr ...

  2. 【Azure Redis 缓存】使用Python代码获取Azure Redis的监控指标值 (含Powershell脚本方式)

    问题描述 通过Metrics监控页面,我们能得知当前资源(如Redis)的运行情况与各种指标.如果我们需要把指标下载到本地或者生成JSON数据导入到第三方的监控平台呢?Azure是否可以通过Pytho ...

  3. 【Azure Developer】使用 Python SDK连接Azure Storage Account, 计算Blob大小代码示例

    问题描述 在微软云环境中,使用python SDK连接存储账号(Storage Account)需要计算Blob大小?虽然Azure提供了一个专用工具Azure Storage Explorer可以统 ...

  4. 【Azure Developer】使用Java代码启动Azure VM(虚拟机)

    问题描述 在使用Java的启动Azure VM的过程中,遇见了com.azure.core.management.exception.ManagementException: Status code ...

  5. 【Azure Developer】【Python 】使用 azure.identity 和 azure.common.credentials 获取Azure AD的Access Token的两种方式

    问题描述 使用Python代码,展示如何从Azure AD 中获取目标资源的 Access Token. 如要了解如何从AAD中获取 client id,client secret,tenant id ...

  6. 【Azure Developer】Python代码通过AAD认证访问微软Azure密钥保管库(Azure Key Vault)中机密信息(Secret)

    关键字说明 什么是 Azure Active Directory?Azure Active Directory(Azure AD, AAD) 是 Microsoft 的基于云的标识和访问管理服务,可帮 ...

  7. 【Azure 存储服务】Python模块(azure.cosmosdb.table)直接对表存储(Storage Account Table)做操作示例

    什么是表存储 Azure 表存储是一项用于在云中存储结构化 NoSQL 数据的服务,通过无结构化的设计提供键/属性存储. 因为表存储无固定的数据结构要求,因此可以很容易地随着应用程序需求的发展使数据适 ...

  8. 【Azure Developer】使用Java SDK代码创建Azure VM (包含设置NSG,及添加数据磁盘SSD)

    在参考Azure官方文档进行VM创建时,发现其中没有包含如何设置NSG的内容,以及如何在创建时就添加数据磁盘的代码(设置磁盘为SSD类型).本文的内容以"使用 Java 创建和管理 Azur ...

  9. 【Azure Redis 缓存】 Python连接Azure Redis, 使用redis.ConnectionPool 出现 "ConnectionResetError: [Errno 104] Connection reset by peer"

    问题描述 Python连接Azure Redis, 使用redis.ConnectionPool 出现 "ConnectionResetError: [Errno 104] Connecti ...

  10. 【Azure 存储服务】代码版 Azure Storage Blob 生成 SAS (Shared Access Signature: 共享访问签名)

    问题描述 在使用Azure存储服务,为了有效的保护Storage的Access Keys.可以使用另一种授权方式访问资源(Shared Access Signature: 共享访问签名), 它的好处可 ...

随机推荐

  1. [转帖]JVM-工具-jcmd

    http://events.jianshu.io/p/011f0e3a39ff 一.jcmd 用法 1.1 基本知识 jcmd 是在 JDK1.7 以后,新增了一个命令行工具. jcmd 是一个多功能 ...

  2. Linux上面批量更新SQLSERVER SQL文本文件的办法

    1. 今天同事让帮忙更新几个SQL文件.. 本着自己虽然low 但是不能太low的想法, 简单写一个 shell 脚本来执行. 2. 因为我的linux 里面都安装了 sqlcmd 的工具 所以办法就 ...

  3. Vue3中readonly 和 shallowReadonly和toRaw

    1.readonly 深度只读 被readonly包裹的数据只能够读取. 是一个深度只读,不能够修改. 我们看一下面的代码. 我们想修改值,但是修改后视图无响应. 并且控制台警告目标为只读 reado ...

  4. C/C++ 实现枚举网上邻居信息

    在Windows系统中,通过网络邻居可以方便地查看本地网络中的共享资源和计算机.通过使用Windows API中的一些网络相关函数,我们可以实现枚举网络邻居信息的功能,获取连接到本地网络的其他计算机的 ...

  5. 1.13 导出表劫持ShellCode加载

    在Windows操作系统中,动态链接库DLL是一种可重用的代码库,它允许多个程序共享同一份代码,从而节省系统资源.在程序运行时,如果需要使用某个库中的函数或变量,就会通过链接库来实现.而在Window ...

  6. Linux 应用Kickstart部署系统

    Kickstart 是一种无人值守系统安装方式,其工作原理是预先把原本需要运维人员手工填写的参数保存成文件,当安装过程中需要填写参数时则自动匹配Kickstart生成的文件,所以只要文件内包含了安装过 ...

  7. iSCSI的客户端messages频繁报错问题解决

    问题现象: 在自己的工作站中安装的RAC测试环境,使用了iSCSI模拟共享存储,环境运行OK,但是在messages信息中频繁报错如下: [root@db01rac2 ~]# tail -20f /v ...

  8. Delphi2010中TResourceStream流使用

    Resource可以是任意文件(图像.声音.office都可以),直接打包到编译的exe文件中,调用也非常方便 打开一个新的或已有的delphi工程 1.先在 Project->resource ...

  9. .NET 云原生架构师训练营(模块二 基础巩固 MVC终结点)--学习笔记

    2.3.4 Web API -- MVC终结点 MVC与MVVM 模型绑定 自定义模型绑定器 模型验证 返回数据处理 MVC与MVVM MVC ASP.NET Core MVC 概述:https:// ...

  10. webpack学习笔记(一)安装与试用

    由于初次接触 webpack(官网),对很多方面都不是很理解,在查找部分资料后记录一下自己的见解(本文实践基于webpack4). 1. 个人见解 简单来说,webpack就是js的 打包 工具.个人 ...