use crate::common::CommaSeparated;
use crate::utils::SortDir;
use osauth::QueryItem;
use serde::Deserialize;
protocol_enum! {
enum ProvisionState = Unknown {
Adopting = "adopting",
AdoptFailed = "adopt failed",
Active = "active",
Available = "available",
Cleaning = "cleaning",
CleanFailed = "clean failed",
CleanWait = "clean wait",
Deploying = "deploying",
DeployFailed = "deploy failed",
DeployWait = "wait call-back",
Inspecting = "inspecting",
InspectFailed = "inspect failed",
InspectWait = "inspect wait",
Enroll = "enroll",
Manageable = "manageable",
Rescue = "rescue",
Rescuing = "rescuing",
RescueFailed = "rescue failed",
RescueWait = "rescue wait",
Undeploying = "deleting",
UndeployFailed = "error",
Unrescuing = "unrescuing",
UnrescueFailed = "unrescue failed",
Verifying = "verifying",
Unknown = ""
}
}
impl ProvisionState {
pub fn is_stable(&self) -> bool {
matches!(
self,
ProvisionState::Active
| ProvisionState::Available
| ProvisionState::Enroll
| ProvisionState::Manageable
| ProvisionState::Rescue
)
}
pub fn is_failure(&self) -> bool {
matches!(
self,
ProvisionState::AdoptFailed
| ProvisionState::CleanFailed
| ProvisionState::DeployFailed
| ProvisionState::InspectFailed
| ProvisionState::RescueFailed
| ProvisionState::UndeployFailed
| ProvisionState::UnrescueFailed
)
}
}
protocol_enum! {
enum TargetProvisionState {
Active = "active",
Deleted = "deleted",
Available = "available",
Manageable = "manageable",
Rescue = "rescue"
}
}
protocol_enum! {
enum PowerState {
Off = "power off",
On = "power on",
Error = "error"
}
}
protocol_enum! {
enum TargetPowerState {
Off = "power off",
On = "power on",
Reboot = "rebooting",
SoftOff = "soft power off",
SoftReboot = "soft rebooting"
}
}
protocol_enum! {
enum StepInterface {
BIOS = "bios",
Deploy = "deploy",
Management = "management",
Power = "power",
RAID = "raid"
}
}
protocol_enum! {
enum Fault {
Power = "power failure",
Clean = "clean failure",
RescueAbort = "rescue abort failure"
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct DeployStep {
pub interface: StepInterface,
#[serde(rename = "step")]
pub name: String,
pub priority: u32,
}
#[derive(Debug, Clone, Deserialize)]
pub struct CleanStep {
#[serde(default)]
pub abortable: bool,
pub interface: StepInterface,
#[serde(rename = "step")]
pub name: String,
pub priority: u32,
#[serde(default = "crate::utils::some_truth")]
pub requires_ramdisk: bool,
}
protocol_enum! {
#[allow(missing_docs)]
enum NodeSortKey {
AllocationID = "allocation_uuid",
AutomatedClean = "automated_clean",
BIOSInterface = "bios_interface",
BootInterface = "boot_interface",
ChassisID = "chassis_uuid",
ConductorGroup = "conductor_group",
ConsoleEnabled = "console_enabled",
ConsoleInterface = "console_interface",
CreatedAt = "created_at",
DeployInterface = "deploy_interface",
Description = "description",
Driver = "driver",
ID = "uuid",
InspectInterface = "inspect_interface",
InspectionFinishedAt = "inspection_finished_at",
InspectionStartedAt = "inspection_started_at",
InstanceID = "instance_uuid",
Lessee = "lessee",
Maintenance = "maintenance",
ManagementInterface = "management_interface",
Name = "name",
NetworkInterface = "network_interface",
Owner = "owner",
PowerInterface = "power_interface",
PowerState = "power_state",
Protected = "protected",
ProvisionState = "provision_state",
ProvisionUpdatedAt = "provision_updated_at",
RAIDInterface = "raid_interface",
RescueInterface = "rescue_interface",
Reservation = "reservation",
ResourceClass = "resource_class",
Retired = "retired",
Shard = "shard",
StorageInterface = "storage_interface",
TargetPowerState = "target_power_state",
TargetProvisionState = "target_provision_state",
UpdatedAt = "updated_at",
VendorInterface = "vendor_interface"
}
}
#[derive(Debug, Clone, QueryItem)]
pub enum NodeFilter {
Marker(String),
Limit(usize),
SortKey(NodeSortKey),
SortDir(SortDir),
Associated(bool),
ChassisID(String),
DescriptionContains(String),
ConductorGroup(String),
Driver(String),
Fault(String),
IncludeChildren(bool),
Lessee(String),
Maintenance(bool),
Owner(String),
ParentNode(String),
Project(String),
ProvisionState(ProvisionState),
ResourceClass(String),
Retired(bool),
Sharded(bool),
ShardIn(CommaSeparated<String>),
}
impl NodeFilter {
pub fn shard_in<I>(shards: I) -> NodeFilter
where
I: IntoIterator,
String: From<I::Item>,
{
NodeFilter::ShardIn(CommaSeparated(shards.into_iter().map(From::from).collect()))
}
}