-
Notifications
You must be signed in to change notification settings - Fork 6
/
eject.go
52 lines (40 loc) · 1.25 KB
/
eject.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
51
52
package server
import (
"fmt"
"github.com/UpCloudLtd/upcloud-cli/v2/internal/commands"
"github.com/UpCloudLtd/upcloud-cli/v2/internal/completion"
"github.com/UpCloudLtd/upcloud-cli/v2/internal/output"
"github.com/UpCloudLtd/upcloud-cli/v2/internal/resolver"
"github.com/UpCloudLtd/upcloud-go-api/v6/upcloud/request"
)
type ejectCommand struct {
*commands.BaseCommand
resolver.CachingServer
completion.Server
params ejectParams
}
type ejectParams struct {
request.EjectCDROMRequest
}
func (s *ejectCommand) InitCommand() {
}
// EjectCommand creates the "server eject" command
func EjectCommand() commands.Command {
return &ejectCommand{
BaseCommand: commands.New("eject", "Eject a CD-ROM from the server", "upctl server eject my_server"),
}
}
// Execute implements commands.MultipleArgumentCommand
func (s *ejectCommand) Execute(exec commands.Executor, uuid string) (output.Output, error) {
svc := exec.Storage()
msg := fmt.Sprintf("Ejecting CD-ROM from %v", uuid)
exec.PushProgressStarted(msg)
req := s.params.EjectCDROMRequest
req.ServerUUID = uuid
res, err := svc.EjectCDROM(exec.Context(), &req)
if err != nil {
return commands.HandleError(exec, msg, err)
}
exec.PushProgressSuccess(msg)
return output.OnlyMarshaled{Value: res}, nil
}