diff options
Diffstat (limited to 'src/machine.rs')
| -rw-r--r-- | src/machine.rs | 156 |
1 files changed, 97 insertions, 59 deletions
diff --git a/src/machine.rs b/src/machine.rs index f1ad94d..f223e66 100644 --- a/src/machine.rs +++ b/src/machine.rs | |||
| @@ -1,6 +1,17 @@ | |||
| 1 | macro_rules! define_machines { | 1 | macro_rules! define_machines { |
| 2 | ($(($name:ident, $idx:expr, $hostname:expr, $interface:expr)),*) => { | 2 | ($(($name:ident, $idx:expr, $hostname:expr, $cpus:expr, $interface:expr)),*) => { |
| 3 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 3 | #[derive(Debug)] |
| 4 | pub struct UnknownMachine; | ||
| 5 | |||
| 6 | impl std::fmt::Display for UnknownMachine { | ||
| 7 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| 8 | f.write_str("unknown machine") | ||
| 9 | } | ||
| 10 | } | ||
| 11 | |||
| 12 | impl std::error::Error for UnknownMachine {} | ||
| 13 | |||
| 14 | #[derive(Debug, Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash)] | ||
| 4 | pub enum Machine { | 15 | pub enum Machine { |
| 5 | $($name,)* | 16 | $($name,)* |
| 6 | } | 17 | } |
| @@ -11,6 +22,17 @@ macro_rules! define_machines { | |||
| 11 | } | 22 | } |
| 12 | } | 23 | } |
| 13 | 24 | ||
| 25 | impl std::str::FromStr for Machine { | ||
| 26 | type Err = UnknownMachine; | ||
| 27 | |||
| 28 | fn from_str(v: &str) -> Result<Self, Self::Err> { | ||
| 29 | match v { | ||
| 30 | $($hostname => Ok(Self::$name),)* | ||
| 31 | _ => Err(UnknownMachine), | ||
| 32 | } | ||
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 14 | impl Machine { | 36 | impl Machine { |
| 15 | pub fn hostname(&self) -> &'static str { | 37 | pub fn hostname(&self) -> &'static str { |
| 16 | match self { | 38 | match self { |
| @@ -31,6 +53,19 @@ macro_rules! define_machines { | |||
| 31 | } | 53 | } |
| 32 | } | 54 | } |
| 33 | 55 | ||
| 56 | pub fn from_index(index: usize) -> Option<Self> { | ||
| 57 | match index { | ||
| 58 | $($idx => Some(Self::$name),)* | ||
| 59 | _ => None, | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | pub fn cpus(&self) -> u32 { | ||
| 64 | match self { | ||
| 65 | $(Self::$name => $cpus,)* | ||
| 66 | } | ||
| 67 | } | ||
| 68 | |||
| 34 | pub fn interface(&self) -> &'static str { | 69 | pub fn interface(&self) -> &'static str { |
| 35 | match self { | 70 | match self { |
| 36 | $(Self::$name => $interface,)* | 71 | $(Self::$name => $interface,)* |
| @@ -40,62 +75,65 @@ macro_rules! define_machines { | |||
| 40 | }; | 75 | }; |
| 41 | } | 76 | } |
| 42 | 77 | ||
| 78 | // node cpu counts | ||
| 79 | // oarnodes | grep '^network_address' | cut -d' ' -f3 | sort | uniq -c | ||
| 80 | |||
| 43 | define_machines!( | 81 | define_machines!( |
| 44 | (Alakazam01, 0, "alakazam-01", todo!()), | 82 | (Alakazam01, 0, "alakazam-01", 64, todo!()), |
| 45 | (Alakazam02, 1, "alakazam-02", todo!()), | 83 | (Alakazam02, 1, "alakazam-02", 64, todo!()), |
| 46 | (Alakazam03, 2, "alakazam-03", todo!()), | 84 | (Alakazam03, 2, "alakazam-03", 64, todo!()), |
| 47 | (Alakazam04, 3, "alakazam-04", todo!()), | 85 | (Alakazam04, 3, "alakazam-04", 64, todo!()), |
| 48 | (Alakazam05, 4, "alakazam-05", todo!()), | 86 | (Alakazam05, 4, "alakazam-05", 64, todo!()), |
| 49 | (Alakazam06, 5, "alakazam-06", todo!()), | 87 | (Alakazam06, 5, "alakazam-06", 64, todo!()), |
| 50 | (Alakazam07, 6, "alakazam-07", todo!()), | 88 | (Alakazam07, 6, "alakazam-07", 64, todo!()), |
| 51 | (Alakazam08, 7, "alakazam-08", todo!()), | 89 | (Alakazam08, 7, "alakazam-08", 64, todo!()), |
| 52 | (Bulbasaur1, 8, "bulbasaur-1", todo!()), | 90 | (Bulbasaur1, 8, "bulbasaur-1", 16, todo!()), |
| 53 | (Bulbasaur2, 9, "bulbasaur-2", todo!()), | 91 | (Bulbasaur2, 9, "bulbasaur-2", 16, todo!()), |
| 54 | (Bulbasaur3, 10, "bulbasaur-3", todo!()), | 92 | (Bulbasaur3, 10, "bulbasaur-3", 16, todo!()), |
| 55 | (Charmander1, 11, "charmander-1", "bond0"), | 93 | (Charmander1, 11, "charmander-1", 32, "bond0"), |
| 56 | (Charmander2, 12, "charmander-2", "bond0"), | 94 | (Charmander2, 12, "charmander-2", 32, "bond0"), |
| 57 | (Charmander3, 13, "charmander-3", "bond0"), | 95 | (Charmander3, 13, "charmander-3", 32, "bond0"), |
| 58 | (Charmander4, 14, "charmander-4", "bond0"), | 96 | (Charmander4, 14, "charmander-4", 32, "bond0"), |
| 59 | (Charmander5, 15, "charmander-5", "bond0"), | 97 | (Charmander5, 15, "charmander-5", 32, "bond0"), |
| 60 | (Gengar1, 16, "gengar-1", "bond0"), | 98 | (Gengar1, 16, "gengar-1", 8, "bond0"), |
| 61 | (Gengar2, 17, "gengar-2", "bond0"), | 99 | (Gengar2, 17, "gengar-2", 8, "bond0"), |
| 62 | (Gengar3, 18, "gengar-3", "bond0"), | 100 | (Gengar3, 18, "gengar-3", 8, "bond0"), |
| 63 | (Gengar4, 19, "gengar-4", "bond0"), | 101 | (Gengar4, 19, "gengar-4", 8, "bond0"), |
| 64 | (Gengar5, 20, "gengar-5", "bond0"), | 102 | (Gengar5, 20, "gengar-5", 8, "bond0"), |
| 65 | (Kadabra01, 21, "kadabra-01", todo!()), | 103 | (Kadabra01, 21, "kadabra-01", 64, todo!()), |
| 66 | (Kadabra02, 22, "kadabra-02", todo!()), | 104 | (Kadabra02, 22, "kadabra-02", 64, todo!()), |
| 67 | (Kadabra03, 23, "kadabra-03", todo!()), | 105 | (Kadabra03, 23, "kadabra-03", 64, todo!()), |
| 68 | (Kadabra04, 24, "kadabra-04", todo!()), | 106 | (Kadabra04, 24, "kadabra-04", 64, todo!()), |
| 69 | (Kadabra05, 25, "kadabra-05", todo!()), | 107 | (Kadabra05, 25, "kadabra-05", 64, todo!()), |
| 70 | (Kadabra06, 26, "kadabra-06", todo!()), | 108 | (Kadabra06, 26, "kadabra-06", 64, todo!()), |
| 71 | (Kadabra07, 27, "kadabra-07", todo!()), | 109 | (Kadabra07, 27, "kadabra-07", 64, todo!()), |
| 72 | (Kadabra08, 28, "kadabra-08", todo!()), | 110 | (Kadabra08, 28, "kadabra-08", 64, todo!()), |
| 73 | (Lugia1, 29, "lugia-1", "bond0"), | 111 | (Lugia1, 29, "lugia-1", 64, "bond0"), |
| 74 | (Lugia2, 30, "lugia-2", "bond0"), | 112 | (Lugia2, 30, "lugia-2", 64, "bond0"), |
| 75 | (Lugia3, 31, "lugia-3", "bond0"), | 113 | (Lugia3, 31, "lugia-3", 64, "bond0"), |
| 76 | (Lugia4, 32, "lugia-4", "bond0"), | 114 | (Lugia4, 32, "lugia-4", 64, "bond0"), |
| 77 | (Lugia5, 33, "lugia-5", "bond0"), | 115 | (Lugia5, 33, "lugia-5", 64, "bond0"), |
| 78 | (Magikarp1, 34, "magikarp-1", todo!()), | 116 | (Magikarp1, 34, "magikarp-1", 16, todo!()), |
| 79 | (Moltres01, 35, "moltres-01", todo!()), | 117 | (Moltres01, 35, "moltres-01", 64, todo!()), |
| 80 | (Moltres02, 36, "moltres-02", todo!()), | 118 | (Moltres02, 36, "moltres-02", 64, todo!()), |
| 81 | (Moltres03, 37, "moltres-03", todo!()), | 119 | (Moltres03, 37, "moltres-03", 64, todo!()), |
| 82 | (Moltres04, 38, "moltres-04", todo!()), | 120 | (Moltres04, 38, "moltres-04", 64, todo!()), |
| 83 | (Moltres05, 39, "moltres-05", todo!()), | 121 | (Moltres05, 39, "moltres-05", 64, todo!()), |
| 84 | (Moltres06, 40, "moltres-06", todo!()), | 122 | (Moltres06, 40, "moltres-06", 64, todo!()), |
| 85 | (Moltres07, 41, "moltres-07", todo!()), | 123 | (Moltres07, 41, "moltres-07", 64, todo!()), |
| 86 | (Moltres08, 42, "moltres-08", todo!()), | 124 | (Moltres08, 42, "moltres-08", 64, todo!()), |
| 87 | (Moltres09, 43, "moltres-09", todo!()), | 125 | (Moltres09, 43, "moltres-09", 64, todo!()), |
| 88 | (Moltres10, 44, "moltres-10", todo!()), | 126 | (Moltres10, 44, "moltres-10", 64, todo!()), |
| 89 | (Oddish1, 45, "oddish-1", todo!()), | 127 | (Oddish1, 45, "oddish-1", 4, todo!()), |
| 90 | (Psyduck1, 46, "psyduck-1", todo!()), | 128 | (Psyduck1, 46, "psyduck-1", 8, todo!()), |
| 91 | (Psyduck2, 47, "psyduck-2", todo!()), | 129 | (Psyduck2, 47, "psyduck-2", 8, todo!()), |
| 92 | (Psyduck3, 48, "psyduck-3", todo!()), | 130 | (Psyduck3, 48, "psyduck-3", 8, todo!()), |
| 93 | (Shelder1, 49, "shelder-1", todo!()), | 131 | (Shelder1, 49, "shelder-1", 64, todo!()), |
| 94 | (Squirtle1, 50, "squirtle-1", todo!()), | 132 | (Squirtle1, 50, "squirtle-1", 24, todo!()), |
| 95 | (Squirtle2, 51, "squirtle-2", todo!()), | 133 | (Squirtle2, 51, "squirtle-2", 24, todo!()), |
| 96 | (Squirtle3, 52, "squirtle-3", todo!()), | 134 | (Squirtle3, 52, "squirtle-3", 24, todo!()), |
| 97 | (Squirtle4, 53, "squirtle-4", todo!()), | 135 | (Squirtle4, 53, "squirtle-4", 24, todo!()), |
| 98 | (Staryu1, 54, "staryu-1", todo!()), | 136 | (Staryu1, 54, "staryu-1", 12, todo!()), |
| 99 | (Sudowoodo1, 55, "sudowoodo-1", todo!()), | 137 | (Sudowoodo1, 55, "sudowoodo-1", 16, todo!()), |
| 100 | (Vulpix1, 56, "vulpix-1", todo!()) | 138 | (Vulpix1, 56, "vulpix-1", 112, todo!()) |
| 101 | ); | 139 | ); |
