forked from huaweicloud/huaweicloud-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverSecurityGroups.go
71 lines (60 loc) · 2.03 KB
/
serverSecurityGroups.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
package main
import (
"fmt"
"github.com/YoungPioneers/huaweicloud-sdk-go/functiontest/common"
"github.com/YoungPioneers/huaweicloud-sdk-go"
"github.com/YoungPioneers/huaweicloud-sdk-go/openstack"
"github.com/YoungPioneers/huaweicloud-sdk-go/openstack/compute/v2/extensions/secgroups"
)
func main() {
fmt.Println("main start...")
provider, err := common.AuthToken()
if err != nil {
fmt.Println("get provider client failed")
if ue, ok := err.(*gophercloud.UnifiedError); ok {
fmt.Println("ErrCode:", ue.ErrorCode())
fmt.Println("Message:", ue.Message())
}
return
}
sc, err := openstack.NewComputeV2(provider, gophercloud.EndpointOpts{})
if err != nil {
fmt.Println("get compute v2 client failed")
if ue, ok := err.(*gophercloud.UnifiedError); ok {
fmt.Println("ErrCode:", ue.ErrorCode())
fmt.Println("Message:", ue.Message())
}
return
}
GetServerSecurityGroupList(sc)
fmt.Println("main end...")
}
func GetServerSecurityGroupList(sc *gophercloud.ServiceClient) {
page, err := secgroups.ListByServer(sc, "81cfeb20-6c63-412c-81bf-4524d0e8e390").AllPages()
if err != nil {
fmt.Println(err)
if ue, ok := err.(*gophercloud.UnifiedError); ok {
fmt.Println("ErrCode:", ue.ErrorCode())
fmt.Println("Message:", ue.Message())
}
return
}
PageData, err := secgroups.ExtractSecurityGroups(page)
if err != nil {
fmt.Println(err)
return
}
fmt.Println("get Server Security Groups List success")
for _, data := range PageData {
fmt.Println("Server Security Groups name is ", data.Name)
fmt.Println("Server Security Groups ID is ", data.ID)
for _, rule := range data.Rules {
fmt.Println("Server Security Groups Rule ID is", rule.ID)
fmt.Println("Server Security Groups Rule FromPort is", rule.FromPort)
fmt.Println("Server Security Groups Rule ToPort is", rule.ToPort)
fmt.Println("Server Security Groups Rule IPProtocol is", rule.IPProtocol)
fmt.Println("Server Security Groups Rule IPRange is", rule.IPRange)
fmt.Println("Server Security Groups Rule ParentGroupID is ", rule.ParentGroupID)
}
}
}