Search in sources :

Example 1 with NetworkInterfaceStateWithDescription

use of com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceStateWithDescription 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);
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) NetworkManagementClientImpl(com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl) VirtualNetworkInner(com.microsoft.azure.management.network.implementation.VirtualNetworkInner) NetworkSecurityGroupInner(com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) NetworkInterfaceStateWithDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceStateWithDescription)

Example 2 with NetworkInterfaceStateWithDescription

use of com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceStateWithDescription in project photon-model by vmware.

the class NetworkInterfaceServiceTest method buildValidStartState.

private static NetworkInterfaceStateWithDescription buildValidStartState(NetworkInterfaceDescription nd) {
    NetworkInterfaceStateWithDescription niStateWithDesc = new NetworkInterfaceStateWithDescription();
    niStateWithDesc.id = UUID.randomUUID().toString();
    niStateWithDesc.name = NetworkInterfaceServiceTest.class.getSimpleName();
    niStateWithDesc.networkLink = "/resources/network/net9";
    niStateWithDesc.subnetLink = "/resources/subnet/subnet9";
    niStateWithDesc.securityGroupLinks = Collections.singletonList("/resources/firewall/fw9");
    niStateWithDesc.networkInterfaceDescriptionLink = nd.documentSelfLink;
    niStateWithDesc.description = nd;
    return niStateWithDesc;
}
Also used : NetworkInterfaceStateWithDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceStateWithDescription)

Aggregations

NetworkInterfaceStateWithDescription (com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceStateWithDescription)2 NetworkManagementClientImpl (com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl)1 NetworkSecurityGroupInner (com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner)1 VirtualNetworkInner (com.microsoft.azure.management.network.implementation.VirtualNetworkInner)1 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)1 NetworkInterfaceState (com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState)1