如何使用加密和网络访问策略创建 Azure 托管磁盘快照?
How to create Azure Managed Disk Snapshot with Encryption and Network Access Policy?
我正在尝试使用 SDK 通过以下方法为托管磁盘创建快照
azureSdkClients
.getComputeManager()
.snapshots()
.define(snapshotName)
.withRegion(disk.regionId)
.withExistingResourceGroup(context.resourceGroupName);
.withWindowsFromDisk(context.azureDisk)
.withIncremental(incr)
.create()
但这没有设置加密和网络访问策略的选项? SDK API 支持吗?还是我应该使用不同的 API ?
我将 SnapshotInner 视为 Snapshot 的一种实现。我不确定我是否可以使用内部 class,因为它不允许我设置快照的名称
问题请参考以下步骤
SDK
<dependency>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager-compute</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager-keyvault</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.2.3</version>
</dependency>
代码
String clientId="";
String clientSecret="";
String tenant="";
String subId="";
AzureProfile profile = new AzureProfile(tenant,subId, AzureEnvironment.AZURE);
TokenCredential credential = new ClientSecretCredentialBuilder()
.clientId(clientId)
.clientSecret(clientSecret)
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
.tenantId(tenant)
.build();
ComputeManagementClientImpl computeClient = new ComputeManagementClientBuilder()
.pipeline(HttpPipelineProvider.buildHttpPipeline(credential,profile))
.endpoint(profile.getEnvironment().getResourceManagerEndpoint())
.subscriptionId(profile.getSubscriptionId())
.buildClient();
SnapshotInner sp = new SnapshotInner()
.withCreationData(new CreationData().withSourceResourceId("") .withCreateOption(DiskCreateOption.COPY))
.withSku(new SnapshotSku().withName(SnapshotStorageAccountTypes.PREMIUM_LRS))
.withEncryption(new Encryption().withType(EncryptionType.ENCRYPTION_AT_REST_WITH_PLATFORM_KEY))
.withNetworkAccessPolicy(NetworkAccessPolicy.ALLOW_ALL)
.withLocation("eastasia");
computeClient.getSnapshots().createOrUpdate("testdata","testdfg",sp);
详情请参考here。
我正在尝试使用 SDK 通过以下方法为托管磁盘创建快照
azureSdkClients
.getComputeManager()
.snapshots()
.define(snapshotName)
.withRegion(disk.regionId)
.withExistingResourceGroup(context.resourceGroupName);
.withWindowsFromDisk(context.azureDisk)
.withIncremental(incr)
.create()
但这没有设置加密和网络访问策略的选项? SDK API 支持吗?还是我应该使用不同的 API ? 我将 SnapshotInner 视为 Snapshot 的一种实现。我不确定我是否可以使用内部 class,因为它不允许我设置快照的名称
问题请参考以下步骤
SDK
<dependency>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager-compute</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager-keyvault</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.2.3</version>
</dependency>
代码
String clientId="";
String clientSecret="";
String tenant="";
String subId="";
AzureProfile profile = new AzureProfile(tenant,subId, AzureEnvironment.AZURE);
TokenCredential credential = new ClientSecretCredentialBuilder()
.clientId(clientId)
.clientSecret(clientSecret)
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
.tenantId(tenant)
.build();
ComputeManagementClientImpl computeClient = new ComputeManagementClientBuilder()
.pipeline(HttpPipelineProvider.buildHttpPipeline(credential,profile))
.endpoint(profile.getEnvironment().getResourceManagerEndpoint())
.subscriptionId(profile.getSubscriptionId())
.buildClient();
SnapshotInner sp = new SnapshotInner()
.withCreationData(new CreationData().withSourceResourceId("") .withCreateOption(DiskCreateOption.COPY))
.withSku(new SnapshotSku().withName(SnapshotStorageAccountTypes.PREMIUM_LRS))
.withEncryption(new Encryption().withType(EncryptionType.ENCRYPTION_AT_REST_WITH_PLATFORM_KEY))
.withNetworkAccessPolicy(NetworkAccessPolicy.ALLOW_ALL)
.withLocation("eastasia");
computeClient.getSnapshots().createOrUpdate("testdata","testdfg",sp);
详情请参考here。