/
replace_vnc_passwd.go
50 lines (46 loc) · 1.05 KB
/
replace_vnc_passwd.go
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
41
42
43
44
45
46
47
48
49
50
package grpcs
import (
"context"
"fmt"
"log"
"strconv"
"github.com/IBM/cloudland/web/clui/model"
"github.com/IBM/cloudland/web/sca/dbs"
)
func init() {
Add("replace_vnc_passwd", ReplaceVncPasswd)
}
func ReplaceVncPasswd(ctx context.Context, job *model.Job, args []string) (status string, err error) {
//|:-COMMAND-:| enable_vm_vnc.sh 6 5909 password 192.168.10.100
db := dbs.DB()
argn := len(args)
if argn < 5 {
err = fmt.Errorf("Wrong params")
log.Println("Invalid args", err)
return
}
instID, err := strconv.Atoi(args[1])
if err != nil {
log.Println("Invalid instance ID", err)
return
}
portN, err := strconv.Atoi(args[2])
if err != nil {
log.Println("Invalid port number", err)
return
}
passwd := args[3]
hyperip := args[4]
vnc := &model.Vnc{
InstanceID: int64(instID),
LocalAddress: hyperip,
LocalPort: int32(portN),
Passwd: passwd,
}
err = db.Where("instance_id = ?", int64(instID)).Assign(vnc).FirstOrCreate(&model.Vnc{}).Error
if err != nil {
log.Println("Failed to update vnc", err)
return
}
return
}