Beispiel #1
0
// pepareInventory prepares the inventory
func (e *discoverEvent) pepareInventory() error {
	hosts := []*configuration.AnsibleHost{}
	for i, addr := range e.nodeAddrs {
		invName := fmt.Sprintf("node%d", i+1)
		hosts = append(hosts, configuration.NewAnsibleHost(
			invName, addr, ansibleDiscoverGroupName,
			map[string]string{
				ansibleNodeNameHostVar: invName,
				ansibleNodeAddrHostVar: addr,
			}))
	}
	e._hosts = hosts

	return nil
}
Beispiel #2
0
func (e *discoveredEvent) process() error {
	//XXX: need to form the name that adheres to collins tag requirements
	name := e.nodes[0].GetLabel() + "-" + e.nodes[0].GetSerial()

	enode, err := e.mgr.findNode(name)
	if err != nil && err.Error() == nodeNotExistsError(name).Error() {
		e.mgr.nodes[name] = &node{
			// XXX: node's role/group shall come from manager's role assignment logic or
			// from user configuration
			Cfg: configuration.NewAnsibleHost(name, e.nodes[0].GetMgmtAddress(),
				ansibleMasterGroupName, map[string]string{
					ansibleNodeNameHostVar: name,
					ansibleNodeAddrHostVar: e.nodes[0].GetMgmtAddress(),
				}),
		}
		enode = e.mgr.nodes[name]
	} else if err != nil {
		return err
	}

	// update node's monitoring info to the one received in the event
	enode.Mon = e.nodes[0]
	enode.Inv = e.mgr.inventory.GetAsset(name)
	if enode.Inv == nil {
		if err := e.mgr.inventory.AddAsset(name); err != nil {
			// XXX. Log this to collins
			logrus.Errorf("adding asset %q to discovered in inventory failed. Error: %s", name, err)
			return err
		}
		enode.Inv = e.mgr.inventory.GetAsset(name)
	} else if err := e.mgr.inventory.SetAssetDiscovered(name); err != nil {
		// XXX. Log this to collins
		logrus.Errorf("setting asset %q to discovered in inventory failed. Error: %s", name, err)
		return err
	}
	return nil
}