我在Azure云中有一个虚拟机规模集(vmss)。 如何通过Java应用程序获取缩放设置json?
通常,我需要获取其最大和最小实例限制及其缩放规则。
要定义我的vmss,请使用:
Azure azure = Azure.configure().authenticate(new File(myAzureCredentialsFilePath)).withDefaultSubscription();
VirtualMachineScaleSet vmss = azure.virtualMachineScaleSets().getById("someId");
答案 0 :(得分:0)
您可以使用Azure-SDK for Java来查询刻度集信息。
System.out.println("Listing scale set virtual machine instance network interfaces and SSH connection string...");
for (VirtualMachineScaleSetVM instance : virtualMachineScaleSet.virtualMachines().list()) {
System.out.println("Scale set virtual machine instance #" + instance.instanceId());
System.out.println(instance.id());
PagedList<VirtualMachineScaleSetNetworkInterface> networkInterfaces = instance.listNetworkInterfaces();
// Pick the first NIC
VirtualMachineScaleSetNetworkInterface networkInterface = networkInterfaces.get(0);
for (VirtualMachineScaleSetNicIPConfiguration ipConfig :networkInterface.ipConfigurations().values()) {
if (ipConfig.isPrimary()) {
List<LoadBalancerInboundNatRule> natRules = ipConfig.listAssociatedLoadBalancerInboundNatRules();
for (LoadBalancerInboundNatRule natRule : natRules) {
if (natRule.backendPort() == 22) {
System.out.println("SSH connection string: " + userName + "@" + publicIPAddress.fqdn() + ":" + natRule.frontendPort());
break;
}
}
break;
}
}
}
virtualMachineScaleSet.virtualMachines().list() might give you what you are looking for.
您可以找到更多示例here。希望对您有所帮助。