@@ -112,19 +112,20 @@ impl AuthenticatedCmd for CmdLinkAdd {
112112 let mut settings = current_port_settings ( client, & self . rack , & self . switch , & self . port )
113113 . await
114114 . unwrap_or ( SwitchPortSettingsCreate {
115- addresses : HashMap :: default ( ) ,
116- bgp_peers : HashMap :: default ( ) ,
115+ addresses : Default :: default ( ) ,
116+ bgp_peers : Default :: default ( ) ,
117117 description : String :: default ( ) ,
118118 groups : Vec :: default ( ) ,
119- interfaces : HashMap :: default ( ) ,
120- links : HashMap :: default ( ) ,
119+ interfaces : Default :: default ( ) ,
120+ links : Default :: default ( ) ,
121121 name : format ! ( "{}-{}" , self . switch, self . port) . parse ( ) . unwrap ( ) ,
122122 port_config : SwitchPortConfigCreate {
123123 geometry : SwitchPortGeometry :: Qsfp28x1 ,
124124 } ,
125- routes : HashMap :: default ( ) ,
125+ routes : Default :: default ( ) ,
126126 } ) ;
127127 let link = LinkConfigCreate {
128+ link_name : PHY0 . parse ( ) . unwrap ( ) ,
128129 autoneg : self . autoneg ,
129130 fec : self . fec . map ( |fec| fec. into ( ) ) ,
130131 mtu : self . mtu ,
@@ -140,12 +141,12 @@ impl AuthenticatedCmd for CmdLinkAdd {
140141 } ,
141142 tx_eq : None ,
142143 } ;
143- match settings. links . get ( PHY0 ) {
144+ match settings. links . iter ( ) . find ( |link| * link . link_name == PHY0 ) {
144145 Some ( _) => {
145146 return Err ( anyhow:: anyhow!( "only one link per port supported" ) ) ;
146147 }
147148 None => {
148- settings. links . insert ( String :: from ( PHY0 ) , link) ;
149+ settings. links . push ( link) ;
149150 }
150151 }
151152 client
@@ -411,7 +412,11 @@ impl AuthenticatedCmd for CmdBgpFilter {
411412 async fn run ( & self , client : & Client ) -> Result < ( ) > {
412413 let mut settings =
413414 current_port_settings ( client, & self . rack , & self . switch , & self . port ) . await ?;
414- match settings. bgp_peers . get_mut ( PHY0 ) {
415+ match settings
416+ . bgp_peers
417+ . iter_mut ( )
418+ . find ( |peer| * peer. link_name == PHY0 )
419+ {
415420 None => return Err ( anyhow:: anyhow!( "no BGP peers configured" ) ) ,
416421 Some ( config) => {
417422 let peer = config
@@ -488,7 +493,11 @@ impl AuthenticatedCmd for CmdBgpAuth {
488493 async fn run ( & self , client : & Client ) -> Result < ( ) > {
489494 let mut settings =
490495 current_port_settings ( client, & self . rack , & self . switch , & self . port ) . await ?;
491- match settings. bgp_peers . get_mut ( PHY0 ) {
496+ match settings
497+ . bgp_peers
498+ . iter_mut ( )
499+ . find ( |peer| * peer. link_name == PHY0 )
500+ {
492501 None => return Err ( anyhow:: anyhow!( "no BGP peers configured" ) ) ,
493502 Some ( config) => {
494503 let peer = config
@@ -546,7 +555,11 @@ impl AuthenticatedCmd for CmdBgpLocalPref {
546555 async fn run ( & self , client : & Client ) -> Result < ( ) > {
547556 let mut settings =
548557 current_port_settings ( client, & self . rack , & self . switch , & self . port ) . await ?;
549- match settings. bgp_peers . get_mut ( PHY0 ) {
558+ match settings
559+ . bgp_peers
560+ . iter_mut ( )
561+ . find ( |link| * link. link_name == PHY0 )
562+ {
550563 None => return Err ( anyhow:: anyhow!( "no BGP peers configured" ) ) ,
551564 Some ( config) => {
552565 let peer = config
@@ -640,19 +653,21 @@ impl AuthenticatedCmd for CmdStaticRouteSet {
640653 let mut settings =
641654 current_port_settings ( client, & self . rack , & self . switch , & self . port ) . await ?;
642655
643- match settings. routes . get_mut ( PHY0 ) {
656+ match settings
657+ . routes
658+ . iter_mut ( )
659+ . find ( |link| * link. link_name == PHY0 )
660+ {
644661 None => {
645- settings. routes . insert (
646- PHY0 . to_owned ( ) ,
647- RouteConfig {
648- routes : vec ! [ Route {
649- dst: self . destination. clone( ) ,
650- gw: self . nexthop,
651- rib_priority: self . rib_priority,
652- vid: self . vlan_id,
653- } ] ,
654- } ,
655- ) ;
662+ settings. routes . push ( RouteConfig {
663+ link_name : PHY0 . parse ( ) . unwrap ( ) ,
664+ routes : vec ! [ Route {
665+ dst: self . destination. clone( ) ,
666+ gw: self . nexthop,
667+ rib_priority: self . rib_priority,
668+ vid: self . vlan_id,
669+ } ] ,
670+ } ) ;
656671 }
657672 Some ( config) => {
658673 let exists = config. routes . iter_mut ( ) . find ( |x| {
@@ -730,7 +745,11 @@ impl AuthenticatedCmd for CmdStaticRouteDelete {
730745 let mut settings =
731746 current_port_settings ( client, & self . rack , & self . switch , & self . port ) . await ?;
732747
733- match settings. routes . get_mut ( PHY0 ) {
748+ match settings
749+ . routes
750+ . iter_mut ( )
751+ . find ( |link| * link. link_name == PHY0 )
752+ {
734753 None => { }
735754 Some ( config) => {
736755 let before = config. routes . len ( ) ;
@@ -828,17 +847,19 @@ impl AuthenticatedCmd for CmdAddrAdd {
828847 address_lot : self . lot . clone ( ) ,
829848 vlan_id : self . vlan ,
830849 } ;
831- match settings. addresses . get_mut ( PHY0 ) {
850+ match settings
851+ . addresses
852+ . iter_mut ( )
853+ . find ( |link| * link. link_name == PHY0 )
854+ {
832855 Some ( ac) => {
833856 ac. addresses . push ( addr) ;
834857 }
835858 None => {
836- settings. addresses . insert (
837- String :: from ( PHY0 ) ,
838- AddressConfig {
839- addresses : vec ! [ addr] ,
840- } ,
841- ) ;
859+ settings. addresses . push ( AddressConfig {
860+ link_name : PHY0 . parse ( ) . unwrap ( ) ,
861+ addresses : vec ! [ addr] ,
862+ } ) ;
842863 }
843864 }
844865 client
@@ -881,7 +902,11 @@ impl AuthenticatedCmd for CmdAddrDel {
881902 async fn run ( & self , client : & Client ) -> Result < ( ) > {
882903 let mut settings =
883904 current_port_settings ( client, & self . rack , & self . switch , & self . port ) . await ?;
884- if let Some ( addrs) = settings. addresses . get_mut ( PHY0 ) {
905+ if let Some ( addrs) = settings
906+ . addresses
907+ . iter_mut ( )
908+ . find ( |link| * link. link_name == PHY0 )
909+ {
885910 let before = addrs. addresses . len ( ) ;
886911 addrs
887912 . addresses
@@ -1101,15 +1126,20 @@ impl AuthenticatedCmd for CmdBgpPeerSet {
11011126 remote_asn : self . remote_asn ,
11021127 vlan_id : self . vlan_id ,
11031128 } ;
1104- match settings. bgp_peers . get_mut ( PHY0 ) {
1129+ match settings
1130+ . bgp_peers
1131+ . iter_mut ( )
1132+ . find ( |link| * link. link_name == PHY0 )
1133+ {
11051134 Some ( conf) => match conf. peers . iter_mut ( ) . find ( |x| x. addr == peer. addr ) {
11061135 Some ( p) => * p = peer,
11071136 None => conf. peers . push ( peer) ,
11081137 } ,
11091138 None => {
1110- settings
1111- . bgp_peers
1112- . insert ( String :: from ( PHY0 ) , BgpPeerConfig { peers : vec ! [ peer] } ) ;
1139+ settings. bgp_peers . push ( BgpPeerConfig {
1140+ peers : vec ! [ peer] ,
1141+ link_name : PHY0 . parse ( ) . unwrap ( ) ,
1142+ } ) ;
11131143 }
11141144 }
11151145 client
@@ -1151,7 +1181,11 @@ impl AuthenticatedCmd for CmdBgpPeerDel {
11511181 async fn run ( & self , client : & Client ) -> Result < ( ) > {
11521182 let mut settings =
11531183 current_port_settings ( client, & self . rack , & self . switch , & self . port ) . await ?;
1154- if let Some ( config) = settings. bgp_peers . get_mut ( PHY0 ) {
1184+ if let Some ( config) = settings
1185+ . bgp_peers
1186+ . iter_mut ( )
1187+ . find ( |link| * link. link_name == PHY0 )
1188+ {
11551189 let before = config. peers . len ( ) ;
11561190 config. peers . retain ( |x| x. addr != self . addr ) ;
11571191 let after = config. peers . len ( ) ;
@@ -1671,77 +1705,66 @@ async fn create_current(settings_id: Uuid, client: &Client) -> Result<SwitchPort
16711705 } )
16721706 . collect ( ) ;
16731707
1674- let mut addresses = HashMap :: new ( ) ;
1675- addresses. insert ( String :: from ( PHY0 ) , AddressConfig { addresses : addrs } ) ;
1708+ let addresses = vec ! [ AddressConfig {
1709+ link_name: PHY0 . parse( ) . unwrap( ) ,
1710+ addresses: addrs,
1711+ } ] ;
16761712
1677- let mut bgp_peers = HashMap :: new ( ) ;
1678- bgp_peers. insert (
1679- String :: from ( PHY0 ) ,
1680- BgpPeerConfig {
1681- peers : current. bgp_peers ,
1682- } ,
1683- ) ;
1713+ let bgp_peers = vec ! [ BgpPeerConfig {
1714+ link_name: PHY0 . parse( ) . unwrap( ) ,
1715+ peers: current. bgp_peers,
1716+ } ] ;
16841717
16851718 let groups: Vec < NameOrId > = current
16861719 . groups
16871720 . iter ( )
16881721 . map ( |x| NameOrId :: Id ( x. port_settings_group_id ) )
16891722 . collect ( ) ;
16901723
1691- let mut interfaces: HashMap < String , SwitchInterfaceConfigCreate > = current
1724+ let mut interfaces = current
16921725 . interfaces
16931726 . iter ( )
1694- . map ( |x| {
1695- (
1696- x. interface_name . clone ( ) ,
1697- SwitchInterfaceConfigCreate {
1698- kind : match x. kind {
1699- SwitchInterfaceKind2 :: Primary => SwitchInterfaceKind :: Primary ,
1700- SwitchInterfaceKind2 :: Loopback => SwitchInterfaceKind :: Loopback ,
1701- SwitchInterfaceKind2 :: Vlan => {
1702- todo ! ( "vlan interface outside vlan interfaces?" )
1703- }
1704- } ,
1705- v6_enabled : x. v6_enabled ,
1706- } ,
1707- )
1727+ . map ( |x| SwitchInterfaceConfigCreate {
1728+ link_name : x. interface_name . parse ( ) . unwrap ( ) ,
1729+ kind : match x. kind {
1730+ SwitchInterfaceKind2 :: Primary => SwitchInterfaceKind :: Primary ,
1731+ SwitchInterfaceKind2 :: Loopback => SwitchInterfaceKind :: Loopback ,
1732+ SwitchInterfaceKind2 :: Vlan => {
1733+ todo ! ( "vlan interface outside vlan interfaces?" )
1734+ }
1735+ } ,
1736+ v6_enabled : x. v6_enabled ,
17081737 } )
1709- . collect ( ) ;
1738+ . collect :: < Vec < _ > > ( ) ;
17101739
17111740 for v in current. vlan_interfaces . iter ( ) {
1712- interfaces. insert (
1713- format ! ( "vlan-{}" , v. vlan_id) ,
1714- SwitchInterfaceConfigCreate {
1715- kind : SwitchInterfaceKind :: Vlan ( v. vlan_id ) ,
1716- v6_enabled : false ,
1717- } ,
1718- ) ;
1741+ interfaces. push ( SwitchInterfaceConfigCreate {
1742+ link_name : format ! ( "vlan-{}" , v. vlan_id) . parse ( ) . unwrap ( ) ,
1743+ kind : SwitchInterfaceKind :: Vlan ( v. vlan_id ) ,
1744+ v6_enabled : false ,
1745+ } ) ;
17191746 }
17201747
1721- let links: HashMap < String , LinkConfigCreate > = current
1748+ let links = current
17221749 . links
17231750 . iter ( )
17241751 . enumerate ( )
1725- . map ( |( i, x) | {
1726- (
1727- format ! ( "phy{}" , i) ,
1728- LinkConfigCreate {
1729- autoneg : x. autoneg ,
1730- fec : x. fec ,
1731- mtu : x. mtu ,
1732- speed : x. speed ,
1733- lldp : LldpLinkConfigCreate {
1734- enabled : false ,
1735- link_name : None ,
1736- link_description : None ,
1737- chassis_id : None ,
1738- system_name : None ,
1739- system_description : None ,
1740- management_ip : None ,
1741- } ,
1742- tx_eq : None ,
1743- } ,
1744- )
1752+ . map ( |( i, x) | LinkConfigCreate {
1753+ link_name : format ! ( "phy{}" , i) . parse ( ) . unwrap ( ) ,
1754+ autoneg : x. autoneg ,
1755+ fec : x. fec ,
1756+ mtu : x. mtu ,
1757+ speed : x. speed ,
1758+ lldp : LldpLinkConfigCreate {
1759+ enabled : false ,
1760+ link_name : None ,
1761+ link_description : None ,
1762+ chassis_id : None ,
1763+ system_name : None ,
1764+ system_description : None ,
1765+ management_ip : None ,
1766+ } ,
1767+ tx_eq : None ,
17451768 } )
17461769 . collect ( ) ;
17471770
@@ -1754,6 +1777,7 @@ async fn create_current(settings_id: Uuid, client: &Client) -> Result<SwitchPort
17541777 } ;
17551778
17561779 let route_config = RouteConfig {
1780+ link_name : PHY0 . parse ( ) . unwrap ( ) ,
17571781 routes : current
17581782 . routes
17591783 . iter ( )
@@ -1769,8 +1793,7 @@ async fn create_current(settings_id: Uuid, client: &Client) -> Result<SwitchPort
17691793 . collect ( ) ,
17701794 } ;
17711795
1772- let mut routes = HashMap :: new ( ) ;
1773- routes. insert ( String :: from ( PHY0 ) , route_config) ;
1796+ let routes = vec ! [ route_config] ;
17741797
17751798 let create = SwitchPortSettingsCreate {
17761799 addresses,
0 commit comments