Search in sources :

Example 51 with SubnetState

use of com.vmware.photon.controller.model.resources.SubnetService.SubnetState in project photon-model by vmware.

the class VSphereNetworkEnumerationHelper method handleNetworkChanges.

/**
 * Handles incremental changes on networks.
 *
 * @param service             the incremental service
 * @param networks            the filtered network overlays
 * @param enumerationProgress the context for enumeration.
 * @param client              the enumeration client
 */
public static void handleNetworkChanges(VSphereIncrementalEnumerationService service, MoRefKeyedMap<NetworkOverlay> networks, EnumerationProgress enumerationProgress, EnumerationClient client) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    enumerationProgress.expectNetworkCount(networks.values().size());
    for (NetworkOverlay netOverlay : networks.values()) {
        // if a network | DVS | DV port group is added.
        if (ObjectUpdateKind.ENTER == netOverlay.getObjectUpdateKind()) {
            // if DV port group is added
            if (netOverlay.getParentSwitch() != null) {
                // check if the parent switch is present as part of this enumeration
                NetworkOverlay parentSwitch = networks.get(netOverlay.getParentSwitch());
                String dvsUUID;
                if (parentSwitch == null) {
                    // retrieve the uuid from vCenter
                    dvsUUID = client.getUUIDForDVS(netOverlay);
                } else {
                    dvsUUID = parentSwitch.getDvsUuid();
                }
                createNewSubnet(service, enumerationProgress, netOverlay, dvsUUID);
            } else {
                createNewNetwork(service, enumerationProgress, netOverlay);
            }
        } else {
            // if DV port group is changed
            if (netOverlay.getId().getType().equals(VimNames.TYPE_PORTGROUP)) {
                ManagedObjectReference parentSwitch = netOverlay.getParentSwitch();
                // if parent is not retrieved, Retrieve it.
                if (null == parentSwitch && ObjectUpdateKind.MODIFY.equals(netOverlay.getObjectUpdateKind())) {
                    parentSwitch = client.getParentSwitchForDVPortGroup(netOverlay.getId());
                }
                QueryTask task = queryForSubnet(enumerationProgress, netOverlay, parentSwitch);
                withTaskResults(service, task, (ServiceDocumentQueryResult result) -> {
                    if (!result.documentLinks.isEmpty()) {
                        SubnetState oldDocument = convertOnlyResultToDocument(result, SubnetState.class);
                        if (ObjectUpdateKind.MODIFY.equals(netOverlay.getObjectUpdateKind())) {
                            updateSubnet(service, oldDocument, enumerationProgress, netOverlay, false);
                        } else {
                            // DV port group has been removed. Remove the subnet state document.
                            deleteNetwork(service, enumerationProgress, netOverlay, oldDocument);
                        }
                    } else {
                        enumerationProgress.getNetworkTracker().track();
                    }
                });
            } else {
                // DVS or Opaque network.
                QueryTask task = queryForNetwork(enumerationProgress, netOverlay);
                VsphereEnumerationHelper.withTaskResults(service, task, result -> {
                    if (!result.documentLinks.isEmpty()) {
                        NetworkState oldDocument = convertOnlyResultToDocument(result, NetworkState.class);
                        if (ObjectUpdateKind.MODIFY.equals(netOverlay.getObjectUpdateKind())) {
                            updateNetwork(service, oldDocument, enumerationProgress, netOverlay);
                        } else {
                            deleteNetwork(service, enumerationProgress, netOverlay, oldDocument);
                        }
                    } else {
                        enumerationProgress.getNetworkTracker().track();
                    }
                });
            }
        }
    }
    try {
        enumerationProgress.getNetworkTracker().await();
    } catch (InterruptedException e) {
        service.logSevere("Interrupted during incremental enumeration for networks!", e);
    }
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 52 with SubnetState

use of com.vmware.photon.controller.model.resources.SubnetService.SubnetState in project photon-model by vmware.

the class VSphereNetworkEnumerationHelper method createNewSubnet.

private static void createNewSubnet(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, NetworkOverlay net, String dvsUuid) {
    SubnetState state = makeSubnetStateFromResults(enumerationProgress, net);
    state.customProperties.put(DvsProperties.DVS_UUID, dvsUuid);
    state.tenantLinks = enumerationProgress.getTenantLinks();
    Operation.createPost(PhotonModelUriUtils.createInventoryUri(service.getHost(), SubnetService.FACTORY_LINK)).setBody(state).setCompletion(trackNetwork(enumerationProgress, net)).sendWith(service);
    service.logFine(() -> String.format("Found new Subnet(Portgroup) %s", net.getName()));
}
Also used : SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState)

Example 53 with SubnetState

use of com.vmware.photon.controller.model.resources.SubnetService.SubnetState in project photon-model by vmware.

the class VSphereNetworkEnumerationHelper method makeSubnetStateFromChanges.

private static SubnetState makeSubnetStateFromChanges(NetworkOverlay networkOverlay) {
    SubnetState state = new SubnetState();
    // if name is changed
    String name = networkOverlay.getNameOrNull();
    if (null != name) {
        state.name = name;
        state.id = name;
    }
    return state;
}
Also used : SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState)

Example 54 with SubnetState

use of com.vmware.photon.controller.model.resources.SubnetService.SubnetState in project photon-model by vmware.

the class ModelUtils method createSubnet.

public static SubnetState createSubnet(BaseModelTest test, NetworkState networkState, EndpointState endpointState) throws Throwable {
    SubnetState subnetState = new SubnetState();
    subnetState.documentSelfLink = subnetState.id;
    subnetState.networkLink = networkState.documentSelfLink;
    subnetState.gatewayAddress = "12.12.12.1";
    subnetState.domain = "vmware.com";
    subnetState.dnsServerAddresses = new ArrayList<>();
    subnetState.dnsServerAddresses.add("192.12.12.12");
    subnetState.subnetCIDR = "12.12.12.0/24";
    subnetState.endpointLink = endpointState.documentSelfLink;
    SubnetState returnState = test.postServiceSynchronously(SubnetService.FACTORY_LINK, subnetState, SubnetState.class);
    return returnState;
}
Also used : SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState)

Example 55 with SubnetState

use of com.vmware.photon.controller.model.resources.SubnetService.SubnetState in project photon-model by vmware.

the class SubnetServiceTest method buildValidStartState.

private static SubnetState buildValidStartState(boolean assignHost) {
    SubnetState subnetState = new SubnetState();
    subnetState.id = UUID.randomUUID().toString();
    subnetState.name = "networkName";
    subnetState.subnetCIDR = "10.0.0.0/10";
    subnetState.networkLink = NetworkService.FACTORY_LINK + "/mynet";
    subnetState.tenantLinks = new ArrayList<>();
    subnetState.tenantLinks.add("tenant-linkA");
    subnetState.dnsServerAddresses = new ArrayList<>();
    subnetState.dnsServerAddresses.addAll(Arrays.asList("1.2.3.4", "11.22.33.44"));
    subnetState.dnsSearchDomains = new ArrayList<>();
    subnetState.dnsSearchDomains.addAll(Arrays.asList("foo.bar", "subdomain.foo.bar"));
    if (assignHost) {
        subnetState.computeHostLink = "host-1";
    }
    return subnetState;
}
Also used : SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState)

Aggregations

SubnetState (com.vmware.photon.controller.model.resources.SubnetService.SubnetState)61 NetworkState (com.vmware.photon.controller.model.resources.NetworkService.NetworkState)22 ArrayList (java.util.ArrayList)16 Test (org.junit.Test)16 Operation (com.vmware.xenon.common.Operation)14 Query (com.vmware.xenon.services.common.QueryTask.Query)12 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)11 QueryByPages (com.vmware.photon.controller.model.query.QueryUtils.QueryByPages)11 NetworkInterfaceState (com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState)11 URI (java.net.URI)11 DeferredResult (com.vmware.xenon.common.DeferredResult)10 HashMap (java.util.HashMap)10 List (java.util.List)10 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)9 StatelessService (com.vmware.xenon.common.StatelessService)9 SubnetService (com.vmware.photon.controller.model.resources.SubnetService)8 UriUtils (com.vmware.xenon.common.UriUtils)8 TagsUtil.newTagState (com.vmware.photon.controller.model.adapters.util.TagsUtil.newTagState)7 NetworkService (com.vmware.photon.controller.model.resources.NetworkService)7 TagState (com.vmware.photon.controller.model.resources.TagService.TagState)7