-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsecurity_group_members.go
executable file
·57 lines (51 loc) · 1.68 KB
/
security_group_members.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
package nsx
import (
"encoding/xml"
"fmt"
"log"
"reflect"
)
type securityGroupsMemberList struct {
SecurityGroups securityGroups `xml:"securityGroups"`
}
type securityGroups struct {
SecurityGroup []securityGroup `xml:"securitygroup"`
}
func getMembers(ResponseData []uint8, securityGroupName string) bool {
var foundGroup = false
//query the security group that has specified virtual machine
var memberListQuery securityGroupsMemberList
//unmarshal the response
xml.Unmarshal([]byte(ResponseData), &memberListQuery)
s := securityGroupsMemberList{}
if reflect.DeepEqual(s, memberListQuery) != true {
//search and log the security group members name
for _, securityGroupMembers := range memberListQuery.SecurityGroups.SecurityGroup {
if securityGroupName == securityGroupMembers.Name {
log.Println("[INFO] Security Group found . ID " + securityGroupMembers.ObjectId + " Name " + securityGroupMembers.Name)
foundGroup = true
break
} //if
} //for
return foundGroup
} else {
fmt.Errorf("[ERROR] No security group was found for specified virtual machine.")
return foundGroup
}
}
func checkMemberDestroyed(ResponseData []uint8, securityGroupName string) bool {
//query the security group that has specified virtual machine
var memberListQuery securityGroupsMemberList
//unmarshal the response
xml.Unmarshal([]byte(ResponseData), &memberListQuery)
s := securityGroupsMemberList{}
if reflect.DeepEqual(s, memberListQuery) != true {
//search and log the security group members name
for _, securityGroupMembers := range memberListQuery.SecurityGroups.SecurityGroup {
if securityGroupMembers.Name == securityGroupName {
return true
}
}
}
return false
}