Search in sources :

Example 1 with RancidNode

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

the class InventoryReportCalculator method getNodeBaseInventory.

/**
     * <p>getNodeBaseInventory</p>
     *
     * @param node a {@link java.lang.String} object.
     * @param group a {@link java.lang.String} object.
     * @param version a {@link java.lang.String} object.
     * @return a {@link org.opennms.report.inventory.NodeBaseInventory} object.
     */
public NodeBaseInventory getNodeBaseInventory(String node, String group, String version) {
    // get the latest version from the given date        
    LOG.debug("getNodeBaseInventory {} {} {}", node, group, version);
    NodeBaseInventory nbi = new NodeBaseInventory();
    RancidNode rn;
    try {
        rn = RWSClientApi.getRWSRancidNodeInventory(m_cp, group, node);
    } catch (RancidApiException e) {
        LOG.debug("getNodeBaseInventory: inventory not found. Skipping");
        return nbi;
    }
    InventoryNode in = (InventoryNode) rn.getNodeVersions().get(version);
    nbi.setDevicename(node);
    nbi.setGroupname(group);
    nbi.setVersion(version);
    nbi.setStatus(in.getParent().getState());
    nbi.setCreationdate(in.getCreationDate());
    nbi.setSwconfigurationurl(in.getSoftwareImageUrl());
    nbi.setConfigurationurl(in.getConfigurationUrl());
    try {
        nbi.setIe(RWSClientApi.getRWSRancidNodeInventoryElement2(m_cp, rn, version));
    } catch (RancidApiException e) {
        LOG.debug("getNodeBaseInventory: inventory not found for version: {}. Skipping", version);
    }
    return nbi;
}
Also used : RancidNode(org.opennms.rancid.RancidNode) RancidApiException(org.opennms.rancid.RancidApiException) InventoryNode(org.opennms.rancid.InventoryNode)

Example 2 with RancidNode

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

the class RancidProvisioningAdapter method updateRancidNodeState.

private void updateRancidNodeState(int nodeid, boolean up) {
    RancidNode rnode = m_onmsNodeRancidNodeMap.get(Integer.valueOf(nodeid));
    rnode.setStateUp(up);
    m_onmsNodeRancidNodeMap.put(nodeid, rnode);
}
Also used : RancidNode(org.opennms.rancid.RancidNode)

Example 3 with RancidNode

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

the class RancidProvisioningAdapter method doDelete.

/**
     * <p>doDelete</p>
     *
     * @param nodeId a int.
     * @param cp a {@link org.opennms.rancid.ConnectionProperties} object.
     * @param retry a boolean.
     * @throws org.opennms.netmgt.provision.ProvisioningAdapterException if any.
     */
public void doDelete(int nodeId, ConnectionProperties cp, boolean retry) throws ProvisioningAdapterException {
    if (!isAdapterConfigured()) {
        return;
    }
    LOG.debug("doDelete: deleting nodeid: {}", nodeId);
    /*
         * The work to maintain the hashmap boils down to needing to do deletes, so
         * here we go.
         */
    try {
        m_rwsConfig.getWriteLock().lock();
        try {
            if (m_onmsNodeRancidNodeMap.containsKey(Integer.valueOf(nodeId))) {
                RancidNode rNode = m_onmsNodeRancidNodeMap.get(Integer.valueOf(nodeId));
                RWSClientApi.deleteRWSRancidNode(cp, rNode);
                RWSClientApi.deleteRWSAuthNode(cp, rNode.getAuth());
                m_onmsNodeRancidNodeMap.remove(Integer.valueOf(nodeId));
                m_onmsNodeIpMap.remove(Integer.valueOf(nodeId));
            } else {
                LOG.warn("doDelete: no device found in node Rancid Map for nodeid: {}", nodeId);
            }
        } finally {
            m_rwsConfig.getWriteLock().unlock();
        }
    } catch (Throwable e) {
        cp = getStandByRWSConnection();
        if (retry && cp != null) {
            LOG.info("doDelete: retry Delete on standByConn: {}", cp.getUrl());
            doDelete(nodeId, cp, false);
        } else {
            sendAndThrow(nodeId, e);
        }
    }
}
Also used : RancidNode(org.opennms.rancid.RancidNode)

Example 4 with RancidNode

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

the class RancidProvisioningAdapter method getSuitableRancidNode.

private RancidNode getSuitableRancidNode(OnmsNode node) {
    //The group should be the foreign source of the node
    String group = node.getForeignSource();
    if (group == null)
        return null;
    RancidNode r_node = new RancidNode(group, node.getLabel());
    String ipaddress = m_onmsNodeIpMap.get(node.getId());
    if (m_rancidAdapterConfig.useCategories(ipaddress)) {
        LOG.debug("getSuitableRancidNode: Using Categories to get Rancid devicetype for node: {}", node.getLabel());
        r_node.setDeviceType(getTypeFromCategories(node));
    } else {
        LOG.debug("getSuitableRancidNode: Using Sysoid to get Rancid devicetype for node: {}", node.getLabel());
        r_node.setDeviceType(getTypeFromSysObjectId(node.getSysObjectId(), node.getSysDescription()));
    }
    r_node.setStateUp(false);
    r_node.setComment(RANCID_COMMENT + " nodeid:" + node.getNodeId());
    r_node.setAuth(getSuitableRancidNodeAuthentication(node));
    return r_node;
}
Also used : RancidNode(org.opennms.rancid.RancidNode)

Example 5 with RancidNode

use of org.opennms.rancid.RancidNode 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)

Aggregations

RancidNode (org.opennms.rancid.RancidNode)21 RancidApiException (org.opennms.rancid.RancidApiException)9 InventoryNode (org.opennms.rancid.InventoryNode)7 RWSResourceList (org.opennms.rancid.RWSResourceList)6 ArrayList (java.util.ArrayList)4 OnmsNode (org.opennms.netmgt.model.OnmsNode)3 RancidNodeAuthentication (org.opennms.rancid.RancidNodeAuthentication)3 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 InventoryElement2 (org.opennms.rancid.InventoryElement2)2 TransactionStatus (org.springframework.transaction.TransactionStatus)2 InventoryMemory (org.opennms.rancid.InventoryMemory)1 InventorySoftware (org.opennms.rancid.InventorySoftware)1 RWSBucket (org.opennms.rancid.RWSBucket)1 BucketItem (org.opennms.rancid.RWSBucket.BucketItem)1 Tuple (org.opennms.rancid.Tuple)1