MML
This commit is contained in:
@@ -330,31 +330,100 @@ func parseRequestUri(httpUri string, mmlMap *dborm.MmlHttpMap, mml *MmlCommand)
|
||||
return requestURI
|
||||
}
|
||||
|
||||
// func DeploymentLicense(mml *MmlCommand, requestURI, token, agent string) {
|
||||
// client := resty.New()
|
||||
// srcLicDep := &struct {
|
||||
// NeType string `json:"ne_type"`
|
||||
// NeID string `json:"ne_id"`
|
||||
// Capability string `json:"capability"`
|
||||
// }{
|
||||
// NeType: fmt.Sprintf("%v", mml.NaMap["srcnetype"]),
|
||||
// NeID: fmt.Sprintf("%v", mml.NaMap["srcneid"]),
|
||||
// Capability: capability - strconv.Atoi(fmt.Sprintf("%v", mml.NaMap["number"])),
|
||||
// }
|
||||
// response, err := client.R().
|
||||
// EnableTrace().
|
||||
// SetHeaders(map[string]string{"accessToken": token}).
|
||||
// SetHeaders(map[string]string{"User-Agent": agent}).
|
||||
// SetHeaders(map[string]string{"Content-Type": "application/json;charset=UTF-8"}).
|
||||
// SetBody(*body).
|
||||
// Put(requestURI)
|
||||
// if err != nil {
|
||||
// log.Error("Failed to Put:", err)
|
||||
// output = ParseErrorOutput(err)
|
||||
// } else {
|
||||
// output = ParseOutputResponse(omcMmlVar, outputJson, response)
|
||||
// }
|
||||
// }
|
||||
func DeploymentLicense(mml *MmlCommand, omcMmlVar *MmlVar, outputJson *dborm.MmlOutput) *[]byte {
|
||||
var output []byte
|
||||
log.Debug("mml:", mml)
|
||||
var srcNeType, srcNeid, dstNeType, dstNeId, value string
|
||||
for _, Param := range mml.Params {
|
||||
switch Param.Name {
|
||||
case "srcnetype":
|
||||
srcNeType = Param.Value
|
||||
case "srcneid":
|
||||
srcNeid = Param.Value
|
||||
case "dstnetype":
|
||||
dstNeType = Param.Value
|
||||
case "dstneid":
|
||||
dstNeId = Param.Value
|
||||
case "number":
|
||||
value = Param.Value
|
||||
}
|
||||
}
|
||||
intValue, _ := strconv.Atoi(value)
|
||||
log.Debugf("srcNeType:%s, srcNeid:%s dstNeType:%s dstNeId:%s intValue:%d", srcNeType, srcNeid, dstNeType, dstNeId, intValue)
|
||||
a1, err := dborm.XormAdjustmentNeLicense(srcNeType, srcNeid, intValue)
|
||||
if err != nil {
|
||||
log.Error("Failed to Put:", err)
|
||||
}
|
||||
|
||||
a2, err := dborm.XormAdjustmentNeLicense(dstNeType, dstNeId, -intValue)
|
||||
if err != nil {
|
||||
log.Error("Failed to Put:", err)
|
||||
output = *ParseErrorOutput(err)
|
||||
} else {
|
||||
//response := &resty.Response{StatusCode: http.StatusOK}
|
||||
//output = ParseOutputResponse(omcMmlVar, outputJson, response.)
|
||||
str := fmt.Sprintf("RetCode = 0 operation succeeded\n\nAffected rows = %d \n\n", a1+a2)
|
||||
output = []byte(str)
|
||||
}
|
||||
|
||||
return &output
|
||||
}
|
||||
|
||||
func AdjustmentLicense(mml *MmlCommand, omcMmlVar *MmlVar, outputJson *dborm.MmlOutput) *[]byte {
|
||||
var output []byte
|
||||
log.Debug("mml:", mml)
|
||||
var neType, neid, number string
|
||||
for _, Param := range mml.Params {
|
||||
switch Param.Name {
|
||||
case "netype":
|
||||
neType = Param.Value
|
||||
case "neid":
|
||||
neid = Param.Value
|
||||
case "number":
|
||||
number = Param.Value
|
||||
}
|
||||
}
|
||||
intValue, _ := strconv.Atoi(number)
|
||||
log.Debugf("neType:%s, neid:%s intValue:%d", neType, neid, intValue)
|
||||
affected, err := dborm.XormAdjustmentNeLicense(neType, neid, intValue)
|
||||
if err != nil {
|
||||
log.Error("Failed to XormAdjustmentNeLicense:", err)
|
||||
output = *ParseErrorOutput(err)
|
||||
} else {
|
||||
str := fmt.Sprintf("RetCode = 0 operation succeeded\n\nAffected rows = %d \n\n", affected)
|
||||
output = []byte(str)
|
||||
}
|
||||
|
||||
return &output
|
||||
}
|
||||
|
||||
func InstallLicense(mml *MmlCommand, omcMmlVar *MmlVar, outputJson *dborm.MmlOutput) *[]byte {
|
||||
var output []byte
|
||||
log.Debug("mml:", mml)
|
||||
var neType, neid, number string
|
||||
for _, Param := range mml.Params {
|
||||
switch Param.Name {
|
||||
case "netype":
|
||||
neType = Param.Value
|
||||
case "neid":
|
||||
neid = Param.Value
|
||||
case "number":
|
||||
number = Param.Value
|
||||
}
|
||||
}
|
||||
intValue, _ := strconv.Atoi(number)
|
||||
log.Debugf("neType:%s, neid:%s intValue:%d", neType, neid, intValue)
|
||||
affected, err := dborm.XormUpdateNeLicense(neType, neid, intValue)
|
||||
if err != nil {
|
||||
log.Error("Failed to XormUpdateNeLicense:", err)
|
||||
output = *ParseErrorOutput(err)
|
||||
} else {
|
||||
str := fmt.Sprintf("RetCode = 0 operation succeeded\n\nAffected rows = %d \n\n", affected)
|
||||
output = []byte(str)
|
||||
}
|
||||
|
||||
return &output
|
||||
}
|
||||
|
||||
func TransMml2HttpReq(omcMmlVar *MmlVar, mml *MmlCommand) (*[]byte, error) {
|
||||
log.Info("TransMml2HttpReq processing ...")
|
||||
@@ -431,18 +500,22 @@ func TransMml2HttpReq(omcMmlVar *MmlVar, mml *MmlCommand) (*[]byte, error) {
|
||||
output = ParseOutputResponse(omcMmlVar, outputJson, response)
|
||||
}
|
||||
case "put":
|
||||
switch inputJson.CallFunc {
|
||||
case "DeploymentLicense":
|
||||
output = DeploymentLicense(mml, omcMmlVar, outputJson)
|
||||
return output, nil
|
||||
case "AdjustmentLicense":
|
||||
output = AdjustmentLicense(mml, omcMmlVar, outputJson)
|
||||
return output, nil
|
||||
case "InstallLicense":
|
||||
output = InstallLicense(mml, omcMmlVar, outputJson)
|
||||
return output, nil
|
||||
default:
|
||||
}
|
||||
|
||||
requestURI = parseRequestUri(omcMmlVar.HttpUri, mmlMap, mml)
|
||||
body := ParseInputBody(inputJson, mml)
|
||||
log.Debugf("method: Put requestURI: %s", requestURI)
|
||||
|
||||
// switch inputJson.CallFunc {
|
||||
// case "DeploymentLicense":
|
||||
// DeploymentLicense(inputJson, requestURI, omcMmlVar)
|
||||
// //output = ParseOutputResponse(inputJson, outputJson, response)
|
||||
// return output, nil
|
||||
// default:
|
||||
// }
|
||||
|
||||
body := ParseInputBody(inputJson, mml)
|
||||
response, err := client.R().
|
||||
EnableTrace().
|
||||
SetHeaders(map[string]string{"accessToken": omcMmlVar.SessionToken}).
|
||||
|
||||
Reference in New Issue
Block a user