public void OnManage() { ListModel model = (ListModel) getWindow(); java.util.ArrayList<EntityModel> items = Linq.<EntityModel>Cast(model.getItems()); java.util.ArrayList<network> networks = Linq.<network>Cast(getItems()); if (getEntity() == null) { Cancel(); return; } java.util.ArrayList<VdcActionParametersBase> prms1 = new java.util.ArrayList<VdcActionParametersBase>(); for (EntityModel a : items) { boolean value = false; for (network b : networks) { if (b.getId().equals(((network) a.getEntity()).getId())) { value = true; break; } } if (a.getIsSelected() && !value) { prms1.add(new AttachNetworkToVdsGroupParameter(getEntity(), (network) a.getEntity())); } } // Call the command only if necessary (i.e. only if there are paramters): if (prms1.size() > 0) { Frontend.RunMultipleAction(VdcActionType.AttachNetworkToVdsGroup, prms1); } java.util.ArrayList<VdcActionParametersBase> prms2 = new java.util.ArrayList<VdcActionParametersBase>(); for (EntityModel a : items) { boolean value = true; for (network b : networks) { if (b.getId().equals(((network) a.getEntity()).getId())) { value = false; break; } } if (!a.getIsSelected() && !value) { prms2.add(new AttachNetworkToVdsGroupParameter(getEntity(), (network) a.getEntity())); } } // Call the command only if necessary (i.e. only if there are paramters): if (prms2.size() > 0) { Frontend.RunMultipleAction(VdcActionType.DetachNetworkToVdsGroup, prms2); } Cancel(); }
public void PostGetClusterNetworkList_New(java.util.ArrayList<network> network_list) { java.util.ArrayList<network> networks = new java.util.ArrayList<network>(); for (network a : network_list) { if (a.getStatus() == NetworkStatus.Operational) { networks.add(a); } } java.util.ArrayList<VmNetworkInterface> nics = Linq.<VmNetworkInterface>Cast(getItems()); int nicCount = nics.size(); String newNicName = DataProvider.GetNewNicName(nics); VmInterfaceModel model = (VmInterfaceModel) getWindow(); model.getNetwork().setItems(networks); model.getNetwork().setSelectedItem(networks.size() > 0 ? networks.get(0) : null); model .getNicType() .setItems(DataProvider.GetNicTypeList(getEntityStronglyTyped().getos(), false)); model .getNicType() .setSelectedItem(DataProvider.GetDefaultNicType(getEntityStronglyTyped().getos())); model.getName().setEntity(newNicName); model.getMAC().setIsAvailable(false); UICommand tempVar = new UICommand("OnSave", this); tempVar.setTitle("OK"); tempVar.setIsDefault(true); model.getCommands().add(tempVar); UICommand tempVar2 = new UICommand("Cancel", this); tempVar2.setTitle("Cancel"); tempVar2.setIsCancel(true); model.getCommands().add(tempVar2); }
public void PostManage(java.util.ArrayList<network> networkList, ListModel model) { Collections.sort(networkList, new Linq.NetworkByNameComparer()); java.util.ArrayList<EntityModel> items = new java.util.ArrayList<EntityModel>(); for (network a : networkList) { if (!a.getname().equals("engine")) { EntityModel tempVar = new EntityModel(); tempVar.setEntity(a); tempVar.setTitle(a.getname()); items.add(tempVar); } } model.setItems(items); boolean noItems = items.isEmpty(); java.util.ArrayList<network> networks = Linq.<network>Cast(getItems()); java.util.ArrayList<EntityModel> selectedItems = new java.util.ArrayList<EntityModel>(); for (EntityModel item : items) { network net = (network) item.getEntity(); boolean value = false; for (network a : networks) { if (a.getId().equals(net.getId())) { value = true; break; } } item.setIsSelected(value); if (value) { selectedItems.add(item); } } model.setSelectedItems(selectedItems); UICommand tempVar2 = new UICommand("Cancel", this); tempVar2.setTitle("Cancel"); tempVar2.setIsDefault(noItems); tempVar2.setIsCancel(true); model.getCommands().add(tempVar2); if (!noItems) { UICommand tempVar3 = new UICommand("OnManage", this); tempVar3.setTitle("OK"); tempVar3.setIsDefault(true); model.getCommands().add(0, tempVar3); } }
public void PostGetClusterNetworkList_Edit(java.util.ArrayList<network> network_list) { VmNetworkInterface nic = (VmNetworkInterface) getSelectedItem(); int nicCount = Linq.<VmNetworkInterface>Cast(getItems()).size(); java.util.ArrayList<network> networks = new java.util.ArrayList<network>(); for (network a : network_list) { if (a.getStatus() == NetworkStatus.Operational) { networks.add(a); } } VmInterfaceModel model = (VmInterfaceModel) getWindow(); model.getNetwork().setItems(networks); network network = null; for (network a : networks) { if (StringHelper.stringsEqual(a.getname(), nic.getNetworkName())) { network = a; break; } } model.getNetwork().setSelectedItem(network); Integer selectedNicType = nic.getType(); java.util.ArrayList<VmInterfaceType> nicTypes = DataProvider.GetNicTypeList( getEntityStronglyTyped().getos(), VmInterfaceType.forValue(selectedNicType) == VmInterfaceType.rtl8139_pv); model.getNicType().setItems(nicTypes); if (selectedNicType == null || !nicTypes.contains(VmInterfaceType.forValue(selectedNicType))) { selectedNicType = DataProvider.GetDefaultNicType(getEntityStronglyTyped().getos()).getValue(); } model.getNicType().setSelectedItem(VmInterfaceType.forValue(selectedNicType)); model.getName().setEntity(nic.getName()); model.getMAC().setIsAvailable(false); UICommand tempVar = new UICommand("OnSave", this); tempVar.setTitle("OK"); tempVar.setIsDefault(true); model.getCommands().add(tempVar); UICommand tempVar2 = new UICommand("Cancel", this); tempVar2.setTitle("Cancel"); tempVar2.setIsCancel(true); model.getCommands().add(tempVar2); }
@Override public void UpdateItemsAvailability() { super.UpdateItemsAvailability(); storage_pool dataCenter = (storage_pool) getModel().getDataCenter().getSelectedItem(); for (IStorageModel item : Linq.<IStorageModel>Cast(getModel().getItems())) { Model model = (Model) item; storage_domains isoStorage = DataProvider.GetIsoDomainByDataCenterId(dataCenter.getId()); storage_domains exportStorage = DataProvider.GetExportDomainByDataCenterId(dataCenter.getId()); // available type/function items are: // all in case of Unassigned DC. // ISO in case the specified DC doesn't have an attached ISO domain. // Export in case the specified DC doesn't have an attached export domain. model.setIsSelectable( (dataCenter.getId().equals(StorageModel.UnassignedDataCenterId) || (item.getRole() == StorageDomainType.ISO && isoStorage == null) || (item.getRole() == StorageDomainType.ImportExport && exportStorage == null))); } }
public void SetDefaultNames(VDS host, RefObject<String> message) { message.argvalue = null; setCommonName(StringFormat.format("%1$s-Local", host.getvds_name().replace('.', '-'))); storage_pool candidate = null; // selecet all possible DCs VdcQueryReturnValue returnValue = Frontend.RunQuery( VdcQueryType.Search, new SearchParameters( StringFormat.format("DataCenter: name=%1$s", getCommonName() + "*"), SearchType.StoragePool)); java.util.ArrayList<storage_pool> dataCenterList = new java.util.ArrayList<storage_pool>(); java.util.ArrayList<VDSGroup> clusterList = null; if (returnValue != null && returnValue.getSucceeded() && returnValue.getReturnValue() != null) { dataCenterList = Linq.<storage_pool>Cast( (java.util.ArrayList<IVdcQueryable>) returnValue.getReturnValue()); } // check if current settings suitable for local setup (in case just SD creation failed - // re-using the same setup) boolean useCurrentSettings = false; if (host.getstorage_pool_id() != null) { storage_pool tempCandidate = DataProvider.GetDataCenterById(host.getstorage_pool_id()); if (IsLocalDataCenterEmpty(tempCandidate)) { candidate = tempCandidate; useCurrentSettings = true; } else { if (tempCandidate != null && tempCandidate.getstorage_pool_type() == StorageType.LOCALFS) { message.argvalue = "Note: Local Storage is already configured for this Host. The Host belongs to " + host.getstorage_pool_name() + " with local Storage Domain. If OK is clicked - this Host will be moved to a new Data Center, and a new Local Storage Domain will be created. Hit Cancel to abort the operation."; } } } // check if there is other DC suitable for re-use if (candidate == null) { for (storage_pool dataCenter : dataCenterList) { // need to check if the new DC is without host. if (IsLocalDataCenterEmpty(dataCenter) && DataProvider.GetLocalStorageHost(dataCenter.getname()) == null) { candidate = dataCenter; break; } } } java.util.ArrayList<String> listNames = new java.util.ArrayList<String>(); // in case we found a suitable candidte for re-use: if (candidate != null) { getDataCenter().setDataCenterId(candidate.getId()); getDataCenter().getName().setEntity(candidate.getname()); getDataCenter().getDescription().setEntity(candidate.getdescription()); Version compVersion = candidate.getcompatibility_version(); getDataCenter().getVersion().setSelectedItem(compVersion); getCluster().getVersion().setSelectedItem(compVersion); setDontCreateDataCenter(true); // if we use current settings there is no need to create cluster. if (useCurrentSettings) { getCluster().setClusterId(host.getvds_group_id().getValue()); getCluster().getName().setEntity(host.getvds_group_name()); VDSGroup cluster = DataProvider.GetClusterById(host.getvds_group_id().getValue()); if (cluster != null) { getCluster().getDescription().setEntity(cluster.getdescription()); ServerCpu tempVar = new ServerCpu(); tempVar.setCpuName(cluster.getcpu_name()); getCluster().getCPU().setSelectedItem(tempVar); } setDontCreateCluster(true); setDontChangeHostCluster(true); } // use differnt cluster else { // check the DC cluster list (for re-use) clusterList = DataProvider.GetClusterList(candidate.getId()); // no clusters avilable - pick up new name. if (clusterList.isEmpty()) { java.util.ArrayList<VDSGroup> listClusters = DataProvider.GetClusterList(); listNames = new java.util.ArrayList<String>(); for (VDSGroup cluster : listClusters) { listNames.add(cluster.getname()); } getCluster().getName().setEntity(AvailableName(listNames)); } else { // use the DC cluster. getCluster().setClusterId(clusterList.get(0).getId()); getCluster().getName().setEntity(clusterList.get(0).getname()); getCluster().getDescription().setEntity(clusterList.get(0).getdescription()); VDSGroup cluster = DataProvider.GetClusterById(getCluster().getClusterId().getValue()); if (cluster != null) { ServerCpu tempVar2 = new ServerCpu(); tempVar2.setCpuName(cluster.getcpu_name()); getCluster().getCPU().setSelectedItem(tempVar2); } setDontCreateCluster(true); if (host.getvds_group_id().getValue().equals(getCluster().getClusterId())) { setDontChangeHostCluster(true); } } } } else { // didn't found DC to re-use, so we select new names: listNames = new java.util.ArrayList<String>(); for (storage_pool storagePool : dataCenterList) { listNames.add(storagePool.getname()); } getDataCenter().getName().setEntity(AvailableName(listNames)); // Choose a Data Center version corresponding to the host. if (!StringHelper.isNullOrEmpty(host.getsupported_cluster_levels())) { // the supported_cluster_levels are sorted. String[] array = host.getsupported_cluster_levels().split("[,]", -1); Version maxCombindVersion = null; for (int i = 0; i < array.length; i++) { Version vdsVersion = new Version(array[i]); for (Version version : (java.util.List<Version>) getDataCenter().getVersion().getItems()) { if (version.equals(vdsVersion) && version.compareTo(maxCombindVersion) > 0) { maxCombindVersion = version; } } } if (maxCombindVersion != null) { getDataCenter().getVersion().setSelectedItem(maxCombindVersion); getCluster().getVersion().setSelectedItem(maxCombindVersion); } } listNames = new java.util.ArrayList<String>(); if (clusterList == null) { clusterList = DataProvider.GetClusterList(); } for (VDSGroup cluster : clusterList) { listNames.add(cluster.getname()); } getCluster().getName().setEntity(AvailableName(listNames)); } // Choose default CPU name to match host. if (host.getCpuName() != null && getCluster().getCPU().getSelectedItem() != null) { getCluster() .getCPU() .setSelectedItem( Linq.FirstOrDefault( (java.util.List<ServerCpu>) getCluster().getCPU().getItems(), new Linq.ServerCpuPredicate(host.getCpuName().getCpuName()))); } // always choose a avialable storage name. java.util.ArrayList<storage_domains> listStorageDomains = DataProvider.GetStorageDomainList(); listNames = new java.util.ArrayList<String>(); for (storage_domains storageDomain : listStorageDomains) { listNames.add(storageDomain.getstorage_name()); } getFormattedStorageName().setEntity(AvailableName(listNames)); }