This repository was archived by the owner on May 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathucloud.go
More file actions
51 lines (43 loc) · 1.35 KB
/
ucloud.go
File metadata and controls
51 lines (43 loc) · 1.35 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
package main
import (
"fmt"
"github.com/ucloud/ucloud-sdk-go/services/pathx"
"github.com/ucloud/ucloud-sdk-go/ucloud"
"github.com/ucloud/ucloud-sdk-go/ucloud/auth"
)
var (
cfg ucloud.Config
credential auth.Credential
)
func initUcloud() {
cfg = ucloud.NewConfig()
cfg.Region = "cn-bj2"
cfg.ProjectId = config.Ucloud.ProjectID
// replace the public/private key by your own
credential = auth.NewCredential()
credential.PrivateKey = config.Ucloud.PrivateKey
credential.PublicKey = config.Ucloud.PublicKey
}
func newGlobalSSH(ip, area string) (domain, instance string, err error) {
pathxClient := pathx.NewClient(&cfg, &credential)
req := pathxClient.NewCreateGlobalSSHInstanceRequest()
req.Port = ucloud.Int(22)
req.TargetIP = ucloud.String(ip)
req.Area = ucloud.String(area)
req.Remark = ucloud.String(fmt.Sprintf("git_ssh_%s_%s", area, ip))
resp, err := pathxClient.CreateGlobalSSHInstance(req)
return resp.AcceleratingDomain, resp.InstanceId, err
}
func deleteGlobalSSH(instanceID string) {
pathxClient := pathx.NewClient(&cfg, &credential)
req := pathxClient.NewDeleteGlobalSSHInstanceRequest()
req.InstanceId = ucloud.String(instanceID)
pathxClient.DeleteGlobalSSHInstance(req)
}
var areaMap = map[string]string{
"洛杉矶": "美国",
"香港": "中国",
"新加坡": "新加坡",
"东京": "日本",
"法兰克福": "德国",
}