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
::{Username, UsernameRef}
;
18 pub use userid
::Userid
;
19 pub use userid
::PROXMOX_GROUP_ID_SCHEMA
;
21 // File names: may not contain slashes, may not start with "."
22 pub const FILENAME_FORMAT
: ApiStringFormat
= ApiStringFormat
::VerifyFn(|name
| {
23 if name
.starts_with('
.'
) {
24 bail
!("file names may not start with '.'");
26 if name
.contains('
/'
) {
27 bail
!("file names may not contain slashes");
32 macro_rules
! DNS_LABEL { () => (r"(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?)") }
33 macro_rules
! DNS_NAME { () => (concat!(r"(?:(?:", DNS_LABEL!() , r"\.)*", DNS_LABEL!(), ")")) }
35 macro_rules
! CIDR_V4_REGEX_STR { () => (concat!(r"(?:", IPV4RE!(), r"/\d{1,2}
)$
")) }
36 macro_rules! CIDR_V6_REGEX_STR { () => (concat!(r"(?:", IPV6RE!(), r"/\d{1,3})$")) }
39 pub IP_V4_REGEX
= concat
!(r
"^", IPV4RE
!(), r
"$");
40 pub IP_V6_REGEX
= concat
!(r
"^", IPV6RE
!(), r
"$");
41 pub IP_REGEX
= concat
!(r
"^", IPRE
!(), r
"$");
42 pub CIDR_V4_REGEX
= concat
!(r
"^", CIDR_V4_REGEX_STR
!(), r
"$");
43 pub CIDR_V6_REGEX
= concat
!(r
"^", CIDR_V6_REGEX_STR
!(), r
"$");
44 pub CIDR_REGEX
= concat
!(r
"^(?:", CIDR_V4_REGEX_STR
!(), "|", CIDR_V6_REGEX_STR
!(), r
")$");
46 pub SHA256_HEX_REGEX
= r
"^[a-f0-9]{64}$"; // fixme: define in common_regex ?
47 pub SYSTEMD_DATETIME_REGEX
= r
"^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}(:\d{2})?)?$"; // fixme: define in common_regex ?
49 pub PASSWORD_REGEX
= r
"^[[:^cntrl:]]*$"; // everything but control characters
51 /// Regex for safe identifiers.
54 /// [article](https://dwheeler.com/essays/fixing-unix-linux-filenames.html)
55 /// contains further information why it is reasonable to restict
56 /// names this way. This is not only useful for filenames, but for
57 /// any identifier command line tools work with.
58 pub PROXMOX_SAFE_ID_REGEX
= concat
!(r
"^", PROXMOX_SAFE_ID_REGEX_STR
!(), r
"$");
60 pub SINGLE_LINE_COMMENT_REGEX
= r
"^[[:^cntrl:]]*$";
62 pub HOSTNAME_REGEX
= r
"^(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?)$";
64 pub DNS_NAME_REGEX
= concat
!(r
"^", DNS_NAME
!(), r
"$");
66 pub DNS_NAME_OR_IP_REGEX
= concat
!(r
"^(?:", DNS_NAME
!(), "|", IPRE
!(), r
")$");
68 pub BACKUP_REPO_URL_REGEX
= concat
!(r
"^^(?:(?:(", USER_ID_REGEX_STR
!(), ")@)?(", DNS_NAME
!(), "|", IPRE_BRACKET
!() ,"):)?(?:([0-9]{1,5}):)?(", PROXMOX_SAFE_ID_REGEX_STR
!(), r
")$");
70 pub CERT_FINGERPRINT_SHA256_REGEX
= r
"^(?:[0-9a-fA-F][0-9a-fA-F])(?::[0-9a-fA-F][0-9a-fA-F]){31}$";
72 pub ACL_PATH_REGEX
= concat
!(r
"^(?:/|", r
"(?:/", PROXMOX_SAFE_ID_REGEX_STR
!(), ")+", r
")$");
74 pub BLOCKDEVICE_NAME_REGEX
= r
"^(:?(:?h|s|x?v)d[a-z]+)|(:?nvme\d+n\d+)$";
76 pub ZPOOL_NAME_REGEX
= r
"^[a-zA-Z][a-z0-9A-Z\-_.:]+$";
79 pub const SYSTEMD_DATETIME_FORMAT
: ApiStringFormat
=
80 ApiStringFormat
::Pattern(&SYSTEMD_DATETIME_REGEX
);
82 pub const IP_V4_FORMAT
: ApiStringFormat
=
83 ApiStringFormat
::Pattern(&IP_V4_REGEX
);
85 pub const IP_V6_FORMAT
: ApiStringFormat
=
86 ApiStringFormat
::Pattern(&IP_V6_REGEX
);
88 pub const IP_FORMAT
: ApiStringFormat
=
89 ApiStringFormat
::Pattern(&IP_REGEX
);
91 pub const PVE_CONFIG_DIGEST_FORMAT
: ApiStringFormat
=
92 ApiStringFormat
::Pattern(&SHA256_HEX_REGEX
);
94 pub const CERT_FINGERPRINT_SHA256_FORMAT
: ApiStringFormat
=
95 ApiStringFormat
::Pattern(&CERT_FINGERPRINT_SHA256_REGEX
);
97 pub const PROXMOX_SAFE_ID_FORMAT
: ApiStringFormat
=
98 ApiStringFormat
::Pattern(&PROXMOX_SAFE_ID_REGEX
);
100 pub const SINGLE_LINE_COMMENT_FORMAT
: ApiStringFormat
=
101 ApiStringFormat
::Pattern(&SINGLE_LINE_COMMENT_REGEX
);
103 pub const HOSTNAME_FORMAT
: ApiStringFormat
=
104 ApiStringFormat
::Pattern(&HOSTNAME_REGEX
);
106 pub const DNS_NAME_FORMAT
: ApiStringFormat
=
107 ApiStringFormat
::Pattern(&DNS_NAME_REGEX
);
109 pub const DNS_NAME_OR_IP_FORMAT
: ApiStringFormat
=
110 ApiStringFormat
::Pattern(&DNS_NAME_OR_IP_REGEX
);
112 pub const PASSWORD_FORMAT
: ApiStringFormat
=
113 ApiStringFormat
::Pattern(&PASSWORD_REGEX
);
115 pub const ACL_PATH_FORMAT
: ApiStringFormat
=
116 ApiStringFormat
::Pattern(&ACL_PATH_REGEX
);
118 pub const NETWORK_INTERFACE_FORMAT
: ApiStringFormat
=
119 ApiStringFormat
::Pattern(&PROXMOX_SAFE_ID_REGEX
);
121 pub const CIDR_V4_FORMAT
: ApiStringFormat
=
122 ApiStringFormat
::Pattern(&CIDR_V4_REGEX
);
124 pub const CIDR_V6_FORMAT
: ApiStringFormat
=
125 ApiStringFormat
::Pattern(&CIDR_V6_REGEX
);
127 pub const CIDR_FORMAT
: ApiStringFormat
=
128 ApiStringFormat
::Pattern(&CIDR_REGEX
);
130 pub const BLOCKDEVICE_NAME_FORMAT
: ApiStringFormat
=
131 ApiStringFormat
::Pattern(&BLOCKDEVICE_NAME_REGEX
);
133 pub const PASSWORD_SCHEMA
: Schema
= StringSchema
::new("Password.")
134 .format(&PASSWORD_FORMAT
)
139 pub const PBS_PASSWORD_SCHEMA
: Schema
= StringSchema
::new("User Password.")
140 .format(&PASSWORD_FORMAT
)
145 pub const CERT_FINGERPRINT_SHA256_SCHEMA
: Schema
= StringSchema
::new(
146 "X509 certificate fingerprint (sha256)."
148 .format(&CERT_FINGERPRINT_SHA256_FORMAT
)
151 pub const PROXMOX_CONFIG_DIGEST_SCHEMA
: Schema
= StringSchema
::new(r
#"\
152 Prevent changes if current configuration file has different SHA256 digest.
153 This can be used to prevent concurrent modifications.
156 .format(&PVE_CONFIG_DIGEST_FORMAT
)
160 pub const CHUNK_DIGEST_FORMAT
: ApiStringFormat
=
161 ApiStringFormat
::Pattern(&SHA256_HEX_REGEX
);
163 pub const CHUNK_DIGEST_SCHEMA
: Schema
= StringSchema
::new("Chunk digest (SHA256).")
164 .format(&CHUNK_DIGEST_FORMAT
)
167 pub const NODE_SCHEMA
: Schema
= StringSchema
::new("Node name (or 'localhost')")
168 .format(&ApiStringFormat
::VerifyFn(|node
| {
169 if node
== "localhost" || node
== proxmox
::tools
::nodename() {
172 bail
!("no such node '{}'", node
);
177 pub const SEARCH_DOMAIN_SCHEMA
: Schema
=
178 StringSchema
::new("Search domain for host-name lookup.").schema();
180 pub const FIRST_DNS_SERVER_SCHEMA
: Schema
=
181 StringSchema
::new("First name server IP address.")
185 pub const SECOND_DNS_SERVER_SCHEMA
: Schema
=
186 StringSchema
::new("Second name server IP address.")
190 pub const THIRD_DNS_SERVER_SCHEMA
: Schema
=
191 StringSchema
::new("Third name server IP address.")
195 pub const IP_V4_SCHEMA
: Schema
=
196 StringSchema
::new("IPv4 address.")
197 .format(&IP_V4_FORMAT
)
201 pub const IP_V6_SCHEMA
: Schema
=
202 StringSchema
::new("IPv6 address.")
203 .format(&IP_V6_FORMAT
)
207 pub const IP_SCHEMA
: Schema
=
208 StringSchema
::new("IP (IPv4 or IPv6) address.")
213 pub const CIDR_V4_SCHEMA
: Schema
=
214 StringSchema
::new("IPv4 address with netmask (CIDR notation).")
215 .format(&CIDR_V4_FORMAT
)
219 pub const CIDR_V6_SCHEMA
: Schema
=
220 StringSchema
::new("IPv6 address with netmask (CIDR notation).")
221 .format(&CIDR_V6_FORMAT
)
225 pub const CIDR_SCHEMA
: Schema
=
226 StringSchema
::new("IP address (IPv4 or IPv6) with netmask (CIDR notation).")
227 .format(&CIDR_FORMAT
)
231 pub const TIME_ZONE_SCHEMA
: Schema
= StringSchema
::new(
232 "Time zone. The file '/usr/share/zoneinfo/zone.tab' contains the list of valid names.")
233 .format(&SINGLE_LINE_COMMENT_FORMAT
)
238 pub const ACL_PATH_SCHEMA
: Schema
= StringSchema
::new(
239 "Access control path.")
240 .format(&ACL_PATH_FORMAT
)
245 pub const ACL_PROPAGATE_SCHEMA
: Schema
= BooleanSchema
::new(
246 "Allow to propagate (inherit) permissions.")
250 pub const ACL_UGID_TYPE_SCHEMA
: Schema
= StringSchema
::new(
251 "Type of 'ugid' property.")
252 .format(&ApiStringFormat
::Enum(&[
253 EnumEntry
::new("user", "User"),
254 EnumEntry
::new("group", "Group")]))
257 pub const BACKUP_ARCHIVE_NAME_SCHEMA
: Schema
=
258 StringSchema
::new("Backup archive name.")
259 .format(&PROXMOX_SAFE_ID_FORMAT
)
262 pub const BACKUP_TYPE_SCHEMA
: Schema
=
263 StringSchema
::new("Backup type.")
264 .format(&ApiStringFormat
::Enum(&[
265 EnumEntry
::new("vm", "Virtual Machine Backup"),
266 EnumEntry
::new("ct", "Container Backup"),
267 EnumEntry
::new("host", "Host Backup")]))
270 pub const BACKUP_ID_SCHEMA
: Schema
=
271 StringSchema
::new("Backup ID.")
272 .format(&PROXMOX_SAFE_ID_FORMAT
)
275 pub const BACKUP_TIME_SCHEMA
: Schema
=
276 IntegerSchema
::new("Backup time (Unix epoch.)")
277 .minimum(1_547_797_308)
280 pub const UPID_SCHEMA
: Schema
= StringSchema
::new("Unique Process/Task ID.")
284 pub const DATASTORE_SCHEMA
: Schema
= StringSchema
::new("Datastore name.")
285 .format(&PROXMOX_SAFE_ID_FORMAT
)
290 pub const SYNC_SCHEDULE_SCHEMA
: Schema
= StringSchema
::new(
291 "Run sync job at specified schedule.")
292 .format(&ApiStringFormat
::VerifyFn(crate::tools
::systemd
::time
::verify_calendar_event
))
295 pub const GC_SCHEDULE_SCHEMA
: Schema
= StringSchema
::new(
296 "Run garbage collection job at specified schedule.")
297 .format(&ApiStringFormat
::VerifyFn(crate::tools
::systemd
::time
::verify_calendar_event
))
300 pub const PRUNE_SCHEDULE_SCHEMA
: Schema
= StringSchema
::new(
301 "Run prune job at specified schedule.")
302 .format(&ApiStringFormat
::VerifyFn(crate::tools
::systemd
::time
::verify_calendar_event
))
305 pub const VERIFICATION_SCHEDULE_SCHEMA
: Schema
= StringSchema
::new(
306 "Run verify job at specified schedule.")
307 .format(&ApiStringFormat
::VerifyFn(crate::tools
::systemd
::time
::verify_calendar_event
))
310 pub const REMOTE_ID_SCHEMA
: Schema
= StringSchema
::new("Remote ID.")
311 .format(&PROXMOX_SAFE_ID_FORMAT
)
316 pub const JOB_ID_SCHEMA
: Schema
= StringSchema
::new("Job ID.")
317 .format(&PROXMOX_SAFE_ID_FORMAT
)
322 pub const REMOVE_VANISHED_BACKUPS_SCHEMA
: Schema
= BooleanSchema
::new(
323 "Delete vanished backups. This remove the local copy if the remote backup was deleted.")
327 pub const IGNORE_VERIFIED_BACKUPS_SCHEMA
: Schema
= BooleanSchema
::new(
328 "Do not verify backups that are already verified if their verification is not outdated.")
332 pub const VERIFICATION_OUTDATED_AFTER_SCHEMA
: Schema
= IntegerSchema
::new(
333 "Days after that a verification becomes outdated")
337 pub const SINGLE_LINE_COMMENT_SCHEMA
: Schema
= StringSchema
::new("Comment (single line).")
338 .format(&SINGLE_LINE_COMMENT_FORMAT
)
341 pub const HOSTNAME_SCHEMA
: Schema
= StringSchema
::new("Hostname (as defined in RFC1123).")
342 .format(&HOSTNAME_FORMAT
)
345 pub const DNS_NAME_OR_IP_SCHEMA
: Schema
= StringSchema
::new("DNS name or IP address.")
346 .format(&DNS_NAME_OR_IP_FORMAT
)
349 pub const BLOCKDEVICE_NAME_SCHEMA
: Schema
= StringSchema
::new("Block device name (/sys/block/<name>).")
350 .format(&BLOCKDEVICE_NAME_FORMAT
)
355 // Complex type definitions
360 schema
: BACKUP_TYPE_SCHEMA
,
363 schema
: BACKUP_ID_SCHEMA
,
366 schema
: BACKUP_TIME_SCHEMA
,
373 schema
: BACKUP_ARCHIVE_NAME_SCHEMA
382 #[derive(Serialize, Deserialize)]
383 #[serde(rename_all="kebab-case")]
384 /// Basic information about a backup group.
385 pub struct GroupListItem
{
386 pub backup_type
: String
, // enum
387 pub backup_id
: String
,
388 pub last_backup
: i64,
389 /// Number of contained snapshots
390 pub backup_count
: u64,
391 /// List of contained archive files.
392 pub files
: Vec
<String
>,
393 /// The owner of group
394 #[serde(skip_serializing_if="Option::is_none")]
395 pub owner
: Option
<Userid
>,
399 #[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
400 #[serde(rename_all = "lowercase")]
401 /// Result of a verify operation.
402 pub enum VerifyState
{
403 /// Verification was successful
405 /// Verification reported one or more errors
419 #[derive(Serialize, Deserialize)]
421 pub struct SnapshotVerifyState
{
422 /// UPID of the verify task
424 /// State of the verification. Enum.
425 pub state
: VerifyState
,
431 schema
: BACKUP_TYPE_SCHEMA
,
434 schema
: BACKUP_ID_SCHEMA
,
437 schema
: BACKUP_TIME_SCHEMA
,
440 schema
: SINGLE_LINE_COMMENT_SCHEMA
,
444 type: SnapshotVerifyState
,
449 schema
: BACKUP_ARCHIVE_NAME_SCHEMA
458 #[derive(Serialize, Deserialize)]
459 #[serde(rename_all="kebab-case")]
460 /// Basic information about backup snapshot.
461 pub struct SnapshotListItem
{
462 pub backup_type
: String
, // enum
463 pub backup_id
: String
,
464 pub backup_time
: i64,
465 /// The first line from manifest "notes"
466 #[serde(skip_serializing_if="Option::is_none")]
467 pub comment
: Option
<String
>,
468 /// The result of the last run verify task
469 #[serde(skip_serializing_if="Option::is_none")]
470 pub verification
: Option
<SnapshotVerifyState
>,
471 /// List of contained archive files.
472 pub files
: Vec
<BackupContent
>,
473 /// Overall snapshot size (sum of all archive sizes).
474 #[serde(skip_serializing_if="Option::is_none")]
475 pub size
: Option
<u64>,
476 /// The owner of the snapshots group
477 #[serde(skip_serializing_if="Option::is_none")]
478 pub owner
: Option
<Userid
>,
484 schema
: BACKUP_TYPE_SCHEMA
,
487 schema
: BACKUP_ID_SCHEMA
,
490 schema
: BACKUP_TIME_SCHEMA
,
494 #[derive(Serialize, Deserialize)]
495 #[serde(rename_all="kebab-case")]
497 pub struct PruneListItem
{
498 pub backup_type
: String
, // enum
499 pub backup_id
: String
,
500 pub backup_time
: i64,
505 pub const PRUNE_SCHEMA_KEEP_DAILY
: Schema
= IntegerSchema
::new(
506 "Number of daily backups to keep.")
510 pub const PRUNE_SCHEMA_KEEP_HOURLY
: Schema
= IntegerSchema
::new(
511 "Number of hourly backups to keep.")
515 pub const PRUNE_SCHEMA_KEEP_LAST
: Schema
= IntegerSchema
::new(
516 "Number of backups to keep.")
520 pub const PRUNE_SCHEMA_KEEP_MONTHLY
: Schema
= IntegerSchema
::new(
521 "Number of monthly backups to keep.")
525 pub const PRUNE_SCHEMA_KEEP_WEEKLY
: Schema
= IntegerSchema
::new(
526 "Number of weekly backups to keep.")
530 pub const PRUNE_SCHEMA_KEEP_YEARLY
: Schema
= IntegerSchema
::new(
531 "Number of yearly backups to keep.")
538 schema
: BACKUP_ARCHIVE_NAME_SCHEMA
,
546 #[derive(Serialize, Deserialize)]
547 #[serde(rename_all="kebab-case")]
548 /// Basic information about archive files inside a backup snapshot.
549 pub struct BackupContent
{
550 pub filename
: String
,
551 /// Info if file is encrypted, signed, or neither.
552 #[serde(skip_serializing_if="Option::is_none")]
553 pub crypt_mode
: Option
<CryptMode
>,
554 /// Archive size (from backup manifest).
555 #[serde(skip_serializing_if="Option::is_none")]
556 pub size
: Option
<u64>,
567 #[derive(Clone, Serialize, Deserialize)]
568 #[serde(rename_all="kebab-case")]
569 /// Garbage collection status.
570 pub struct GarbageCollectionStatus
{
571 pub upid
: Option
<String
>,
572 /// Number of processed index files.
573 pub index_file_count
: usize,
574 /// Sum of bytes referred by index files.
575 pub index_data_bytes
: u64,
576 /// Bytes used on disk.
578 /// Chunks used on disk.
579 pub disk_chunks
: usize,
580 /// Sum of removed bytes.
581 pub removed_bytes
: u64,
582 /// Number of removed chunks.
583 pub removed_chunks
: usize,
584 /// Sum of pending bytes (pending removal - kept for safety).
585 pub pending_bytes
: u64,
586 /// Number of pending chunks (pending removal - kept for safety).
587 pub pending_chunks
: usize,
588 /// Number of chunks marked as .bad by verify that have been removed by GC.
589 pub removed_bad
: usize,
590 /// Number of chunks still marked as .bad after garbage collection.
591 pub still_bad
: usize,
594 impl Default
for GarbageCollectionStatus
{
595 fn default() -> Self {
596 GarbageCollectionStatus
{
614 #[derive(Serialize, Deserialize)]
615 /// Storage space usage information.
616 pub struct StorageStatus
{
617 /// Total space (bytes).
619 /// Used space (bytes).
621 /// Available space (bytes).
626 #[derive(Serialize, Deserialize, Default)]
627 /// Backup Type group/snapshot counts.
628 pub struct TypeCounts
{
629 /// The number of groups of the type.
631 /// The number of snapshots of the type.
655 #[derive(Serialize, Deserialize)]
656 /// Counts of groups/snapshots per BackupType.
658 /// The counts for CT backups
659 pub ct
: Option
<TypeCounts
>,
660 /// The counts for Host backups
661 pub host
: Option
<TypeCounts
>,
662 /// The counts for VM backups
663 pub vm
: Option
<TypeCounts
>,
664 /// The counts for other backup types
665 pub other
: Option
<TypeCounts
>,
670 "gc-status": { type: GarbageCollectionStatus, }
,
671 counts
: { type: Counts, }
674 #[derive(Serialize, Deserialize)]
675 #[serde(rename_all="kebab-case")]
676 /// Overall Datastore status and useful information.
677 pub struct DataStoreStatus
{
678 /// Total space (bytes).
680 /// Used space (bytes).
682 /// Available space (bytes).
684 /// Status of last GC
685 pub gc_status
: GarbageCollectionStatus
,
686 /// Group/Snapshot counts
692 upid
: { schema: UPID_SCHEMA }
,
693 user
: { type: Userid }
,
696 #[derive(Serialize, Deserialize)]
698 pub struct TaskListItem
{
700 /// The node name where the task is running on.
704 /// The task start time (Epoch)
706 /// The task start time (Epoch)
708 /// Worker type (arbitrary ASCII string)
709 pub worker_type
: String
,
710 /// Worker ID (arbitrary ASCII string)
711 pub worker_id
: Option
<String
>,
712 /// The user who started the task
714 /// The task end time (Epoch)
715 #[serde(skip_serializing_if="Option::is_none")]
716 pub endtime
: Option
<i64>,
718 #[serde(skip_serializing_if="Option::is_none")]
719 pub status
: Option
<String
>,
722 impl From
<crate::server
::TaskListInfo
> for TaskListItem
{
723 fn from(info
: crate::server
::TaskListInfo
) -> Self {
724 let (endtime
, status
) = info
726 .map_or_else(|| (None
, None
), |a
| (Some(a
.endtime()), Some(a
.to_string())));
730 node
: "localhost".to_string(),
731 pid
: info
.upid
.pid
as i64,
732 pstart
: info
.upid
.pstart
,
733 starttime
: info
.upid
.starttime
,
734 worker_type
: info
.upid
.worker_type
,
735 worker_id
: info
.upid
.worker_id
,
736 user
: info
.upid
.userid
,
744 #[derive(Eq, PartialEq, Debug, Serialize, Deserialize)]
745 #[serde(rename_all = "lowercase")]
746 pub enum TaskStateType
{
758 #[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
759 #[serde(rename_all = "lowercase")]
760 /// Node Power command type.
761 pub enum NodePowerCommand
{
762 /// Restart the server
764 /// Shutdown the server
769 #[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
770 #[serde(rename_all = "lowercase")]
771 /// Interface configuration method
772 pub enum NetworkConfigMethod
{
773 /// Configuration is done manually using other tools
775 /// Define interfaces with statically allocated addresses.
777 /// Obtain an address via DHCP
779 /// Define the loopback interface.
784 #[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
785 #[serde(rename_all = "kebab-case")]
786 #[allow(non_camel_case_types)]
789 pub enum LinuxBondMode
{
790 /// Round-robin policy
792 /// Active-backup policy
798 /// IEEE 802.3ad Dynamic link aggregation
799 #[serde(rename = "802.3ad")]
801 /// Adaptive transmit load balancing
803 /// Adaptive load balancing
808 #[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
809 #[serde(rename_all = "kebab-case")]
810 #[allow(non_camel_case_types)]
812 /// Bond Transmit Hash Policy for LACP (802.3ad)
813 pub enum BondXmitHashPolicy
{
817 #[serde(rename = "layer2+3")]
820 #[serde(rename = "layer3+4")]
825 #[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
826 #[serde(rename_all = "lowercase")]
827 /// Network interface type
828 pub enum NetworkInterfaceType
{
831 /// Physical Ethernet device
837 /// Linux VLAN (eth.10)
839 /// Interface Alias (eth:1)
841 /// Unknown interface type
845 pub const NETWORK_INTERFACE_NAME_SCHEMA
: Schema
= StringSchema
::new("Network interface name.")
846 .format(&NETWORK_INTERFACE_FORMAT
)
848 .max_length(libc
::IFNAMSIZ
-1)
851 pub const NETWORK_INTERFACE_ARRAY_SCHEMA
: Schema
= ArraySchema
::new(
852 "Network interface list.", &NETWORK_INTERFACE_NAME_SCHEMA
)
855 pub const NETWORK_INTERFACE_LIST_SCHEMA
: Schema
= StringSchema
::new(
856 "A list of network devices, comma separated.")
857 .format(&ApiStringFormat
::PropertyString(&NETWORK_INTERFACE_ARRAY_SCHEMA
))
863 schema
: NETWORK_INTERFACE_NAME_SCHEMA
,
866 type: NetworkInterfaceType
,
869 type: NetworkConfigMethod
,
873 type: NetworkConfigMethod
,
877 schema
: CIDR_V4_SCHEMA
,
881 schema
: CIDR_V6_SCHEMA
,
885 schema
: IP_V4_SCHEMA
,
889 schema
: IP_V6_SCHEMA
,
893 description
: "Option list (inet)",
896 description
: "Optional attribute line.",
901 description
: "Option list (inet6)",
904 description
: "Optional attribute line.",
909 description
: "Comments (inet, may span multiple lines)",
914 description
: "Comments (inet6, may span multiple lines)",
919 schema
: NETWORK_INTERFACE_ARRAY_SCHEMA
,
923 schema
: NETWORK_INTERFACE_ARRAY_SCHEMA
,
931 schema
: NETWORK_INTERFACE_NAME_SCHEMA
,
934 bond_xmit_hash_policy
: {
935 type: BondXmitHashPolicy
,
940 #[derive(Debug, Serialize, Deserialize)]
941 /// Network Interface configuration
942 pub struct Interface
{
943 /// Autostart interface
944 #[serde(rename = "autostart")]
946 /// Interface is active (UP)
951 #[serde(rename = "type")]
952 pub interface_type
: NetworkInterfaceType
,
953 #[serde(skip_serializing_if="Option::is_none")]
954 pub method
: Option
<NetworkConfigMethod
>,
955 #[serde(skip_serializing_if="Option::is_none")]
956 pub method6
: Option
<NetworkConfigMethod
>,
957 #[serde(skip_serializing_if="Option::is_none")]
958 /// IPv4 address with netmask
959 pub cidr
: Option
<String
>,
960 #[serde(skip_serializing_if="Option::is_none")]
962 pub gateway
: Option
<String
>,
963 #[serde(skip_serializing_if="Option::is_none")]
964 /// IPv6 address with netmask
965 pub cidr6
: Option
<String
>,
966 #[serde(skip_serializing_if="Option::is_none")]
968 pub gateway6
: Option
<String
>,
970 #[serde(skip_serializing_if="Vec::is_empty")]
971 pub options
: Vec
<String
>,
972 #[serde(skip_serializing_if="Vec::is_empty")]
973 pub options6
: Vec
<String
>,
975 #[serde(skip_serializing_if="Option::is_none")]
976 pub comments
: Option
<String
>,
977 #[serde(skip_serializing_if="Option::is_none")]
978 pub comments6
: Option
<String
>,
980 #[serde(skip_serializing_if="Option::is_none")]
981 /// Maximum Transmission Unit
982 pub mtu
: Option
<u64>,
984 #[serde(skip_serializing_if="Option::is_none")]
985 pub bridge_ports
: Option
<Vec
<String
>>,
986 /// Enable bridge vlan support.
987 #[serde(skip_serializing_if="Option::is_none")]
988 pub bridge_vlan_aware
: Option
<bool
>,
990 #[serde(skip_serializing_if="Option::is_none")]
991 pub slaves
: Option
<Vec
<String
>>,
992 #[serde(skip_serializing_if="Option::is_none")]
993 pub bond_mode
: Option
<LinuxBondMode
>,
994 #[serde(skip_serializing_if="Option::is_none")]
995 #[serde(rename = "bond-primary")]
996 pub bond_primary
: Option
<String
>,
997 pub bond_xmit_hash_policy
: Option
<BondXmitHashPolicy
>,
1003 fn test_cert_fingerprint_schema() -> Result
<(), anyhow
::Error
> {
1005 let schema
= CERT_FINGERPRINT_SHA256_SCHEMA
;
1007 let invalid_fingerprints
= [
1008 "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",
1009 "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",
1010 "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",
1011 "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",
1012 "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",
1013 "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",
1016 for fingerprint
in invalid_fingerprints
.iter() {
1017 if let Ok(_
) = parse_simple_value(fingerprint
, &schema
) {
1018 bail
!("test fingerprint '{}' failed - got Ok() while exception an error.", fingerprint
);
1022 let valid_fingerprints
= [
1023 "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",
1024 "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",
1027 for fingerprint
in valid_fingerprints
.iter() {
1028 let v
= match parse_simple_value(fingerprint
, &schema
) {
1031 bail
!("unable to parse fingerprint '{}' - {}", fingerprint
, err
);
1035 if v
!= serde_json
::json
!(fingerprint
) {
1036 bail
!("unable to parse fingerprint '{}' - got wrong value {:?}", fingerprint
, v
);
1044 fn test_proxmox_user_id_schema() -> Result
<(), anyhow
::Error
> {
1045 let invalid_user_ids
= [
1050 "xx x@test", // contains space
1051 "xx\nx@test", // contains control character
1052 "x:xx@test", // contains collon
1053 "xx/x@test", // contains slash
1054 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@test", // too long
1057 for name
in invalid_user_ids
.iter() {
1058 if let Ok(_
) = parse_simple_value(name
, &Userid
::API_SCHEMA
) {
1059 bail
!("test userid '{}' failed - got Ok() while exception an error.", name
);
1063 let valid_user_ids
= [
1067 "xxx@_T_E_S_T-it.com",
1068 "x_x-x.x@test-it.com",
1071 for name
in valid_user_ids
.iter() {
1072 let v
= match parse_simple_value(name
, &Userid
::API_SCHEMA
) {
1075 bail
!("unable to parse userid '{}' - {}", name
, err
);
1079 if v
!= serde_json
::json
!(name
) {
1080 bail
!("unable to parse userid '{}' - got wrong value {:?}", name
, v
);
1088 #[derive(Copy, Clone, Serialize, Deserialize)]
1089 #[serde(rename_all = "UPPERCASE")]
1100 #[derive(Copy, Clone, Serialize, Deserialize)]
1101 #[serde(rename_all = "lowercase")]
1102 pub enum RRDTimeFrameResolution
{
1103 /// 1 min => last 70 minutes
1105 /// 30 min => last 35 hours
1107 /// 3 hours => about 8 days
1109 /// 12 hours => last 35 days
1111 /// 1 week => last 490 days
1116 #[derive(Serialize, Deserialize)]
1117 #[serde(rename_all = "PascalCase")]
1118 /// Describes a package for which an update is available.
1119 pub struct APTUpdateInfo
{
1121 pub package
: String
,
1124 /// Package architecture
1126 /// Human readable package description
1127 pub description
: String
,
1128 /// New version to be updated to
1129 pub version
: String
,
1130 /// Old version currently installed
1131 pub old_version
: String
,
1134 /// Package priority in human-readable form
1135 pub priority
: String
,
1137 pub section
: String
,
1138 /// URL under which the package's changelog can be retrieved
1139 pub change_log_url
: String
,