我正在尝试使用javasdk在azure中创建几个vm。问题是,在创建机器之后,我无法连接(公共ip是在java代码创建vm之后手动添加的-这对我来说不是强制性的,公共ip不是必需的)。
这是我用来创建机器的代码。
List<Creatable<VirtualMachine>> creatableVirtualMachines = new ArrayList<>();
List<Creatable<NetworkInterface>> creatableNetworkInterfaces = new ArrayList<>();
List<Creatable<Disk>> creatableDisk = new ArrayList<>();
for (int i = 0; i < vmCount; i++) {
Creatable<NetworkInterface> networkInterfaceCreatable = azure.networkInterfaces()
.define("testNIC-" + i)
.withRegion(Region.EUROPE_WEST)
.withExistingResourceGroup("TestRes2")
.withExistingPrimaryNetwork(network)
.withSubnet("default")
.withPrimaryPrivateIPAddressDynamic();
creatableNetworkInterfaces.add(networkInterfaceCreatable);
Creatable<Disk> disksCreatable= azure.disks()
.define(SdkContext.randomResourceName("test_dsk", 30))
.withRegion(Region.EUROPE_WEST)
.withNewResourceGroup("TestRes2")
.withWindowsFromVhd("image url")
.withSizeInGB(127)
.withSku(DiskSkuTypes.STANDARD_LRS);
creatableDisk.add(disksCreatable);
}
networkInterfaces = azure.networkInterfaces().create(creatableNetworkInterfaces);
networkInterfacesKeys = new ArrayList(networkInterfaces.keySet());
disks = azure.disks().create(creatableDisk);
disksKeys = new ArrayList(disks.keySet());
for (int i = 0; i < vmCount; i++) {
// Create one virtual machine Creatable
Creatable<VirtualMachine> virtualMachineCreatable = azure.virtualMachines()
.define("TESTVM-" + i)
.withRegion(Region.EUROPE_WEST)
.withExistingResourceGroup("TestRes2")
.withExistingPrimaryNetworkInterface(networkInterfaces.get(networkInterfacesKeys.get(i)))
.withSpecializedOSDisk(disks.get(disksKeys.get(i)), OperatingSystemTypes.WINDOWS)
.withSize(VirtualMachineSizeTypes.STANDARD_B2S);
// add the virtual machine Creatable to the list
creatableVirtualMachines.add(virtualMachineCreatable);
}
virtualMachines = azure.virtualMachines().create(creatableVirtualMachines);
virtualMachinesKeys = new ArrayList(virtualMachines.keySet());
编辑:
当我用的不是图像而是“最新估计”
.withLatestWindowsImage("MicrosoftWindowsServer", "WindowsServer", "2012-R2-Datacenter")
它起作用了。
暂无答案!
目前还没有任何答案,快来回答吧!