use of com.microsoft.azure.management.network.implementation.VirtualNetworksInner 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.VirtualNetworksInner in project photon-model by vmware.
the class AzureLoadBalancerServiceTest method setUpTests.
@Before
public void setUpTests() throws Throwable {
if (computeHost == null) {
ResourcePoolState resourcePool = createDefaultResourcePool(this.host);
endpointState = this.createEndpointState();
// create a compute host for the Azure
computeHost = createDefaultComputeHost(this.host, resourcePool.documentSelfLink, endpointState);
}
AuthCredentialsServiceState azureVMAuth = new AuthCredentialsServiceState();
azureVMAuth.userEmail = AZURE_ADMIN_USERNAME;
azureVMAuth.privateKey = AZURE_ADMIN_PASSWORD;
azureVMAuth = TestUtils.doPost(host, azureVMAuth, AuthCredentialsServiceState.class, UriUtils.buildUri(host, AuthCredentialsService.FACTORY_LINK));
ComputeDescription compDesc = buildComputeDescription(host, computeHost, endpointState, azureVMAuth);
this.rgName = AzureUtils.DEFAULT_GROUP_PREFIX + compDesc.documentCreationTimeMicros / 1000;
ResourceGroupState rgState = createDefaultResourceGroupState(this.host, this.rgName, computeHost, endpointState, ResourceGroupStateType.AzureResourceGroup);
networkState = createNetworkState(rgState.documentSelfLink);
vmStates = new ArrayList<>();
for (int i = 0; i < poolSize; i++) {
ComputeState vmState = createDefaultVMResource(getHost(), this.rgName + "VM" + i, computeHost, endpointState, NO_PUBLIC_IP_NIC_SPEC, null, 0, compDesc, this.rgName);
vmStates.add(vmState);
}
subnetState = createSubnetState(this.subnetName);
if (!this.isMock) {
this.loadBalancerClient = getAzureSdkClients().getNetworkManagementClientImpl().loadBalancers();
this.rgOpsClient = getAzureSdkClients().getResourceManagementClientImpl().resourceGroups();
ResourceGroupInner rg = new ResourceGroupInner();
rg.withName(this.rgName);
rg.withLocation(this.regionId);
this.rgOpsClient.createOrUpdate(this.rgName, rg);
VirtualNetworkInner vNet = new VirtualNetworkInner();
AddressSpace addressSpace = new AddressSpace();
addressSpace.withAddressPrefixes(Collections.singletonList(AZURE_DEFAULT_VPC_CIDR));
vNet.withAddressSpace(addressSpace);
vNet.withLocation(this.regionId);
VirtualNetworksInner vNetClient = getAzureSdkClients().getNetworkManagementClientImpl().virtualNetworks();
vNetClient.createOrUpdate(this.rgName, this.vNetName, vNet);
kickOffComputeProvision();
kickOffSubnetProvision(InstanceRequestType.CREATE, subnetState, TaskStage.FINISHED);
}
}
Aggregations