private void addDefaultNetworks() { Network net = new Network(); net.setId(Guid.newGuid()); net.setName(managementNetworkUtil.getDefaultManagementNetworkName()); net.setDescription(AddClusterCommand.DefaultNetworkDescription); net.setDataCenterId(getStoragePool().getId()); net.setVmNetwork(true); getNetworkDao().save(net); NetworkHelper.addPermissionsOnNetwork(getCurrentUser().getId(), net.getId()); VnicProfile profile = NetworkHelper.createVnicProfile(net); getVnicProfileDao().save(profile); NetworkHelper.addPermissionsOnVnicProfile(getCurrentUser().getId(), profile.getId(), true); }
/** * Checks that the destination cluster has all the networks that the given NICs require.<br> * No network on a NIC is allowed (it's checked when running VM). * * @param interfaces The NICs to check networks on. * @return Whether the destination cluster has all networks configured or not. */ private boolean validateDestinationClusterContainsNetworks(List<VmNic> interfaces) { List<Network> networks = DbFacade.getInstance().getNetworkDao().getAllForCluster(targetClusterId); StringBuilder missingNets = new StringBuilder(); for (VmNic iface : interfaces) { Network network = NetworkHelper.getNetworkByVnicProfileId(iface.getVnicProfileId()); if (network != null) { boolean exists = false; for (Network net : networks) { if (net.getName().equals(network.getName())) { exists = true; break; } } if (!exists) { if (missingNets.length() > 0) { missingNets.append(", "); } missingNets.append(network.getName()); } } } if (missingNets.length() > 0) { parentCommand.addCanDoActionMessage(EngineMessage.MOVE_VM_CLUSTER_MISSING_NETWORK); parentCommand.addCanDoActionMessageVariable("networks", missingNets.toString()); return false; } return true; }
@Override protected void executeCommand() { setStoragePoolId(getNetwork().getDataCenterId()); TransactionSupport.executeInNewTransaction( new TransactionMethod<Void>() { @Override public Void runInTransaction() { removeVnicProfiles(); removeFromClusters(); getCompensationContext().snapshotEntity(getNetwork()); getNetworkDAO().remove(getNetwork().getId()); getCompensationContext().stateChanged(); return null; } }); if (getNetwork().isExternal()) { if (getParameters().isRemoveFromNetworkProvider()) { removeExternalNetwork(); } } if (NetworkHelper.shouldRemoveNetworkFromHostUponNetworkRemoval( getNetwork(), getStoragePool().getcompatibility_version())) { removeNetworkFromHosts(); } setSucceeded(true); }
private void removeNetworkFromHosts() { NetworkHelper.removeNetworkFromHostsInDataCenter( getNetwork(), getStoragePoolId(), cloneContextAndDetachFromParent()); }