using System; using System.Collections.Generic; using System.Text.Json.Serialization; namespace BinaryLane.Api.V2.Models; /// /// Base payload for POST /v2/servers/{server_id}/actions. /// /// /// The upstream contract is a discriminated union on type. Its public /// documentation also creates fragment-bearing pseudo-paths for each variant; /// those are not separate HTTP routes. Prefer a concrete derived type for a /// documented action. permits new provider /// action types without waiting for an SDK release. /// public class ServerAction : BinaryLaneRequestModel { /// Creates an empty action for serializers and advanced callers. public ServerAction() { } /// Creates a typed action with the provider discriminator value. protected ServerAction(string type) { Type = type; } [JsonPropertyName("type")] public string Type { get; init; } = string.Empty; } /// An action type not yet represented by a concrete SDK class. public sealed class UnknownServerAction : ServerAction { public UnknownServerAction(string type) : base(type) { } } /// Adds an additional disk to a server. public sealed class AddDiskServerAction : ServerAction { public AddDiskServerAction() : base("add_disk") { } [JsonPropertyName("size_gigabytes")] public int SizeGigabytes { get; init; } [JsonPropertyName("description")] public string? Description { get; init; } } /// Attaches a backup image to a server. public sealed class AttachBackupServerAction : ServerAction { public AttachBackupServerAction() : base("attach_backup") { } [JsonPropertyName("image")] public long ImageId { get; init; } } /// Changes advanced virtual-machine features. public sealed class ChangeAdvancedFeaturesServerAction : ServerAction { public ChangeAdvancedFeaturesServerAction() : base("change_advanced_features") { } [JsonPropertyName("enabled_advanced_features")] public IReadOnlyList? EnabledAdvancedFeatures { get; init; } [JsonPropertyName("processor_model")] public long? ProcessorModel { get; init; } [JsonPropertyName("automatic_processor_model")] public bool? AutomaticProcessorModel { get; init; } [JsonPropertyName("machine_type")] public string? MachineType { get; init; } [JsonPropertyName("automatic_machine_type")] public bool? AutomaticMachineType { get; init; } [JsonPropertyName("video_device")] public string? VideoDevice { get; init; } } /// Replaces the advanced firewall rules on a server. public sealed class ChangeAdvancedFirewallRulesServerAction : ServerAction { public ChangeAdvancedFirewallRulesServerAction() : base("change_advanced_firewall_rules") { } [JsonPropertyName("firewall_rules")] public IReadOnlyList FirewallRules { get; init; } = Array.Empty(); } /// Changes a server backup schedule. public sealed class ChangeBackupScheduleServerAction : ServerAction { public ChangeBackupScheduleServerAction() : base("change_backup_schedule") { } [JsonPropertyName("backup_hour_of_day")] public int? BackupHourOfDay { get; init; } [JsonPropertyName("backup_day_of_week")] public int? BackupDayOfWeek { get; init; } [JsonPropertyName("backup_day_of_month")] public int? BackupDayOfMonth { get; init; } } /// Enables or disables IPv6 for a server. public sealed class ChangeIpv6ServerAction : ServerAction { public ChangeIpv6ServerAction() : base("change_ipv6") { } [JsonPropertyName("enabled")] public bool Enabled { get; init; } } /// Changes a server's IPv6 reverse nameservers. public sealed class ChangeIpv6ReverseNameserversServerAction : ServerAction { public ChangeIpv6ReverseNameserversServerAction() : base("change_ipv6_reverse_nameservers") { } [JsonPropertyName("ipv6_reverse_nameservers")] public IReadOnlyList Ipv6ReverseNameservers { get; init; } = Array.Empty(); } /// Changes a server kernel. public sealed class ChangeKernelServerAction : ServerAction { public ChangeKernelServerAction() : base("change_kernel") { } [JsonPropertyName("kernel")] public long KernelId { get; init; } } /// Changes whether offsite backup copies are managed automatically. public sealed class ChangeManageOffsiteBackupCopiesServerAction : ServerAction { public ChangeManageOffsiteBackupCopiesServerAction() : base("change_manage_offsite_backup_copies") { } [JsonPropertyName("manage_offsite_backup_copies")] public bool ManageOffsiteBackupCopies { get; init; } } /// Moves a server onto or off a VPC network. public sealed class ChangeNetworkServerAction : ServerAction { public ChangeNetworkServerAction() : base("change_network") { } [JsonPropertyName("vpc_id")] public long? VpcId { get; init; } } /// Changes the server's offsite backup location. public sealed class ChangeOffsiteBackupLocationServerAction : ServerAction { public ChangeOffsiteBackupLocationServerAction() : base("change_offsite_backup_location") { } [JsonPropertyName("offsite_backup_location")] public string? OffsiteBackupLocation { get; init; } } /// Changes the server's partner server relationship. public sealed class ChangePartnerServerAction : ServerAction { public ChangePartnerServerAction() : base("change_partner") { } [JsonPropertyName("partner_server_id")] public long? PartnerServerId { get; init; } } /// Enables or disables port blocking. public sealed class ChangePortBlockingServerAction : ServerAction { public ChangePortBlockingServerAction() : base("change_port_blocking") { } [JsonPropertyName("enabled")] public bool Enabled { get; init; } } /// Moves a server to a new region. public sealed class ChangeRegionServerAction : ServerAction { public ChangeRegionServerAction() : base("change_region") { } [JsonPropertyName("region")] public string Region { get; init; } = string.Empty; } /// Changes an IPv4 reverse name. public sealed class ChangeReverseNameServerAction : ServerAction { public ChangeReverseNameServerAction() : base("change_reverse_name") { } [JsonPropertyName("ipv4_address")] public string Ipv4Address { get; init; } = string.Empty; [JsonPropertyName("reverse_name")] public string? ReverseName { get; init; } } /// Enables or disables a separate private network interface. public sealed class ChangeSeparatePrivateNetworkInterfaceServerAction : ServerAction { public ChangeSeparatePrivateNetworkInterfaceServerAction() : base("change_separate_private_network_interface") { } [JsonPropertyName("enabled")] public bool Enabled { get; init; } } /// Enables or disables source-and-destination checking. public sealed class ChangeSourceAndDestinationCheckServerAction : ServerAction { public ChangeSourceAndDestinationCheckServerAction() : base("change_source_and_destination_check") { } [JsonPropertyName("enabled")] public bool Enabled { get; init; } } /// Replaces a server's threshold-alert configuration. public sealed class ChangeThresholdAlertsServerAction : ServerAction { public ChangeThresholdAlertsServerAction() : base("change_threshold_alerts") { } [JsonPropertyName("threshold_alerts")] public IReadOnlyList ThresholdAlerts { get; init; } = Array.Empty(); } /// Changes a VPC IPv4 address on a server. public sealed class ChangeVpcIpv4ServerAction : ServerAction { public ChangeVpcIpv4ServerAction() : base("change_vpc_ipv4") { } [JsonPropertyName("current_ipv4_address")] public string CurrentIpv4Address { get; init; } = string.Empty; [JsonPropertyName("new_ipv4_address")] public string NewIpv4Address { get; init; } = string.Empty; } /// Clones a backup image onto another server. public sealed class CloneUsingBackupServerAction : ServerAction { public CloneUsingBackupServerAction() : base("clone_using_backup") { } [JsonPropertyName("image_id")] public long ImageId { get; init; } [JsonPropertyName("target_server_id")] public long TargetServerId { get; init; } [JsonPropertyName("name")] public string? Name { get; init; } } /// Deletes a non-primary disk. public sealed class DeleteDiskServerAction : ServerAction { public DeleteDiskServerAction() : base("delete_disk") { } [JsonPropertyName("disk_id")] public long DiskId { get; init; } } /// Detaches an attached backup from a server. public sealed class DetachBackupServerAction : ServerAction { public DetachBackupServerAction() : base("detach_backup") { } } /// Disables automatic backups. public sealed class DisableBackupsServerAction : ServerAction { public DisableBackupsServerAction() : base("disable_backups") { } } /// Disables SELinux in a compatible installed distribution. public sealed class DisableSelinuxServerAction : ServerAction { public DisableSelinuxServerAction() : base("disable_selinux") { } } /// Enables automatic backups. public sealed class EnableBackupsServerAction : ServerAction { public EnableBackupsServerAction() : base("enable_backups") { } } /// Enables IPv6 on a server. public sealed class EnableIpv6ServerAction : ServerAction { public EnableIpv6ServerAction() : base("enable_ipv6") { } } /// Checks whether a server is running. public sealed class IsRunningServerAction : ServerAction { public IsRunningServerAction() : base("is_running") { } } /// Resets a server password. public sealed class PasswordResetServerAction : ServerAction { public PasswordResetServerAction() : base("password_reset") { } [JsonPropertyName("username")] public string? Username { get; init; } /// Do not log this value. [JsonPropertyName("password")] public string? Password { get; init; } } /// Pings a server. public sealed class PingServerAction : ServerAction { public PingServerAction() : base("ping") { } } /// Power cycles a server. public sealed class PowerCycleServerAction : ServerAction { public PowerCycleServerAction() : base("power_cycle") { } } /// Powers a server off. public sealed class PowerOffServerAction : ServerAction { public PowerOffServerAction() : base("power_off") { } } /// Powers a server on. public sealed class PowerOnServerAction : ServerAction { public PowerOnServerAction() : base("power_on") { } } /// Reboots a server. public sealed class RebootServerAction : ServerAction { public RebootServerAction() : base("reboot") { } } /// Rebuilds a server from an image. public sealed class RebuildServerAction : ServerAction { public RebuildServerAction() : base("rebuild") { } /// An image ID or image slug. Omit to reuse the existing image. [JsonPropertyName("image")] public object? Image { get; init; } [JsonPropertyName("options")] public ImageOptions? Options { get; init; } } /// Renames a server. public sealed class RenameServerAction : ServerAction { public RenameServerAction() : base("rename") { } [JsonPropertyName("name")] public string Name { get; init; } = string.Empty; } /// Changes selected size options during a resize action. public sealed class ChangeSizeOptionsRequest : BinaryLaneRequestModel { [JsonPropertyName("daily_backups")] public int? DailyBackups { get; init; } [JsonPropertyName("weekly_backups")] public int? WeeklyBackups { get; init; } [JsonPropertyName("monthly_backups")] public int? MonthlyBackups { get; init; } [JsonPropertyName("offsite_backups")] public bool? OffsiteBackups { get; init; } [JsonPropertyName("ipv4_addresses")] public int? Ipv4Addresses { get; init; } [JsonPropertyName("memory")] public int? MemoryMegabytes { get; init; } [JsonPropertyName("disk")] public int? DiskGigabytes { get; init; } [JsonPropertyName("transfer")] public double? TransferGigabytes { get; init; } [JsonPropertyName("ipv4_addresses_to_remove")] public IReadOnlyList? Ipv4AddressesToRemove { get; init; } } /// Changes the source image selected by a resize operation. public sealed class ChangeImage : BinaryLaneRequestModel { /// An image ID or image slug. [JsonPropertyName("image")] public object? Image { get; init; } [JsonPropertyName("options")] public ImageOptions? Options { get; init; } } /// Changes licences selected by a resize operation. public sealed class ChangeLicenses : BinaryLaneRequestModel { [JsonPropertyName("licenses")] public IReadOnlyList Licenses { get; init; } = Array.Empty(); } /// Resizes a server. public sealed class ResizeServerAction : ServerAction { public ResizeServerAction() : base("resize") { } [JsonPropertyName("size")] public string? Size { get; init; } [JsonPropertyName("options")] public ChangeSizeOptionsRequest? Options { get; init; } [JsonPropertyName("change_image")] public ChangeImage? ChangeImage { get; init; } [JsonPropertyName("change_licenses")] public ChangeLicenses? ChangeLicenses { get; init; } [JsonPropertyName("pre_action_backup")] public TakeBackupServerAction? PreActionBackup { get; init; } } /// Resizes an individual server disk. public sealed class ResizeDiskServerAction : ServerAction { public ResizeDiskServerAction() : base("resize_disk") { } [JsonPropertyName("disk_id")] public long DiskId { get; init; } [JsonPropertyName("size_gigabytes")] public int SizeGigabytes { get; init; } } /// Restores a server from an image. public sealed class RestoreServerAction : ServerAction { public RestoreServerAction() : base("restore") { } /// An image ID or image slug. [JsonPropertyName("image")] public object Image { get; init; } = string.Empty; } /// Requests a graceful shutdown. public sealed class ShutdownServerAction : ServerAction { public ShutdownServerAction() : base("shutdown") { } } /// Creates a backup of a server. public sealed class TakeBackupServerAction : ServerAction { public TakeBackupServerAction() : base("take_backup") { } /// Provider backup slot, such as daily or temporary. [JsonPropertyName("backup_type")] public string? BackupType { get; init; } /// Provider replacement strategy. [JsonPropertyName("replacement_strategy")] public string ReplacementStrategy { get; init; } = string.Empty; [JsonPropertyName("backup_id_to_replace")] public long? BackupIdToReplace { get; init; } [JsonPropertyName("label")] public string? Label { get; init; } } /// Reverses a scheduled server cancellation. public sealed class UncancelServerAction : ServerAction { public UncancelServerAction() : base("uncancel") { } } /// Checks server uptime. public sealed class UptimeServerAction : ServerAction { public UptimeServerAction() : base("uptime") { } } /// An advanced firewall rule supplied in a server-action request. public sealed class AdvancedFirewallRuleRequest : BinaryLaneRequestModel { [JsonPropertyName("source_addresses")] public IReadOnlyList SourceAddresses { get; init; } = Array.Empty(); [JsonPropertyName("destination_addresses")] public IReadOnlyList DestinationAddresses { get; init; } = Array.Empty(); [JsonPropertyName("destination_ports")] public IReadOnlyList? DestinationPorts { get; init; } /// Provider protocol value, such as tcp. [JsonPropertyName("protocol")] public string Protocol { get; init; } = string.Empty; /// Provider action value, such as accept. [JsonPropertyName("action")] public string Action { get; init; } = string.Empty; [JsonPropertyName("description")] public string? Description { get; init; } }