Can enable VNC access
This commit is contained in:
		@@ -155,6 +155,11 @@ impl AppConfig {
 | 
				
			|||||||
    pub fn iso_storage_path(&self) -> PathBuf {
 | 
					    pub fn iso_storage_path(&self) -> PathBuf {
 | 
				
			||||||
        self.storage_path().join("iso")
 | 
					        self.storage_path().join("iso")
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// Get VM vnc sockets
 | 
				
			||||||
 | 
					    pub fn vnc_sockets_path(&self) -> PathBuf {
 | 
				
			||||||
 | 
					        self.storage_path().to_path_buf()
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Debug, Clone, serde::Serialize)]
 | 
					#[derive(Debug, Clone, serde::Serialize)]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,6 +19,8 @@ impl DomainXMLUuid {
 | 
				
			|||||||
#[derive(serde::Serialize, serde::Deserialize)]
 | 
					#[derive(serde::Serialize, serde::Deserialize)]
 | 
				
			||||||
#[serde(rename = "os")]
 | 
					#[serde(rename = "os")]
 | 
				
			||||||
pub struct OSXML {
 | 
					pub struct OSXML {
 | 
				
			||||||
 | 
					    #[serde(rename(serialize = "@firmware"))]
 | 
				
			||||||
 | 
					    pub firmware: String,
 | 
				
			||||||
    pub r#type: OSTypeXML,
 | 
					    pub r#type: OSTypeXML,
 | 
				
			||||||
    pub loader: Option<OSLoaderXML>,
 | 
					    pub loader: Option<OSLoaderXML>,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -41,6 +43,37 @@ pub struct OSLoaderXML {
 | 
				
			|||||||
    pub secure: String,
 | 
					    pub secure: String,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Hypervisor features
 | 
				
			||||||
 | 
					#[derive(serde::Serialize, serde::Deserialize)]
 | 
				
			||||||
 | 
					#[serde(rename = "features")]
 | 
				
			||||||
 | 
					pub struct FeaturesXML {
 | 
				
			||||||
 | 
					    pub acpi: ACPIXML,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// ACPI feature
 | 
				
			||||||
 | 
					#[derive(serde::Serialize, serde::Deserialize)]
 | 
				
			||||||
 | 
					#[serde(rename = "acpi")]
 | 
				
			||||||
 | 
					pub struct ACPIXML {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Devices information
 | 
				
			||||||
 | 
					#[derive(serde::Serialize, serde::Deserialize)]
 | 
				
			||||||
 | 
					#[serde(rename = "devices")]
 | 
				
			||||||
 | 
					pub struct DevicesXML {
 | 
				
			||||||
 | 
					    #[serde(skip_serializing_if = "Option::is_none")]
 | 
				
			||||||
 | 
					    pub graphics: Option<GraphicsXML>,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Screen information
 | 
				
			||||||
 | 
					#[derive(serde::Serialize, serde::Deserialize)]
 | 
				
			||||||
 | 
					#[serde(rename = "graphics")]
 | 
				
			||||||
 | 
					pub struct GraphicsXML {
 | 
				
			||||||
 | 
					    #[serde(rename(serialize = "@type"))]
 | 
				
			||||||
 | 
					    pub r#type: String,
 | 
				
			||||||
 | 
					    #[serde(rename(serialize = "@socket"))]
 | 
				
			||||||
 | 
					    pub socket: String,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Domain RAM information
 | 
				
			||||||
#[derive(serde::Serialize, serde::Deserialize)]
 | 
					#[derive(serde::Serialize, serde::Deserialize)]
 | 
				
			||||||
#[serde(rename = "memory")]
 | 
					#[serde(rename = "memory")]
 | 
				
			||||||
pub struct DomainMemoryXML {
 | 
					pub struct DomainMemoryXML {
 | 
				
			||||||
@@ -65,6 +98,8 @@ pub struct DomainXML {
 | 
				
			|||||||
    pub title: Option<String>,
 | 
					    pub title: Option<String>,
 | 
				
			||||||
    pub description: Option<String>,
 | 
					    pub description: Option<String>,
 | 
				
			||||||
    pub os: OSXML,
 | 
					    pub os: OSXML,
 | 
				
			||||||
 | 
					    pub features: FeaturesXML,
 | 
				
			||||||
 | 
					    pub devices: DevicesXML,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// The maximum allocation of memory for the guest at boot time
 | 
					    /// The maximum allocation of memory for the guest at boot time
 | 
				
			||||||
    pub memory: DomainMemoryXML,
 | 
					    pub memory: DomainMemoryXML,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,8 @@
 | 
				
			|||||||
 | 
					use crate::app_config::AppConfig;
 | 
				
			||||||
use crate::constants;
 | 
					use crate::constants;
 | 
				
			||||||
use crate::libvirt_lib_structures::{
 | 
					use crate::libvirt_lib_structures::{
 | 
				
			||||||
    DomainMemoryXML, DomainXML, DomainXMLUuid, OSLoaderXML, OSTypeXML, OSXML,
 | 
					    DevicesXML, DomainMemoryXML, DomainXML, DomainXMLUuid, FeaturesXML, GraphicsXML, OSLoaderXML,
 | 
				
			||||||
 | 
					    OSTypeXML, ACPIXML, OSXML,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use crate::libvirt_rest_structures::LibVirtStructError::StructureExtraction;
 | 
					use crate::libvirt_rest_structures::LibVirtStructError::StructureExtraction;
 | 
				
			||||||
use lazy_regex::regex;
 | 
					use lazy_regex::regex;
 | 
				
			||||||
@@ -66,11 +68,12 @@ pub struct VMInfo {
 | 
				
			|||||||
    pub architecture: VMArchitecture,
 | 
					    pub architecture: VMArchitecture,
 | 
				
			||||||
    /// VM allocated memory, in megabytes
 | 
					    /// VM allocated memory, in megabytes
 | 
				
			||||||
    pub memory: usize,
 | 
					    pub memory: usize,
 | 
				
			||||||
 | 
					    /// Enable VNC access through admin console
 | 
				
			||||||
 | 
					    pub vnc_access: bool,
 | 
				
			||||||
    // TODO : storage
 | 
					    // TODO : storage
 | 
				
			||||||
    // TODO : iso
 | 
					    // TODO : iso
 | 
				
			||||||
    // TODO : autostart
 | 
					    // TODO : autostart
 | 
				
			||||||
    // TODO : vnc
 | 
					    // TODO : network interface
 | 
				
			||||||
    // TODO : interface
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl VMInfo {
 | 
					impl VMInfo {
 | 
				
			||||||
@@ -102,6 +105,18 @@ impl VMInfo {
 | 
				
			|||||||
            return Err(StructureExtraction("VM memory is invalid!").into());
 | 
					            return Err(StructureExtraction("VM memory is invalid!").into());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        let vnc_graphics = match self.vnc_access {
 | 
				
			||||||
 | 
					            true => Some(GraphicsXML {
 | 
				
			||||||
 | 
					                r#type: "vnc".to_string(),
 | 
				
			||||||
 | 
					                socket: AppConfig::get()
 | 
				
			||||||
 | 
					                    .vnc_sockets_path()
 | 
				
			||||||
 | 
					                    .join(format!("vnc-{}", self.name))
 | 
				
			||||||
 | 
					                    .to_string_lossy()
 | 
				
			||||||
 | 
					                    .to_string(),
 | 
				
			||||||
 | 
					            }),
 | 
				
			||||||
 | 
					            false => None,
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Ok(DomainXML {
 | 
					        Ok(DomainXML {
 | 
				
			||||||
            r#type: "kvm".to_string(),
 | 
					            r#type: "kvm".to_string(),
 | 
				
			||||||
            name: self.name,
 | 
					            name: self.name,
 | 
				
			||||||
@@ -119,6 +134,7 @@ impl VMInfo {
 | 
				
			|||||||
                    .to_string(),
 | 
					                    .to_string(),
 | 
				
			||||||
                    body: "hvm".to_string(),
 | 
					                    body: "hvm".to_string(),
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
 | 
					                firmware: "efi".to_string(),
 | 
				
			||||||
                loader: Some(OSLoaderXML {
 | 
					                loader: Some(OSLoaderXML {
 | 
				
			||||||
                    secure: match self.boot_type {
 | 
					                    secure: match self.boot_type {
 | 
				
			||||||
                        BootType::UEFI => "no".to_string(),
 | 
					                        BootType::UEFI => "no".to_string(),
 | 
				
			||||||
@@ -126,6 +142,13 @@ impl VMInfo {
 | 
				
			|||||||
                    },
 | 
					                    },
 | 
				
			||||||
                }),
 | 
					                }),
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            features: FeaturesXML { acpi: ACPIXML {} },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            devices: DevicesXML {
 | 
				
			||||||
 | 
					                graphics: vnc_graphics,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            memory: DomainMemoryXML {
 | 
					            memory: DomainMemoryXML {
 | 
				
			||||||
                unit: "MB".to_string(),
 | 
					                unit: "MB".to_string(),
 | 
				
			||||||
                memory: self.memory,
 | 
					                memory: self.memory,
 | 
				
			||||||
@@ -163,6 +186,7 @@ impl VMInfo {
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            memory: convert_to_mb(&domain.memory.unit, domain.memory.memory)?,
 | 
					            memory: convert_to_mb(&domain.memory.unit, domain.memory.memory)?,
 | 
				
			||||||
 | 
					            vnc_access: domain.devices.graphics.is_some(),
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user