pub struct SshHost { /* private fields */ }
Expand description
this structure is used for storing the hostdata for easier storrage of the related information
The name
field is the name of the remote.
The address
field store the address of the remote hosts.
The port
is for the remote port that ssh must use to connect.
The private_key
is the path to the private_key to use.
Implementations§
Source§impl SshHost
impl SshHost
Sourcepub fn new(
name: String,
address: String,
user: Option<String>,
port: Option<i64>,
private_key: Option<PathBuf>,
) -> SshHost
pub fn new( name: String, address: String, user: Option<String>, port: Option<i64>, private_key: Option<PathBuf>, ) -> SshHost
return a new struct SshHost
§Examples
use std::path::PathBuf;
let val = SshHost::new(String::from("hello"), String::from("127.0.0.1"), Some(String::from("user")), None, Some(PathBuf::from("private_key")));
assert_eq!(val.get_name(), String::from("hello"));
assert_eq!(val.get_address(), String::from("127.0.0.1"));
assert_eq!(val.get_user(), String::from("user"));
assert_eq!(val.get_port(), 22);
assert_eq!(val.get_private_key().unwrap(), PathBuf::from("private_key"));
assert_eq!(val.is_reachable(), true);
assert_eq!(val.get_url().unwrap(), String::from("127.0.0.1:22"));
Sourcepub fn get_name(&self) -> String
pub fn get_name(&self) -> String
return the name of the remote
§Examples
let val = SshHost::new(String::from("hello"), String::from("127.0.0.1"), None, None, None);
assert_eq!(val.get_name(), String::from("hello"));
Sourcepub fn set_name(&mut self, new_name: String)
pub fn set_name(&mut self, new_name: String)
set the name of the remote
§Examples
let mut val = SshHost::new(String::from("hello"), String::from("127.0.0.1"), None, None, None);
assert_eq!(val.get_name(), String::from("hello"));
val.set_name(String::from("foobar"));
assert_eq!(val.get_name(), String::from("foobar"));
Sourcepub fn get_address(&self) -> String
pub fn get_address(&self) -> String
return the address of the remote
§Examples
let val = SshHost::new(String::from("hello"), String::from("127.0.0.1"), None, None, None);
assert_eq!(val.get_address(), String::from("127.0.0.1"));
Sourcepub fn set_address(&mut self, new_address: String)
pub fn set_address(&mut self, new_address: String)
set the address of the remote
§Examples
let mut val = SshHost::new(String::from("hello"), String::from("127.0.0.2"), None, None, None);
assert_eq!(val.get_address(), String::from("127.0.0.2"));
val.set_address(String::from("127.0.0.1"));
assert_eq!(val.get_address(), String::from("127.0.0.1"));
Sourcepub fn get_user(&self) -> String
pub fn get_user(&self) -> String
return the user of the remote
§Examples
let val = SshHost::new(String::from("hello"), String::from("127.0.0.1"), Some(String::from("user")), None, None);
assert_eq!(val.get_user(), String::from("user"));
Sourcepub fn set_user(&mut self, new_user: String)
pub fn set_user(&mut self, new_user: String)
set the address of the remote
§Examples
let mut val = SshHost::new(String::from("hello"), String::from("127.0.0.1"), Some(String::from("user")), None, None);
assert_eq!(val.get_user(), String::from("user"));
val.set_user(String::from("root"));
assert_eq!(val.get_user(), String::from("root"));
Sourcepub fn get_port(&self) -> i64
pub fn get_port(&self) -> i64
return the port of the remote
§Examples
let val = SshHost::new(String::from("hello"), String::from("127.0.0.1"), None, Some(2222), None);
assert_eq!(val.get_port(), 2222);
Sourcepub fn set_port(&mut self, new_port: i64)
pub fn set_port(&mut self, new_port: i64)
set the port of the remote
§Examples
let mut val = SshHost::new(String::from("hello"), String::from("127.0.0.1"), None, None, None);
assert_eq!(val.get_port(), 22);
val.set_port(2222);
assert_eq!(val.get_port(), 2222);
Sourcepub fn get_private_key(&self) -> Option<PathBuf>
pub fn get_private_key(&self) -> Option<PathBuf>
return the private key file of the remote
§Examples
use std::path::PathBuf;
let val = SshHost::new(String::from("hello"), String::from("127.0.0.1"), None, None, Some(PathBuf::from("private_key")));
assert_eq!(val.get_private_key().unwrap(), PathBuf::from("private_key"));
Sourcepub fn set_private_key(&mut self, new_key: Option<PathBuf>)
pub fn set_private_key(&mut self, new_key: Option<PathBuf>)
set the the private_key of the remote
§Examples
use std::path::PathBuf;
let mut val = SshHost::new(String::from("hello"), String::from("127.0.0.1"), None, None, Some(PathBuf::from("private_key")));
assert_eq!(val.get_private_key().unwrap(), PathBuf::from("private_key"));
val.set_private_key(Some(PathBuf::from("private_key_2")));
assert_eq!(val.get_private_key().unwrap(), PathBuf::from("private_key_2"));
Sourcepub fn is_reachable(&self) -> bool
pub fn is_reachable(&self) -> bool
return if the remote hosts is available or not
§Examples
use std::path::PathBuf;
let val = SshHost::new(String::from("hello"), String::from("127.0.0.1"), None, None, None);
assert_eq!(val.is_reachable(), true);
Sourcepub fn set_reachable(&mut self, new_val: bool)
pub fn set_reachable(&mut self, new_val: bool)
set the remote value
§Examples
use std::path::PathBuf;
let mut val = SshHost::new(String::from("hello"), String::from("127.0.0.1"), None, None, None);
assert_eq!(val.is_reachable(), true);
val.set_reachable(false);
assert_eq!(val.is_reachable(), false);
Sourcepub fn get_url(&self) -> Result<String, &str>
pub fn get_url(&self) -> Result<String, &str>
return the url of the hosts
It will be in the form of address:port
like 127.0.0.1:22
§Examples
use std::path::PathBuf;
let val = SshHost::new(String::from("hello"), String::from("127.0.0.1"), None, Some(2222), None);
assert_eq!(val.get_url().unwrap(), String::from("127.0.0.1:2222"));