use of com.microsoft.azure.management.network.implementation.SubnetsInner in project photon-model by vmware.
the class AzureSubnetService method createSubnet.
private DeferredResult<AzureSubnetContext> createSubnet(AzureSubnetContext context) {
SubnetInner subnet = new SubnetInner();
subnet.withName(context.subnetState.name);
subnet.withAddressPrefix(context.subnetState.subnetCIDR);
String rgName = context.parentNetworkResourceGroupName;
String vNetName = context.parentNetwork.name;
final String msg = "Creating Azure Subnet [" + subnet.name() + "] in vNet [" + vNetName + "] in resource group [" + rgName + "].";
SubnetsInner subnetsInner = context.azureSdkClients.getNetworkManagementClientImpl().subnets();
AzureProvisioningCallback<SubnetInner> handler = new AzureProvisioningCallback<SubnetInner>(this, msg) {
@Override
protected DeferredResult<SubnetInner> consumeProvisioningSuccess(SubnetInner subnet) {
// Populate the subnet id with Azure Subnet ID
context.subnetState.id = subnet.id();
return DeferredResult.completed(subnet);
}
@Override
protected String getProvisioningState(SubnetInner subnet) {
return subnet.provisioningState();
}
@Override
protected Runnable checkProvisioningStateCall(ServiceCallback<SubnetInner> checkProvisioningStateCallback) {
return () -> subnetsInner.getAsync(rgName, vNetName, subnet.name(), null, /* expand */
checkProvisioningStateCallback);
}
};
subnetsInner.createOrUpdateAsync(rgName, vNetName, subnet.name(), subnet, handler);
return handler.toDeferredResult().thenApply(ignore -> context);
}
use of com.microsoft.azure.management.network.implementation.SubnetsInner in project photon-model by vmware.
the class AzureInstanceContext method getNetworks.
/**
* For every NIC lookup associated Azure Subnets as specified by
* {@code AzureNicContext.networkState.name} and {@code AzureNicContext.subnetState.name}. If
* any of the subnets is not found leave the {@link AzureNicContext#subnet} as null and proceed
* without an exception.
*/
private DeferredResult<AzureInstanceContext> getNetworks(AzureInstanceContext context) {
if (context.nics.isEmpty()) {
return DeferredResult.completed(context);
}
SubnetsInner azureClient = service().getNetworkManagementClientImpl(context).subnets();
List<DeferredResult<SubnetInner>> getSubnetDRs = context.nics.stream().filter(nicCtx -> nicCtx.networkRGState != null).map(nicCtx -> {
String msg = "Getting Azure Subnet [" + nicCtx.networkRGState.name + "/" + nicCtx.networkState.name + "/" + nicCtx.subnetState.name + "] for [" + nicCtx.nicStateWithDesc.name + "] NIC for [" + context.vmName + "] VM";
AzureDeferredResultServiceCallback<SubnetInner> handler = new AzureDeferredResultServiceCallback<SubnetInner>(service(), msg) {
@Override
protected DeferredResult<SubnetInner> consumeSuccess(SubnetInner subnet) {
nicCtx.subnet = subnet;
return DeferredResult.completed(subnet);
}
};
azureClient.getAsync(nicCtx.networkRGState.name, nicCtx.networkState.name, nicCtx.subnetState.name, null, /* expand */
handler);
return handler.toDeferredResult();
}).collect(Collectors.toList());
return DeferredResult.allOf(getSubnetDRs).handle((all, exc) -> {
if (exc != null) {
String msg = String.format("Error getting Subnets from Azure for [%s] VM.", context.child.name);
throw new IllegalStateException(msg, exc);
}
return context;
});
}
Aggregations