use of com.microsoft.azure.management.network.implementation.NetworkSecurityGroupsInner in project photon-model by vmware.
the class AzureInstanceService method createSecurityGroupsIfNotExist.
private void createSecurityGroupsIfNotExist(AzureInstanceContext ctx, AzureInstanceStage nextStage) {
if (ctx.nics.isEmpty()) {
handleAllocation(ctx, nextStage);
return;
}
NetworkSecurityGroupsInner azureClient = getNetworkManagementClientImpl(ctx).networkSecurityGroups();
List<DeferredResult<NetworkSecurityGroupInner>> createSGDR = ctx.nics.stream().filter(nicCtx -> nicCtx.securityGroupState() != null && nicCtx.securityGroup == null).map(nicCtx -> {
SecurityGroupState sgState = nicCtx.securityGroupState();
String rgName = nicCtx.securityGroupRGState != null ? nicCtx.securityGroupRGState.name : ctx.resourceGroup.name();
String msg = "Create Azure Security Group [" + rgName + "/" + sgState.name + "] for [" + nicCtx.nicStateWithDesc.name + "] NIC for [" + ctx.vmName + "] VM";
return AzureSecurityGroupUtils.createSecurityGroup(this, azureClient, sgState, rgName, ctx.resourceGroup.location(), msg).thenCompose(sg -> {
String addMsg = "Add Azure Security Rules to Group [" + rgName + "/" + sgState.name + "] for [" + nicCtx.nicStateWithDesc.name + "] NIC for [" + ctx.vmName + "] VM";
return AzureSecurityGroupUtils.addSecurityRules(this, azureClient, sgState, rgName, sg, addMsg);
}).thenApply(updatedSG -> {
nicCtx.securityGroup = updatedSG;
return updatedSG;
});
}).collect(Collectors.toList());
DeferredResult.allOf(createSGDR).whenComplete((all, exc) -> {
if (exc != null) {
handleError(ctx, exc);
} else {
handleAllocation(ctx, nextStage);
}
});
}
use of com.microsoft.azure.management.network.implementation.NetworkSecurityGroupsInner in project photon-model by vmware.
the class AzureLoadBalancerService method getNetworkSecurityGroupInners.
/**
* Get security groups from Azure and store in context
* These are updated to add firewall rules to allow traffic to flow through the load balancer
*
* @param context Azure load balancer context
* @return DeferredResult
*/
private DeferredResult<AzureLoadBalancerContext> getNetworkSecurityGroupInners(AzureLoadBalancerContext context) {
if (CollectionUtils.isEmpty(context.securityGroupStates)) {
return DeferredResult.completed(context);
}
NetworkSecurityGroupsInner azureSecurityGroupClient = context.azureSdkClients.getNetworkManagementClientImpl().networkSecurityGroups();
List<DeferredResult<NetworkSecurityGroupInner>> networkSecurityGroupInners = context.securityGroupStates.stream().map(securityGroupState -> {
String securityGroupName = securityGroupState.name;
final String msg = "Getting Azure Security Group [" + securityGroupName + "].";
return AzureSecurityGroupUtils.getSecurityGroup(this, azureSecurityGroupClient, AzureUtils.getResourceGroupName(securityGroupState.id), securityGroupName, msg);
}).collect(Collectors.toList());
return DeferredResult.allOf(networkSecurityGroupInners).thenApply(networkSecurityGroupInnerList -> {
context.securityGroupInners = networkSecurityGroupInnerList;
return context;
});
}
use of com.microsoft.azure.management.network.implementation.NetworkSecurityGroupsInner in project photon-model by vmware.
the class AzureLoadBalancerService method updateSecurityGroupRules.
/**
* Update isolation security group with rule to allow traffic on load balancing ports for VMs
* being load balanced
*
* @param context Azure load balancer context
* @return DeferredResult
*/
private DeferredResult<AzureLoadBalancerContext> updateSecurityGroupRules(AzureLoadBalancerContext context) {
if (CollectionUtils.isEmpty(context.securityGroupInners)) {
return DeferredResult.completed(context);
}
// Add security group firewall rules to allow traffic to flow through load balancer routes
updateSecurityRules(context);
NetworkSecurityGroupsInner azureSecurityGroupClient = context.azureSdkClients.getNetworkManagementClientImpl().networkSecurityGroups();
List<DeferredResult<NetworkSecurityGroupInner>> networkSecurityGroupInnerList = context.securityGroupInners.stream().map(networkSecurityGroupInner -> {
final String msg = "Updating security group rules for [" + networkSecurityGroupInner.name() + "] for load balancer [" + context.loadBalancerStateExpanded.name + "].";
logInfo(() -> msg);
return AzureSecurityGroupUtils.createOrUpdateSecurityGroup(this, azureSecurityGroupClient, AzureUtils.getResourceGroupName(networkSecurityGroupInner.id()), networkSecurityGroupInner.name(), networkSecurityGroupInner, msg);
}).collect(Collectors.toList());
return DeferredResult.allOf(networkSecurityGroupInnerList).thenApply(ignored -> context);
}
use of com.microsoft.azure.management.network.implementation.NetworkSecurityGroupsInner in project photon-model by vmware.
the class AzureInstanceContext method getSecurityGroups.
/**
* For every NIC lookup associated Azure Security Groups as specified by
* {@code AzureNicContext.securityGroupState.name}. If any of the security groups is not found
* leave the {@code AzureNicContext.securityGroup} as null and proceed without an exception.
*/
private DeferredResult<AzureInstanceContext> getSecurityGroups(AzureInstanceContext context) {
if (context.nics.isEmpty()) {
return DeferredResult.completed(context);
}
NetworkSecurityGroupsInner azureClient = context.azureSdkClients.getNetworkManagementClientImpl().networkSecurityGroups();
List<DeferredResult<NetworkSecurityGroupInner>> getSecurityGroupDRs = context.nics.stream().filter(nicCtx -> nicCtx.securityGroupState() != null && nicCtx.securityGroupRGState != null).map(nicCtx -> {
String sgName = nicCtx.securityGroupState().name;
String msg = "Getting Azure Security Group [" + nicCtx.securityGroupRGState.name + "/" + sgName + "] for [" + nicCtx.nicStateWithDesc.name + "] NIC for [" + context.vmName + "] VM";
return AzureSecurityGroupUtils.getSecurityGroup(service(), azureClient, nicCtx.securityGroupRGState.name, sgName, msg).thenApply(sg -> {
nicCtx.securityGroup = sg;
return sg;
});
}).collect(Collectors.toList());
return DeferredResult.allOf(getSecurityGroupDRs).handle((all, exc) -> {
if (exc != null) {
String msg = String.format("Error getting Security Group from Azure for [%s] VM.", context.child.name);
throw new IllegalStateException(msg, exc);
}
return context;
});
}
use of com.microsoft.azure.management.network.implementation.NetworkSecurityGroupsInner in project photon-model by vmware.
the class AzureSecurityGroupService method updateRules.
private DeferredResult<AzureSecurityGroupContext> updateRules(AzureSecurityGroupContext context) {
String rgName = context.resourceGroup.name();
final String msg = "Adding Azure Security Rules to Group [" + context.securityGroupState.name + "] in resource group [" + rgName + "].";
NetworkSecurityGroupsInner azureSecurityGroupClient = context.azureSdkClients.getNetworkManagementClientImpl().networkSecurityGroups();
return AzureSecurityGroupUtils.addSecurityRules(this, azureSecurityGroupClient, context.securityGroupState, rgName, context.securityGroup, msg).thenApply(__ -> context);
}
Aggregations