-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.go
More file actions
68 lines (54 loc) · 1.58 KB
/
cli.go
File metadata and controls
68 lines (54 loc) · 1.58 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package gospoc
import (
"context"
"net/http"
)
const (
cliBasePath = "/oc/api/cli"
cliContentType = "text/plain"
)
// CLI is an interface for interacting with
// IBM Spectrum Protect CLI
type CLI interface {
IssueCommand(ctx context.Context, serverName string, command string) (*http.Response, error)
IssueConfirmCommand(ctx context.Context, serverName string, command string) (*http.Response, error)
}
// CLIOp handles communication with the cli related methods of the
// IBM Spectrum Protect Operations Center REST API
type CLIOp struct {
client *Client
}
// IssueCommand issues a TSM Command
func (s *CLIOp) IssueCommand(ctx context.Context, serverName string, command string) (*http.Response, error) {
path := cliBasePath + "/issueCommand"
if serverName != "" {
path = path + "/" + serverName
}
req, err := s.client.NewRequest(ctx, http.MethodPost, path, command)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", cliContentType)
resp, err := s.client.Do(ctx, req, nil)
if err != nil {
return resp, err
}
return resp, err
}
// IssueConfirmCommand issues a confirmed TSM Command
func (s *CLIOp) IssueConfirmCommand(ctx context.Context, serverName string, command string) (*http.Response, error) {
path := cliBasePath + "/issueConfirmedCommand"
if serverName != "" {
path = path + "/" + serverName
}
req, err := s.client.NewRequest(ctx, http.MethodPost, path, command)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", cliContentType)
resp, err := s.client.Do(ctx, req, nil)
if err != nil {
return resp, err
}
return resp, err
}