
io.k8s.api.resource.v1beta1.AllocatedDeviceStatus.scala Maven / Gradle / Ivy
package io.k8s.api.resource.v1beta1
import dev.hnaderi.k8s.utils._
/** AllocatedDeviceStatus contains the status of an allocated device, if the driver chooses to report it. This may include driver-specific information. */
final case class AllocatedDeviceStatus(
driver : String,
pool : String,
device : String,
conditions : Option[Seq[io.k8s.apimachinery.pkg.apis.meta.v1.Condition]] = None,
data : Option[io.k8s.apimachinery.pkg.runtime.RawExtension] = None,
networkData : Option[io.k8s.api.resource.v1beta1.NetworkDeviceData] = None
) {
/** Returns a new data with driver set to new value */
def withDriver(value: String) : AllocatedDeviceStatus = copy(driver = value)
/** transforms driver to result of function */
def mapDriver(f: String => String) : AllocatedDeviceStatus = copy(driver = f(driver))
/** Returns a new data with pool set to new value */
def withPool(value: String) : AllocatedDeviceStatus = copy(pool = value)
/** transforms pool to result of function */
def mapPool(f: String => String) : AllocatedDeviceStatus = copy(pool = f(pool))
/** Returns a new data with device set to new value */
def withDevice(value: String) : AllocatedDeviceStatus = copy(device = value)
/** transforms device to result of function */
def mapDevice(f: String => String) : AllocatedDeviceStatus = copy(device = f(device))
/** Returns a new data with conditions set to new value */
def withConditions(value: Seq[io.k8s.apimachinery.pkg.apis.meta.v1.Condition]) : AllocatedDeviceStatus = copy(conditions = Some(value))
/** Appends new values to conditions */
def addConditions(newValues: io.k8s.apimachinery.pkg.apis.meta.v1.Condition*) : AllocatedDeviceStatus = copy(conditions = Some(conditions.fold(newValues)(_ ++ newValues)))
/** if conditions has a value, transforms to the result of function*/
def mapConditions(f: Seq[io.k8s.apimachinery.pkg.apis.meta.v1.Condition] => Seq[io.k8s.apimachinery.pkg.apis.meta.v1.Condition]) : AllocatedDeviceStatus = copy(conditions = conditions.map(f))
/** Returns a new data with data set to new value */
def withData(value: io.k8s.apimachinery.pkg.runtime.RawExtension) : AllocatedDeviceStatus = copy(data = Some(value))
/** if data has a value, transforms to the result of function*/
def mapData(f: io.k8s.apimachinery.pkg.runtime.RawExtension => io.k8s.apimachinery.pkg.runtime.RawExtension) : AllocatedDeviceStatus = copy(data = data.map(f))
/** Returns a new data with networkData set to new value */
def withNetworkData(value: io.k8s.api.resource.v1beta1.NetworkDeviceData) : AllocatedDeviceStatus = copy(networkData = Some(value))
/** if networkData has a value, transforms to the result of function*/
def mapNetworkData(f: io.k8s.api.resource.v1beta1.NetworkDeviceData => io.k8s.api.resource.v1beta1.NetworkDeviceData) : AllocatedDeviceStatus = copy(networkData = networkData.map(f))
}
object AllocatedDeviceStatus {
implicit val encoder : Encoder[io.k8s.api.resource.v1beta1.AllocatedDeviceStatus] = new Encoder[io.k8s.api.resource.v1beta1.AllocatedDeviceStatus] {
def apply[T : Builder](o: io.k8s.api.resource.v1beta1.AllocatedDeviceStatus) : T = {
val obj = ObjectWriter[T]()
obj
.write("driver", o.driver)
.write("pool", o.pool)
.write("device", o.device)
.write("conditions", o.conditions)
.write("data", o.data)
.write("networkData", o.networkData)
.build
}
}
implicit val decoder: Decoder[AllocatedDeviceStatus] = new Decoder[AllocatedDeviceStatus] {
def apply[T : Reader](t: T): Either[String, AllocatedDeviceStatus] = for {
obj <- ObjectReader(t)
driver <- obj.read[String]("driver")
pool <- obj.read[String]("pool")
device <- obj.read[String]("device")
conditions <- obj.readOpt[Seq[io.k8s.apimachinery.pkg.apis.meta.v1.Condition]]("conditions")
data <- obj.readOpt[io.k8s.apimachinery.pkg.runtime.RawExtension]("data")
networkData <- obj.readOpt[io.k8s.api.resource.v1beta1.NetworkDeviceData]("networkData")
} yield AllocatedDeviceStatus (
driver = driver,
pool = pool,
device = device,
conditions = conditions,
data = data,
networkData = networkData
)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy