Search in sources :

Example 1 with RancidNodeAuthentication

use of org.opennms.rancid.RancidNodeAuthentication in project opennms by OpenNMS.

the class RancidProvisioningAdapter method getSuitableRancidNodeAuthentication.

private RancidNodeAuthentication getSuitableRancidNodeAuthentication(OnmsNode node) {
    // RancidAuthentication
    RancidNodeAuthentication r_auth_node = new RancidNodeAuthentication();
    r_auth_node.setDeviceName(node.getLabel());
    OnmsAssetRecord asset_node = node.getAssetRecord();
    //
    if (asset_node == null) {
        return r_auth_node;
    }
    if (asset_node.getUsername() != null) {
        r_auth_node.setUser(asset_node.getUsername());
    }
    if (asset_node.getPassword() != null) {
        r_auth_node.setPassword(asset_node.getPassword());
    }
    if (asset_node.getEnable() != null) {
        r_auth_node.setEnablePass(asset_node.getEnable());
    }
    if (asset_node.getAutoenable() != null) {
        r_auth_node.setAutoEnable(asset_node.getAutoenable().equals(OnmsAssetRecord.AUTOENABLED));
    }
    if (asset_node.getConnection() != null) {
        r_auth_node.setConnectionMethod(asset_node.getConnection());
    } else {
        r_auth_node.setConnectionMethod("telnet");
    }
    return r_auth_node;
}
Also used : RancidNodeAuthentication(org.opennms.rancid.RancidNodeAuthentication) OnmsAssetRecord(org.opennms.netmgt.model.OnmsAssetRecord)

Example 2 with RancidNodeAuthentication

use of org.opennms.rancid.RancidNodeAuthentication in project opennms by OpenNMS.

the class InventoryService method getRancidNodeWithCLogin.

/*
     * getRancidNodeWithClogin will filter any exception, the page will show an empty table
     * in case of node not in DB or device name not in RWS 
     */
/**
     * <p>getRancidNodeWithCLogin</p>
     *
     * @param nodeid a int.
     * @param adminRole a boolean.
     * @return a java$util$Map object.
     */
public Map<String, Object> getRancidNodeWithCLogin(int nodeid, boolean adminRole) {
    LOG.debug("getRancidNodeWithClogin start");
    Map<String, Object> nodeModel = getRancidNodeBase(nodeid);
    String rancidName = (String) nodeModel.get("id");
    // Group list 
    RWSResourceList groups;
    try {
        groups = RWSClientApi.getRWSResourceGroupsList(m_cp);
    } catch (RancidApiException e) {
        nodeModel.put("RWSStatus", e.getLocalizedMessage());
        LOG.error(e.getLocalizedMessage());
        return nodeModel;
    }
    List<String> grouplist = groups.getResource();
    nodeModel.put("grouplist", grouplist);
    Iterator<String> iter1 = grouplist.iterator();
    String groupname;
    while (iter1.hasNext()) {
        groupname = iter1.next();
        nodeModel.put("groupname", groupname);
        LOG.debug("getRancidNodeWithClogin {} group {}", rancidName, groupname);
        try {
            RancidNode rn = RWSClientApi.getRWSRancidNodeTLO(m_cp, groupname, rancidName);
            nodeModel.put("devicename", rn.getDeviceName());
            nodeModel.put("status", rn.getState());
            nodeModel.put("devicetype", rn.getDeviceType());
            nodeModel.put("comment", rn.getComment());
            nodeModel.put("deviceexist", true);
            break;
        } catch (RancidApiException e) {
            if (e.getRancidCode() == 2) {
                nodeModel.put("deviceexist", false);
                LOG.debug("No device found in router.db for:{}on Group: {}", rancidName, groupname);
            } else {
                nodeModel.put("RWSStatus", e.getLocalizedMessage());
                LOG.error(e.getLocalizedMessage());
                return nodeModel;
            }
        }
    }
    // DeviceType list 
    RWSResourceList devicetypes;
    try {
        devicetypes = RWSClientApi.getRWSResourceDeviceTypesPatternList(m_cp);
    } catch (RancidApiException e) {
        nodeModel.put("RWSStatus", e.getLocalizedMessage());
        LOG.error(e.getLocalizedMessage());
        return nodeModel;
    }
    List<String> devicetypelist = devicetypes.getResource();
    nodeModel.put("devicetypelist", devicetypelist);
    //CLOGIN
    if (adminRole) {
        LOG.debug("getRancidNode: getting clogin info for: {}", rancidName);
        RancidNodeAuthentication rn5;
        try {
            rn5 = RWSClientApi.getRWSAuthNode(m_cp, rancidName);
            nodeModel.put("isadmin", "true");
            nodeModel.put("cloginuser", rn5.getUser());
            nodeModel.put("cloginpassword", rn5.getPassword());
            nodeModel.put("cloginconnmethod", rn5.getConnectionMethodString());
            nodeModel.put("cloginenablepass", rn5.getEnablePass());
            String autoen = "0";
            if (rn5.isAutoEnable()) {
                autoen = "1";
            }
            nodeModel.put("cloginautoenable", autoen);
        } catch (RancidApiException e) {
            nodeModel.put("RWSStatus", e.getLocalizedMessage());
            LOG.error("getRancidNode: clogin get failed with reason: {}", e.getLocalizedMessage());
        }
    }
    return nodeModel;
}
Also used : RancidNode(org.opennms.rancid.RancidNode) RancidNodeAuthentication(org.opennms.rancid.RancidNodeAuthentication) RWSResourceList(org.opennms.rancid.RWSResourceList) RancidApiException(org.opennms.rancid.RancidApiException)

Example 3 with RancidNodeAuthentication

use of org.opennms.rancid.RancidNodeAuthentication in project opennms by OpenNMS.

the class InventoryService method getRancidNodeWithCLoginForGroup.

/**
     * <p>getRancidNodeWithCLoginForGroup</p>
     *
     * @param nodeid a int.
     * @param group a {@link java.lang.String} object.
     * @param adminRole a boolean.
     * @return a java$util$Map object.
     */
public Map<String, Object> getRancidNodeWithCLoginForGroup(int nodeid, String group, boolean adminRole) {
    LOG.debug("getRancidNodeWithCloginFroGroup start: group: {}", group);
    Map<String, Object> nodeModel = getRancidNodeBase(nodeid);
    String rancidName = (String) nodeModel.get("id");
    // Group list 
    RWSResourceList groups;
    try {
        groups = RWSClientApi.getRWSResourceGroupsList(m_cp);
    } catch (RancidApiException e) {
        nodeModel.put("RWSStatus", e.getLocalizedMessage());
        LOG.error(e.getLocalizedMessage());
        return nodeModel;
    }
    List<String> grouplist = groups.getResource();
    nodeModel.put("grouplist", grouplist);
    // DeviceType list 
    RWSResourceList devicetypes;
    try {
        devicetypes = RWSClientApi.getRWSResourceDeviceTypesPatternList(m_cp);
    } catch (RancidApiException e) {
        nodeModel.put("RWSStatus", e.getLocalizedMessage());
        LOG.error(e.getLocalizedMessage());
        return nodeModel;
    }
    List<String> devicetypelist = devicetypes.getResource();
    nodeModel.put("devicetypelist", devicetypelist);
    nodeModel.put("groupname", group);
    try {
        RancidNode rn = RWSClientApi.getRWSRancidNodeTLO(m_cp, group, rancidName);
        nodeModel.put("devicename", rn.getDeviceName());
        nodeModel.put("status", rn.getState());
        nodeModel.put("devicetype", rn.getDeviceType());
        nodeModel.put("comment", rn.getComment());
        nodeModel.put("deviceexist", true);
    } catch (RancidApiException e) {
        if (e.getRancidCode() == 2) {
            nodeModel.put("deviceexist", false);
            LOG.debug("No device found in router.db for:{}on Group: {}", rancidName, group);
        } else {
            nodeModel.put("RWSStatus", e.getLocalizedMessage());
            LOG.error(e.getLocalizedMessage());
            return nodeModel;
        }
    }
    if (adminRole) {
        LOG.debug("getRancidNode: getting clogin info for: {}", rancidName);
        RancidNodeAuthentication rn5;
        try {
            rn5 = RWSClientApi.getRWSAuthNode(m_cp, rancidName);
            nodeModel.put("isadmin", "true");
            nodeModel.put("cloginuser", rn5.getUser());
            nodeModel.put("cloginpassword", rn5.getPassword());
            nodeModel.put("cloginconnmethod", rn5.getConnectionMethodString());
            nodeModel.put("cloginenablepass", rn5.getEnablePass());
            String autoen = "0";
            if (rn5.isAutoEnable()) {
                autoen = "1";
            }
            nodeModel.put("cloginautoenable", autoen);
        } catch (RancidApiException e) {
            nodeModel.put("RWSStatus", e.getLocalizedMessage());
            LOG.error("getRancidNode: clogin get failed with reason: {}", e.getLocalizedMessage());
        }
    }
    return nodeModel;
}
Also used : RancidNode(org.opennms.rancid.RancidNode) RancidNodeAuthentication(org.opennms.rancid.RancidNodeAuthentication) RWSResourceList(org.opennms.rancid.RWSResourceList) RancidApiException(org.opennms.rancid.RancidApiException)

Example 4 with RancidNodeAuthentication

use of org.opennms.rancid.RancidNodeAuthentication in project opennms by OpenNMS.

the class InventoryService method updateClogin.

/**
     * <p>updateClogin</p>
     *
     * @param deviceName a {@link java.lang.String} object.
     * @param groupName a {@link java.lang.String} object.
     * @param userID a {@link java.lang.String} object.
     * @param pass a {@link java.lang.String} object.
     * @param enPass a {@link java.lang.String} object.
     * @param loginM a {@link java.lang.String} object.
     * @param autoE a {@link java.lang.String} object.
     * @return a boolean.
     */
public boolean updateClogin(String deviceName, String groupName, String userID, String pass, String enPass, String loginM, String autoE) {
    LOG.debug("InventoryService updateClogin for following changes userID [{}] pass [{}] enpass [{}] loginM [{}] autoE [{}] groupName (ignored) [{}] deviceName [{}]", userID, pass, enPass, loginM, autoE, groupName, deviceName);
    try {
        RancidNodeAuthentication rna = RWSClientApi.getRWSAuthNode(m_cp, deviceName);
        rna.setUser(userID);
        rna.setPassword(pass);
        rna.setConnectionMethod(loginM);
        rna.setEnablePass(enPass);
        boolean autoeb = false;
        if (autoE.compareTo("1") == 0) {
            autoeb = true;
        }
        rna.setAutoEnable(autoeb);
        RWSClientApi.createOrUpdateRWSAuthNode(m_cp, rna);
        LOG.debug("InventoryService ModelAndView updateClogin changes submitted");
    } catch (Throwable e) {
        LOG.debug("updateClogin has given exception on node {} {}", deviceName, e.getMessage());
        return false;
    }
    return true;
}
Also used : RancidNodeAuthentication(org.opennms.rancid.RancidNodeAuthentication)

Example 5 with RancidNodeAuthentication

use of org.opennms.rancid.RancidNodeAuthentication in project opennms by OpenNMS.

the class InventoryService method deleteClogin.

/**
     * <p>deleteClogin</p>
     *
     * @param deviceName a {@link java.lang.String} object.
     * @return a boolean.
     */
public boolean deleteClogin(String deviceName) {
    LOG.debug("InventoryService deleteClogin deviceName [{}] ", deviceName);
    try {
        RancidNodeAuthentication rna = RWSClientApi.getRWSAuthNode(m_cp, deviceName);
        RWSClientApi.deleteRWSAuthNode(m_cp, rna);
        LOG.debug("InventoryService ModelAndView updateClogin changes submitted");
    } catch (Throwable e) {
        LOG.debug("updateClogin has given exception on node {} {}", deviceName, e.getMessage());
        return false;
    }
    return true;
}
Also used : RancidNodeAuthentication(org.opennms.rancid.RancidNodeAuthentication)

Aggregations

RancidNodeAuthentication (org.opennms.rancid.RancidNodeAuthentication)6 RancidApiException (org.opennms.rancid.RancidApiException)3 RancidNode (org.opennms.rancid.RancidNode)3 RWSResourceList (org.opennms.rancid.RWSResourceList)2 OnmsAssetRecord (org.opennms.netmgt.model.OnmsAssetRecord)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1