001/* 002 * VM-Operator 003 * Copyright (C) 2024 Michael N. Lipp 004 * 005 * This program is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Affero General Public License as 007 * published by the Free Software Foundation, either version 3 of the 008 * License, or (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Affero General Public License for more details. 014 * 015 * You should have received a copy of the GNU Affero General Public License 016 * along with this program. If not, see <https://www.gnu.org/licenses/>. 017 */ 018 019package org.jdrupes.vmoperator.manager.events; 020 021import java.util.Collections; 022import java.util.List; 023import java.util.Optional; 024import org.jdrupes.vmoperator.common.VmDefinition; 025import org.jgrapes.core.Event; 026 027/** 028 * Gets the known VMs' definitions and channels. 029 */ 030@SuppressWarnings("PMD.DataClass") 031public class GetVms extends Event<List<GetVms.VmData>> { 032 033 private String name; 034 private String user; 035 private List<String> roles = Collections.emptyList(); 036 private String fromPool; 037 private String toUser; 038 039 /** 040 * Return only the VMs with the given name. 041 * 042 * @param name the name 043 * @return the returns the vms 044 */ 045 public GetVms withName(String name) { 046 this.name = name; 047 return this; 048 } 049 050 /** 051 * Return only {@link VmDefinition}s that are accessible by 052 * the given user or roles. 053 * 054 * @param user the user 055 * @param roles the roles 056 * @return the event 057 */ 058 public GetVms accessibleFor(String user, List<String> roles) { 059 this.user = user; 060 this.roles = roles; 061 return this; 062 } 063 064 /** 065 * Return only {@link VmDefinition}s that are assigned from the given pool. 066 * 067 * @param pool the pool 068 * @return the returns the vms 069 */ 070 public GetVms assignedFrom(String pool) { 071 this.fromPool = pool; 072 return this; 073 } 074 075 /** 076 * Return only {@link VmDefinition}s that are assigned to the given user. 077 * 078 * @param user the user 079 * @return the returns the vms 080 */ 081 public GetVms assignedTo(String user) { 082 this.toUser = user; 083 return this; 084 } 085 086 /** 087 * Returns the name filter criterion, if set. 088 * 089 * @return the optional 090 */ 091 public Optional<String> name() { 092 return Optional.ofNullable(name); 093 } 094 095 /** 096 * Returns the user filter criterion, if set. 097 * 098 * @return the optional 099 */ 100 public Optional<String> user() { 101 return Optional.ofNullable(user); 102 } 103 104 /** 105 * Returns the roles criterion. 106 * 107 * @return the list 108 */ 109 public List<String> roles() { 110 return roles; 111 } 112 113 /** 114 * Returns the pool filter criterion, if set. 115 * 116 * @return the optional 117 */ 118 public Optional<String> fromPool() { 119 return Optional.ofNullable(fromPool); 120 } 121 122 /** 123 * Returns the user filter criterion, if set. 124 * 125 * @return the optional 126 */ 127 public Optional<String> toUser() { 128 return Optional.ofNullable(toUser); 129 } 130 131 /** 132 * Return tuple. 133 * 134 * @param definition the definition 135 * @param channel the channel 136 */ 137 public record VmData(VmDefinition definition, VmChannel channel) { 138 } 139}