use of com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner in project photon-model by vmware.
the class AzureSecurityGroupServiceTest method testCreateSecurityGroupNoRules.
@Test
public void testCreateSecurityGroupNoRules() throws Throwable {
SecurityGroupState securityGroupState = provisionSecurityGroup(new ArrayList<>(), new ArrayList<>(), TaskStage.FINISHED);
assertNotNull(securityGroupState.id);
assertNotEquals(securityGroupState.id, this.securityGroupName);
if (!this.isMock) {
// Verify that the security group was created.
NetworkSecurityGroupInner sgResponse = this.securityGroupsClient.getByResourceGroup(this.rgName, this.securityGroupName);
assertEquals(this.securityGroupName, sgResponse.name());
assertEquals(securityGroupState.id, sgResponse.id());
assertEquals(sgResponse.securityRules().size(), 0);
// delete the security group
startSecurityGroupProvisioning(InstanceRequestType.DELETE, securityGroupState, TaskStage.FINISHED);
}
}
use of com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner in project photon-model by vmware.
the class AzureTestUtil method createAzureNetworkSecurityGroup.
private static void createAzureNetworkSecurityGroup(String resourceGroupName, NetworkManagementClientImpl networkManagementClient) throws Exception {
final NetworkSecurityGroupInner sharedNSG = new NetworkSecurityGroupInner();
sharedNSG.withLocation(AzureTestUtil.AZURE_RESOURCE_GROUP_LOCATION);
SecurityRuleInner sr = new SecurityRuleInner();
sr.withPriority(AzureConstants.AZURE_SECURITY_GROUP_PRIORITY);
sr.withAccess(SecurityRuleAccess.ALLOW);
sr.withDirection(SecurityRuleDirection.INBOUND);
sr.withSourceAddressPrefix(AzureConstants.AZURE_SECURITY_GROUP_SOURCE_ADDRESS_PREFIX);
sr.withDestinationAddressPrefix(AzureConstants.AZURE_SECURITY_GROUP_DESTINATION_ADDRESS_PREFIX);
sr.withSourcePortRange(AzureConstants.AZURE_SECURITY_GROUP_SOURCE_PORT_RANGE);
sr.withDestinationPortRange(AzureConstants.AZURE_LINUX_SECURITY_GROUP_DESTINATION_PORT_RANGE);
sr.withName(AzureConstants.AZURE_LINUX_SECURITY_GROUP_NAME);
sr.withProtocol(SecurityRuleProtocol.TCP);
// Azure's custom serializers don't handle well collections constructed with
// Collections.singletonList(), so initialize an ArrayList
ArrayList<SecurityRuleInner> rules = new ArrayList<>();
rules.add(sr);
sharedNSG.withSecurityRules(rules);
networkManagementClient.networkSecurityGroups().createOrUpdate(resourceGroupName, AzureTestUtil.AZURE_SECURITY_GROUP_NAME, sharedNSG);
}
use of com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner 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;
});
}
Aggregations