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
;
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}
;
23 // File names: may not contain slashes, may not start with "."
24 pub const FILENAME_FORMAT
: ApiStringFormat
= ApiStringFormat
::VerifyFn(|name
| {
25 if name
.starts_with('
.'
) {
26 bail
!("file names may not start with '.'");
28 if name
.contains('
/'
) {
29 bail
!("file names may not contain slashes");
34 macro_rules
! DNS_LABEL { () => (r"(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?)") }
35 macro_rules
! DNS_NAME { () => (concat!(r"(?:(?:", DNS_LABEL!() , r"\.)*", DNS_LABEL!(), ")")) }
37 macro_rules
! CIDR_V4_REGEX_STR { () => (concat!(r"(?:", IPV4RE!(), r"/\d{1,2}
)$
")) }
38 macro_rules! CIDR_V6_REGEX_STR { () => (concat!(r"(?:", IPV6RE!(), r"/\d{1,3})$")) }
41 pub IP_V4_REGEX
= concat
!(r
"^", IPV4RE
!(), r
"$");
42 pub IP_V6_REGEX
= concat
!(r
"^", IPV6RE
!(), r
"$");
43 pub IP_REGEX
= concat
!(r
"^", IPRE
!(), r
"$");
44 pub CIDR_V4_REGEX
= concat
!(r
"^", CIDR_V4_REGEX_STR
!(), r
"$");
45 pub CIDR_V6_REGEX
= concat
!(r
"^", CIDR_V6_REGEX_STR
!(), r
"$");
46 pub CIDR_REGEX
= concat
!(r
"^(?:", CIDR_V4_REGEX_STR
!(), "|", CIDR_V6_REGEX_STR
!(), r
")$");
48 pub SHA256_HEX_REGEX
= r
"^[a-f0-9]{64}$"; // fixme: define in common_regex ?
49 pub SYSTEMD_DATETIME_REGEX
= r
"^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}(:\d{2})?)?$"; // fixme: define in common_regex ?
51 pub PASSWORD_REGEX
= r
"^[[:^cntrl:]]*$"; // everything but control characters
53 /// Regex for safe identifiers.
56 /// [article](https://dwheeler.com/essays/fixing-unix-linux-filenames.html)
57 /// contains further information why it is reasonable to restict
58 /// names this way. This is not only useful for filenames, but for
59 /// any identifier command line tools work with.
60 pub PROXMOX_SAFE_ID_REGEX
= concat
!(r
"^", PROXMOX_SAFE_ID_REGEX_STR
!(), r
"$");
62 pub SINGLE_LINE_COMMENT_REGEX
= r
"^[[:^cntrl:]]*$";
64 pub HOSTNAME_REGEX
= r
"^(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?)$";
66 pub DNS_NAME_REGEX
= concat
!(r
"^", DNS_NAME
!(), r
"$");
68 pub DNS_NAME_OR_IP_REGEX
= concat
!(r
"^(?:", DNS_NAME
!(), "|", IPRE
!(), r
")$");
70 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
")$");
72 pub CERT_FINGERPRINT_SHA256_REGEX
= r
"^(?:[0-9a-fA-F][0-9a-fA-F])(?::[0-9a-fA-F][0-9a-fA-F]){31}$";
74 pub ACL_PATH_REGEX
= concat
!(r
"^(?:/|", r
"(?:/", PROXMOX_SAFE_ID_REGEX_STR
!(), ")+", r
")$");
76 pub BLOCKDEVICE_NAME_REGEX
= r
"^(:?(:?h|s|x?v)d[a-z]+)|(:?nvme\d+n\d+)$";
78 pub ZPOOL_NAME_REGEX
= r
"^[a-zA-Z][a-z0-9A-Z\-_.:]+$";
81 pub const SYSTEMD_DATETIME_FORMAT
: ApiStringFormat
=
82 ApiStringFormat
::Pattern(&SYSTEMD_DATETIME_REGEX
);
84 pub const IP_V4_FORMAT
: ApiStringFormat
=
85 ApiStringFormat
::Pattern(&IP_V4_REGEX
);
87 pub const IP_V6_FORMAT
: ApiStringFormat
=
88 ApiStringFormat
::Pattern(&IP_V6_REGEX
);
90 pub const IP_FORMAT
: ApiStringFormat
=
91 ApiStringFormat
::Pattern(&IP_REGEX
);
93 pub const PVE_CONFIG_DIGEST_FORMAT
: ApiStringFormat
=
94 ApiStringFormat
::Pattern(&SHA256_HEX_REGEX
);
96 pub const CERT_FINGERPRINT_SHA256_FORMAT
: ApiStringFormat
=
97 ApiStringFormat
::Pattern(&CERT_FINGERPRINT_SHA256_REGEX
);
99 pub const PROXMOX_SAFE_ID_FORMAT
: ApiStringFormat
=
100 ApiStringFormat
::Pattern(&PROXMOX_SAFE_ID_REGEX
);
102 pub const SINGLE_LINE_COMMENT_FORMAT
: ApiStringFormat
=
103 ApiStringFormat
::Pattern(&SINGLE_LINE_COMMENT_REGEX
);
105 pub const HOSTNAME_FORMAT
: ApiStringFormat
=
106 ApiStringFormat
::Pattern(&HOSTNAME_REGEX
);
108 pub const DNS_NAME_FORMAT
: ApiStringFormat
=
109 ApiStringFormat
::Pattern(&DNS_NAME_REGEX
);
111 pub const DNS_NAME_OR_IP_FORMAT
: ApiStringFormat
=
112 ApiStringFormat
::Pattern(&DNS_NAME_OR_IP_REGEX
);
114 pub const PASSWORD_FORMAT
: ApiStringFormat
=
115 ApiStringFormat
::Pattern(&PASSWORD_REGEX
);
117 pub const ACL_PATH_FORMAT
: ApiStringFormat
=
118 ApiStringFormat
::Pattern(&ACL_PATH_REGEX
);
120 pub const NETWORK_INTERFACE_FORMAT
: ApiStringFormat
=
121 ApiStringFormat
::Pattern(&PROXMOX_SAFE_ID_REGEX
);
123 pub const CIDR_V4_FORMAT
: ApiStringFormat
=
124 ApiStringFormat
::Pattern(&CIDR_V4_REGEX
);
126 pub const CIDR_V6_FORMAT
: ApiStringFormat
=
127 ApiStringFormat
::Pattern(&CIDR_V6_REGEX
);
129 pub const CIDR_FORMAT
: ApiStringFormat
=
130 ApiStringFormat
::Pattern(&CIDR_REGEX
);
132 pub const BLOCKDEVICE_NAME_FORMAT
: ApiStringFormat
=
133 ApiStringFormat
::Pattern(&BLOCKDEVICE_NAME_REGEX
);
135 pub const PASSWORD_SCHEMA
: Schema
= StringSchema
::new("Password.")
136 .format(&PASSWORD_FORMAT
)
141 pub const PBS_PASSWORD_SCHEMA
: Schema
= StringSchema
::new("User Password.")
142 .format(&PASSWORD_FORMAT
)
147 pub const CERT_FINGERPRINT_SHA256_SCHEMA
: Schema
= StringSchema
::new(
148 "X509 certificate fingerprint (sha256)."
150 .format(&CERT_FINGERPRINT_SHA256_FORMAT
)
153 pub const PROXMOX_CONFIG_DIGEST_SCHEMA
: Schema
= StringSchema
::new(r
#"\
154 Prevent changes if current configuration file has different SHA256 digest.
155 This can be used to prevent concurrent modifications.
158 .format(&PVE_CONFIG_DIGEST_FORMAT
)
162 pub const CHUNK_DIGEST_FORMAT
: ApiStringFormat
=
163 ApiStringFormat
::Pattern(&SHA256_HEX_REGEX
);
165 pub const CHUNK_DIGEST_SCHEMA
: Schema
= StringSchema
::new("Chunk digest (SHA256).")
166 .format(&CHUNK_DIGEST_FORMAT
)
169 pub const NODE_SCHEMA
: Schema
= StringSchema
::new("Node name (or 'localhost')")
170 .format(&ApiStringFormat
::VerifyFn(|node
| {
171 if node
== "localhost" || node
== proxmox
::tools
::nodename() {
174 bail
!("no such node '{}'", node
);
179 pub const SEARCH_DOMAIN_SCHEMA
: Schema
=
180 StringSchema
::new("Search domain for host-name lookup.").schema();
182 pub const FIRST_DNS_SERVER_SCHEMA
: Schema
=
183 StringSchema
::new("First name server IP address.")
187 pub const SECOND_DNS_SERVER_SCHEMA
: Schema
=
188 StringSchema
::new("Second name server IP address.")
192 pub const THIRD_DNS_SERVER_SCHEMA
: Schema
=
193 StringSchema
::new("Third name server IP address.")
197 pub const IP_V4_SCHEMA
: Schema
=
198 StringSchema
::new("IPv4 address.")
199 .format(&IP_V4_FORMAT
)
203 pub const IP_V6_SCHEMA
: Schema
=
204 StringSchema
::new("IPv6 address.")
205 .format(&IP_V6_FORMAT
)
209 pub const IP_SCHEMA
: Schema
=
210 StringSchema
::new("IP (IPv4 or IPv6) address.")
215 pub const CIDR_V4_SCHEMA
: Schema
=
216 StringSchema
::new("IPv4 address with netmask (CIDR notation).")
217 .format(&CIDR_V4_FORMAT
)
221 pub const CIDR_V6_SCHEMA
: Schema
=
222 StringSchema
::new("IPv6 address with netmask (CIDR notation).")
223 .format(&CIDR_V6_FORMAT
)
227 pub const CIDR_SCHEMA
: Schema
=
228 StringSchema
::new("IP address (IPv4 or IPv6) with netmask (CIDR notation).")
229 .format(&CIDR_FORMAT
)
233 pub const TIME_ZONE_SCHEMA
: Schema
= StringSchema
::new(
234 "Time zone. The file '/usr/share/zoneinfo/zone.tab' contains the list of valid names.")
235 .format(&SINGLE_LINE_COMMENT_FORMAT
)
240 pub const ACL_PATH_SCHEMA
: Schema
= StringSchema
::new(
241 "Access control path.")
242 .format(&ACL_PATH_FORMAT
)
247 pub const ACL_PROPAGATE_SCHEMA
: Schema
= BooleanSchema
::new(
248 "Allow to propagate (inherit) permissions.")
252 pub const ACL_UGID_TYPE_SCHEMA
: Schema
= StringSchema
::new(
253 "Type of 'ugid' property.")
254 .format(&ApiStringFormat
::Enum(&[
255 EnumEntry
::new("user", "User"),
256 EnumEntry
::new("group", "Group")]))
259 pub const BACKUP_ARCHIVE_NAME_SCHEMA
: Schema
=
260 StringSchema
::new("Backup archive name.")
261 .format(&PROXMOX_SAFE_ID_FORMAT
)
264 pub const BACKUP_TYPE_SCHEMA
: Schema
=
265 StringSchema
::new("Backup type.")
266 .format(&ApiStringFormat
::Enum(&[
267 EnumEntry
::new("vm", "Virtual Machine Backup"),
268 EnumEntry
::new("ct", "Container Backup"),
269 EnumEntry
::new("host", "Host Backup")]))
272 pub const BACKUP_ID_SCHEMA
: Schema
=
273 StringSchema
::new("Backup ID.")
274 .format(&PROXMOX_SAFE_ID_FORMAT
)
277 pub const BACKUP_TIME_SCHEMA
: Schema
=
278 IntegerSchema
::new("Backup time (Unix epoch.)")
279 .minimum(1_547_797_308)
282 pub const UPID_SCHEMA
: Schema
= StringSchema
::new("Unique Process/Task ID.")
286 pub const DATASTORE_SCHEMA
: Schema
= StringSchema
::new("Datastore name.")
287 .format(&PROXMOX_SAFE_ID_FORMAT
)
292 pub const SYNC_SCHEDULE_SCHEMA
: Schema
= StringSchema
::new(
293 "Run sync job at specified schedule.")
294 .format(&ApiStringFormat
::VerifyFn(crate::tools
::systemd
::time
::verify_calendar_event
))
297 pub const GC_SCHEDULE_SCHEMA
: Schema
= StringSchema
::new(
298 "Run garbage collection job at specified schedule.")
299 .format(&ApiStringFormat
::VerifyFn(crate::tools
::systemd
::time
::verify_calendar_event
))
302 pub const PRUNE_SCHEDULE_SCHEMA
: Schema
= StringSchema
::new(
303 "Run prune job at specified schedule.")
304 .format(&ApiStringFormat
::VerifyFn(crate::tools
::systemd
::time
::verify_calendar_event
))
307 pub const VERIFICATION_SCHEDULE_SCHEMA
: Schema
= StringSchema
::new(
308 "Run verify job at specified schedule.")
309 .format(&ApiStringFormat
::VerifyFn(crate::tools
::systemd
::time
::verify_calendar_event
))
312 pub const REMOTE_ID_SCHEMA
: Schema
= StringSchema
::new("Remote ID.")
313 .format(&PROXMOX_SAFE_ID_FORMAT
)
318 pub const JOB_ID_SCHEMA
: Schema
= StringSchema
::new("Job ID.")
319 .format(&PROXMOX_SAFE_ID_FORMAT
)
324 pub const REMOVE_VANISHED_BACKUPS_SCHEMA
: Schema
= BooleanSchema
::new(
325 "Delete vanished backups. This remove the local copy if the remote backup was deleted.")
329 pub const IGNORE_VERIFIED_BACKUPS_SCHEMA
: Schema
= BooleanSchema
::new(
330 "Do not verify backups that are already verified if their verification is not outdated.")
334 pub const VERIFICATION_OUTDATED_AFTER_SCHEMA
: Schema
= IntegerSchema
::new(
335 "Days after that a verification becomes outdated")
339 pub const SINGLE_LINE_COMMENT_SCHEMA
: Schema
= StringSchema
::new("Comment (single line).")
340 .format(&SINGLE_LINE_COMMENT_FORMAT
)
343 pub const HOSTNAME_SCHEMA
: Schema
= StringSchema
::new("Hostname (as defined in RFC1123).")
344 .format(&HOSTNAME_FORMAT
)
347 pub const DNS_NAME_OR_IP_SCHEMA
: Schema
= StringSchema
::new("DNS name or IP address.")
348 .format(&DNS_NAME_OR_IP_FORMAT
)
351 pub const BLOCKDEVICE_NAME_SCHEMA
: Schema
= StringSchema
::new("Block device name (/sys/block/<name>).")
352 .format(&BLOCKDEVICE_NAME_FORMAT
)
357 // Complex type definitions
362 schema
: BACKUP_TYPE_SCHEMA
,
365 schema
: BACKUP_ID_SCHEMA
,
368 schema
: BACKUP_TIME_SCHEMA
,
375 schema
: BACKUP_ARCHIVE_NAME_SCHEMA
384 #[derive(Serialize, Deserialize)]
385 #[serde(rename_all="kebab-case")]
386 /// Basic information about a backup group.
387 pub struct GroupListItem
{
388 pub backup_type
: String
, // enum
389 pub backup_id
: String
,
390 pub last_backup
: i64,
391 /// Number of contained snapshots
392 pub backup_count
: u64,
393 /// List of contained archive files.
394 pub files
: Vec
<String
>,
395 /// The owner of group
396 #[serde(skip_serializing_if="Option::is_none")]
397 pub owner
: Option
<Authid
>,
401 #[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
402 #[serde(rename_all = "lowercase")]
403 /// Result of a verify operation.
404 pub enum VerifyState
{
405 /// Verification was successful
407 /// Verification reported one or more errors
421 #[derive(Serialize, Deserialize)]
423 pub struct SnapshotVerifyState
{
424 /// UPID of the verify task
426 /// State of the verification. Enum.
427 pub state
: VerifyState
,
433 schema
: BACKUP_TYPE_SCHEMA
,
436 schema
: BACKUP_ID_SCHEMA
,
439 schema
: BACKUP_TIME_SCHEMA
,
442 schema
: SINGLE_LINE_COMMENT_SCHEMA
,
446 type: SnapshotVerifyState
,
451 schema
: BACKUP_ARCHIVE_NAME_SCHEMA
460 #[derive(Serialize, Deserialize)]
461 #[serde(rename_all="kebab-case")]
462 /// Basic information about backup snapshot.
463 pub struct SnapshotListItem
{
464 pub backup_type
: String
, // enum
465 pub backup_id
: String
,
466 pub backup_time
: i64,
467 /// The first line from manifest "notes"
468 #[serde(skip_serializing_if="Option::is_none")]
469 pub comment
: Option
<String
>,
470 /// The result of the last run verify task
471 #[serde(skip_serializing_if="Option::is_none")]
472 pub verification
: Option
<SnapshotVerifyState
>,
473 /// List of contained archive files.
474 pub files
: Vec
<BackupContent
>,
475 /// Overall snapshot size (sum of all archive sizes).
476 #[serde(skip_serializing_if="Option::is_none")]
477 pub size
: Option
<u64>,
478 /// The owner of the snapshots group
479 #[serde(skip_serializing_if="Option::is_none")]
480 pub owner
: Option
<Authid
>,
486 schema
: BACKUP_TYPE_SCHEMA
,
489 schema
: BACKUP_ID_SCHEMA
,
492 schema
: BACKUP_TIME_SCHEMA
,
496 #[derive(Serialize, Deserialize)]
497 #[serde(rename_all="kebab-case")]
499 pub struct PruneListItem
{
500 pub backup_type
: String
, // enum
501 pub backup_id
: String
,
502 pub backup_time
: i64,
507 pub const PRUNE_SCHEMA_KEEP_DAILY
: Schema
= IntegerSchema
::new(
508 "Number of daily backups to keep.")
512 pub const PRUNE_SCHEMA_KEEP_HOURLY
: Schema
= IntegerSchema
::new(
513 "Number of hourly backups to keep.")
517 pub const PRUNE_SCHEMA_KEEP_LAST
: Schema
= IntegerSchema
::new(
518 "Number of backups to keep.")
522 pub const PRUNE_SCHEMA_KEEP_MONTHLY
: Schema
= IntegerSchema
::new(
523 "Number of monthly backups to keep.")
527 pub const PRUNE_SCHEMA_KEEP_WEEKLY
: Schema
= IntegerSchema
::new(
528 "Number of weekly backups to keep.")
532 pub const PRUNE_SCHEMA_KEEP_YEARLY
: Schema
= IntegerSchema
::new(
533 "Number of yearly backups to keep.")
540 schema
: BACKUP_ARCHIVE_NAME_SCHEMA
,
548 #[derive(Serialize, Deserialize)]
549 #[serde(rename_all="kebab-case")]
550 /// Basic information about archive files inside a backup snapshot.
551 pub struct BackupContent
{
552 pub filename
: String
,
553 /// Info if file is encrypted, signed, or neither.
554 #[serde(skip_serializing_if="Option::is_none")]
555 pub crypt_mode
: Option
<CryptMode
>,
556 /// Archive size (from backup manifest).
557 #[serde(skip_serializing_if="Option::is_none")]
558 pub size
: Option
<u64>,
569 #[derive(Clone, Serialize, Deserialize)]
570 #[serde(rename_all="kebab-case")]
571 /// Garbage collection status.
572 pub struct GarbageCollectionStatus
{
573 pub upid
: Option
<String
>,
574 /// Number of processed index files.
575 pub index_file_count
: usize,
576 /// Sum of bytes referred by index files.
577 pub index_data_bytes
: u64,
578 /// Bytes used on disk.
580 /// Chunks used on disk.
581 pub disk_chunks
: usize,
582 /// Sum of removed bytes.
583 pub removed_bytes
: u64,
584 /// Number of removed chunks.
585 pub removed_chunks
: usize,
586 /// Sum of pending bytes (pending removal - kept for safety).
587 pub pending_bytes
: u64,
588 /// Number of pending chunks (pending removal - kept for safety).
589 pub pending_chunks
: usize,
590 /// Number of chunks marked as .bad by verify that have been removed by GC.
591 pub removed_bad
: usize,
592 /// Number of chunks still marked as .bad after garbage collection.
593 pub still_bad
: usize,
596 impl Default
for GarbageCollectionStatus
{
597 fn default() -> Self {
598 GarbageCollectionStatus
{
616 #[derive(Serialize, Deserialize)]
617 /// Storage space usage information.
618 pub struct StorageStatus
{
619 /// Total space (bytes).
621 /// Used space (bytes).
623 /// Available space (bytes).
628 #[derive(Serialize, Deserialize, Default)]
629 /// Backup Type group/snapshot counts.
630 pub struct TypeCounts
{
631 /// The number of groups of the type.
633 /// The number of snapshots of the type.
657 #[derive(Serialize, Deserialize)]
658 /// Counts of groups/snapshots per BackupType.
660 /// The counts for CT backups
661 pub ct
: Option
<TypeCounts
>,
662 /// The counts for Host backups
663 pub host
: Option
<TypeCounts
>,
664 /// The counts for VM backups
665 pub vm
: Option
<TypeCounts
>,
666 /// The counts for other backup types
667 pub other
: Option
<TypeCounts
>,
672 "gc-status": { type: GarbageCollectionStatus, }
,
673 counts
: { type: Counts, }
676 #[derive(Serialize, Deserialize)]
677 #[serde(rename_all="kebab-case")]
678 /// Overall Datastore status and useful information.
679 pub struct DataStoreStatus
{
680 /// Total space (bytes).
682 /// Used space (bytes).
684 /// Available space (bytes).
686 /// Status of last GC
687 pub gc_status
: GarbageCollectionStatus
,
688 /// Group/Snapshot counts
694 upid
: { schema: UPID_SCHEMA }
,
695 userid
: { type: Authid }
,
698 #[derive(Serialize, Deserialize)]
700 pub struct TaskListItem
{
702 /// The node name where the task is running on.
706 /// The task start time (Epoch)
708 /// The task start time (Epoch)
710 /// Worker type (arbitrary ASCII string)
711 pub worker_type
: String
,
712 /// Worker ID (arbitrary ASCII string)
713 pub worker_id
: Option
<String
>,
714 /// The authenticated entity who started the task
716 /// The task end time (Epoch)
717 #[serde(skip_serializing_if="Option::is_none")]
718 pub endtime
: Option
<i64>,
720 #[serde(skip_serializing_if="Option::is_none")]
721 pub status
: Option
<String
>,
724 impl From
<crate::server
::TaskListInfo
> for TaskListItem
{
725 fn from(info
: crate::server
::TaskListInfo
) -> Self {
726 let (endtime
, status
) = info
728 .map_or_else(|| (None
, None
), |a
| (Some(a
.endtime()), Some(a
.to_string())));
732 node
: "localhost".to_string(),
733 pid
: info
.upid
.pid
as i64,
734 pstart
: info
.upid
.pstart
,
735 starttime
: info
.upid
.starttime
,
736 worker_type
: info
.upid
.worker_type
,
737 worker_id
: info
.upid
.worker_id
,
738 userid
: info
.upid
.auth_id
,
746 #[derive(Eq, PartialEq, Debug, Serialize, Deserialize)]
747 #[serde(rename_all = "lowercase")]
748 pub enum TaskStateType
{
760 #[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
761 #[serde(rename_all = "lowercase")]
762 /// Node Power command type.
763 pub enum NodePowerCommand
{
764 /// Restart the server
766 /// Shutdown the server
771 #[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
772 #[serde(rename_all = "lowercase")]
773 /// Interface configuration method
774 pub enum NetworkConfigMethod
{
775 /// Configuration is done manually using other tools
777 /// Define interfaces with statically allocated addresses.
779 /// Obtain an address via DHCP
781 /// Define the loopback interface.
786 #[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
787 #[serde(rename_all = "kebab-case")]
788 #[allow(non_camel_case_types)]
791 pub enum LinuxBondMode
{
792 /// Round-robin policy
794 /// Active-backup policy
800 /// IEEE 802.3ad Dynamic link aggregation
801 #[serde(rename = "802.3ad")]
803 /// Adaptive transmit load balancing
805 /// Adaptive load balancing
810 #[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
811 #[serde(rename_all = "kebab-case")]
812 #[allow(non_camel_case_types)]
814 /// Bond Transmit Hash Policy for LACP (802.3ad)
815 pub enum BondXmitHashPolicy
{
819 #[serde(rename = "layer2+3")]
822 #[serde(rename = "layer3+4")]
827 #[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
828 #[serde(rename_all = "lowercase")]
829 /// Network interface type
830 pub enum NetworkInterfaceType
{
833 /// Physical Ethernet device
839 /// Linux VLAN (eth.10)
841 /// Interface Alias (eth:1)
843 /// Unknown interface type
847 pub const NETWORK_INTERFACE_NAME_SCHEMA
: Schema
= StringSchema
::new("Network interface name.")
848 .format(&NETWORK_INTERFACE_FORMAT
)
850 .max_length(libc
::IFNAMSIZ
-1)
853 pub const NETWORK_INTERFACE_ARRAY_SCHEMA
: Schema
= ArraySchema
::new(
854 "Network interface list.", &NETWORK_INTERFACE_NAME_SCHEMA
)
857 pub const NETWORK_INTERFACE_LIST_SCHEMA
: Schema
= StringSchema
::new(
858 "A list of network devices, comma separated.")
859 .format(&ApiStringFormat
::PropertyString(&NETWORK_INTERFACE_ARRAY_SCHEMA
))
865 schema
: NETWORK_INTERFACE_NAME_SCHEMA
,
868 type: NetworkInterfaceType
,
871 type: NetworkConfigMethod
,
875 type: NetworkConfigMethod
,
879 schema
: CIDR_V4_SCHEMA
,
883 schema
: CIDR_V6_SCHEMA
,
887 schema
: IP_V4_SCHEMA
,
891 schema
: IP_V6_SCHEMA
,
895 description
: "Option list (inet)",
898 description
: "Optional attribute line.",
903 description
: "Option list (inet6)",
906 description
: "Optional attribute line.",
911 description
: "Comments (inet, may span multiple lines)",
916 description
: "Comments (inet6, may span multiple lines)",
921 schema
: NETWORK_INTERFACE_ARRAY_SCHEMA
,
925 schema
: NETWORK_INTERFACE_ARRAY_SCHEMA
,
933 schema
: NETWORK_INTERFACE_NAME_SCHEMA
,
936 bond_xmit_hash_policy
: {
937 type: BondXmitHashPolicy
,
942 #[derive(Debug, Serialize, Deserialize)]
943 /// Network Interface configuration
944 pub struct Interface
{
945 /// Autostart interface
946 #[serde(rename = "autostart")]
948 /// Interface is active (UP)
953 #[serde(rename = "type")]
954 pub interface_type
: NetworkInterfaceType
,
955 #[serde(skip_serializing_if="Option::is_none")]
956 pub method
: Option
<NetworkConfigMethod
>,
957 #[serde(skip_serializing_if="Option::is_none")]
958 pub method6
: Option
<NetworkConfigMethod
>,
959 #[serde(skip_serializing_if="Option::is_none")]
960 /// IPv4 address with netmask
961 pub cidr
: Option
<String
>,
962 #[serde(skip_serializing_if="Option::is_none")]
964 pub gateway
: Option
<String
>,
965 #[serde(skip_serializing_if="Option::is_none")]
966 /// IPv6 address with netmask
967 pub cidr6
: Option
<String
>,
968 #[serde(skip_serializing_if="Option::is_none")]
970 pub gateway6
: Option
<String
>,
972 #[serde(skip_serializing_if="Vec::is_empty")]
973 pub options
: Vec
<String
>,
974 #[serde(skip_serializing_if="Vec::is_empty")]
975 pub options6
: Vec
<String
>,
977 #[serde(skip_serializing_if="Option::is_none")]
978 pub comments
: Option
<String
>,
979 #[serde(skip_serializing_if="Option::is_none")]
980 pub comments6
: Option
<String
>,
982 #[serde(skip_serializing_if="Option::is_none")]
983 /// Maximum Transmission Unit
984 pub mtu
: Option
<u64>,
986 #[serde(skip_serializing_if="Option::is_none")]
987 pub bridge_ports
: Option
<Vec
<String
>>,
988 /// Enable bridge vlan support.
989 #[serde(skip_serializing_if="Option::is_none")]
990 pub bridge_vlan_aware
: Option
<bool
>,
992 #[serde(skip_serializing_if="Option::is_none")]
993 pub slaves
: Option
<Vec
<String
>>,
994 #[serde(skip_serializing_if="Option::is_none")]
995 pub bond_mode
: Option
<LinuxBondMode
>,
996 #[serde(skip_serializing_if="Option::is_none")]
997 #[serde(rename = "bond-primary")]
998 pub bond_primary
: Option
<String
>,
999 pub bond_xmit_hash_policy
: Option
<BondXmitHashPolicy
>,
1005 fn test_cert_fingerprint_schema() -> Result
<(), anyhow
::Error
> {
1007 let schema
= CERT_FINGERPRINT_SHA256_SCHEMA
;
1009 let invalid_fingerprints
= [
1010 "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",
1011 "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",
1012 "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",
1013 "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",
1014 "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",
1015 "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",
1018 for fingerprint
in invalid_fingerprints
.iter() {
1019 if let Ok(_
) = parse_simple_value(fingerprint
, &schema
) {
1020 bail
!("test fingerprint '{}' failed - got Ok() while exception an error.", fingerprint
);
1024 let valid_fingerprints
= [
1025 "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",
1026 "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",
1029 for fingerprint
in valid_fingerprints
.iter() {
1030 let v
= match parse_simple_value(fingerprint
, &schema
) {
1033 bail
!("unable to parse fingerprint '{}' - {}", fingerprint
, err
);
1037 if v
!= serde_json
::json
!(fingerprint
) {
1038 bail
!("unable to parse fingerprint '{}' - got wrong value {:?}", fingerprint
, v
);
1046 fn test_proxmox_user_id_schema() -> Result
<(), anyhow
::Error
> {
1047 let invalid_user_ids
= [
1052 "xx x@test", // contains space
1053 "xx\nx@test", // contains control character
1054 "x:xx@test", // contains collon
1055 "xx/x@test", // contains slash
1056 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@test", // too long
1059 for name
in invalid_user_ids
.iter() {
1060 if let Ok(_
) = parse_simple_value(name
, &Userid
::API_SCHEMA
) {
1061 bail
!("test userid '{}' failed - got Ok() while exception an error.", name
);
1065 let valid_user_ids
= [
1069 "xxx@_T_E_S_T-it.com",
1070 "x_x-x.x@test-it.com",
1073 for name
in valid_user_ids
.iter() {
1074 let v
= match parse_simple_value(name
, &Userid
::API_SCHEMA
) {
1077 bail
!("unable to parse userid '{}' - {}", name
, err
);
1081 if v
!= serde_json
::json
!(name
) {
1082 bail
!("unable to parse userid '{}' - got wrong value {:?}", name
, v
);
1090 #[derive(Copy, Clone, Serialize, Deserialize)]
1091 #[serde(rename_all = "UPPERCASE")]
1102 #[derive(Copy, Clone, Serialize, Deserialize)]
1103 #[serde(rename_all = "lowercase")]
1104 pub enum RRDTimeFrameResolution
{
1105 /// 1 min => last 70 minutes
1107 /// 30 min => last 35 hours
1109 /// 3 hours => about 8 days
1111 /// 12 hours => last 35 days
1113 /// 1 week => last 490 days
1118 #[derive(Serialize, Deserialize)]
1119 #[serde(rename_all = "PascalCase")]
1120 /// Describes a package for which an update is available.
1121 pub struct APTUpdateInfo
{
1123 pub package
: String
,
1126 /// Package architecture
1128 /// Human readable package description
1129 pub description
: String
,
1130 /// New version to be updated to
1131 pub version
: String
,
1132 /// Old version currently installed
1133 pub old_version
: String
,
1136 /// Package priority in human-readable form
1137 pub priority
: String
,
1139 pub section
: String
,
1140 /// URL under which the package's changelog can be retrieved
1141 pub change_log_url
: String
,