use of com.microsoft.azure.management.network.implementation.SubnetInner 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.SubnetInner 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;
});
}
use of com.microsoft.azure.management.network.implementation.SubnetInner in project photon-model by vmware.
the class AzureInstanceService method createNetwork.
private void createNetwork(AzureInstanceContext ctx, AzureInstanceStage nextStage, List<SubnetInner> subnetsToCreate) {
// All NICs MUST be at the same vNet (no cross vNet VMs),
// so we select the Primary vNet.
final AzureNicContext primaryNic = ctx.getPrimaryNic();
final VirtualNetworkInner vNetToCreate = newAzureVirtualNetwork(ctx, primaryNic, subnetsToCreate);
final String vNetName = primaryNic.networkState.name;
final String vNetRGName = primaryNic.networkRGState != null ? primaryNic.networkRGState.name : ctx.resourceGroup.name();
VirtualNetworksInner azureClient = getNetworkManagementClientImpl(ctx).virtualNetworks();
final String subnetNames = vNetToCreate.subnets().stream().map(SubnetInner::name).collect(Collectors.joining(","));
final String msg = "Creating Azure vNet-Subnet [v=" + vNetName + "; s=" + subnetNames + "] for [" + ctx.vmName + "] VM";
AzureProvisioningCallbackWithRetry<VirtualNetworkInner> handler = new AzureProvisioningCallbackWithRetry<VirtualNetworkInner>(this, msg) {
@Override
protected DeferredResult<VirtualNetworkInner> consumeProvisioningSuccess(VirtualNetworkInner vNet) {
// Populate NICs with Azure Subnet
for (AzureNicContext nicCtx : ctx.nics) {
if (nicCtx.subnet == null) {
nicCtx.subnet = vNet.subnets().stream().filter(subnet -> subnet.name().equals(nicCtx.subnetState.name)).findFirst().get();
}
}
return DeferredResult.completed(vNet);
}
@Override
protected String getProvisioningState(VirtualNetworkInner vNet) {
// or PROVISIONING_STATE_SUCCEEDED if all are Succeeded
if (vNet.subnets().size() == 0) {
return PROVISIONING_STATE_FAILED_NO_SUBNET;
}
String subnetPS = vNet.subnets().stream().map(SubnetInner::provisioningState).filter(ps -> !PROVISIONING_STATE_SUCCEEDED.equalsIgnoreCase(ps)).findFirst().orElse(PROVISIONING_STATE_SUCCEEDED);
if (PROVISIONING_STATE_SUCCEEDED.equalsIgnoreCase(vNet.provisioningState()) && PROVISIONING_STATE_SUCCEEDED.equalsIgnoreCase(subnetPS)) {
return PROVISIONING_STATE_SUCCEEDED;
}
return vNet.provisioningState() + ":" + subnetPS;
}
@Override
protected Runnable checkProvisioningStateCall(ServiceCallback<VirtualNetworkInner> checkProvisioningStateCallback) {
return () -> azureClient.getByResourceGroupAsync(vNetRGName, vNetName, null, /* expand */
checkProvisioningStateCallback);
}
@Override
protected Runnable retryServiceCall(ServiceCallback<VirtualNetworkInner> retryCallback) {
return () -> azureClient.createOrUpdateAsync(vNetRGName, vNetName, vNetToCreate, retryCallback);
}
};
azureClient.createOrUpdateAsync(vNetRGName, vNetName, vNetToCreate, handler);
handler.toDeferredResult().thenApply(ignore -> ctx).whenComplete(thenAllocation(ctx, nextStage, NETWORK_NAMESPACE));
}
use of com.microsoft.azure.management.network.implementation.SubnetInner in project photon-model by vmware.
the class AzureSubnetTaskServiceTest method createAzureSubnet.
private SubnetInner createAzureSubnet() throws Throwable {
SubnetInner subnet = new SubnetInner();
subnet.withName(this.subnetName);
subnet.withId(UUID.randomUUID().toString());
subnet.withAddressPrefix(AZURE_NON_EXISTING_SUBNET_CIDR);
if (this.isMock) {
return subnet;
}
SubnetInner subnetResponse = this.subnetsClient.createOrUpdate(this.rgName, this.vNetName, this.subnetName, subnet);
return subnetResponse;
}
use of com.microsoft.azure.management.network.implementation.SubnetInner in project photon-model by vmware.
the class AzureInstanceService method newAzureSubnet.
/**
* Converts Photon model constructs to underlying Azure VirtualNetwork-Subnet model.
*/
private SubnetInner newAzureSubnet(AzureNicContext nicCtx) {
SubnetInner subnet = new SubnetInner();
subnet.withName(nicCtx.subnetState.name);
subnet.withAddressPrefix(nicCtx.subnetState.subnetCIDR);
return subnet;
}
Aggregations