2 use serde
::{Deserialize, Serialize}
;
4 use proxmox
::api
::{api, schema::*}
;
5 use proxmox
::const_regex
;
6 use proxmox
::{IPRE, IPRE_BRACKET, IPV4RE, IPV6RE, IPV4OCTET, IPV6H16, IPV6LS32}
;
8 use crate::backup
::{CryptMode, Fingerprint, BACKUP_ID_REGEX}
;
9 use crate::server
::UPID
;
16 pub use userid
::{Realm, RealmRef}
;
17 pub use userid
::{Tokenname, TokennameRef}
;
18 pub use userid
::{Username, UsernameRef}
;
19 pub use userid
::Userid
;
20 pub use userid
::Authid
;
21 pub use userid
::{PROXMOX_TOKEN_ID_SCHEMA, PROXMOX_TOKEN_NAME_SCHEMA, PROXMOX_GROUP_ID_SCHEMA}
;
26 // File names: may not contain slashes, may not start with "."
27 pub const FILENAME_FORMAT
: ApiStringFormat
= ApiStringFormat
::VerifyFn(|name
| {
28 if name
.starts_with('
.'
) {
29 bail
!("file names may not start with '.'");
31 if name
.contains('
/'
) {
32 bail
!("file names may not contain slashes");
37 macro_rules
! DNS_LABEL { () => (r"(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?)") }
38 macro_rules
! DNS_NAME { () => (concat!(r"(?:(?:", DNS_LABEL!() , r"\.)*", DNS_LABEL!(), ")")) }
40 macro_rules
! CIDR_V4_REGEX_STR { () => (concat!(r"(?:", IPV4RE!(), r"/\d{1,2}
)$
")) }
41 macro_rules! CIDR_V6_REGEX_STR { () => (concat!(r"(?:", IPV6RE!(), r"/\d{1,3})$")) }
44 pub IP_V4_REGEX
= concat
!(r
"^", IPV4RE
!(), r
"$");
45 pub IP_V6_REGEX
= concat
!(r
"^", IPV6RE
!(), r
"$");
46 pub IP_REGEX
= concat
!(r
"^", IPRE
!(), r
"$");
47 pub CIDR_V4_REGEX
= concat
!(r
"^", CIDR_V4_REGEX_STR
!(), r
"$");
48 pub CIDR_V6_REGEX
= concat
!(r
"^", CIDR_V6_REGEX_STR
!(), r
"$");
49 pub CIDR_REGEX
= concat
!(r
"^(?:", CIDR_V4_REGEX_STR
!(), "|", CIDR_V6_REGEX_STR
!(), r
")$");
51 pub SHA256_HEX_REGEX
= r
"^[a-f0-9]{64}$"; // fixme: define in common_regex ?
52 pub SYSTEMD_DATETIME_REGEX
= r
"^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}(:\d{2})?)?$"; // fixme: define in common_regex ?
54 pub PASSWORD_REGEX
= r
"^[[:^cntrl:]]*$"; // everything but control characters
56 /// Regex for safe identifiers.
59 /// [article](https://dwheeler.com/essays/fixing-unix-linux-filenames.html)
60 /// contains further information why it is reasonable to restict
61 /// names this way. This is not only useful for filenames, but for
62 /// any identifier command line tools work with.
63 pub PROXMOX_SAFE_ID_REGEX
= concat
!(r
"^", PROXMOX_SAFE_ID_REGEX_STR
!(), r
"$");
65 /// Regex for verification jobs 'DATASTORE:ACTUAL_JOB_ID'
66 pub VERIFICATION_JOB_WORKER_ID_REGEX
= concat
!(r
"^(", PROXMOX_SAFE_ID_REGEX_STR
!(), r
"):");
67 /// Regex for sync jobs 'REMOTE:REMOTE_DATASTORE:LOCAL_DATASTORE:ACTUAL_JOB_ID'
68 pub SYNC_JOB_WORKER_ID_REGEX
= concat
!(r
"^(", PROXMOX_SAFE_ID_REGEX_STR
!(), r
"):(", PROXMOX_SAFE_ID_REGEX_STR
!(), r
"):(", PROXMOX_SAFE_ID_REGEX_STR
!(), r
"):");
70 pub SINGLE_LINE_COMMENT_REGEX
= r
"^[[:^cntrl:]]*$";
72 pub HOSTNAME_REGEX
= r
"^(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?)$";
74 pub DNS_NAME_REGEX
= concat
!(r
"^", DNS_NAME
!(), r
"$");
76 pub DNS_NAME_OR_IP_REGEX
= concat
!(r
"^(?:", DNS_NAME
!(), "|", IPRE
!(), r
")$");
78 pub BACKUP_REPO_URL_REGEX
= concat
!(r
"^^(?:(?:(", USER_ID_REGEX_STR
!(), "|", APITOKEN_ID_REGEX_STR
!(), ")@)?(", DNS_NAME
!(), "|", IPRE_BRACKET
!() ,"):)?(?:([0-9]{1,5}):)?(", PROXMOX_SAFE_ID_REGEX_STR
!(), r
")$");
80 pub FINGERPRINT_SHA256_REGEX
= r
"^(?:[0-9a-fA-F][0-9a-fA-F])(?::[0-9a-fA-F][0-9a-fA-F]){31}$";
82 pub ACL_PATH_REGEX
= concat
!(r
"^(?:/|", r
"(?:/", PROXMOX_SAFE_ID_REGEX_STR
!(), ")+", r
")$");
84 pub SUBSCRIPTION_KEY_REGEX
= concat
!(r
"^pbs(?:[cbsp])-[0-9a-f]{10}$");
86 pub BLOCKDEVICE_NAME_REGEX
= r
"^(:?(:?h|s|x?v)d[a-z]+)|(:?nvme\d+n\d+)$";
88 pub ZPOOL_NAME_REGEX
= r
"^[a-zA-Z][a-z0-9A-Z\-_.:]+$";
91 pub const SYSTEMD_DATETIME_FORMAT
: ApiStringFormat
=
92 ApiStringFormat
::Pattern(&SYSTEMD_DATETIME_REGEX
);
94 pub const IP_V4_FORMAT
: ApiStringFormat
=
95 ApiStringFormat
::Pattern(&IP_V4_REGEX
);
97 pub const IP_V6_FORMAT
: ApiStringFormat
=
98 ApiStringFormat
::Pattern(&IP_V6_REGEX
);
100 pub const IP_FORMAT
: ApiStringFormat
=
101 ApiStringFormat
::Pattern(&IP_REGEX
);
103 pub const PVE_CONFIG_DIGEST_FORMAT
: ApiStringFormat
=
104 ApiStringFormat
::Pattern(&SHA256_HEX_REGEX
);
106 pub const FINGERPRINT_SHA256_FORMAT
: ApiStringFormat
=
107 ApiStringFormat
::Pattern(&FINGERPRINT_SHA256_REGEX
);
109 pub const PROXMOX_SAFE_ID_FORMAT
: ApiStringFormat
=
110 ApiStringFormat
::Pattern(&PROXMOX_SAFE_ID_REGEX
);
112 pub const BACKUP_ID_FORMAT
: ApiStringFormat
=
113 ApiStringFormat
::Pattern(&BACKUP_ID_REGEX
);
115 pub const SINGLE_LINE_COMMENT_FORMAT
: ApiStringFormat
=
116 ApiStringFormat
::Pattern(&SINGLE_LINE_COMMENT_REGEX
);
118 pub const HOSTNAME_FORMAT
: ApiStringFormat
=
119 ApiStringFormat
::Pattern(&HOSTNAME_REGEX
);
121 pub const DNS_NAME_FORMAT
: ApiStringFormat
=
122 ApiStringFormat
::Pattern(&DNS_NAME_REGEX
);
124 pub const DNS_NAME_OR_IP_FORMAT
: ApiStringFormat
=
125 ApiStringFormat
::Pattern(&DNS_NAME_OR_IP_REGEX
);
127 pub const PASSWORD_FORMAT
: ApiStringFormat
=
128 ApiStringFormat
::Pattern(&PASSWORD_REGEX
);
130 pub const ACL_PATH_FORMAT
: ApiStringFormat
=
131 ApiStringFormat
::Pattern(&ACL_PATH_REGEX
);
133 pub const NETWORK_INTERFACE_FORMAT
: ApiStringFormat
=
134 ApiStringFormat
::Pattern(&PROXMOX_SAFE_ID_REGEX
);
136 pub const CIDR_V4_FORMAT
: ApiStringFormat
=
137 ApiStringFormat
::Pattern(&CIDR_V4_REGEX
);
139 pub const CIDR_V6_FORMAT
: ApiStringFormat
=
140 ApiStringFormat
::Pattern(&CIDR_V6_REGEX
);
142 pub const CIDR_FORMAT
: ApiStringFormat
=
143 ApiStringFormat
::Pattern(&CIDR_REGEX
);
145 pub const SUBSCRIPTION_KEY_FORMAT
: ApiStringFormat
=
146 ApiStringFormat
::Pattern(&SUBSCRIPTION_KEY_REGEX
);
148 pub const BLOCKDEVICE_NAME_FORMAT
: ApiStringFormat
=
149 ApiStringFormat
::Pattern(&BLOCKDEVICE_NAME_REGEX
);
151 pub const PASSWORD_SCHEMA
: Schema
= StringSchema
::new("Password.")
152 .format(&PASSWORD_FORMAT
)
157 pub const PBS_PASSWORD_SCHEMA
: Schema
= StringSchema
::new("User Password.")
158 .format(&PASSWORD_FORMAT
)
163 pub const CERT_FINGERPRINT_SHA256_SCHEMA
: Schema
= StringSchema
::new(
164 "X509 certificate fingerprint (sha256)."
166 .format(&FINGERPRINT_SHA256_FORMAT
)
169 pub const TAPE_ENCRYPTION_KEY_FINGERPRINT_SCHEMA
: Schema
= StringSchema
::new(
170 "Tape encryption key fingerprint (sha256)."
172 .format(&FINGERPRINT_SHA256_FORMAT
)
175 pub const PROXMOX_CONFIG_DIGEST_SCHEMA
: Schema
= StringSchema
::new(
176 "Prevent changes if current configuration file has different \
177 SHA256 digest. This can be used to prevent concurrent \
180 .format(&PVE_CONFIG_DIGEST_FORMAT
) .schema();
183 pub const CHUNK_DIGEST_FORMAT
: ApiStringFormat
=
184 ApiStringFormat
::Pattern(&SHA256_HEX_REGEX
);
186 pub const CHUNK_DIGEST_SCHEMA
: Schema
= StringSchema
::new("Chunk digest (SHA256).")
187 .format(&CHUNK_DIGEST_FORMAT
)
190 pub const NODE_SCHEMA
: Schema
= StringSchema
::new("Node name (or 'localhost')")
191 .format(&ApiStringFormat
::VerifyFn(|node
| {
192 if node
== "localhost" || node
== proxmox
::tools
::nodename() {
195 bail
!("no such node '{}'", node
);
200 pub const SEARCH_DOMAIN_SCHEMA
: Schema
=
201 StringSchema
::new("Search domain for host-name lookup.").schema();
203 pub const FIRST_DNS_SERVER_SCHEMA
: Schema
=
204 StringSchema
::new("First name server IP address.")
208 pub const SECOND_DNS_SERVER_SCHEMA
: Schema
=
209 StringSchema
::new("Second name server IP address.")
213 pub const THIRD_DNS_SERVER_SCHEMA
: Schema
=
214 StringSchema
::new("Third name server IP address.")
218 pub const IP_V4_SCHEMA
: Schema
=
219 StringSchema
::new("IPv4 address.")
220 .format(&IP_V4_FORMAT
)
224 pub const IP_V6_SCHEMA
: Schema
=
225 StringSchema
::new("IPv6 address.")
226 .format(&IP_V6_FORMAT
)
230 pub const IP_SCHEMA
: Schema
=
231 StringSchema
::new("IP (IPv4 or IPv6) address.")
236 pub const CIDR_V4_SCHEMA
: Schema
=
237 StringSchema
::new("IPv4 address with netmask (CIDR notation).")
238 .format(&CIDR_V4_FORMAT
)
242 pub const CIDR_V6_SCHEMA
: Schema
=
243 StringSchema
::new("IPv6 address with netmask (CIDR notation).")
244 .format(&CIDR_V6_FORMAT
)
248 pub const CIDR_SCHEMA
: Schema
=
249 StringSchema
::new("IP address (IPv4 or IPv6) with netmask (CIDR notation).")
250 .format(&CIDR_FORMAT
)
254 pub const TIME_ZONE_SCHEMA
: Schema
= StringSchema
::new(
255 "Time zone. The file '/usr/share/zoneinfo/zone.tab' contains the list of valid names.")
256 .format(&SINGLE_LINE_COMMENT_FORMAT
)
261 pub const ACL_PATH_SCHEMA
: Schema
= StringSchema
::new(
262 "Access control path.")
263 .format(&ACL_PATH_FORMAT
)
268 pub const ACL_PROPAGATE_SCHEMA
: Schema
= BooleanSchema
::new(
269 "Allow to propagate (inherit) permissions.")
273 pub const ACL_UGID_TYPE_SCHEMA
: Schema
= StringSchema
::new(
274 "Type of 'ugid' property.")
275 .format(&ApiStringFormat
::Enum(&[
276 EnumEntry
::new("user", "User"),
277 EnumEntry
::new("group", "Group")]))
280 pub const BACKUP_ARCHIVE_NAME_SCHEMA
: Schema
=
281 StringSchema
::new("Backup archive name.")
282 .format(&PROXMOX_SAFE_ID_FORMAT
)
285 pub const BACKUP_TYPE_SCHEMA
: Schema
=
286 StringSchema
::new("Backup type.")
287 .format(&ApiStringFormat
::Enum(&[
288 EnumEntry
::new("vm", "Virtual Machine Backup"),
289 EnumEntry
::new("ct", "Container Backup"),
290 EnumEntry
::new("host", "Host Backup")]))
293 pub const BACKUP_ID_SCHEMA
: Schema
=
294 StringSchema
::new("Backup ID.")
295 .format(&BACKUP_ID_FORMAT
)
298 pub const BACKUP_TIME_SCHEMA
: Schema
=
299 IntegerSchema
::new("Backup time (Unix epoch.)")
300 .minimum(1_547_797_308)
303 pub const UPID_SCHEMA
: Schema
= StringSchema
::new("Unique Process/Task ID.")
307 pub const DATASTORE_SCHEMA
: Schema
= StringSchema
::new("Datastore name.")
308 .format(&PROXMOX_SAFE_ID_FORMAT
)
313 pub const SYNC_SCHEDULE_SCHEMA
: Schema
= StringSchema
::new(
314 "Run sync job at specified schedule.")
315 .format(&ApiStringFormat
::VerifyFn(crate::tools
::systemd
::time
::verify_calendar_event
))
318 pub const GC_SCHEDULE_SCHEMA
: Schema
= StringSchema
::new(
319 "Run garbage collection job at specified schedule.")
320 .format(&ApiStringFormat
::VerifyFn(crate::tools
::systemd
::time
::verify_calendar_event
))
323 pub const PRUNE_SCHEDULE_SCHEMA
: Schema
= StringSchema
::new(
324 "Run prune job at specified schedule.")
325 .format(&ApiStringFormat
::VerifyFn(crate::tools
::systemd
::time
::verify_calendar_event
))
328 pub const VERIFICATION_SCHEDULE_SCHEMA
: Schema
= StringSchema
::new(
329 "Run verify job at specified schedule.")
330 .format(&ApiStringFormat
::VerifyFn(crate::tools
::systemd
::time
::verify_calendar_event
))
333 pub const REMOTE_ID_SCHEMA
: Schema
= StringSchema
::new("Remote ID.")
334 .format(&PROXMOX_SAFE_ID_FORMAT
)
339 pub const JOB_ID_SCHEMA
: Schema
= StringSchema
::new("Job ID.")
340 .format(&PROXMOX_SAFE_ID_FORMAT
)
345 pub const REMOVE_VANISHED_BACKUPS_SCHEMA
: Schema
= BooleanSchema
::new(
346 "Delete vanished backups. This remove the local copy if the remote backup was deleted.")
350 pub const IGNORE_VERIFIED_BACKUPS_SCHEMA
: Schema
= BooleanSchema
::new(
351 "Do not verify backups that are already verified if their verification is not outdated.")
355 pub const VERIFICATION_OUTDATED_AFTER_SCHEMA
: Schema
= IntegerSchema
::new(
356 "Days after that a verification becomes outdated")
360 pub const SINGLE_LINE_COMMENT_SCHEMA
: Schema
= StringSchema
::new("Comment (single line).")
361 .format(&SINGLE_LINE_COMMENT_FORMAT
)
364 pub const HOSTNAME_SCHEMA
: Schema
= StringSchema
::new("Hostname (as defined in RFC1123).")
365 .format(&HOSTNAME_FORMAT
)
368 pub const DNS_NAME_OR_IP_SCHEMA
: Schema
= StringSchema
::new("DNS name or IP address.")
369 .format(&DNS_NAME_OR_IP_FORMAT
)
372 pub const SUBSCRIPTION_KEY_SCHEMA
: Schema
= StringSchema
::new("Proxmox Backup Server subscription key.")
373 .format(&SUBSCRIPTION_KEY_FORMAT
)
378 pub const BLOCKDEVICE_NAME_SCHEMA
: Schema
= StringSchema
::new("Block device name (/sys/block/<name>).")
379 .format(&BLOCKDEVICE_NAME_FORMAT
)
384 // Complex type definitions
389 schema
: DATASTORE_SCHEMA
,
393 schema
: SINGLE_LINE_COMMENT_SCHEMA
,
397 #[derive(Serialize, Deserialize)]
398 #[serde(rename_all="kebab-case")]
399 /// Basic information about a datastore.
400 pub struct DataStoreListItem
{
402 pub comment
: Option
<String
>,
408 schema
: BACKUP_TYPE_SCHEMA
,
411 schema
: BACKUP_ID_SCHEMA
,
414 schema
: BACKUP_TIME_SCHEMA
,
421 schema
: BACKUP_ARCHIVE_NAME_SCHEMA
430 #[derive(Serialize, Deserialize)]
431 #[serde(rename_all="kebab-case")]
432 /// Basic information about a backup group.
433 pub struct GroupListItem
{
434 pub backup_type
: String
, // enum
435 pub backup_id
: String
,
436 pub last_backup
: i64,
437 /// Number of contained snapshots
438 pub backup_count
: u64,
439 /// List of contained archive files.
440 pub files
: Vec
<String
>,
441 /// The owner of group
442 #[serde(skip_serializing_if="Option::is_none")]
443 pub owner
: Option
<Authid
>,
447 #[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
448 #[serde(rename_all = "lowercase")]
449 /// Result of a verify operation.
450 pub enum VerifyState
{
451 /// Verification was successful
453 /// Verification reported one or more errors
467 #[derive(Serialize, Deserialize)]
469 pub struct SnapshotVerifyState
{
470 /// UPID of the verify task
472 /// State of the verification. Enum.
473 pub state
: VerifyState
,
479 schema
: BACKUP_TYPE_SCHEMA
,
482 schema
: BACKUP_ID_SCHEMA
,
485 schema
: BACKUP_TIME_SCHEMA
,
488 schema
: SINGLE_LINE_COMMENT_SCHEMA
,
492 type: SnapshotVerifyState
,
501 schema
: BACKUP_ARCHIVE_NAME_SCHEMA
510 #[derive(Serialize, Deserialize)]
511 #[serde(rename_all="kebab-case")]
512 /// Basic information about backup snapshot.
513 pub struct SnapshotListItem
{
514 pub backup_type
: String
, // enum
515 pub backup_id
: String
,
516 pub backup_time
: i64,
517 /// The first line from manifest "notes"
518 #[serde(skip_serializing_if="Option::is_none")]
519 pub comment
: Option
<String
>,
520 /// The result of the last run verify task
521 #[serde(skip_serializing_if="Option::is_none")]
522 pub verification
: Option
<SnapshotVerifyState
>,
523 /// Fingerprint of encryption key
524 #[serde(skip_serializing_if="Option::is_none")]
525 pub fingerprint
: Option
<Fingerprint
>,
526 /// List of contained archive files.
527 pub files
: Vec
<BackupContent
>,
528 /// Overall snapshot size (sum of all archive sizes).
529 #[serde(skip_serializing_if="Option::is_none")]
530 pub size
: Option
<u64>,
531 /// The owner of the snapshots group
532 #[serde(skip_serializing_if="Option::is_none")]
533 pub owner
: Option
<Authid
>,
539 schema
: BACKUP_TYPE_SCHEMA
,
542 schema
: BACKUP_ID_SCHEMA
,
545 schema
: BACKUP_TIME_SCHEMA
,
549 #[derive(Serialize, Deserialize)]
550 #[serde(rename_all="kebab-case")]
552 pub struct PruneListItem
{
553 pub backup_type
: String
, // enum
554 pub backup_id
: String
,
555 pub backup_time
: i64,
560 pub const PRUNE_SCHEMA_KEEP_DAILY
: Schema
= IntegerSchema
::new(
561 "Number of daily backups to keep.")
565 pub const PRUNE_SCHEMA_KEEP_HOURLY
: Schema
= IntegerSchema
::new(
566 "Number of hourly backups to keep.")
570 pub const PRUNE_SCHEMA_KEEP_LAST
: Schema
= IntegerSchema
::new(
571 "Number of backups to keep.")
575 pub const PRUNE_SCHEMA_KEEP_MONTHLY
: Schema
= IntegerSchema
::new(
576 "Number of monthly backups to keep.")
580 pub const PRUNE_SCHEMA_KEEP_WEEKLY
: Schema
= IntegerSchema
::new(
581 "Number of weekly backups to keep.")
585 pub const PRUNE_SCHEMA_KEEP_YEARLY
: Schema
= IntegerSchema
::new(
586 "Number of yearly backups to keep.")
593 schema
: BACKUP_ARCHIVE_NAME_SCHEMA
,
601 #[derive(Serialize, Deserialize)]
602 #[serde(rename_all="kebab-case")]
603 /// Basic information about archive files inside a backup snapshot.
604 pub struct BackupContent
{
605 pub filename
: String
,
606 /// Info if file is encrypted, signed, or neither.
607 #[serde(skip_serializing_if="Option::is_none")]
608 pub crypt_mode
: Option
<CryptMode
>,
609 /// Archive size (from backup manifest).
610 #[serde(skip_serializing_if="Option::is_none")]
611 pub size
: Option
<u64>,
622 #[derive(Clone, Serialize, Deserialize)]
623 #[serde(rename_all="kebab-case")]
624 /// Garbage collection status.
625 pub struct GarbageCollectionStatus
{
626 pub upid
: Option
<String
>,
627 /// Number of processed index files.
628 pub index_file_count
: usize,
629 /// Sum of bytes referred by index files.
630 pub index_data_bytes
: u64,
631 /// Bytes used on disk.
633 /// Chunks used on disk.
634 pub disk_chunks
: usize,
635 /// Sum of removed bytes.
636 pub removed_bytes
: u64,
637 /// Number of removed chunks.
638 pub removed_chunks
: usize,
639 /// Sum of pending bytes (pending removal - kept for safety).
640 pub pending_bytes
: u64,
641 /// Number of pending chunks (pending removal - kept for safety).
642 pub pending_chunks
: usize,
643 /// Number of chunks marked as .bad by verify that have been removed by GC.
644 pub removed_bad
: usize,
645 /// Number of chunks still marked as .bad after garbage collection.
646 pub still_bad
: usize,
649 impl Default
for GarbageCollectionStatus
{
650 fn default() -> Self {
651 GarbageCollectionStatus
{
669 #[derive(Serialize, Deserialize)]
670 /// Storage space usage information.
671 pub struct StorageStatus
{
672 /// Total space (bytes).
674 /// Used space (bytes).
676 /// Available space (bytes).
681 #[derive(Serialize, Deserialize, Default)]
682 /// Backup Type group/snapshot counts.
683 pub struct TypeCounts
{
684 /// The number of groups of the type.
686 /// The number of snapshots of the type.
710 #[derive(Serialize, Deserialize, Default)]
711 /// Counts of groups/snapshots per BackupType.
713 /// The counts for CT backups
714 pub ct
: Option
<TypeCounts
>,
715 /// The counts for Host backups
716 pub host
: Option
<TypeCounts
>,
717 /// The counts for VM backups
718 pub vm
: Option
<TypeCounts
>,
719 /// The counts for other backup types
720 pub other
: Option
<TypeCounts
>,
726 type: GarbageCollectionStatus
,
735 #[derive(Serialize, Deserialize)]
736 #[serde(rename_all="kebab-case")]
737 /// Overall Datastore status and useful information.
738 pub struct DataStoreStatus
{
739 /// Total space (bytes).
741 /// Used space (bytes).
743 /// Available space (bytes).
745 /// Status of last GC
746 #[serde(skip_serializing_if="Option::is_none")]
747 pub gc_status
: Option
<GarbageCollectionStatus
>,
748 /// Group/Snapshot counts
749 #[serde(skip_serializing_if="Option::is_none")]
750 pub counts
: Option
<Counts
>,
755 upid
: { schema: UPID_SCHEMA }
,
756 user
: { type: Authid }
,
759 #[derive(Serialize, Deserialize)]
761 pub struct TaskListItem
{
763 /// The node name where the task is running on.
767 /// The task start time (Epoch)
769 /// The task start time (Epoch)
771 /// Worker type (arbitrary ASCII string)
772 pub worker_type
: String
,
773 /// Worker ID (arbitrary ASCII string)
774 pub worker_id
: Option
<String
>,
775 /// The authenticated entity who started the task
777 /// The task end time (Epoch)
778 #[serde(skip_serializing_if="Option::is_none")]
779 pub endtime
: Option
<i64>,
781 #[serde(skip_serializing_if="Option::is_none")]
782 pub status
: Option
<String
>,
785 impl From
<crate::server
::TaskListInfo
> for TaskListItem
{
786 fn from(info
: crate::server
::TaskListInfo
) -> Self {
787 let (endtime
, status
) = info
789 .map_or_else(|| (None
, None
), |a
| (Some(a
.endtime()), Some(a
.to_string())));
793 node
: "localhost".to_string(),
794 pid
: info
.upid
.pid
as i64,
795 pstart
: info
.upid
.pstart
,
796 starttime
: info
.upid
.starttime
,
797 worker_type
: info
.upid
.worker_type
,
798 worker_id
: info
.upid
.worker_id
,
799 user
: info
.upid
.auth_id
,
807 #[derive(Eq, PartialEq, Debug, Serialize, Deserialize)]
808 #[serde(rename_all = "lowercase")]
809 pub enum TaskStateType
{
821 #[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
822 #[serde(rename_all = "lowercase")]
823 /// Node Power command type.
824 pub enum NodePowerCommand
{
825 /// Restart the server
827 /// Shutdown the server
832 #[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
833 #[serde(rename_all = "lowercase")]
834 /// Interface configuration method
835 pub enum NetworkConfigMethod
{
836 /// Configuration is done manually using other tools
838 /// Define interfaces with statically allocated addresses.
840 /// Obtain an address via DHCP
842 /// Define the loopback interface.
847 #[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
848 #[serde(rename_all = "kebab-case")]
849 #[allow(non_camel_case_types)]
852 pub enum LinuxBondMode
{
853 /// Round-robin policy
855 /// Active-backup policy
861 /// IEEE 802.3ad Dynamic link aggregation
862 #[serde(rename = "802.3ad")]
864 /// Adaptive transmit load balancing
866 /// Adaptive load balancing
871 #[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
872 #[serde(rename_all = "kebab-case")]
873 #[allow(non_camel_case_types)]
875 /// Bond Transmit Hash Policy for LACP (802.3ad)
876 pub enum BondXmitHashPolicy
{
880 #[serde(rename = "layer2+3")]
883 #[serde(rename = "layer3+4")]
888 #[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
889 #[serde(rename_all = "lowercase")]
890 /// Network interface type
891 pub enum NetworkInterfaceType
{
894 /// Physical Ethernet device
900 /// Linux VLAN (eth.10)
902 /// Interface Alias (eth:1)
904 /// Unknown interface type
908 pub const NETWORK_INTERFACE_NAME_SCHEMA
: Schema
= StringSchema
::new("Network interface name.")
909 .format(&NETWORK_INTERFACE_FORMAT
)
911 .max_length(libc
::IFNAMSIZ
-1)
914 pub const NETWORK_INTERFACE_ARRAY_SCHEMA
: Schema
= ArraySchema
::new(
915 "Network interface list.", &NETWORK_INTERFACE_NAME_SCHEMA
)
918 pub const NETWORK_INTERFACE_LIST_SCHEMA
: Schema
= StringSchema
::new(
919 "A list of network devices, comma separated.")
920 .format(&ApiStringFormat
::PropertyString(&NETWORK_INTERFACE_ARRAY_SCHEMA
))
926 schema
: NETWORK_INTERFACE_NAME_SCHEMA
,
929 type: NetworkInterfaceType
,
932 type: NetworkConfigMethod
,
936 type: NetworkConfigMethod
,
940 schema
: CIDR_V4_SCHEMA
,
944 schema
: CIDR_V6_SCHEMA
,
948 schema
: IP_V4_SCHEMA
,
952 schema
: IP_V6_SCHEMA
,
956 description
: "Option list (inet)",
959 description
: "Optional attribute line.",
964 description
: "Option list (inet6)",
967 description
: "Optional attribute line.",
972 description
: "Comments (inet, may span multiple lines)",
977 description
: "Comments (inet6, may span multiple lines)",
982 schema
: NETWORK_INTERFACE_ARRAY_SCHEMA
,
986 schema
: NETWORK_INTERFACE_ARRAY_SCHEMA
,
994 schema
: NETWORK_INTERFACE_NAME_SCHEMA
,
997 bond_xmit_hash_policy
: {
998 type: BondXmitHashPolicy
,
1003 #[derive(Debug, Serialize, Deserialize)]
1004 /// Network Interface configuration
1005 pub struct Interface
{
1006 /// Autostart interface
1007 #[serde(rename = "autostart")]
1008 pub autostart
: bool
,
1009 /// Interface is active (UP)
1014 #[serde(rename = "type")]
1015 pub interface_type
: NetworkInterfaceType
,
1016 #[serde(skip_serializing_if="Option::is_none")]
1017 pub method
: Option
<NetworkConfigMethod
>,
1018 #[serde(skip_serializing_if="Option::is_none")]
1019 pub method6
: Option
<NetworkConfigMethod
>,
1020 #[serde(skip_serializing_if="Option::is_none")]
1021 /// IPv4 address with netmask
1022 pub cidr
: Option
<String
>,
1023 #[serde(skip_serializing_if="Option::is_none")]
1025 pub gateway
: Option
<String
>,
1026 #[serde(skip_serializing_if="Option::is_none")]
1027 /// IPv6 address with netmask
1028 pub cidr6
: Option
<String
>,
1029 #[serde(skip_serializing_if="Option::is_none")]
1031 pub gateway6
: Option
<String
>,
1033 #[serde(skip_serializing_if="Vec::is_empty")]
1034 pub options
: Vec
<String
>,
1035 #[serde(skip_serializing_if="Vec::is_empty")]
1036 pub options6
: Vec
<String
>,
1038 #[serde(skip_serializing_if="Option::is_none")]
1039 pub comments
: Option
<String
>,
1040 #[serde(skip_serializing_if="Option::is_none")]
1041 pub comments6
: Option
<String
>,
1043 #[serde(skip_serializing_if="Option::is_none")]
1044 /// Maximum Transmission Unit
1045 pub mtu
: Option
<u64>,
1047 #[serde(skip_serializing_if="Option::is_none")]
1048 pub bridge_ports
: Option
<Vec
<String
>>,
1049 /// Enable bridge vlan support.
1050 #[serde(skip_serializing_if="Option::is_none")]
1051 pub bridge_vlan_aware
: Option
<bool
>,
1053 #[serde(skip_serializing_if="Option::is_none")]
1054 pub slaves
: Option
<Vec
<String
>>,
1055 #[serde(skip_serializing_if="Option::is_none")]
1056 pub bond_mode
: Option
<LinuxBondMode
>,
1057 #[serde(skip_serializing_if="Option::is_none")]
1058 #[serde(rename = "bond-primary")]
1059 pub bond_primary
: Option
<String
>,
1060 pub bond_xmit_hash_policy
: Option
<BondXmitHashPolicy
>,
1066 fn test_cert_fingerprint_schema() -> Result
<(), anyhow
::Error
> {
1068 let schema
= CERT_FINGERPRINT_SHA256_SCHEMA
;
1070 let invalid_fingerprints
= [
1071 "86:88:7c:be:26:77:a5:62:67:d9:06:f5:e4::61:3e:20:dc:cd:43:92:07:7f:fb:65:54:6c:ff:d2:96:36:f8",
1072 "88:7C:BE:26:77:a5:62:67:D9:06:f5:e4:14:61:3e:20:dc:cd:43:92:07:7f:fb:65:54:6c:ff:d2:96:36:f8",
1073 "86:88:7c:be:26:77:a5:62:67:d9:06:f5:e4::14:61:3e:20:dc:cd:43:92:07:7f:fb:65:54:6c:ff:d2:96:36:f8:ff",
1074 "XX:88:7c:be:26:77:a5:62:67:d9:06:f5:e4::14:61:3e:20:dc:cd:43:92:07:7f:fb:65:54:6c:ff:d2:96:36:f8",
1075 "86:88:Y4:be:26:77:a5:62:67:d9:06:f5:e4:14:61:3e:20:dc:cd:43:92:07:7f:fb:65:54:6c:ff:d2:96:36:f8",
1076 "86:88:0:be:26:77:a5:62:67:d9:06:f5:e4:14:61:3e:20:dc:cd:43:92:07:7f:fb:65:54:6c:ff:d2:96:36:f8",
1079 for fingerprint
in invalid_fingerprints
.iter() {
1080 if parse_simple_value(fingerprint
, &schema
).is_ok() {
1081 bail
!("test fingerprint '{}' failed - got Ok() while exception an error.", fingerprint
);
1085 let valid_fingerprints
= [
1086 "86:88:7c:be:26:77:a5:62:67:d9:06:f5:e4:14:61:3e:20:dc:cd:43:92:07:7f:fb:65:54:6c:ff:d2:96:36:f8",
1087 "86:88:7C:BE:26:77:a5:62:67:D9:06:f5:e4:14:61:3e:20:dc:cd:43:92:07:7f:fb:65:54:6c:ff:d2:96:36:f8",
1090 for fingerprint
in valid_fingerprints
.iter() {
1091 let v
= match parse_simple_value(fingerprint
, &schema
) {
1094 bail
!("unable to parse fingerprint '{}' - {}", fingerprint
, err
);
1098 if v
!= serde_json
::json
!(fingerprint
) {
1099 bail
!("unable to parse fingerprint '{}' - got wrong value {:?}", fingerprint
, v
);
1107 fn test_proxmox_user_id_schema() -> Result
<(), anyhow
::Error
> {
1108 let invalid_user_ids
= [
1113 "xx x@test", // contains space
1114 "xx\nx@test", // contains control character
1115 "x:xx@test", // contains collon
1116 "xx/x@test", // contains slash
1117 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@test", // too long
1120 for name
in invalid_user_ids
.iter() {
1121 if parse_simple_value(name
, &Userid
::API_SCHEMA
).is_ok() {
1122 bail
!("test userid '{}' failed - got Ok() while exception an error.", name
);
1126 let valid_user_ids
= [
1130 "xxx@_T_E_S_T-it.com",
1131 "x_x-x.x@test-it.com",
1134 for name
in valid_user_ids
.iter() {
1135 let v
= match parse_simple_value(name
, &Userid
::API_SCHEMA
) {
1138 bail
!("unable to parse userid '{}' - {}", name
, err
);
1142 if v
!= serde_json
::json
!(name
) {
1143 bail
!("unable to parse userid '{}' - got wrong value {:?}", name
, v
);
1151 #[derive(Copy, Clone, Serialize, Deserialize)]
1152 #[serde(rename_all = "UPPERCASE")]
1163 #[derive(Copy, Clone, Serialize, Deserialize)]
1164 #[serde(rename_all = "lowercase")]
1165 pub enum RRDTimeFrameResolution
{
1166 /// 1 min => last 70 minutes
1168 /// 30 min => last 35 hours
1170 /// 3 hours => about 8 days
1172 /// 12 hours => last 35 days
1174 /// 1 week => last 490 days
1179 #[derive(Debug, Clone, Serialize, Deserialize)]
1180 #[serde(rename_all = "PascalCase")]
1181 /// Describes a package for which an update is available.
1182 pub struct APTUpdateInfo
{
1184 pub package
: String
,
1187 /// Package architecture
1189 /// Human readable package description
1190 pub description
: String
,
1191 /// New version to be updated to
1192 pub version
: String
,
1193 /// Old version currently installed
1194 pub old_version
: String
,
1197 /// Package priority in human-readable form
1198 pub priority
: String
,
1200 pub section
: String
,
1201 /// URL under which the package's changelog can be retrieved
1202 pub change_log_url
: String
,
1203 /// Custom extra field for additional package information
1204 #[serde(skip_serializing_if="Option::is_none")]
1205 pub extra_info
: Option
<String
>,
1209 #[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
1210 #[serde(rename_all = "lowercase")]
1211 /// When do we send notifications
1213 /// Never send notification
1215 /// Send notifications for failed and sucessful jobs
1217 /// Send notifications for failed jobs only
1237 #[derive(Debug, Serialize, Deserialize)]
1238 /// Datastore notify settings
1239 pub struct DatastoreNotify
{
1240 /// Garbage collection settings
1241 pub gc
: Option
<Notify
>,
1242 /// Verify job setting
1243 pub verify
: Option
<Notify
>,
1244 /// Sync job setting
1245 pub sync
: Option
<Notify
>,
1248 pub const DATASTORE_NOTIFY_STRING_SCHEMA
: Schema
= StringSchema
::new(
1249 "Datastore notification setting")
1250 .format(&ApiStringFormat
::PropertyString(&DatastoreNotify
::API_SCHEMA
))