chore: rename none to notset in enums, add policy and rol + checkinfo out formats

This commit is contained in:
Jesús Pérez Lorenzo 2021-10-16 00:34:09 +01:00
parent c2db9661ce
commit beb0c52cb7
7 changed files with 102 additions and 34 deletions

View File

@ -3,6 +3,7 @@ use serde::{Serialize,Deserialize};
use crate::pkgs::{PkgInfo};
use crate::defs::{TskSrvcName,IsCritical,AppName,Cntrllr};
use app_env::appenv::{Language,Rol,Policy};
// use crate::cmds::ssh;
// use tempfile::tempfile;
@ -213,6 +214,22 @@ pub struct DeployConfig {
#[allow(non_snake_case)]
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct TskSrvc {
pub name: TskSrvcName,
pub path: String,
pub req: String,
pub target: String,
pub liveness: String,
pub critical: IsCritical,
pub policy: Policy,
pub target_policy: String,
pub rol: Rol,
pub target_rol: String,
}
#[allow(clippy::missing_docs_in_private_items)]
#[allow(non_snake_case)]
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct TskSrvcOut {
pub name: TskSrvcName,
pub path: String,
pub req: String,
@ -225,6 +242,22 @@ pub struct TskSrvc {
#[allow(non_snake_case)]
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct App {
pub name: AppName,
pub path: String,
pub req: String,
pub target: String,
pub liveness: String,
pub critical: IsCritical,
pub policy: Policy,
pub target_policy: String,
pub rol: Rol,
pub target_rol: String,
}
#[allow(clippy::missing_docs_in_private_items)]
#[allow(non_snake_case)]
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct AppOut {
pub name: AppName,
pub path: String,
pub req: String,
@ -285,19 +318,44 @@ pub struct TsksrvcInfo {
pub srvc: TskSrvc,
}
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct TsksrvcInfOut {
pub name: String,
pub info: String, // serde_yaml::Value,
pub srvc: TskSrvcOut,
}
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct AppsrvcInfo {
pub name: String,
pub info: String, // serde_yaml::Value,
pub srvc: App,
}
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct AppsrvcInfOut {
pub name: String,
pub info: String, // serde_yaml::Value,
pub srvc: AppOut,
}
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct SrvcsHostInfo {
pub hostname: String,
pub tsksrvcs: Vec<TsksrvcInfo>,
pub appsrvcs: Vec<AppsrvcInfo>,
}
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct SrvcsHostInfOut {
pub hostname: String,
pub tsksrvcs: Vec<TsksrvcInfOut>,
pub appsrvcs: Vec<AppsrvcInfOut>,
}
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct HostInfo {
pub hostname: String,
pub info: String,
}
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct InfoStatus {
pub title: String,
pub content: String,
pub lang: Language,
pub datetime: String,
}

View File

@ -1,6 +1,7 @@
use serde::{Serialize, Deserialize, Deserializer};
use std::fmt;
use app_env::appenv::{Policy,Rol};
use crate::clouds::on_clouds::load_config_data;
use crate::clouds::defs::{Cloud,SrvcsHostInfo};
@ -197,7 +198,7 @@ impl TskSrvcName {
#[derive(Eq, PartialEq, Copy, Clone, Debug, Serialize, Deserialize)]
#[allow(non_camel_case_types)]
pub enum AppName {
none,
notset,
registry,
repo,
wp_site,
@ -212,14 +213,14 @@ pub enum AppName {
impl Default for AppName {
fn default() -> Self {
AppName::none
AppName::notset
}
}
impl fmt::Display for AppName {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
AppName::none => write!(f,"none"),
AppName::notset => write!(f,"notset"),
AppName::registry => write!(f,"registry"),
AppName::repo => write!(f,"repo"),
AppName::wp_site => write!(f,"wp_site"),
@ -237,7 +238,7 @@ impl fmt::Display for AppName {
impl AppName {
pub fn set_appname(pack: String) -> AppName {
match pack.as_str() {
"none" => AppName::none,
"notset" => AppName::notset,
"registry" => AppName::registry,
"repo" => AppName::repo,
"wp_site" => AppName::wp_site,
@ -256,21 +257,21 @@ impl AppName {
#[derive(Eq, PartialEq, Copy, Clone, Debug, Serialize, Deserialize)]
#[allow(non_camel_case_types)]
pub enum ProviderName {
none,
notset,
manual,
upcloud,
}
impl Default for ProviderName {
fn default() -> Self {
ProviderName::none
ProviderName::notset
}
}
impl fmt::Display for ProviderName {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ProviderName::none => write!(f,"none"),
ProviderName::notset => write!(f,"notset"),
ProviderName::manual => write!(f,"manual"),
ProviderName::upcloud => write!(f,"upcloud"),
}
@ -280,10 +281,10 @@ impl fmt::Display for ProviderName {
impl ProviderName {
pub fn set_provider(provider: String) -> ProviderName {
match provider.as_str() {
"none" => ProviderName::none,
"notset" => ProviderName::notset,
"manual" => ProviderName::manual,
"upcloud" => ProviderName::upcloud,
_ => ProviderName::none,
_ => ProviderName::notset,
}
}
}
@ -291,14 +292,14 @@ impl ProviderName {
#[derive(Eq, PartialEq, Copy, Clone, Debug, Serialize, Deserialize)]
#[allow(non_camel_case_types)]
pub enum InfaceMode {
none,
notset,
float,
alias,
}
impl InfaceMode {
pub fn set_infacemode(pack: String) -> InfaceMode {
match pack.as_str() {
"none" => InfaceMode::none,
"notset" => InfaceMode::notset,
"float" => InfaceMode::float,
"alias" => InfaceMode::alias,
&_ => InfaceMode::default(),
@ -308,14 +309,14 @@ impl InfaceMode {
impl Default for InfaceMode {
fn default() -> Self {
InfaceMode::none
InfaceMode::notset
}
}
impl fmt::Display for InfaceMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
InfaceMode::none => write!(f,"none"),
InfaceMode::notset => write!(f,"notset"),
InfaceMode::float => write!(f,"float"),
InfaceMode::alias => write!(f,"alias"),
}
@ -325,7 +326,7 @@ impl fmt::Display for InfaceMode {
#[derive(Eq, PartialEq, Copy, Clone, Debug, Serialize, Deserialize)]
#[allow(non_camel_case_types)]
pub enum InfaceNet {
none,
notset,
public,
sdn,
prv,
@ -334,7 +335,7 @@ pub enum InfaceNet {
impl InfaceNet {
pub fn set_infacenet(pack: String) -> InfaceNet {
match pack.as_str() {
"none" => InfaceNet::none,
"notset" => InfaceNet::notset,
"public" => InfaceNet::public,
"pub" => InfaceNet::public,
"sdn" => InfaceNet::sdn,
@ -346,13 +347,13 @@ impl InfaceNet {
}
impl Default for InfaceNet {
fn default() -> Self {
InfaceNet::none
InfaceNet::notset
}
}
impl fmt::Display for InfaceNet {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
InfaceNet::none => write!(f,"none"),
InfaceNet::notset => write!(f,"notset"),
InfaceNet::public => write!(f,"pub"),
InfaceNet::sdn => write!(f,"sdn"),
InfaceNet::prv => write!(f,"prv"),
@ -363,13 +364,13 @@ impl fmt::Display for InfaceNet {
#[derive(Eq, PartialEq, Copy, Clone, Debug, Serialize, Deserialize)]
#[allow(non_camel_case_types)]
pub enum NetworkMethodName {
none,
notset,
firstavailable,
}
impl NetworkMethodName {
pub fn set_providername(pack: String) -> NetworkMethodName {
match pack.as_str() {
"none" => NetworkMethodName::none,
"notset" => NetworkMethodName::notset,
"firstavailable" => NetworkMethodName::firstavailable,
&_ => NetworkMethodName::default(),
}
@ -377,13 +378,13 @@ impl NetworkMethodName {
}
impl Default for NetworkMethodName {
fn default() -> Self {
NetworkMethodName::none
NetworkMethodName::notset
}
}
impl fmt::Display for NetworkMethodName {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
NetworkMethodName::none => write!(f,"none"),
NetworkMethodName::notset => write!(f,"notset"),
NetworkMethodName::firstavailable => write!(f,"firstavailable"),
}
}
@ -479,6 +480,10 @@ pub struct IpDef {
pub monitor: String,
pub critical: IsCritical,
pub graph: GraphNode,
pub policy: Policy,
pub target_policy: String,
pub rol: Rol,
pub target_rol: String,
}
impl Default for IpDef {
fn default() -> Self {
@ -495,6 +500,10 @@ impl Default for IpDef {
monitor: String::from(""),
critical: IsCritical::no,
graph: GraphNode::default(),
policy: Policy::default(),
target_policy: String::from(""),
rol: Rol::default(),
target_rol: String::from(""),
}
}
}
@ -799,4 +808,4 @@ impl Default for GraphNode {
edges: Vec::new(), // vec!(GraphEdge::default()),
}
}
}
}

View File

@ -6,3 +6,4 @@ pub mod pkgs;
pub mod cmds;
pub mod utils;
pub mod monitor;
pub mod status;

View File

@ -44,7 +44,7 @@ impl fmt::Display for RuleContext {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
RuleContext::Server(c) => write!(f,"server: {}",c),
RuleContext::None => write!(f,"none"),
RuleContext::None => write!(f,"notset"),
RuleContext::Service(c) => write!(f,"service: {}",c),
RuleContext::Ip(c) => write!(f,"ip: {}",c),
}
@ -79,7 +79,7 @@ impl Default for MonitorAction {
impl fmt::Display for MonitorAction {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
MonitorAction::None => write!(f,"none"),
MonitorAction::None => write!(f,"notset"),
MonitorAction::Start(v,p,a) => write!(f,"start: {} {} {}",v,p,a),
MonitorAction::Stop(v,p,a) => write!(f,"stop: {} {} {}",v,p,a),
MonitorAction::Restart(v,p,a) => write!(f,"restart: {} {} {}",v,p,a),
@ -171,7 +171,7 @@ impl Default for RuleSchedule {
impl fmt::Display for RuleSchedule {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
RuleSchedule::None => write!(f,"none"),
RuleSchedule::None => write!(f,"notset"),
RuleSchedule::Check=> write!(f,"chechk"),
RuleSchedule::OnDemand=> write!(f,"ondemand"),
}
@ -207,7 +207,7 @@ impl RuleOperator {
impl fmt::Display for RuleOperator {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
RuleOperator::None => write!(f,"none"),
RuleOperator::None => write!(f,"notset"),
RuleOperator::Equal => write!(f,"equal"),
RuleOperator::NotEqual=> write!(f,"not_equal"),
RuleOperator::Contains => write!(f,"matches"),

View File

@ -36,7 +36,7 @@ pub fn run_command(str_cmd: &str) -> Result<String> {
if res.ends_with("\n") {
res.pop();
}
res = res.replace("\n"," ").replace("<none>","");
res = res.replace("\n"," ").replace("<notset>","");
Ok(res)
} else {
let err = str::from_utf8(&result.stderr).unwrap_or_else(|_| "");

View File

@ -18,7 +18,7 @@ pub enum ProviderServerPlan {
upcloud_1xCPU_2GB,
upcloud_2xCPU_4GB,
upcloud_4xCPU_8GB,
none,
notset,
}
impl Default for ProviderServerPlan {
@ -33,7 +33,7 @@ impl ProviderServerPlan {
ProviderServerPlan::upcloud_1xCPU_2GB => String::from("1xCPU-2GB"),
ProviderServerPlan::upcloud_2xCPU_4GB => String::from("2xCPU-4GB"),
ProviderServerPlan::upcloud_4xCPU_8GB => String::from("4xCPU-8GB"),
ProviderServerPlan::none => String::from(""),
ProviderServerPlan::notset => String::from(""),
}
}
pub fn set_plan (plan: String) -> ProviderServerPlan {
@ -46,7 +46,7 @@ impl ProviderServerPlan {
"upcloud_2xCPU_4GB" => ProviderServerPlan::upcloud_2xCPU_4GB,
"4xCPU-8GB" => ProviderServerPlan::upcloud_4xCPU_8GB,
"upcloud_4xCPU_8GB" => ProviderServerPlan::upcloud_4xCPU_8GB,
"" => ProviderServerPlan::none,
"" => ProviderServerPlan::notset,
&_ => ProviderServerPlan::default(),
}
}
@ -58,7 +58,7 @@ pub enum ProviderZone {
upcloud_nl_ams1,
upcloud_es_mad1,
upcloud_de_fra1,
none,
notset,
}
impl Default for ProviderZone {
@ -72,7 +72,7 @@ impl ProviderZone {
ProviderZone::upcloud_nl_ams1 => String::from("nl-ams1"),
ProviderZone::upcloud_es_mad1 => String::from("es-mad1"),
ProviderZone::upcloud_de_fra1=> String::from("de-fra1"),
ProviderZone::none => String::from(""),
ProviderZone::notset => String::from(""),
}
}
pub fn set_zone (zone: String) -> ProviderZone {
@ -83,7 +83,7 @@ impl ProviderZone {
"upcloud_es_mad1" => ProviderZone::upcloud_es_mad1,
"de-fra1" => ProviderZone::upcloud_de_fra1,
"upcloud_de_fra1" => ProviderZone::upcloud_de_fra1,
"" => ProviderZone::none,
"" => ProviderZone::notset,
&_ => ProviderZone::default(),
}
}

View File

@ -50,7 +50,7 @@ pub fn parse_yaml_value(value: serde_yaml::Value, key: String, ctx: &mut tera::C
} else if value.is_sequence() {
if let Some(seq) = value.as_sequence() {
// let mut data_seq: Vec<String> = Vec::new();
// for (line, elem) in seq.iter().enumerate() {
// for (line, elem) in seq.iter().te() {
// if let Some(s) = elem.as_str() {
// data_seq.push(s.to_owned());
// } else {