-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #186 from softlayer/IterTests
Iteration Helpers
- Loading branch information
Showing
19 changed files
with
463 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/softlayer/softlayer-go/filter" | ||
"github.com/softlayer/softlayer-go/helpers/virtual" | ||
"github.com/softlayer/softlayer-go/session" | ||
"github.com/softlayer/softlayer-go/sl" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(listVirtCmd) | ||
} | ||
|
||
var listVirtCmd = &cobra.Command{ | ||
Use: "virt-list", | ||
Short: "Lists all VSI on the account", | ||
Long: `Lists all VSI on the account using an iterative aproach.`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return RunListVirtCmd(cmd, args) | ||
}, | ||
} | ||
|
||
func RunListVirtCmd(cmd *cobra.Command, args []string) error { | ||
|
||
objectMask := "mask[id,hostname,domain,primaryIpAddress,primaryBackendIpAddress]" | ||
// When using a result Limit to break up your API request, its important to include an orderBy objectFilter | ||
// to enforce an order on the query, as the database might not always return results in the same order between | ||
// queries otherwise | ||
filters := filter.New() | ||
filters = append(filters, filter.Path("virtualGuests.id").OrderBy("ASC")) | ||
objectFilter := filters.Build() | ||
// Sets up the session with authentication headers. | ||
sess := session.New() | ||
// uncomment to output API calls as they are made. | ||
sess.Debug = true | ||
|
||
// Sets the mask, filter, result limit, and then makes the API call SoftLayer_Account::getHardware() | ||
limit := 5 | ||
options := sl.Options{ | ||
Mask: objectMask, | ||
Filter: objectFilter, | ||
Limit: &limit, | ||
} | ||
|
||
servers, err := virtual.GetVirtualGuestsIter(sess, &options) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Printf("Id, Hostname, Domain, IP Address\n") | ||
|
||
for _, server := range servers { | ||
ipAddress := "-" | ||
// Servers with a private only connection will not have a primary IP | ||
if server.PrimaryIpAddress != nil { | ||
ipAddress = *server.PrimaryIpAddress | ||
} | ||
fmt.Printf("%v, %v, %v, %v\n", *server.Id, *server.Hostname, *server.Domain, ipAddress) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package hardware_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/softlayer/softlayer-go/helpers/hardware" | ||
"github.com/softlayer/softlayer-go/session/sessionfakes" | ||
"github.com/softlayer/softlayer-go/sl" | ||
"testing" | ||
) | ||
|
||
func TestServices(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Helper Hardware Tests") | ||
} | ||
|
||
var _ = Describe("Helper Hardware Tests", func() { | ||
var slsession *sessionfakes.FakeSLSession | ||
var options *sl.Options | ||
BeforeEach(func() { | ||
limit := 10 | ||
slsession = &sessionfakes.FakeSLSession{} | ||
options = &sl.Options{ | ||
Mask: "mask[id,hostname]", | ||
Filter: "", | ||
Limit: &limit, | ||
} | ||
}) | ||
|
||
Context("GetHardwareIter Tests", func() { | ||
|
||
It("API call made properly", func() { | ||
_, err := hardware.GetHardwareIter(slsession, options) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(slsession.DoRequestCallCount()).To(Equal(1)) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package virtual_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
// "github.com/softlayer/softlayer-go/datatypes" | ||
|
||
"github.com/softlayer/softlayer-go/helpers/virtual" | ||
"github.com/softlayer/softlayer-go/session/sessionfakes" | ||
"github.com/softlayer/softlayer-go/sl" | ||
"testing" | ||
) | ||
|
||
func TestServices(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Helper Virtual Tests") | ||
} | ||
|
||
var _ = Describe("Helper Virtual Tests", func() { | ||
var slsession *sessionfakes.FakeSLSession | ||
var options *sl.Options | ||
BeforeEach(func() { | ||
limit := 10 | ||
slsession = &sessionfakes.FakeSLSession{} | ||
options = &sl.Options{ | ||
Mask: "mask[id,hostname]", | ||
Filter: "", | ||
Limit: &limit, | ||
} | ||
}) | ||
|
||
Context("GetVirtualGuestsIter Tests", func() { | ||
|
||
It("API call made properly", func() { | ||
_, err := virtual.GetVirtualGuestsIter(slsession, options) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(slsession.DoRequestCallCount()).To(Equal(1)) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.