// Put takes a list of nodes and attempts to add the nodes to inventory.
// Returns:
// recordCount - the number of records in the underlying db
// statusCode - the http response code
// respBody.Message - the reply (message) from the API
// err - any error
Put takes a list of nodes and attempts to add the nodes to inventory.
Returns:
recordCount - the number of records in the underlying db
statusCode - the http response code
respBody.Message - the reply (message) from the API
err - any error
// Put takes a list of nodes and attempts to add the nodes to inventory . // Returns : // recordCount - the number of records in the underlying db // statusCode - the http response code // respBody . Message - the reply ( message ) from the API // err - any error
func (o *InventoryApiOp) Put(ncis []NodeConsoleInfo) (recordCount int64,
	statusCode int, responseBodyMessage string, err error) {
	const uri = "http://cray-console-data/v1/inventory"
	client := &http.Client{Timeout: 15 * time.Second}
	if ncis == nil {
		return 0, 0, "", errors.New("NodeConsoleInfo is required but was nil.")
	}
	jsonReq, err := json.Marshal(ncis)
	if err != nil {
		return 0, 0, "", err
	}
	httpReq, err := http.NewRequest(http.MethodPut, "http://cray-console-data/v1/inventory", bytes.NewBuffer(jsonReq))
	if err != nil {
		return 0, 0, "", err
	}
	httpReq.Header.Set("Content-Type", "application/json")
	httpResp, err := client.Do(httpReq)
	if err != nil {
		return 0, 0, "", err
	}
	statusCode = httpResp.StatusCode
	responseBodyMessage = ""
	json.NewDecoder(httpResp.Body).Decode(&o.respBody)
	defer httpResp.Body.Close()
	responseBodyMessage = o.respBody.Message
	var ds DataStore
	ds.Init()
	defer ds.Close()
	recordCount, err = ds.GetCount()
	log.Printf("InventoryApiOp.Put() returning %d , %d , %s , %s\n", recordCount, statusCode, responseBodyMessage, err)
	return recordCount, statusCode, responseBodyMessage, nil
}
func ( o * InventoryApiOp ) Put ( ncis [ ] NodeConsoleInfo ) ( recordCount int64 , statusCode int , responseBodyMessage string , err error ) { const uri = " " client := & http . Client { Timeout : 15 * time . Second } if ncis == nil { return 0 , 0 , " " , errors . New ( " " ) } jsonReq , err := json . Marshal ( ncis ) if err != nil { return 0 , 0 , " " , err } httpReq , err := http . NewRequest ( http . MethodPut , " " , bytes . NewBuffer ( jsonReq ) ) if err != nil { return 0 , 0 , " " , err } httpReq . Header . Set ( " " , " " ) httpResp , err := client . Do ( httpReq ) if err != nil { return 0 , 0 , " " , err } statusCode = httpResp . StatusCode responseBodyMessage = " " json . NewDecoder ( httpResp . Body ) . Decode ( & o . respBody ) defer httpResp . Body . Close ( ) responseBodyMessage = o . respBody . Message var ds DataStore ds . Init ( ) defer ds . Close ( ) recordCount , err = ds . GetCount ( ) log . Printf ( " \n " , recordCount , statusCode , responseBodyMessage , err ) return recordCount , statusCode , responseBodyMessage , nil }
Put takes a list of nodes and attempts to add the nodes to inventory.
Put takes a list of nodes and attempts to add the nodes to inventory .
//log.Println("InventoryApiOp.Put() called") // Send the request //log.Printf("statusCode=%d", statusCode) // Peek at the response //log.Printf("responseBodyMessage=%d", responseBodyMessage) // Peek under the hood to check the record count //log.Printf("recordsCreated=%d", recordCount) // Return everything to the caller for evaluation.