use of com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner in project photon-model by vmware.
the class AzureSecurityGroupUtils method buildSecurityGroup.
private static NetworkSecurityGroupInner buildSecurityGroup(SecurityGroupState sg, String location) {
AssertUtil.assertNotNull(sg, "SecurityGroup state should not be null.");
NetworkSecurityGroupInner nsg = new NetworkSecurityGroupInner();
nsg.withLocation(location);
return nsg;
}
use of com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner 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.NetworkSecurityGroupInner 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.NetworkSecurityGroupInner in project photon-model by vmware.
the class TestAzureProvisionTask method assertVmNetworksConfiguration.
private void assertVmNetworksConfiguration(AzureNicSpecs azureNicSpec, String vmName) throws Throwable {
// This assert is only suitable for real (non-mocking env).
if (this.isMock) {
return;
}
getHost().log(Level.INFO, "%s: Assert network configuration for [%s] VM", this.currentTestName.getMethodName(), this.vmState.name);
ComputeState vm = getHost().getServiceState(null, ComputeState.class, UriUtils.buildUri(getHost(), this.vmState.documentSelfLink));
NetworkInterfaceStateWithDescription primaryNicState = getHost().getServiceState(null, NetworkInterfaceStateWithDescription.class, NetworkInterfaceStateWithDescription.buildUri(UriUtils.buildUri(getHost(), vm.networkInterfaceLinks.get(0))));
// In case that private ip is set explicitly.
assertStaticPrivateIPAddress(azureNicSpec, primaryNicState.address);
assertNotNull("Primary NIC private IP should be set.", primaryNicState.address);
if (primaryNicState.description.assignPublicIpAddress == null || primaryNicState.description.assignPublicIpAddress == Boolean.TRUE) {
assertNotNull("VM address should be set.", vm.address);
assertNotEquals("VM address should not be the same as primary NIC private IP.", vm.address, primaryNicState.address);
} else {
assertNull("VM address should be empty.", vm.address);
}
assertNotNull("Primary NIC security group should be set.", primaryNicState.securityGroupLinks != null);
for (int i = 1; i < vm.networkInterfaceLinks.size(); i++) {
NetworkInterfaceState nonPrimaryNicState = getHost().getServiceState(null, NetworkInterfaceState.class, UriUtils.buildUri(getHost(), vm.networkInterfaceLinks.get(i)));
assertNotNull("Non-primary NIC" + i + " IP should not be set to the privatese ip.", nonPrimaryNicState.address);
assertNull("Non-primary NIC" + i + " security group should not be set.", nonPrimaryNicState.securityGroupLinks);
}
// Ensure that from the list of provided network resource groups,
// and security group resource groups, the one with the correct type has been chosen.
// Verifying the resources can be obtained from this RG, ensures they have been placed
// correctly.
NetworkManagementClientImpl networkClient = getAzureSdkClients().getNetworkManagementClientImpl();
final String vmRGName = vm.customProperties.get(ComputeProperties.RESOURCE_GROUP_NAME);
VirtualNetworkInner provisionedNetwork = AzureTestUtil.getAzureVirtualNetwork(networkClient, vmRGName, AzureTestUtil.AZURE_NETWORK_NAME);
assertNotNull("Azure virtual network object '" + vmRGName + "/" + AzureTestUtil.AZURE_NETWORK_NAME + "' is not found.", provisionedNetwork);
final String sgName = AzureTestUtil.AZURE_SECURITY_GROUP_NAME + "-" + vmName;
NetworkSecurityGroupInner provisionedSG = AzureTestUtil.getAzureSecurityGroup(networkClient, vmRGName, sgName);
assertNotNull("Azure security group object '" + vmRGName + "/" + sgName + "' is not found.", provisionedSG);
}
use of com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner in project photon-model by vmware.
the class TestAzureLongRunningEnumeration method tagAzureResources.
/**
* Add tags, that later should be discovered as part of first enumeration cycle.
*/
private void tagAzureResources() throws Exception {
for (int i = 0; i < numOfVMsToTest; i++) {
// tag v-Net
VirtualNetworkInner vmNetwUpdate = getAzureVirtualNetwork(this.networkManagementClient, azureVMNames.get(i), nicSpecs.get(i).network.name);
Map<String, String> vmNetwTags = new HashMap<>();
vmNetwTags.put(NETWORK_TAG_KEY_PREFIX + azureVMNames.get(i), NETWORK_TAG_VALUE);
vmNetwUpdate.withTags(vmNetwTags);
updateAzureVirtualNetwork(this.networkManagementClient, azureVMNames.get(i), nicSpecs.get(i).network.name, vmNetwUpdate);
// tag VM
VirtualMachineInner vmUpdate = getAzureVirtualMachine(this.computeManagementClient, azureVMNames.get(i), azureVMNames.get(i));
Map<String, String> vmTags = new HashMap<>();
String timeStamp = String.valueOf(Utils.getNowMicrosUtc());
vmTags.put(VM_TAG_KEY_PREFIX + azureVMNames.get(i), VM_TAG_VALUE);
vmTags.put(TIME_STAMP_TAG_KEY, timeStamp);
vmUpdate.withTags(vmTags);
updateAzureVirtualMachine(this.computeManagementClient, azureVMNames.get(i), azureVMNames.get(i), vmUpdate);
// tag Security Group
NetworkSecurityGroupInner sgUpdate = getAzureSecurityGroup(this.networkManagementClient, azureVMNames.get(i), AZURE_SECURITY_GROUP_NAME + "-" + azureVMNames.get(i));
Map<String, String> sgTags = new HashMap<>();
sgTags.put(SG_TAG_KEY_PREFIX + azureVMNames.get(i), SG_TAG_VALUE);
sgUpdate.withTags(sgTags);
sgUpdate.withLocation(AzureTestUtil.AZURE_RESOURCE_GROUP_LOCATION);
updateAzureSecurityGroup(this.networkManagementClient, azureVMNames.get(i), AZURE_SECURITY_GROUP_NAME, sgUpdate);
}
}
Aggregations