-
Notifications
You must be signed in to change notification settings - Fork 5
/
system_dump_types.go
116 lines (99 loc) · 2.34 KB
/
system_dump_types.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package cfbackup
import (
"fmt"
"io"
"github.com/pivotalservices/gtils/command"
"github.com/pivotalservices/gtils/persistence"
"github.com/xchapter7x/goutil"
)
const (
SD_PRODUCT string = "Product"
SD_COMPONENT string = "Component"
SD_IDENTITY string = "Identity"
SD_IP string = "Ip"
SD_USER string = "User"
SD_PASS string = "Pass"
SD_VCAPUSER string = "VcapUser"
SD_VCAPPASS string = "VcapPass"
)
type (
PersistanceBackup interface {
Dump(io.Writer) error
Import(io.Reader) error
}
stringGetterSetter interface {
Get(string) string
Set(string, string)
}
SystemDump interface {
stringGetterSetter
Error() error
GetPersistanceBackup() (dumper PersistanceBackup, err error)
}
SystemInfo struct {
goutil.GetSet
Product string
Component string
Identity string
Ip string
User string
Pass string
VcapUser string
VcapPass string
}
PgInfo struct {
SystemInfo
Database string
}
MysqlInfo struct {
SystemInfo
Database string
}
NfsInfo struct {
SystemInfo
}
)
func (s *SystemInfo) Get(name string) string {
return s.GetSet.Get(s, name).(string)
}
func (s *SystemInfo) Set(name string, val string) {
s.GetSet.Set(s, name, val)
}
func (s *NfsInfo) GetPersistanceBackup() (dumper PersistanceBackup, err error) {
return NewNFSBackup(s.Pass, s.Ip)
}
func (s *MysqlInfo) GetPersistanceBackup() (dumper PersistanceBackup, err error) {
sshConfig := command.SshConfig{
Username: s.VcapUser,
Password: s.VcapPass,
Host: s.Ip,
Port: 22,
}
return persistence.NewRemoteMysqlDump(s.User, s.Pass, sshConfig)
}
func (s *PgInfo) GetPersistanceBackup() (dumper PersistanceBackup, err error) {
sshConfig := command.SshConfig{
Username: s.VcapUser,
Password: s.VcapPass,
Host: s.Ip,
Port: 22,
}
return persistence.NewPgRemoteDump(2544, s.Database, s.User, s.Pass, sshConfig)
}
func (s *SystemInfo) GetPersistanceBackup() (dumper PersistanceBackup, err error) {
panic("you have to extend SystemInfo and implement GetPersistanceBackup method on the child")
return
}
func (s *SystemInfo) Error() (err error) {
if s.Product == "" ||
s.Component == "" ||
s.Identity == "" ||
s.Ip == "" ||
s.User == "" ||
s.Pass == "" ||
s.VcapUser == "" ||
s.VcapPass == "" {
err = fmt.Errorf("invalid or incomplete system info object: %s", s)
}
return
}