packer-cn/vendor/github.com/profitbricks/profitbricks-sdk-go/test_helpers.go

73 lines
1.5 KiB
Go
Raw Normal View History

2016-06-28 22:35:41 -04:00
package profitbricks
2016-08-01 07:15:21 -04:00
import (
"fmt"
"time"
)
2016-06-28 22:35:41 -04:00
func mkdcid(name string) string {
2016-08-01 07:15:21 -04:00
request := Datacenter{
Properties: DatacenterProperties{
2016-06-28 22:35:41 -04:00
Name: name,
Description: "description",
Location: "us/las",
},
}
dc := CreateDatacenter(request)
fmt.Println("===========================")
fmt.Println("Created a DC " + name)
fmt.Println("Created a DC id " + dc.Id)
2016-08-01 07:15:21 -04:00
fmt.Println(dc.StatusCode)
2016-06-28 22:35:41 -04:00
fmt.Println("===========================")
return dc.Id
}
func mksrvid(srv_dcid string) string {
2016-08-01 07:15:21 -04:00
var req = Server{
Properties: ServerProperties{
2016-06-28 22:35:41 -04:00
Name: "GO SDK test",
Ram: 1024,
Cores: 2,
},
}
srv := CreateServer(srv_dcid, req)
fmt.Println("===========================")
fmt.Println("Created a server " + srv.Id)
2016-08-01 07:15:21 -04:00
fmt.Println(srv.StatusCode)
2016-06-28 22:35:41 -04:00
fmt.Println("===========================")
2016-08-01 07:15:21 -04:00
waitTillProvisioned(srv.Headers.Get("Location"))
2016-06-28 22:35:41 -04:00
return srv.Id
}
func mknic(lbal_dcid, serverid string) string {
2016-08-01 07:15:21 -04:00
var request = Nic{
Properties: NicProperties{
2016-06-28 22:35:41 -04:00
Name: "GO SDK Original Nic",
2016-08-01 07:15:21 -04:00
Lan: 1,
2016-06-28 22:35:41 -04:00
},
}
resp := CreateNic(lbal_dcid, serverid, request)
fmt.Println("===========================")
fmt.Println("created a nic at server " + serverid)
fmt.Println("created a nic with id " + resp.Id)
2016-08-01 07:15:21 -04:00
fmt.Println(resp.StatusCode)
2016-06-28 22:35:41 -04:00
fmt.Println("===========================")
return resp.Id
}
2016-08-01 07:15:21 -04:00
func waitTillProvisioned(path string) {
waitCount := 20
fmt.Println(path)
for i := 0; i < waitCount; i++ {
request := GetRequestStatus(path)
if request.Metadata.Status == "DONE" {
break
}
time.Sleep(10 * time.Second)
i++
}
}