]> git.proxmox.com Git - proxmox-backup.git/commitdiff
src/config/network.rs: move type definitions to src/api2/types.rs
authorDietmar Maurer <dietmar@proxmox.com>
Tue, 21 Apr 2020 15:25:05 +0000 (17:25 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 21 Apr 2020 15:25:05 +0000 (17:25 +0200)
src/api2/config/network.rs
src/api2/types.rs
src/config/network.rs

index 8b06007ab795418c61b05c0d12925daa0e0a916c..6f6de282b10289f29e42b9b23e8e7e4ac72fa180 100644 (file)
@@ -6,6 +6,7 @@ use proxmox::api::{api, ApiMethod, Router, RpcEnvironment, Permission};
 //use crate::api2::types::*;
 use crate::config::network;
 use crate::config::acl::{PRIV_SYS_AUDIT};
+use crate::api2::types::Interface;
 
 #[api(
     input: {
@@ -15,7 +16,7 @@ use crate::config::acl::{PRIV_SYS_AUDIT};
         description: "List network devices (with config digest).",
         type: Array,
         items: {
-            type: network::Interface,
+            type: Interface,
         },
     },
     access: {
index a224243da279609f71f3d1522a774a8388a8dc1f..050bfe68b38635e022baa5a83861419afa8651e3 100644 (file)
@@ -443,6 +443,93 @@ pub struct TaskListItem {
     pub status: Option<String>,
 }
 
+#[api()]
+#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
+#[serde(rename_all = "lowercase")]
+/// Interface configuration method
+pub enum NetworkConfigMethod {
+    /// Configuration is done manually using other tools
+    Manual,
+    /// Define interfaces with statically allocated addresses.
+    Static,
+    /// Obtain an address via DHCP
+    DHCP,
+    /// Define the loopback interface.
+    Loopback,
+}
+
+#[api(
+    properties: {
+        name: {
+            type: String,
+            min_length: 1,
+            max_length: libc::IFNAMSIZ-1,
+        },
+        method_v4: {
+            type: NetworkConfigMethod,
+            optional: true,
+        },
+        method_v6: {
+            type: NetworkConfigMethod,
+            optional: true,
+        },
+        options_v4: {
+            description: "Option list (inet)",
+            type: Array,
+            items: {
+                description: "Optional attribute.",
+                type: String,
+            },
+        },
+        options_v6: {
+            description: "Option list (inet6)",
+            type: Array,
+            items: {
+                description: "Optional attribute.",
+                type: String,
+            },
+        },
+    }
+)]
+#[derive(Debug, Serialize, Deserialize)]
+/// Network Interface configuration
+pub struct Interface {
+    /// Autostart interface
+    pub autostart: bool,
+    /// Interface is a physical network device
+    pub exists: bool,
+    /// Interface is active (UP)
+    pub active: bool,
+    /// Interface name
+    pub name: String,
+    #[serde(skip_serializing_if="Option::is_none")]
+     pub method_v4: Option<NetworkConfigMethod>,
+    #[serde(skip_serializing_if="Option::is_none")]
+    pub method_v6: Option<NetworkConfigMethod>,
+    #[serde(skip_serializing_if="Option::is_none")]
+    /// IPv4 address
+    pub address_v4: Option<String>,
+    #[serde(skip_serializing_if="Option::is_none")]
+    /// IPv4 gateway
+    pub gateway_v4: Option<String>,
+    #[serde(skip_serializing_if="Option::is_none")]
+    /// IPv4 netmask
+    pub netmask_v4: Option<u8>,
+    #[serde(skip_serializing_if="Option::is_none")]
+    /// IPv6 address
+    pub address_v6: Option<String>,
+    #[serde(skip_serializing_if="Option::is_none")]
+    /// IPv6 gateway
+    pub gateway_v6: Option<String>,
+    #[serde(skip_serializing_if="Option::is_none")]
+    /// IPv6 netmask
+    pub netmask_v6: Option<u8>,
+    #[serde(skip_serializing_if="Vec::is_empty")]
+    pub options_v4: Vec<String>,
+    #[serde(skip_serializing_if="Vec::is_empty")]
+    pub options_v6: Vec<String>,
+}
+
 // Regression tests
 
 #[test]
index 380e5201b2a23c711bc66052e22e19f75d10419c..70e027e0b8d9424a40fbbba4e37b23e8a4790386 100644 (file)
@@ -2,10 +2,8 @@ use std::io::{Write};
 use std::collections::{HashSet, HashMap};
 
 use anyhow::{Error, bail};
-use serde::{Serialize, Deserialize};
 
 use proxmox::tools::{fs::replace_file, fs::CreateOptions};
-use proxmox::api::api;
 
 mod helper;
 pub use helper::*;
@@ -16,92 +14,7 @@ pub use lexer::*;
 mod parser;
 pub use parser::*;
 
-#[api()]
-#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
-#[serde(rename_all = "lowercase")]
-/// Interface configuration method
-pub enum NetworkConfigMethod {
-    /// Configuration is done manually using other tools
-    Manual,
-    /// Define interfaces with statically allocated addresses.
-    Static,
-    /// Obtain an address via DHCP
-    DHCP,
-    /// Define the loopback interface.
-    Loopback,
-}
-
-#[api(
-    properties: {
-        name: {
-            type: String,
-            min_length: 1,
-            max_length: libc::IFNAMSIZ-1,
-        },
-        method_v4: {
-            type: NetworkConfigMethod,
-            optional: true,
-        },
-        method_v6: {
-            type: NetworkConfigMethod,
-            optional: true,
-        },
-        options_v4: {
-            description: "Option list (inet)",
-            type: Array,
-            items: {
-                description: "Optional attribute.",
-                type: String,
-            },
-        },
-        options_v6: {
-            description: "Option list (inet6)",
-            type: Array,
-            items: {
-                description: "Optional attribute.",
-                type: String,
-            },
-        },
-    }
-)]
-#[derive(Debug, Serialize, Deserialize)]
-/// Network Interface configuration
-pub struct Interface {
-    /// Autostart interface
-    pub autostart: bool,
-    /// Interface is a physical network device
-    pub exists: bool,
-    /// Interface is active (UP)
-    pub active: bool,
-    /// Interface name
-    pub name: String,
-    #[serde(skip_serializing_if="Option::is_none")]
-     pub method_v4: Option<NetworkConfigMethod>,
-    #[serde(skip_serializing_if="Option::is_none")]
-    pub method_v6: Option<NetworkConfigMethod>,
-    #[serde(skip_serializing_if="Option::is_none")]
-    /// IPv4 address
-    pub address_v4: Option<String>,
-    #[serde(skip_serializing_if="Option::is_none")]
-    /// IPv4 gateway
-    pub gateway_v4: Option<String>,
-    #[serde(skip_serializing_if="Option::is_none")]
-    /// IPv4 netmask
-    pub netmask_v4: Option<u8>,
-    #[serde(skip_serializing_if="Option::is_none")]
-    /// IPv6 address
-    pub address_v6: Option<String>,
-    #[serde(skip_serializing_if="Option::is_none")]
-    /// IPv6 gateway
-    pub gateway_v6: Option<String>,
-    #[serde(skip_serializing_if="Option::is_none")]
-    /// IPv6 netmask
-    pub netmask_v6: Option<u8>,
-    #[serde(skip_serializing_if="Vec::is_empty")]
-    pub options_v4: Vec<String>,
-    #[serde(skip_serializing_if="Vec::is_empty")]
-    pub options_v6: Vec<String>,
-}
+use crate::api2::types::{Interface, NetworkConfigMethod};
 
 impl Interface {