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);
}
}
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()));
}
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;
}
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;
}
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;
}
Aggregations