Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added PatchVirtualServer and PatchVirtualAddress functions #87

Merged
merged 1 commit into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions ltm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1824,11 +1824,17 @@ func (b *BigIP) DeleteVirtualServer(name string) error {
}

// ModifyVirtualServer allows you to change any attribute of a virtual server. Fields that
// can be modified are referenced in the VirtualServer struct.
// can be modified are referenced in the VirtualServer struct. Set all the attributes.
func (b *BigIP) ModifyVirtualServer(name string, config *VirtualServer) error {
return b.put(config, uriLtm, uriVirtual, name)
}

// PatchVirtualServer allows you to change any attribute of a virtual server. Fields that
// can be modified are referenced in the VirtualServer struct. Sets only the attributes specified.
func (b *BigIP) PatchVirtualServer(name string, config *VirtualServer) error {
return b.patch(config, uriLtm, uriVirtual, name)
}

// VirtualServerProfiles gets the profiles currently associated with a virtual server.
func (b *BigIP) VirtualServerProfiles(vs string) (*Profiles, error) {
var p Profiles
Expand Down Expand Up @@ -1891,11 +1897,17 @@ func (b *BigIP) VirtualAddressStatus(vaddr, state string) error {
}

// ModifyVirtualAddress allows you to change any attribute of a virtual address. Fields that
// can be modified are referenced in the VirtualAddress struct.
// can be modified are referenced in the VirtualAddress struct. Sets all the attributes.
func (b *BigIP) ModifyVirtualAddress(vaddr string, config *VirtualAddress) error {
return b.put(config, uriLtm, uriVirtualAddress, vaddr)
}

// PatchVirtualAddress allows you to change any attribute of a virtual address. Fields that
// can be modified are referenced in the VirtualAddress struct. Sets only the attributes specified.
func (b *BigIP) PatchVirtualAddress(vaddr string, config *VirtualAddress) error {
return b.patch(config, uriLtm, uriVirtualAddress, vaddr)
}

func (b *BigIP) DeleteVirtualAddress(vaddr string) error {
return b.delete(uriLtm, uriVirtualAddress, vaddr)
}
Expand Down
32 changes: 32 additions & 0 deletions ltm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ func (s *LTMTestSuite) TestModifyVirtualAddress() {
assert.Equal(s.T(), "PUT", s.LastRequest.Method)
}

func (s *LTMTestSuite) TestPatchVirtualAddress() {
d := &VirtualAddress{}
s.Client.PatchVirtualAddress("address1", d)

assert.Equal(s.T(), fmt.Sprintf("/mgmt/tm/%s/%s/%s", uriLtm, uriVirtualAddress, "address1"), s.LastRequest.URL.Path)
assert.Equal(s.T(), "PATCH", s.LastRequest.Method)
}

func (s *LTMTestSuite) TestGetPolicies() {
s.ResponseFunc = func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`{
Expand Down Expand Up @@ -468,6 +476,30 @@ func (s *LTMTestSuite) TestModifyVirtualServer() {

}

func (s *LTMTestSuite) TestPatchVirtualServer() {
vs := &VirtualServer{
Name: "test",
Profiles: []Profile{
Profile{Name: "/Common/tcp", Context: CONTEXT_CLIENT},
Profile{Name: "/Common/tcp", Context: CONTEXT_SERVER}},
//TODO: test more
}

s.Client.PatchVirtualServer("test", vs)

assert.Equal(s.T(), "PATCH", s.LastRequest.Method)
assert.Equal(s.T(), fmt.Sprintf("/mgmt/tm/%s/%s/test", uriLtm, uriVirtual), s.LastRequest.URL.Path)
assert.JSONEq(s.T(), `
{"name":"test",
"sourceAddressTranslation":{},
"profiles":[
{"name":"/Common/tcp","context":"clientside"},
{"name":"/Common/tcp","context":"serverside"}
]
}`, s.LastRequestBody)

}

func (s *LTMTestSuite) TestDeleteVirtualServer() {
s.Client.DeleteVirtualServer("/Common/test-vs")

Expand Down