Skip to content

Commit cdc3814

Browse files
authored
Automated cherry pick of #23377: Automated cherry pick of #23374: fix(region,host): guest add vnc screen dump support (#23378)
* fix(host): update nic confs inside vm on qga delete nics Signed-off-by: wanyaoqi <[email protected]> * fix(region,host): guest add vnc screen dump support --------- Signed-off-by: wanyaoqi <[email protected]>
1 parent dd2450d commit cdc3814

File tree

25 files changed

+500
-33
lines changed

25 files changed

+500
-33
lines changed

cmd/climc/shell/compute/servers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ func init() {
144144
cmd.Get("sshport", new(options.ServerIdOptions))
145145
cmd.Get("qemu-info", new(options.ServerIdOptions))
146146
cmd.Get("hardware-info", new(options.ServerIdOptions))
147+
cmd.Get("screen-dump-show", new(options.ServerScreenDumpOptions))
148+
cmd.BatchPerform("screen-dump", new(options.ServerIdsOptions))
147149

148150
cmd.GetProperty(&options.ServerStatusStatisticsOptions{})
149151
cmd.GetProperty(&options.ServerProjectStatisticsOptions{})
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package compute
2+
3+
import (
4+
"yunion.io/x/jsonutils"
5+
6+
"yunion.io/x/onecloud/cmd/climc/shell"
7+
modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
8+
"yunion.io/x/onecloud/pkg/mcclient/options"
9+
)
10+
11+
type ServerScreenDumpListOptions struct {
12+
options.BaseListOptions
13+
Server string `help:"Id or name of server"`
14+
}
15+
16+
func (o *ServerScreenDumpListOptions) Params() (jsonutils.JSONObject, error) {
17+
return jsonutils.Marshal(o), nil
18+
}
19+
20+
func init() {
21+
cmd := shell.NewResourceCmd(&modules.ServerScreenDumps)
22+
cmd.List(new(ServerScreenDumpListOptions))
23+
}

pkg/apis/compute/guest_image.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,26 @@ type SImagesInGuest struct {
2727
RootImage SSubImage
2828
DataImages []SSubImage
2929
}
30+
31+
type SGuestScreenDump struct {
32+
S3AccessKey string
33+
S3SecretKey string
34+
S3Endpoint string
35+
S3BucketName string
36+
S3ObjectName string
37+
S3UseSSL bool
38+
}
39+
40+
type GuestScreenDumpListInput struct {
41+
Server string
42+
}
43+
44+
type GetDetailsGuestScreenDumpInput struct {
45+
ObjectName string
46+
}
47+
48+
type GetDetailsGuestScreenDumpOutput struct {
49+
GuestId string
50+
Name string
51+
ScreenDump string
52+
}

pkg/cloudcommon/db/db_dispatcher.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,12 +1077,15 @@ func (dispatcher *DBModelDispatcher) GetSpecific(ctx context.Context, idStr stri
10771077

10781078
funcName := fmt.Sprintf("GetDetails%s", specCamel)
10791079
funcValue := modelValue.MethodByName(funcName)
1080+
log.Errorf("MethodByName %s", funcName)
10801081
if !funcValue.IsValid() || funcValue.IsNil() {
1082+
log.Errorf("MethodByName2 %s", funcName)
10811083
return nil, httperrors.NewSpecNotFoundError("%s %s %s not found", dispatcher.Keyword(), idStr, spec)
10821084
}
10831085

10841086
outs, err := callFunc(funcValue, funcName, params...)
10851087
if err != nil {
1088+
log.Errorf("MethodByName4 %s", funcName)
10861089
return nil, err
10871090
}
10881091
if len(outs) != 2 {
@@ -1092,6 +1095,7 @@ func (dispatcher *DBModelDispatcher) GetSpecific(ctx context.Context, idStr stri
10921095
resVal := outs[0]
10931096
errVal := outs[1].Interface()
10941097
if !gotypes.IsNil(errVal) {
1098+
log.Errorf("MethodByName3 %s", funcName)
10951099
return nil, errVal.(error)
10961100
} else {
10971101
if gotypes.IsNil(resVal.Interface()) {

pkg/cloudcommon/db/opslog_const.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ const (
267267
ACT_GUEST_CREATE_FROM_IMPORT_SUCC = "guest_create_from_import_succ"
268268
ACT_GUEST_CREATE_FROM_IMPORT_FAIL = "guest_create_from_import_fail"
269269
ACT_GUEST_PANICKED = "guest_panicked"
270+
ACT_GUEST_SCREEN_DUMP = "guest_screen_dump"
270271
ACT_HOST_MAINTENANCE = "host_maintenance"
271272
ACT_HOST_DOWN = "host_down"
272273

pkg/cloudcommon/options/options.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ type CommonOptions struct {
163163

164164
type HostCommonOptions struct {
165165
CommonOptions
166+
S3ScreenDumpOptions
166167

167168
ExecutorSocketPath string `help:"Executor socket path" default:"/var/run/onecloud/exec.sock"`
168169
DeployServerSocketPath string `help:"Deploy server listen socket path" default:"/var/run/onecloud/deploy.sock"`
@@ -176,6 +177,15 @@ type HostCommonOptions struct {
176177
Qcow2Preallocation string `help:"Qcow2 image create preallocation" default:"metadata" choices:"disable|metadata|falloc|full"`
177178
}
178179

180+
type S3ScreenDumpOptions struct {
181+
S3AccessKey string `help:"s3 access key"`
182+
S3SecretKey string `help:"s3 secret key"`
183+
S3Endpoint string `help:"s3 endpoint"`
184+
S3UseSSL bool `help:"s3 access use ssl"`
185+
S3BucketName string `help:"s3 bucket name" default:"onecloud-screendump"`
186+
S3BucketLifecycleKeepDay int `help:"s3 bucket lifecycle keep day" default:"180"`
187+
}
188+
179189
type DBOptions struct {
180190
SqlConnection string `help:"SQL connection string" alias:"connection"`
181191

pkg/compute/guestdrivers/base.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,10 @@ func (drv *SBaseGuestDriver) RequestQgaCommand(ctx context.Context, userCred mcc
522522
return nil, httperrors.ErrNotImplemented
523523
}
524524

525+
func (self *SBaseGuestDriver) RequestGuestScreenDump(ctx context.Context, userCred mcclient.TokenCredential, body jsonutils.JSONObject, host *models.SHost, guest *models.SGuest) (jsonutils.JSONObject, error) {
526+
return nil, httperrors.ErrNotImplemented
527+
}
528+
525529
func (drv *SBaseGuestDriver) FetchMonitorUrl(ctx context.Context, guest *models.SGuest) string {
526530
s := auth.GetAdminSessionWithPublic(ctx, consts.GetRegion())
527531
tsdbURL, err := tsdb.GetDefaultServiceSourceURL(s, options.Options.MonitorEndpointType)

pkg/compute/guestdrivers/kvm.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,17 @@ func (self *SKVMGuestDriver) RequestQgaCommand(ctx context.Context, userCred mcc
12011201
return res, nil
12021202
}
12031203

1204+
func (self *SKVMGuestDriver) RequestGuestScreenDump(ctx context.Context, userCred mcclient.TokenCredential, body jsonutils.JSONObject, host *models.SHost, guest *models.SGuest) (jsonutils.JSONObject, error) {
1205+
url := fmt.Sprintf("%s/servers/%s/guest-screen-dump", host.ManagerUri, guest.Id)
1206+
httpClient := httputils.GetDefaultClient()
1207+
header := mcclient.GetTokenHeaders(userCred)
1208+
_, res, err := httputils.JSONRequest(httpClient, ctx, "POST", url, header, nil, false)
1209+
if err != nil {
1210+
return nil, errors.Wrap(err, "host request")
1211+
}
1212+
return res, nil
1213+
}
1214+
12041215
func (self *SKVMGuestDriver) FetchMonitorUrl(ctx context.Context, guest *models.SGuest) string {
12051216
if options.Options.KvmMonitorAgentUseMetadataService && !guest.IsSriov() {
12061217
var metadataIp string

pkg/compute/models/guest_actions.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,27 @@ func (self *SGuest) PerformEvent(ctx context.Context, userCred mcclient.TokenCre
148148
}
149149
if event == "GUEST_PANICKED" {
150150
kwargs := jsonutils.NewDict()
151-
kwargs.Set("reason", data)
151+
kwargs.Set("reason", jsonutils.NewString(event))
152+
if data.Contains("screen_dump_info") {
153+
screenDumpInfo := api.SGuestScreenDump{}
154+
if err := data.Unmarshal(&screenDumpInfo, "screen_dump_info"); err != nil {
155+
log.Errorf("failed unmarshal screen_dump_info %s", err)
156+
} else {
157+
kwargs.Set("screen_dump_name", jsonutils.NewString(screenDumpInfo.S3ObjectName))
158+
if _, err := self.SaveGuestScreenDump(ctx, userCred, &screenDumpInfo); err != nil {
159+
log.Errorf("SaveGuestScreenDump failed %s", err)
160+
}
161+
}
162+
}
152163

153-
db.OpsLog.LogEvent(self, db.ACT_GUEST_PANICKED, data.String(), userCred)
154-
logclient.AddSimpleActionLog(self, logclient.ACT_GUEST_PANICKED, data.String(), userCred, true)
164+
db.OpsLog.LogEvent(self, db.ACT_GUEST_PANICKED, kwargs.String(), userCred)
165+
logclient.AddSimpleActionLog(self, logclient.ACT_GUEST_PANICKED, kwargs.String(), userCred, true)
155166
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
156167
Obj: self,
157168
Action: notifyclient.ActionServerPanicked,
158169
IsFail: true,
159170
})
171+
160172
}
161173
return nil, nil
162174
}

pkg/compute/models/guestdrivers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ type IGuestDriver interface {
255255

256256
BeforeDetachIsolatedDevice(ctx context.Context, cred mcclient.TokenCredential, guest *SGuest, dev *SIsolatedDevice) error
257257
BeforeAttachIsolatedDevice(ctx context.Context, cred mcclient.TokenCredential, guest *SGuest, dev *SIsolatedDevice) error
258+
259+
RequestGuestScreenDump(ctx context.Context, userCred mcclient.TokenCredential, body jsonutils.JSONObject, host *SHost, guest *SGuest) (jsonutils.JSONObject, error)
258260
}
259261

260262
var guestDrivers map[string]IGuestDriver

0 commit comments

Comments
 (0)