-
Notifications
You must be signed in to change notification settings - Fork 0
/
ngw.go
executable file
·102 lines (96 loc) · 3 KB
/
ngw.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
package main
import (
"flag"
"fmt"
"ngw/conf"
"ngw/run"
"os"
)
//**********创建************
// 1、创建rbd(已有池) √
// 2、修改rbdmap 双节点 √
// 3、挂载rbd(需要确认是否格dir化) vip节点 mkfs.xfs /dev/rbd/poolname/rbdname (两次确认) √
// 4、修改/etc/exports 双节点 √
// 5、执行exportfs vip节点 √
// 6、修改pacemaker vip节点
//***********停用卷***********
//
// 1、删除/etc/exports条目 双节点
// 2、执行exportfs使其生效 vip节点
// 3、删除rbd条目 双节点
// 4、卸载rbd vip节点
// 5、删除pacemaker条目 vip节点
//***********配置************
// format: yaml
// cluster:
// vip: 192.168.1.11
// nodes:
// - node12:
// ip: 192.168.1.12
// username: root
// password: xxxx
// port: 22
// - node13:
// ip: 192.168.1.13
// username: root
// password: xxxx
// port: 22
//***********exports********
// /mnt/ec1 *(rw,no_root_squash,sync,no_subtree_check)
// /mnt/ec6/ec1 *(rw,no_root_squash,sync,no_subtree_check)
// /mnt/db/d1 *(rw,no_root_squash,sync,no_subtree_check)
func main() {
var (
f_cluster = flag.String("cluster", "", "要添加卷到哪个集群")
f_tree = flag.Bool("tree", false, "列出所有集群")
f_create = flag.Bool("create", false, "创建nfs卷时使用该参数")
f_delete = flag.Bool("delete", false, "删除nfs卷时使用该参数")
f_pool = flag.String("pool", "", "添加卷到哪个池")
f_rbd = flag.String("rbd", "", "所要添加卷的名称")
f_size = flag.String("size", "", "需要添加卷的大小,例如: 1G, 1000T")
f_format = flag.Bool("format", false, "如果是首次创建,请加上该参数,该参数会格式化rbd卷,如果有数据请勿使用该参数")
f_force = flag.Bool("force", false, "是否强制重载nfs网关,如果遇到nfs网关因为有活跃客户端重载失败时,可尝试强制重载")
)
//func CreateVolume(clusterName, pool, rbd, size string, format, force bool)
flag.Parse()
if *f_create {
if *f_cluster == "" {
fmt.Println("error: cluster name cannot be null")
os.Exit(2)
}
if *f_pool == "" {
fmt.Println("error: pool name cannot be null")
os.Exit(2)
}
if *f_rbd == "" {
fmt.Println("error: rbd name cannot be null")
os.Exit(2)
}
run.CreateVolume(*f_cluster, *f_pool, *f_rbd, *f_size, *f_format, *f_force)
} else if *f_delete {
if *f_cluster == "" {
fmt.Println("error: cluster name cannot be null")
os.Exit(2)
}
if *f_pool == "" {
fmt.Println("error: pool name cannot be null")
os.Exit(2)
}
if *f_rbd == "" {
fmt.Println("error: rbd name cannot be null")
os.Exit(2)
}
run.RemoveVolume(*f_cluster, *f_pool, *f_rbd, *f_format, *f_force)
} else if *f_tree {
c := conf.GetConfig()
fmt.Println("Tree node of nfs gateway:")
for _, v := range c.Clusters {
fmt.Printf("-> %s:\n", v.Name)
for _, v1 := range v.Nodes {
fmt.Printf("%15s\n", v1.Name)
}
}
} else {
flag.Usage()
}
}