CumulusVlanHelper { public boolean updateLAGOnSwitchPorts( SwitchNode switchNode, SwitchLacpGroup lacpGroup ) throws HmsException { if ( lacpGroup == null || lacpGroup.getName() == null || lacpGroup.getName().trim().equals( "" ) ) { throw new HmsException( "Cannot create LACP group with empty/null name." ); } if ( lacpGroup.getPorts() == null || lacpGroup.getPorts().isEmpty() ) { throw new HmsException( "Cannot create LACP group with empty port list." ); } CumulusTorSwitchSession session = (CumulusTorSwitchSession) CumulusUtil.getSession( switchNode ); Configuration configuration = null; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); session.download( baos, CumulusConstants.INTERFACES_FILE ); configuration = Configuration.parse( new ByteArrayInputStream( baos.toByteArray() ) ); } catch ( Exception e ) { logger.error( "Exception received while parsing interfaces file.", e ); } try { configuration = updateLAGOnSwitchPorts( lacpGroup, configuration ); } catch ( Exception e ) { String errMsg = String.format( "Error on Switch %s : %s", switchNode.getSwitchId(), e.getMessage() ); throw new HmsOobNetworkException( errMsg, e, HmsOobNetworkErrorCode.ARGUMENT_SYNTAX_ERROR ); } ByteArrayInputStream bais = new ByteArrayInputStream( configuration.getString().getBytes() ); CumulusUtil.validateSourceClause( switchNode ); CumulusUtil.uploadAsRoot( switchNode, bais, CumulusConstants.INTERFACES_FILE ); CumulusUtil.configurePersistenceDirectory( switchNode ); SshExecResult result = session.executeEnhanced( CumulusConstants.RELOAD_INTERFACES.replaceAll( "\\{password\\}", CumulusUtil.qr( switchNode.getPassword() ) ) ); result.logIfError( logger ); return true; } CumulusVlanHelper( CumulusTorSwitchService service ); List<String> getSwitchVlans( SwitchNode switchNode ); SwitchVlan getSwitchVlan( SwitchNode switchNode, String vlanName ); List<SwitchVlan> getSwitchVlansBulk( SwitchNode switchNode ); boolean createVlan( SwitchNode switchNode, SwitchVlan vlan ); boolean updateVlan( SwitchNode switchNode, String vlanName, SwitchVlan vlan ); boolean updateLAGOnSwitchPorts( SwitchNode switchNode, SwitchLacpGroup lacpGroup ); boolean deletePortFromVlanConfiguration( SwitchNode switchNode, String vlanId, String port ); boolean deleteVlan( SwitchNode switchNode, String vlanName ); Configuration deleteVlan( SwitchVlan vlan, Configuration configuration );  }
@Test public void testAddLAGOnSwitchPort() throws Exception { Configuration configuration = Configuration.parse( interfacesFileWithBond ); CumulusVlanHelper helper = new CumulusVlanHelper( null ); SwitchLacpGroup lacpGroup = new SwitchLacpGroup(); lacpGroup.setMode( "asdf" ); lacpGroup.setName( "bond2" ); lacpGroup.setPorts( new ArrayList<String>() ); lacpGroup.getPorts().add( "swp2" ); configuration = helper.updateLAGOnSwitchPorts( lacpGroup, configuration ); System.out.println( configuration.getString() ); }