Example #1
0
// NewCollinsSubsys initializes and return an instance of collins based inventory Subsys
func NewCollinsSubsys(config collins.Config) (*inventory.GeneralSubsys, error) {
	client := collins.NewClientFromConfig(config)
	subsys := inventory.NewGeneralSubsys(client)

	// create the customs states in collins
	for state, desc := range inventory.StateDescription {
		if err := client.CreateState(state.String(), desc, inventory.Any.String()); err != nil {
			return nil, errored.Errorf("failed to create state %q in collins. Error: %s", state, err)
		}
	}

	// restore any previously added hosts
	assets, err := client.GetAllAssets()
	if err != nil {
		return nil, err
	}
	assets1 := assets.([]collins.Asset)
	for _, asset := range assets1 {
		a := inventory.NewAssetWithState(client, asset.Tag, inventory.AssetStatusVals[asset.Status],
			inventory.AssetStateVals[asset.State.Name])
		if err := subsys.RestoreAsset(asset.Tag, a); err != nil {
			logrus.Infof("failed to restore asset %q. Error: %v", asset.Tag, err)
			continue
		}
	}

	return subsys, nil
}
Example #2
0
// NewBoltdbSubsys initializes and return an instance of boltdb based inventory subsystem
func NewBoltdbSubsys(config boltdb.Config) (*inventory.GeneralSubsys, error) {
	client, err := boltdb.NewClientFromConfig(config)
	if err != nil {
		return nil, err
	}
	subsys := inventory.NewGeneralSubsys(client)

	// restore any previously added hosts
	assets, err := client.GetAllAssets()
	if err != nil {
		return nil, err
	}
	assets1 := assets.([]boltdb.Asset)
	for _, asset := range assets1 {
		a := inventory.NewAssetWithState(client, asset.Name, inventory.AssetStatusVals[asset.Status],
			inventory.AssetStateVals[asset.State])
		if err := subsys.RestoreAsset(asset.Name, a); err != nil {
			logrus.Infof("failed to restore asset %q. Error: %v", asset.Name, err)
			continue
		}
	}

	return subsys, nil
}