问题描述
我正在尝试使用 SDK 使用以下内容为托管磁盘创建快照
azureSdkClients
.getComputeManager()
.snapshots()
.define(snapshotName)
.withRegion(disk.regionId)
.withExistingResourceGroup(context.resourceGroupName);
.withWindowsFromdisk(context.azuredisk)
.withIncremental(incr)
.create()
但是这没有用于设置加密和网络访问策略的选项? SDK API 是否支持它?还是应该使用不同的 API? 我将 SnapshotInner 视为 Snapshot 的一种实现。我不确定是否可以使用内部类,因为它不允许我设置快照的名称
解决方法
关于问题,请参考以下步骤
开发工具包
<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。