Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Commit

Permalink
added addLocations, removeLocations, setAvailableLocations to VGBDTG …
Browse files Browse the repository at this point in the history
…service
  • Loading branch information
maximilien committed Dec 8, 2015
1 parent 9afe56f commit 0ec3b5f
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package data_types

type SoftLayer_Virtual_Guest_Block_Device_Template_GroupInitParameters struct {
Parameters SoftLayer_Virtual_Guest_Block_Device_Template_GroupInitParameter `json:"parameters"`
}

type SoftLayer_Virtual_Guest_Block_Device_Template_GroupInitParameter struct {
AccountId int `json:"accountId"`
}

type SoftLayer_Virtual_Guest_Block_Device_Template_Group_LocationsInitParameters struct {
Parameters SoftLayer_Virtual_Guest_Block_Device_Template_Group_LocationsInitParameter `json:"parameters"`
}

type SoftLayer_Virtual_Guest_Block_Device_Template_Group_LocationsInitParameter struct {
Locations []SoftLayer_Location `json:"locations"`
}
72 changes: 72 additions & 0 deletions services/softLayer_virtual_guest_block_device_template_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,75 @@ func (slvgbdtg *softLayer_Virtual_Guest_Block_Device_Template_Group_Service) Per

return true, nil
}

func (slvgbdtg *softLayer_Virtual_Guest_Block_Device_Template_Group_Service) AddLocations(id int, locations []datatypes.SoftLayer_Location) (bool, error) {
parameters := datatypes.SoftLayer_Virtual_Guest_Block_Device_Template_Group_LocationsInitParameters{
Parameters: datatypes.SoftLayer_Virtual_Guest_Block_Device_Template_Group_LocationsInitParameter{
Locations: locations,
},
}

requestBody, err := json.Marshal(parameters)
if err != nil {
return false, err
}

response, err := slvgbdtg.client.DoRawHttpRequest(fmt.Sprintf("%s/%d/addLocations.json", slvgbdtg.GetName(), id), "POST", bytes.NewBuffer(requestBody))
if err != nil {
return false, err
}

if res := string(response[:]); res != "true" {
return false, errors.New(fmt.Sprintf("Failed to add locations access to VGDBTG with ID: %d", id))
}

return true, nil
}

func (slvgbdtg *softLayer_Virtual_Guest_Block_Device_Template_Group_Service) RemoveLocations(id int, locations []datatypes.SoftLayer_Location) (bool, error) {
parameters := datatypes.SoftLayer_Virtual_Guest_Block_Device_Template_Group_LocationsInitParameters{
Parameters: datatypes.SoftLayer_Virtual_Guest_Block_Device_Template_Group_LocationsInitParameter{
Locations: locations,
},
}

requestBody, err := json.Marshal(parameters)
if err != nil {
return false, err
}

response, err := slvgbdtg.client.DoRawHttpRequest(fmt.Sprintf("%s/%d/removeLocations.json", slvgbdtg.GetName(), id), "POST", bytes.NewBuffer(requestBody))
if err != nil {
return false, err
}

if res := string(response[:]); res != "true" {
return false, errors.New(fmt.Sprintf("Failed to remove locations access to VGDBTG with ID: %d", id))
}

return true, nil
}

func (slvgbdtg *softLayer_Virtual_Guest_Block_Device_Template_Group_Service) SetAvailableLocations(id int, locations []datatypes.SoftLayer_Location) (bool, error) {
parameters := datatypes.SoftLayer_Virtual_Guest_Block_Device_Template_Group_LocationsInitParameters{
Parameters: datatypes.SoftLayer_Virtual_Guest_Block_Device_Template_Group_LocationsInitParameter{
Locations: locations,
},
}

requestBody, err := json.Marshal(parameters)
if err != nil {
return false, err
}

response, err := slvgbdtg.client.DoRawHttpRequest(fmt.Sprintf("%s/%d/setAvailableLocations.json", slvgbdtg.GetName(), id), "POST", bytes.NewBuffer(requestBody))
if err != nil {
return false, err
}

if res := string(response[:]); res != "true" {
return false, errors.New(fmt.Sprintf("Failed to set available locations access to VGDBTG with ID: %d", id))
}

return true, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ var _ = Describe("SoftLayer_Virtual_Guest_Service", func() {
vgbdtgService softlayer.SoftLayer_Virtual_Guest_Block_Device_Template_Group_Service

vgbdtGroup datatypes.SoftLayer_Virtual_Guest_Block_Device_Template_Group

locations []datatypes.SoftLayer_Location
)

BeforeEach(func() {
Expand Down Expand Up @@ -314,4 +316,71 @@ var _ = Describe("SoftLayer_Virtual_Guest_Service", func() {
Expect(permitSharing).To(BeTrue())
})
})

Context("#XyzLocations", func() {
BeforeEach(func() {
locations = []datatypes.SoftLayer_Location{
datatypes.SoftLayer_Location{
Id: 0,
Name: "0",
LongName: "Location 0",
},
datatypes.SoftLayer_Location{
Id: 1,
Name: "1",
LongName: "Location 1",
},
datatypes.SoftLayer_Location{
Id: 2,
Name: "2",
LongName: "Location 2",
},
}
})

Context("#AddLocations", func() {
BeforeEach(func() {
vgbdtGroup.Id = 1234567
fakeClient.DoRawHttpRequestResponse, err = testhelpers.ReadJsonTestFixtures("services", "SoftLayer_Virtual_Guest_Block_Device_Template_Group_Service_addLocations.json")
Expect(err).ToNot(HaveOccurred())
})

It("sucessfully adds locations to VGBDTG instance", func() {
result, err := vgbdtgService.AddLocations(vgbdtGroup.Id, locations)
Expect(err).ToNot(HaveOccurred())

Expect(result).To(BeTrue())
})
})

Context("#RemoveLocations", func() {
BeforeEach(func() {
vgbdtGroup.Id = 1234567
fakeClient.DoRawHttpRequestResponse, err = testhelpers.ReadJsonTestFixtures("services", "SoftLayer_Virtual_Guest_Block_Device_Template_Group_Service_removeLocations.json")
Expect(err).ToNot(HaveOccurred())
})

It("sucessfully removes locations to VGBDTG instance", func() {
result, err := vgbdtgService.RemoveLocations(vgbdtGroup.Id, locations)
Expect(err).ToNot(HaveOccurred())

Expect(result).To(BeTrue())
})
})

Context("#SetAvailableLocations", func() {
BeforeEach(func() {
vgbdtGroup.Id = 1234567
fakeClient.DoRawHttpRequestResponse, err = testhelpers.ReadJsonTestFixtures("services", "SoftLayer_Virtual_Guest_Block_Device_Template_Group_Service_setAvailableLocations.json")
Expect(err).ToNot(HaveOccurred())
})

It("sucessfully sets available locations to VGBDTG instance", func() {
result, err := vgbdtgService.SetAvailableLocations(vgbdtGroup.Id, locations)
Expect(err).ToNot(HaveOccurred())

Expect(result).To(BeTrue())
})
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
type SoftLayer_Virtual_Guest_Block_Device_Template_Group_Service interface {
Service

AddLocations(id int, locations []datatypes.SoftLayer_Location) (bool, error)

CreateFromExternalSource(configuration datatypes.SoftLayer_Container_Virtual_Guest_Block_Device_Template_Configuration) (datatypes.SoftLayer_Virtual_Guest_Block_Device_Template_Group, error)
CopyToExternalSource(configuration datatypes.SoftLayer_Container_Virtual_Guest_Block_Device_Template_Configuration) (bool, error)

Expand All @@ -26,4 +28,8 @@ type SoftLayer_Virtual_Guest_Block_Device_Template_Group_Service interface {
GetTransaction(id int) (datatypes.SoftLayer_Provisioning_Version1_Transaction, error)

PermitSharingAccess(id int, accountId int) (bool, error)

RemoveLocations(id int, locations []datatypes.SoftLayer_Location) (bool, error)

SetAvailableLocations(id int, locations []datatypes.SoftLayer_Location) (bool, error)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
true

0 comments on commit 0ec3b5f

Please sign in to comment.