1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
// 更新k8s字段信息
func UpdateK8sStatus(jobid, message string) error {
token := getToken(CUrl, CUsername, CPwd)
data := map[string]interface{}{
"label": "VM",
"cql": fmt.Sprintf("match (n:VM{jobid:'%s'}) set n.info='%s' return n", jobid, message),
}
body, err := json.Marshal(data)
if err != nil {
return err
}
// log.Debug("data", string(body))
// log.Debug("url", fmt.Sprintf("%s/node/?token=%s", CUrl, token.Token))
client := &http.Client{}
request, err := http.NewRequest("POST", fmt.Sprintf("%s/phy/?token=%s", curl, token.Token), bytes.NewReader(body))
if err != nil {
return err
}
request.Header.Set("Content-Type", "application/json")
request.Header.Set("WWW-Authenticate", `Basic realm="hehehe"`)
request.Header.Set("Authorization", "Basic hahahaha")
resp, err := client.Do(request)
if err != nil {
return err
}
defer resp.Body.Close()
rs, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
log.Debug("http request", string(rs))
return nil
}
|