Files

82 lines
1.8 KiB
Go
Raw Permalink Normal View History

2019-03-29 13:35:47 +08:00
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2018-08-31 19:32:53 +08:00
package command
import (
"os/exec"
"yunion.io/x/log"
2022-04-18 21:38:30 +08:00
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/webconsole/recorder"
2018-08-31 19:32:53 +08:00
)
const (
PROTOCOL_TTY string = "tty"
//PROTOCOL_VNC string = "vnc"
)
type ICommand interface {
GetProtocol() string
GetCommand() *exec.Cmd
GetSafeCommandString() string
2018-08-31 19:32:53 +08:00
Cleanup() error
2020-07-13 15:34:31 +08:00
Scan(d byte, send func(msg string))
2022-04-18 21:38:30 +08:00
GetClientSession() *mcclient.ClientSession
GetRecordObject() *recorder.Object
2018-08-31 19:32:53 +08:00
}
type BaseCommand struct {
2022-04-18 21:38:30 +08:00
s *mcclient.ClientSession
2018-08-31 19:32:53 +08:00
name string
args []string
}
2022-04-18 21:38:30 +08:00
func NewBaseCommand(s *mcclient.ClientSession, name string, args ...string) *BaseCommand {
2018-08-31 19:32:53 +08:00
return &BaseCommand{
2022-04-18 21:38:30 +08:00
s: s,
2018-08-31 19:32:53 +08:00
name: name,
args: args,
}
}
2022-04-18 21:38:30 +08:00
func (c *BaseCommand) GetClientSession() *mcclient.ClientSession {
return c.s
}
2018-08-31 19:32:53 +08:00
func (c *BaseCommand) AppendArgs(args ...string) *BaseCommand {
2024-05-07 18:19:15 +08:00
c.args = append(c.args, args...)
2018-08-31 19:32:53 +08:00
return c
}
func (c BaseCommand) GetCommand() *exec.Cmd {
return exec.Command(c.name, c.args...)
}
func (c BaseCommand) GetSafeCommandString() string {
return c.GetCommand().String()
}
2020-07-13 15:34:31 +08:00
func (c BaseCommand) Scan(byte, func(msg string)) {
}
2018-08-31 19:32:53 +08:00
func (c BaseCommand) Cleanup() error {
log.Infof("BaseCommand Cleanup do nothing")
return nil
}
2022-04-18 21:38:30 +08:00
func (c BaseCommand) GetRecordObject() *recorder.Object {
return nil
}