Search in sources :

Example 1 with NetworkInterfaceDescription

use of com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription in project photon-model by vmware.

the class VmOverlayTest method findPublicIpAddressWithMacAddresses.

@Test
public void findPublicIpAddressWithMacAddresses() {
    NetworkInterfaceStateWithDetails n1 = new NetworkInterfaceStateWithDetails();
    NetworkInterfaceStateWithDetails n2 = new NetworkInterfaceStateWithDetails();
    String mac1Address = "00:50:56:8b:54:bd";
    String mac2Address = "98:87:fd:9e:ed:6d";
    List<NetworkInterfaceStateWithDetails> nics = new ArrayList();
    nics.add(n1);
    n1.customProperties = new HashMap<>();
    n1.customProperties.put(NIC_MAC_ADDRESS, mac1Address);
    nics.add(n2);
    n2.customProperties = new HashMap<>();
    n2.customProperties.put(NIC_MAC_ADDRESS, mac2Address);
    String publicIpAddress = this.overlay.findPublicIpV4Address(nics);
    Assert.assertTrue("publicIpAddress is null", publicIpAddress != null);
    // test with assignPublicIpAddress
    n1.description = new NetworkInterfaceDescription();
    n1.description.assignPublicIpAddress = true;
    publicIpAddress = this.overlay.findPublicIpV4Address(nics);
    Assert.assertTrue("publicIpAddress is null", publicIpAddress != null);
    Assert.assertTrue("publicIpAddress is null", publicIpAddress.equals("192.168.1.10"));
}
Also used : NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription) ArrayList(java.util.ArrayList) NetworkInterfaceStateWithDetails(com.vmware.photon.controller.model.adapters.vsphere.ProvisionContext.NetworkInterfaceStateWithDetails) Test(org.junit.Test)

Example 2 with NetworkInterfaceDescription

use of com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription in project photon-model by vmware.

the class NetworkInterfaceDescriptionServiceTest method buildValidStartState.

public static NetworkInterfaceDescription buildValidStartState(boolean assignHost) throws Throwable {
    NetworkInterfaceDescription nd = new NetworkInterfaceDescription();
    nd.id = UUID.randomUUID().toString();
    nd.name = NetworkInterfaceDescriptionServiceTest.class.getSimpleName();
    nd.address = "8.8.8.8";
    nd.assignment = IpAssignment.STATIC;
    nd.securityGroupLinks = Collections.singletonList("/resources/security-groups/1");
    nd.networkLink = "/resources/network/net8";
    nd.subnetLink = "/resources/subnet/subnet8";
    if (assignHost) {
        nd.computeHostLink = "host-1";
    }
    return nd;
}
Also used : NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription)

Example 3 with NetworkInterfaceDescription

use of com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription in project photon-model by vmware.

the class NetworkInterfaceService method handleGet.

@Override
public void handleGet(Operation get) {
    NetworkInterfaceState currentState = getState(get);
    boolean doExpand = get.getUri().getQuery() != null && UriUtils.hasODataExpandParamValue(get.getUri());
    if (!doExpand) {
        get.setBody(currentState).complete();
        return;
    }
    // retrieve the description and include in an augmented version of our
    // state.
    Operation getDesc = Operation.createGet(this, currentState.networkInterfaceDescriptionLink).setCompletion((o, e) -> {
        if (e != null) {
            get.fail(e);
            return;
        }
        NetworkInterfaceDescription desc = o.getBody(NetworkInterfaceDescription.class);
        NetworkInterfaceStateWithDescription stateWithDesc = NetworkInterfaceStateWithDescription.create(desc, currentState);
        get.setBody(stateWithDesc).complete();
    });
    sendRequest(getDesc);
}
Also used : NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription) Operation(com.vmware.xenon.common.Operation)

Example 4 with NetworkInterfaceDescription

use of com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription in project photon-model by vmware.

the class AzureInstanceService method newAzureNetworkInterface.

/**
 * Converts Photon model constructs to underlying Azure NetworkInterface model.
 */
private NetworkInterfaceInner newAzureNetworkInterface(AzureInstanceContext ctx, AzureNicContext nicCtx) {
    NetworkInterfaceDescription description = nicCtx.nicStateWithDesc.description;
    NetworkInterfaceIPConfigurationInner ipConfig = new NetworkInterfaceIPConfigurationInner();
    ipConfig.withName(AzureUtils.generateClusterCommonName(NICCONFIG_NAME_PREFIX, ctx));
    ipConfig.withSubnet(nicCtx.subnet);
    if (nicCtx.publicIP != null) {
        // Public IP is not auto-assigned so check for existence
        ipConfig.withPublicIPAddress(new SubResource().withId(nicCtx.publicIP.id()));
    }
    ipConfig.withPrivateIPAllocationMethod(new IPAllocationMethod(description.assignment.name()));
    if (description.assignment == IpAssignment.STATIC) {
        ipConfig.withPrivateIPAddress(description.address);
    }
    NetworkInterfaceInner nic = new NetworkInterfaceInner();
    nic.withLocation(ctx.resourceGroup.location());
    // Azure's custom serializers don't handle well collections constructed with
    // Collections.singletonList(), so initialize an ArrayList
    List<NetworkInterfaceIPConfigurationInner> ipConfigs = new ArrayList<>();
    ipConfigs.add(ipConfig);
    nic.withIpConfigurations(ipConfigs);
    if (nicCtx.securityGroup != null) {
        // Security group is optional so check for existence
        nic.withNetworkSecurityGroup(new SubResource().withId(nicCtx.securityGroup.id()));
    }
    return nic;
}
Also used : NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription) IPAllocationMethod(com.microsoft.azure.management.network.IPAllocationMethod) SubResource(com.microsoft.azure.SubResource) NetworkInterfaceIPConfigurationInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceIPConfigurationInner) ArrayList(java.util.ArrayList) NetworkInterfaceInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceInner)

Example 5 with NetworkInterfaceDescription

use of com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription in project photon-model by vmware.

the class TestAWSSetupUtils method createAWSNicStates.

/*
     * NOTE: It is highly recommended to keep this method in sync with its Azure counterpart:
     * AzureTestUtil.createDefaultNicStates
     */
public static List<NetworkInterfaceState> createAWSNicStates(VerificationHost host, ComputeState computeHost, EndpointState endpointState, String vmName, AwsNicSpecs nicSpecs, boolean addNewSecurityGroup, Map<String, Object> awsTestContext) throws Throwable {
    // Create network state.
    NetworkState networkState;
    {
        networkState = new NetworkState();
        networkState.id = nicSpecs.network.id;
        networkState.name = nicSpecs.network.name;
        networkState.subnetCIDR = nicSpecs.network.cidr;
        networkState.authCredentialsLink = endpointState.authCredentialsLink;
        networkState.resourcePoolLink = computeHost.resourcePoolLink;
        networkState.instanceAdapterReference = UriUtils.buildUri(host, AWSUriPaths.AWS_NETWORK_ADAPTER);
        networkState.regionId = regionId;
        networkState.endpointLink = endpointState.documentSelfLink;
        networkState.endpointLinks = new HashSet<String>();
        networkState.endpointLinks.add(endpointState.documentSelfLink);
        networkState.tenantLinks = endpointState.tenantLinks;
        networkState.computeHostLink = computeHost.documentSelfLink;
        networkState = TestUtils.doPost(host, networkState, NetworkState.class, UriUtils.buildUri(host, NetworkService.FACTORY_LINK));
    }
    // Create NIC states.
    List<NetworkInterfaceState> nics = new ArrayList<>();
    for (int i = 0; i < nicSpecs.nicSpecs.size(); i++) {
        // Create subnet state per NIC.
        SubnetState subnetState;
        {
            subnetState = new SubnetState();
            subnetState.id = nicSpecs.nicSpecs.get(i).subnetSpec.id;
            subnetState.name = nicSpecs.nicSpecs.get(i).subnetSpec.name;
            subnetState.subnetCIDR = nicSpecs.nicSpecs.get(i).subnetSpec.cidr;
            subnetState.zoneId = nicSpecs.nicSpecs.get(i).subnetSpec.zoneId;
            subnetState.networkLink = networkState.documentSelfLink;
            subnetState.regionId = regionId;
            subnetState.endpointLink = endpointState.documentSelfLink;
            subnetState.endpointLinks = new HashSet<String>();
            subnetState.endpointLinks.add(endpointState.documentSelfLink);
            subnetState.tenantLinks = endpointState.tenantLinks;
            subnetState = TestUtils.doPost(host, subnetState, SubnetState.class, UriUtils.buildUri(host, SubnetService.FACTORY_LINK));
        }
        // Create NIC description.
        NetworkInterfaceDescription nicDescription;
        NicSpec nicSpec = nicSpecs.nicSpecs.get(0);
        {
            nicDescription = new NetworkInterfaceDescription();
            nicDescription.id = "nicDesc" + i;
            nicDescription.name = "nicDesc" + i;
            nicDescription.deviceIndex = i;
            nicDescription.assignment = nicSpec.getIpAssignment();
            nicDescription.regionId = regionId;
            nicDescription.endpointLink = endpointState.documentSelfLink;
            nicDescription.endpointLinks = new HashSet<String>();
            nicDescription.endpointLinks.add(endpointState.documentSelfLink);
            nicDescription.tenantLinks = endpointState.tenantLinks;
            nicDescription = TestUtils.doPost(host, nicDescription, NetworkInterfaceDescription.class, UriUtils.buildUri(host, NetworkInterfaceDescriptionService.FACTORY_LINK));
        }
        // Create security group state for an existing security group
        SecurityGroupState existingSecurityGroupState = createSecurityGroupState(host, computeHost, endpointState, true, awsTestContext);
        NetworkInterfaceState nicState = new NetworkInterfaceState();
        nicState.id = UUID.randomUUID().toString();
        nicState.name = vmName + "-nic-" + i;
        nicState.deviceIndex = nicDescription.deviceIndex;
        nicState.networkLink = networkState.documentSelfLink;
        nicState.subnetLink = subnetState.documentSelfLink;
        nicState.networkInterfaceDescriptionLink = nicDescription.documentSelfLink;
        nicState.regionId = regionId;
        nicState.endpointLink = endpointState.documentSelfLink;
        nicState.endpointLinks = new HashSet<String>();
        nicState.endpointLinks.add(endpointState.documentSelfLink);
        nicState.tenantLinks = endpointState.tenantLinks;
        nicState.securityGroupLinks = new ArrayList<>();
        nicState.securityGroupLinks.add(existingSecurityGroupState.documentSelfLink);
        if (addNewSecurityGroup) {
            // Create security group state for a new security group
            SecurityGroupState newSecurityGroupState = createSecurityGroupState(host, computeHost, endpointState, false, awsTestContext);
            nicState.securityGroupLinks.add(newSecurityGroupState.documentSelfLink);
        }
        nicState = TestUtils.doPost(host, nicState, NetworkInterfaceState.class, UriUtils.buildUri(host, NetworkInterfaceService.FACTORY_LINK));
        nics.add(nicState);
    }
    return nics;
}
Also used : NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) ArrayList(java.util.ArrayList) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) NicSpec(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.AwsNicSpecs.NicSpec) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) HashSet(java.util.HashSet)

Aggregations

NetworkInterfaceDescription (com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription)11 ArrayList (java.util.ArrayList)7 SubnetState (com.vmware.photon.controller.model.resources.SubnetService.SubnetState)5 NetworkInterfaceState (com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState)4 NetworkState (com.vmware.photon.controller.model.resources.NetworkService.NetworkState)3 Operation (com.vmware.xenon.common.Operation)3 NetworkInterfaceStateWithDetails (com.vmware.photon.controller.model.adapters.vsphere.ProvisionContext.NetworkInterfaceStateWithDetails)2 SecurityGroupState (com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState)2 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)2 URI (java.net.URI)2 Test (org.junit.Test)2 SubResource (com.microsoft.azure.SubResource)1 IPAllocationMethod (com.microsoft.azure.management.network.IPAllocationMethod)1 NetworkInterfaceIPConfigurationInner (com.microsoft.azure.management.network.implementation.NetworkInterfaceIPConfigurationInner)1 NetworkInterfaceInner (com.microsoft.azure.management.network.implementation.NetworkInterfaceInner)1 ComputeProperties (com.vmware.photon.controller.model.ComputeProperties)1 IAAS_API_ENABLED (com.vmware.photon.controller.model.UriPaths.IAAS_API_ENABLED)1 ComputeInstanceRequest (com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest)1 InstanceRequestType (com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest.InstanceRequestType)1 ResourceRequest (com.vmware.photon.controller.model.adapterapi.ResourceRequest)1