-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsecurity_group_xml_marshal.go
executable file
·116 lines (105 loc) · 3.54 KB
/
security_group_xml_marshal.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 nsx
import (
"encoding/xml"
"log"
)
//Security group tag and subtag
type securityGroupList struct {
ObjectId string `xml:"objectId"`
VsmUuid string `xml:"vsmUuid"`
NodeId string `xml:"nodeId"`
Revision int `xml:"revision"`
Name string `xml:"name"`
Description string `xml:"description"`
Member member `xml:"member"`
TypeSecurity typeSecurity `xml:"type"`
Scope scope `xml:"scope"`
ExtendedAttributes extendedAttributes `xml:"extendedAttributes"`
ClientHandle string `xml:"clientHandle"`
}
//structure of scope tag
type scope struct {
Id string `xml:"id"`
ObjectTypeName string `xml:"objectTypeName"`
Name string `xml:"name"`
}
//structure of member tag
type member struct {
ObjectId string `xml:"objectId"`
ObjectTypeName string `xml:"objectTypeName"`
VsmUuid string `xml:"vsmUuid"`
NodeId string `xml:"nodeId"`
Revision int `xml:"revision"`
Name string `xml:"name"`
ClientHandle string `xml:"clientHandle"`
ExtendedAttributes string `xml:"extendedAttributes"`
IsUniversal bool `xml:"isUniversal"`
UniversalRevision int `xml:"universalRevision"`
TypeSecurity typeSecurity `xml:"type"`
Scope scope `xml:"scope"`
}
//structure of extendedAttributes tag
type extendedAttributes struct {
ExtendedAttribute []extendedAttribute `xml:"extendedAttribute"`
}
//structure of extendedattribute subtag
type extendedAttribute struct {
Name string `xml:"name"`
Value bool `xml:"value"`
}
//structure of type tag
type typeSecurity struct {
TypeName string `xml:"typeName"`
}
//parse the xml formed
func parseXMLMarshal(securityGroupDetails securityGroupDetails, virtualMachineDetails virtualMachineDetails) string {
requestBody := securityGroupList{
//assigning security group details
ObjectId: securityGroupDetails.ObjectIdDetail,
VsmUuid: securityGroupDetails.VsmUuidDetail,
NodeId: securityGroupDetails.NodeIdDetail,
Revision: securityGroupDetails.RevisionDetail,
TypeSecurity: typeSecurity{
TypeName: "SecurityGroup",
},
Scope: scope{
Id: "globalroot-0",
ObjectTypeName: "GlobalRoot",
Name: "Global",
},
ExtendedAttributes: extendedAttributes{
ExtendedAttribute: []extendedAttribute{
{
Name: "localMembersOnly",
Value: false,
},
},
},
//defining the type of the members to be added into security group i.e. Virtual Machine
Member: member{
ObjectId: virtualMachineDetails.virtualMachineid,
ObjectTypeName: "VirtualMachine",
VsmUuid: securityGroupDetails.VsmUuidDetail,
NodeId: securityGroupDetails.NodeIdDetail,
Revision: securityGroupDetails.RevisionDetail,
Name: virtualMachineDetails.virtualMachinename,
TypeSecurity: typeSecurity{
TypeName: "VirtualMachine",
},
Scope: scope{
Id: virtualMachineDetails.domainid,
ObjectTypeName: "ClusterComputeResource",
Name: virtualMachineDetails.clustername,
},
IsUniversal: false,
UniversalRevision: 0,
},
}
//formating the xml including the indentation
securityDetailsBody, err := xml.MarshalIndent(&requestBody, "", "\t")
if err != nil {
log.Println(err)
}
//return the xml
return string(securityDetailsBody)
}