diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json
index 2d7256c50..1f8642287 100644
--- a/Godeps/Godeps.json
+++ b/Godeps/Godeps.json
@@ -1001,6 +1001,11 @@
{
"ImportPath": "gopkg.in/xmlpath.v2",
"Rev": "860cbeca3ebcc600db0b213c0e83ad6ce91f5739"
+ },
+ {
+ "ImportPath": "github.com/profitbricks/profitbricks-sdk-go",
+ "Comment": "v2.1.0",
+ "Rev": "565df72e7b92b63c68c17b2c305256ba09a251f4"
}
]
}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/README.md b/vendor/github.com/profitbricks/profitbricks-sdk-go/README.md
index 055c63096..b41efd679 100644
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/README.md
+++ b/vendor/github.com/profitbricks/profitbricks-sdk-go/README.md
@@ -98,15 +98,15 @@ ProfitBricks introduces the concept of Data Centers. These are logically separat
The following code example shows you how to programmatically create a data center:
```go
-request := profitbricks.CreateDatacenterRequest{
- DCProperties: profitbricks.DCProperties{
- Name: "test",
+dcrequest := profitbricks.Datacenter{
+ Properties: profitbricks.DatacenterProperties{
+ Name: "example.go3",
Description: "description",
Location: "us/lasdev",
- },
-}
+ },
+ }
-response := profitbricks.CreateDatacenter(request)
+datacenter := profitbricks.CreateDatacenter(dcrequest)
```
## How To: Create Data Center with Multiple Resources
@@ -139,7 +139,7 @@ datacenter := model.Datacenter{
Image:"1f46a4a3-3f47-11e6-91c6-52540005ab80",
Bus:"VIRTIO",
ImagePassword:"test1234",
- SshKeys: []string{"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCoLVLHON4BSK3D8L4H79aFo+0cj7VM2NiRR/K9wrfkK/XiTc7FlEU4Bs8WLZcsIOxbCGWn2zKZmrLaxYlY+/3aJrxDxXYCy8lRUMnqcQ2JCFY6tpZt/DylPhS9L6qYNpJ0F4FlqRsWxsjpF8TDdJi64k2JFJ8TkvX36P2/kqyFfI+N0/axgjhqV3BgNgApvMt9jxWB5gi8LgDpw9b+bHeMS7TrAVDE7bzT86dmfbTugtiME8cIday8YcRb4xAFgRH8XJVOcE3cs390V/dhgCKy1P5+TjQMjKbFIy2LJoxb7bd38kAl1yafZUIhI7F77i7eoRidKV71BpOZsaPEbWUP jasmin@Jasmins-MBP"},
+ SshKeys: []string{"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCoLVLHON4BSK3D8L4H79aFo..."},
},
},
},
@@ -183,14 +183,13 @@ The server create method has a list of required parameters followed by a hash of
The following example shows you how to create a new server in the data center created above:
```go
-request = CreateServerRequest{
- ServerProperties: ServerProperties{
- Name: "go01",
- Ram: 1024,
- Cores: 2,
- },
+req := profitbricks.Server{
+ Properties: profitbricks.ServerProperties{
+ Name: "go01",
+ Ram: 1024,
+ Cores: 2,
+ },
}
-
server := CreateServer(datacenter.Id, req)
```
@@ -209,14 +208,13 @@ This will return a [collection](#Collection) object
ProfitBricks allows for the creation of multiple storage volumes that can be attached and detached as needed. It is useful to attach an image when creating a storage volume. The storage size is in gigabytes.
```go
-volumerequest := CreateVolumeRequest{
- VolumeProperties: VolumeProperties{
- Size: 1,
- Name: "Volume Test",
- ImageId: "imageid",
- Type: "HDD",
- SshKey: []string{"hQGOEJeFL91EG3+l9TtRbWNjzhDVHeLuL3NWee6bekA="},
- },
+volumerequest := profitbricks.Volume{
+ Properties: profitbricks.VolumeProperties{
+ Size: 1,
+ Name: "Volume Test",
+ LicenceType: "LINUX",
+ Type: "HDD",
+ },
}
storage := CreateVolume(datacenter.Id, volumerequest)
@@ -274,6 +272,8 @@ package main
import (
"fmt"
+ "time"
+
"github.com/profitbricks/profitbricks-sdk-go"
)
@@ -282,11 +282,11 @@ func main() {
//Sets username and password
profitbricks.SetAuth("username", "password")
//Sets depth.
- profitbricks.SetDepth(5)
+ profitbricks.SetDepth("5")
- dcrequest := profitbricks.CreateDatacenterRequest{
- DCProperties: profitbricks.DCProperties{
- Name: "test",
+ dcrequest := profitbricks.Datacenter{
+ Properties: profitbricks.DatacenterProperties{
+ Name: "example.go3",
Description: "description",
Location: "us/lasdev",
},
@@ -294,25 +294,21 @@ func main() {
datacenter := profitbricks.CreateDatacenter(dcrequest)
- serverrequest := profitbricks.CreateServerRequest{
- ServerProperties: profitbricks.ServerProperties{
+ serverrequest := profitbricks.Server{
+ Properties: profitbricks.ServerProperties{
Name: "go01",
Ram: 1024,
Cores: 2,
},
}
+ server := profitbricks.CreateServer(datacenter.Id, serverrequest)
- server := profitbricks.CreateServer(datacenter.Id, serverrequest)
-
- images := profitbricks.ListImages()
-
- fmt.Println(images.Items)
-
- volumerequest := profitbricks.CreateVolumeRequest{
- VolumeProperties: profitbricks.VolumeProperties{
+ volumerequest := profitbricks.Volume{
+ Properties: profitbricks.VolumeProperties{
Size: 1,
Name: "Volume Test",
LicenceType: "LINUX",
+ Type: "HDD",
},
}
@@ -324,57 +320,23 @@ func main() {
Ram: 256,
}
- resp := profitbricks.PatchServer(datacenter.Id, server.Id, serverupdaterequest)
+ profitbricks.PatchServer(datacenter.Id, server.Id, serverupdaterequest)
+ //It takes a moment for a volume to be provisioned so we wait.
+ time.Sleep(60 * time.Second)
+
+ profitbricks.AttachVolume(datacenter.Id, server.Id, storage.Id)
volumes := profitbricks.ListVolumes(datacenter.Id)
+ fmt.Println(volumes.Items)
servers := profitbricks.ListServers(datacenter.Id)
+ fmt.Println(servers.Items)
datacenters := profitbricks.ListDatacenters()
+ fmt.Println(datacenters.Items)
profitbricks.DeleteServer(datacenter.Id, server.Id)
profitbricks.DeleteDatacenter(datacenter.Id)
}
```
-# Return Types
-
-## Resp struct
-* Resp is the struct returned by all REST request functions
-
-```go
-type Resp struct {
- Req *http.Request
- StatusCode int
- Headers http.Header
- Body []byte
-}
-```
-
-## Instance struct
-* `Get`, `Create`, and `Patch` functions all return an Instance struct.
-* A Resp struct is embedded in the Instance struct.
-* The raw server response is available as `Instance.Resp.Body`.
-
-```go
-type Instance struct {
- Id_Type_Href
- MetaData StringMap `json:"metaData"`
- Properties StringIfaceMap `json:"properties"`
- Entities StringCollectionMap `json:"entities"`
- Resp Resp `json:"-"`
-}
-```
-
-## Collection struct
-* Collection Structs contain Instance arrays.
-* List functions return Collections
-
-```go
-type Collection struct {
- Id_Type_Href
- Items []Instance `json:"items,omitempty"`
- Resp Resp `json:"-"`
-}
-```
-
# Support
You are welcome to contact us with questions or comments at [ProfitBricks DevOps Central](https://devops.profitbricks.com/). Please report any issues via [GitHub's issue tracker](https://github.com/profitbricks/profitbricks-sdk-go/issues).
\ No newline at end of file
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/datacenter.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/datacenter.go
index b9c5ba69c..eb3d9094f 100644
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/datacenter.go
+++ b/vendor/github.com/profitbricks/profitbricks-sdk-go/datacenter.go
@@ -1,55 +1,121 @@
package profitbricks
import (
+ "bytes"
"encoding/json"
- "github.com/profitbricks/profitbricks-sdk-go/model"
+ "net/http"
+ "time"
)
-type CreateDatacenterRequest struct {
- DCProperties `json:"properties"`
+type Datacenter struct {
+ Id string `json:"id,omitempty"`
+ Type_ string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+ Metadata *DatacenterElementMetadata `json:"metadata,omitempty"`
+ Properties DatacenterProperties `json:"properties,omitempty"`
+ Entities DatacenterEntities `json:"entities,omitempty"`
+ Response string `json:"Response,omitempty"`
+ Headers *http.Header `json:"headers,omitempty"`
+ StatusCode int `json:"headers,omitempty"`
}
-type DCProperties struct {
+type DatacenterElementMetadata struct {
+ CreatedDate time.Time `json:"createdDate,omitempty"`
+ CreatedBy string `json:"createdBy,omitempty"`
+ Etag string `json:"etag,omitempty"`
+ LastModifiedDate time.Time `json:"lastModifiedDate,omitempty"`
+ LastModifiedBy string `json:"lastModifiedBy,omitempty"`
+ State string `json:"state,omitempty"`
+}
+
+type DatacenterProperties struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Location string `json:"location,omitempty"`
+ Version int32 `json:"version,omitempty"`
}
-// ListDatacenters returns a Collection struct
-func ListDatacenters() Collection {
+type DatacenterEntities struct {
+ Servers *Servers `json:"servers,omitempty"`
+ Volumes *Volumes `json:"volumes,omitempty"`
+ Loadbalancers *Loadbalancers `json:"loadbalancers,omitempty"`
+ Lans *Lans `json:"lans,omitempty"`
+}
+
+type Datacenters struct {
+ Id string `json:"id,omitempty"`
+ Type_ string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+ Items []Datacenter `json:"items,omitempty"`
+ Response string `json:"Response,omitempty"`
+ Headers *http.Header `json:"headers,omitempty"`
+ StatusCode int `json:"headers,omitempty"`
+}
+
+func ListDatacenters() Datacenters {
path := dc_col_path()
- return is_list(path)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ resp := do(req)
+ return toDataCenters(resp)
}
-// CreateDatacenter creates a datacenter and returns a Instance struct
-func CreateDatacenter(dc CreateDatacenterRequest) Instance {
+func CreateDatacenter(dc Datacenter) Datacenter {
obj, _ := json.Marshal(dc)
path := dc_col_path()
- return is_post(path, obj)
+ url := mk_url(path)
+ req, _ := http.NewRequest("POST", url, bytes.NewBuffer(obj))
+ req.Header.Add("Content-Type", FullHeader)
+
+ return toDataCenter(do(req))
}
-func CompositeCreateDatacenter(datacenter model.Datacenter) model.Datacenter {
+func CompositeCreateDatacenter(datacenter Datacenter) Datacenter {
obj, _ := json.Marshal(datacenter)
path := dc_col_path()
- return is_composite_post(path, obj)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("POST", url, bytes.NewBuffer(obj))
+ req.Header.Add("Content-Type", FullHeader)
+ return toDataCenter(do(req))
}
-// GetDatacenter returns a Instance struct where id == dcid
-func GetDatacenter(dcid string) Instance {
+func GetDatacenter(dcid string) Datacenter {
path := dc_path(dcid)
- return is_get(path)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ return toDataCenter(do(req))
}
-// PatchDatacenter replaces any Datacenter properties with the values in jason
-//returns an Instance struct where id ==dcid
-func PatchDatacenter(dcid string, obj map[string]string) Instance {
+func PatchDatacenter(dcid string, obj DatacenterProperties) Datacenter {
jason_patch := []byte(MkJson(obj))
path := dc_path(dcid)
- return is_patch(path, jason_patch)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("PATCH", url, bytes.NewBuffer(jason_patch))
+ req.Header.Add("Content-Type", PatchHeader)
+ return toDataCenter(do(req))
}
-// Deletes a Datacenter where id==dcid
func DeleteDatacenter(dcid string) Resp {
path := dc_path(dcid)
return is_delete(path)
}
+
+func toDataCenter(resp Resp) Datacenter {
+ var dc Datacenter
+ json.Unmarshal(resp.Body, &dc)
+ dc.Response = string(resp.Body)
+ dc.Headers = &resp.Headers
+ dc.StatusCode = resp.StatusCode
+ return dc
+}
+
+func toDataCenters(resp Resp) Datacenters {
+ var col Datacenters
+ json.Unmarshal(resp.Body, &col)
+ col.Response = string(resp.Body)
+ col.Headers = &resp.Headers
+ col.StatusCode = resp.StatusCode
+ return col
+}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/firewallrule.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/firewallrule.go
new file mode 100644
index 000000000..11cae62a5
--- /dev/null
+++ b/vendor/github.com/profitbricks/profitbricks-sdk-go/firewallrule.go
@@ -0,0 +1,99 @@
+package profitbricks
+
+import (
+ "bytes"
+ "encoding/json"
+ "net/http"
+)
+
+type FirewallRule struct {
+ Id string `json:"id,omitempty"`
+ Type_ string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+ Metadata *DatacenterElementMetadata `json:"metadata,omitempty"`
+ Properties FirewallruleProperties `json:"properties,omitempty"`
+ Response string `json:"Response,omitempty"`
+ Headers *http.Header `json:"headers,omitempty"`
+ StatusCode int `json:"headers,omitempty"`
+}
+
+type FirewallruleProperties struct {
+ Name string `json:"name,omitempty"`
+ Protocol string `json:"protocol,omitempty"`
+ SourceMac string `json:"sourceMac,omitempty"`
+ SourceIp string `json:"sourceIp,omitempty"`
+ TargetIp string `json:"targetIp,omitempty"`
+ IcmpCode int `json:"icmpCode,omitempty"`
+ IcmpType int `json:"icmpType,omitempty"`
+ PortRangeStart int `json:"portRangeStart,omitempty"`
+ PortRangeEnd int `json:"portRangeEnd,omitempty"`
+}
+
+type FirewallRules struct {
+ Id string `json:"id,omitempty"`
+ Type_ string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+ Items []FirewallRule `json:"items,omitempty"`
+ Response string `json:"Response,omitempty"`
+ Headers *http.Header `json:"headers,omitempty"`
+ StatusCode int `json:"headers,omitempty"`
+}
+
+func ListFirewallRules(dcId string, serverid string, nicId string) FirewallRules {
+ path := fwrule_col_path(dcId, serverid, nicId)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ resp := do(req)
+ return toFirewallRules(resp)
+}
+
+func GetFirewallRule(dcid string, srvid string, nicId string, fwId string) FirewallRule {
+ path := fwrule_path(dcid, srvid, nicId, fwId)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ resp := do(req)
+ return toFirewallRule(resp)
+}
+
+func CreateFirewallRule(dcid string, srvid string, nicId string, fw FirewallRule) FirewallRule {
+ path := fwrule_col_path(dcid, srvid, nicId)
+ url := mk_url(path) + `?depth=` + Depth
+ obj, _ := json.Marshal(fw)
+ req, _ := http.NewRequest("POST", url, bytes.NewBuffer(obj))
+ req.Header.Add("Content-Type", FullHeader)
+ return toFirewallRule(do(req))
+}
+
+func PatchFirewallRule(dcid string, srvid string, nicId string, fwId string, obj FirewallruleProperties) FirewallRule {
+ jason_patch := []byte(MkJson(obj))
+ path := fwrule_path(dcid, srvid, nicId, fwId)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("PATCH", url, bytes.NewBuffer(jason_patch))
+ req.Header.Add("Content-Type", PatchHeader)
+ return toFirewallRule(do(req))
+}
+
+func DeleteFirewallRule(dcid string, srvid string, nicId string, fwId string) Resp {
+ path := fwrule_path(dcid, srvid, nicId, fwId)
+ return is_delete(path)
+}
+
+func toFirewallRule(resp Resp) FirewallRule {
+ var dc FirewallRule
+ json.Unmarshal(resp.Body, &dc)
+ dc.Response = string(resp.Body)
+ dc.Headers = &resp.Headers
+ dc.StatusCode = resp.StatusCode
+ return dc
+}
+
+func toFirewallRules(resp Resp) FirewallRules {
+ var col FirewallRules
+ json.Unmarshal(resp.Body, &col)
+ col.Response = string(resp.Body)
+ col.Headers = &resp.Headers
+ col.StatusCode = resp.StatusCode
+ return col
+}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/image.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/image.go
index b27dcb8ae..95ec9e25a 100644
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/image.go
+++ b/vendor/github.com/profitbricks/profitbricks-sdk-go/image.go
@@ -1,27 +1,98 @@
package profitbricks
+import (
+ "encoding/json"
+ "net/http"
+)
+
+type Image struct {
+ Id string `json:"id,omitempty"`
+ Type string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+ Metadata *DatacenterElementMetadata `json:"metadata,omitempty"`
+ Properties ImageProperties `json:"properties,omitempty"`
+ Response string `json:"Response,omitempty"`
+ Headers *http.Header `json:"headers,omitempty"`
+ StatusCode int `json:"headers,omitempty"`
+}
+
+type ImageProperties struct {
+ Name string `json:"name,omitempty"`
+ Description string `json:"description,omitempty"`
+ Location string `json:"location,omitempty"`
+ Size int `json:"size,omitempty"`
+ CpuHotPlug bool `json:"cpuHotPlug,omitempty"`
+ CpuHotUnplug bool `json:"cpuHotUnplug,omitempty"`
+ RamHotPlug bool `json:"ramHotPlug,omitempty"`
+ RamHotUnplug bool `json:"ramHotUnplug,omitempty"`
+ NicHotPlug bool `json:"nicHotPlug,omitempty"`
+ NicHotUnplug bool `json:"nicHotUnplug,omitempty"`
+ DiscVirtioHotPlug bool `json:"discVirtioHotPlug,omitempty"`
+ DiscVirtioHotUnplug bool `json:"discVirtioHotUnplug,omitempty"`
+ DiscScsiHotPlug bool `json:"discScsiHotPlug,omitempty"`
+ DiscScsiHotUnplug bool `json:"discScsiHotUnplug,omitempty"`
+ LicenceType string `json:"licenceType,omitempty"`
+ ImageType string `json:"imageType,omitempty"`
+ Public bool `json:"public,omitempty"`
+ Response string `json:"Response,omitempty"`
+ Headers *http.Header `json:"headers,omitempty"`
+ StatusCode int `json:"headers,omitempty"`
+}
+
+type Images struct {
+ Id string `json:"id,omitempty"`
+ Type_ string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+ Items []Image `json:"items,omitempty"`
+ Response string `json:"Response,omitempty"`
+ Headers *http.Header `json:"headers,omitempty"`
+ StatusCode int `json:"headers,omitempty"`
+}
+
+type Cdroms struct {
+ Id string `json:"id,omitempty"`
+ Type_ string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+ Items []Image `json:"items,omitempty"`
+ Response string `json:"Response,omitempty"`
+ Headers *http.Header `json:"headers,omitempty"`
+ StatusCode int `json:"headers,omitempty"`
+}
+
// ListImages returns an Collection struct
-func ListImages() Collection {
+func ListImages() Images {
path := image_col_path()
- return is_list(path)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ resp := do(req)
+ return toImages(resp)
}
// GetImage returns an Instance struct where id ==imageid
-func GetImage(imageid string) Instance {
+func GetImage(imageid string) Image {
path := image_path(imageid)
- return is_get(path)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ resp := do(req)
+ return toImage(resp)
}
-// PatchImage replaces any image properties from values in jason
-//returns an Instance struct where id ==imageid
-func PatchImage(imageid string, obj map[string]string) Instance {
- jason := []byte(MkJson(obj))
- path := image_path(imageid)
- return is_patch(path, jason)
+func toImage(resp Resp) Image {
+ var image Image
+ json.Unmarshal(resp.Body, &image)
+ image.Response = string(resp.Body)
+ image.Headers = &resp.Headers
+ image.StatusCode = resp.StatusCode
+ return image
}
-// Deletes an image where id==imageid
-func DeleteImage(imageid string) Resp {
- path := image_path(imageid)
- return is_delete(path)
+func toImages(resp Resp) Images {
+ var col Images
+ json.Unmarshal(resp.Body, &col)
+ col.Response = string(resp.Body)
+ col.Headers = &resp.Headers
+ col.StatusCode = resp.StatusCode
+ return col
}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/ipblock.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/ipblock.go
index 91900c1e1..1b78262bb 100644
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/ipblock.go
+++ b/vendor/github.com/profitbricks/profitbricks-sdk-go/ipblock.go
@@ -1,34 +1,82 @@
package profitbricks
-import "encoding/json"
+import (
+ "bytes"
+ "encoding/json"
+ "net/http"
+)
-type IPBlockReserveRequest struct {
- IPBlockProperties `json:"properties"`
+type IpBlock struct {
+ Id string `json:"id,omitempty"`
+ Type_ string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+ Metadata *DatacenterElementMetadata `json:"metadata,omitempty"`
+ Properties IpBlockProperties `json:"properties,omitempty"`
+ Response string `json:"Response,omitempty"`
+ Headers *http.Header `json:"headers,omitempty"`
+ StatusCode int `json:"headers,omitempty"`
}
-type IPBlockProperties struct {
- Size int `json:"size,omitempty"`
- Location string `json:"location,omitempty"`
+type IpBlockProperties struct {
+ Ips []string `json:"ips,omitempty"`
+ Location string `json:"location,omitempty"`
+ Size int `json:"size,omitempty"`
+}
+
+type IpBlocks struct {
+ Id string `json:"id,omitempty"`
+ Type_ string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+ Items []IpBlock `json:"items,omitempty"`
+ Response string `json:"Response,omitempty"`
+ Headers *http.Header `json:"headers,omitempty"`
+ StatusCode int `json:"headers,omitempty"`
}
// ListIpBlocks
-func ListIpBlocks() Collection {
+func ListIpBlocks() IpBlocks {
path := ipblock_col_path()
- return is_list(path)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ return toIpBlocks(do(req))
}
-func ReserveIpBlock(request IPBlockReserveRequest) Instance {
+func ReserveIpBlock(request IpBlock) IpBlock {
obj, _ := json.Marshal(request)
path := ipblock_col_path()
- return is_post(path, obj)
-
+ url := mk_url(path)
+ req, _ := http.NewRequest("POST", url, bytes.NewBuffer(obj))
+ req.Header.Add("Content-Type", FullHeader)
+ return toIpBlock(do(req))
}
-func GetIpBlock(ipblockid string) Instance {
+func GetIpBlock(ipblockid string) IpBlock {
path := ipblock_path(ipblockid)
- return is_get(path)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ return toIpBlock(do(req))
}
func ReleaseIpBlock(ipblockid string) Resp {
path := ipblock_path(ipblockid)
return is_delete(path)
}
+
+func toIpBlock(resp Resp) IpBlock {
+ var obj IpBlock
+ json.Unmarshal(resp.Body, &obj)
+ obj.Response = string(resp.Body)
+ obj.Headers = &resp.Headers
+ obj.StatusCode = resp.StatusCode
+ return obj
+}
+
+func toIpBlocks(resp Resp) IpBlocks {
+ var col IpBlocks
+ json.Unmarshal(resp.Body, &col)
+ col.Response = string(resp.Body)
+ col.Headers = &resp.Headers
+ col.StatusCode = resp.StatusCode
+ return col
+}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/lan.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/lan.go
index 88cb16bb9..2b7f85ed4 100644
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/lan.go
+++ b/vendor/github.com/profitbricks/profitbricks-sdk-go/lan.go
@@ -1,43 +1,87 @@
package profitbricks
-import "encoding/json"
+import (
+ "bytes"
+ "encoding/json"
+ "net/http"
+)
-type CreateLanRequest struct {
- LanProperties `json:"properties"`
+type Lan struct {
+ Id string `json:"id,omitempty"`
+ Type_ string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+ Metadata *DatacenterElementMetadata `json:"metadata,omitempty"`
+ Properties LanProperties `json:"properties,omitempty"`
+ Entities *LanEntities `json:"entities,omitempty"`
+ Response string `json:"Response,omitempty"`
+ Headers *http.Header `json:"headers,omitempty"`
+ StatusCode int `json:"headers,omitempty"`
}
type LanProperties struct {
- Name string `json:"name,omitempty"`
- Public bool `json:"public,omitempty"`
- Nics []string `json:"nics,omitempty"`
+ Name string `json:"name,omitempty"`
+ Public bool `json:"public,omitempty"`
+}
+
+type LanEntities struct {
+ Nics *LanNics `json:"nics,omitempty"`
+}
+
+type LanNics struct {
+ Id string `json:"id,omitempty"`
+ Type_ string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+ Items []Nic `json:"items,omitempty"`
+}
+
+type Lans struct {
+ Id string `json:"id,omitempty"`
+ Type_ string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+ Items []Lan `json:"items,omitempty"`
+ Response string `json:"Response,omitempty"`
+ Headers *http.Header `json:"headers,omitempty"`
+ StatusCode int `json:"headers,omitempty"`
}
// ListLan returns a Collection for lans in the Datacenter
-func ListLans(dcid string) Collection {
+func ListLans(dcid string) Lans {
path := lan_col_path(dcid)
- return is_list(path)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ return toLans(do(req))
}
// CreateLan creates a lan in the datacenter
// from a jason []byte and returns a Instance struct
-func CreateLan(dcid string, request CreateLanRequest) Instance {
+func CreateLan(dcid string, request Lan) Lan {
obj, _ := json.Marshal(request)
path := lan_col_path(dcid)
- return is_post(path, obj)
+ url := mk_url(path)
+ req, _ := http.NewRequest("POST", url, bytes.NewBuffer(obj))
+ req.Header.Add("Content-Type", FullHeader)
+ return toLan(do(req))
}
// GetLan pulls data for the lan where id = lanid returns an Instance struct
-func GetLan(dcid, lanid string) Instance {
+func GetLan(dcid, lanid string) Lan {
path := lan_path(dcid, lanid)
- return is_get(path)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ return toLan(do(req))
}
// PatchLan does a partial update to a lan using json from []byte jason
// returns a Instance struct
-func PatchLan(dcid string, lanid string, obj map[string]string) Instance {
+func PatchLan(dcid string, lanid string, obj LanProperties) Lan {
jason := []byte(MkJson(obj))
path := lan_path(dcid, lanid)
- return is_patch(path, jason)
+ url := mk_url(path)
+ req, _ := http.NewRequest("PATCH", url, bytes.NewBuffer(jason))
+ req.Header.Add("Content-Type", PatchHeader)
+ return toLan(do(req))
}
// DeleteLan deletes a lan where id == lanid
@@ -46,8 +90,20 @@ func DeleteLan(dcid, lanid string) Resp {
return is_delete(path)
}
-// ListLanMembers returns a Nic struct collection for the Lan
-func ListLanMembers(dcid, lanid string) Collection {
- path := lan_nic_col(dcid, lanid)
- return is_list(path)
+func toLan(resp Resp) Lan {
+ var lan Lan
+ json.Unmarshal(resp.Body, &lan)
+ lan.Response = string(resp.Body)
+ lan.Headers = &resp.Headers
+ lan.StatusCode = resp.StatusCode
+ return lan
+}
+
+func toLans(resp Resp) Lans {
+ var col Lans
+ json.Unmarshal(resp.Body, &col)
+ col.Response = string(resp.Body)
+ col.Headers = &resp.Headers
+ col.StatusCode = resp.StatusCode
+ return col
}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/loadbalancer.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/loadbalancer.go
index 7f6c186aa..2a5b3389f 100644
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/loadbalancer.go
+++ b/vendor/github.com/profitbricks/profitbricks-sdk-go/loadbalancer.go
@@ -1,43 +1,93 @@
package profitbricks
-import "encoding/json"
+import (
+ "bytes"
+ "encoding/json"
+ "net/http"
+)
-type LoablanacerCreateRequest struct {
- LoablanacerProperties `json:"properties"`
+type Loadbalancer struct {
+ Id string `json:"id,omitempty"`
+ Type_ string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+ Metadata *DatacenterElementMetadata `json:"metadata,omitempty"`
+ Properties LoadbalancerProperties `json:"properties,omitempty"`
+ Entities LoadbalancerEntities `json:"entities,omitempty"`
+ Response string `json:"Response,omitempty"`
+ Headers *http.Header `json:"headers,omitempty"`
+ StatusCode int `json:"headers,omitempty"`
}
-type LoablanacerProperties struct {
+type LoadbalancerProperties struct {
Name string `json:"name,omitempty"`
Ip string `json:"ip,omitempty"`
Dhcp bool `json:"dhcp,omitempty"`
}
+type LoadbalancerEntities struct {
+ Balancednics *BalancedNics `json:"balancednics,omitempty"`
+}
+
+type BalancedNics struct {
+ Id string `json:"id,omitempty"`
+ Type_ string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+ Items []Nic `json:"items,omitempty"`
+}
+
+type Loadbalancers struct {
+ Id string `json:"id,omitempty"`
+ Type_ string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+ Items []Loadbalancer `json:"items,omitempty"`
+
+ Response string `json:"Response,omitempty"`
+ Headers *http.Header `json:"headers,omitempty"`
+ StatusCode int `json:"headers,omitempty"`
+}
+
+type LoablanacerCreateRequest struct {
+ LoadbalancerProperties `json:"properties"`
+}
+
// Listloadbalancers returns a Collection struct
// for loadbalancers in the Datacenter
-func ListLoadbalancers(dcid string) Collection {
+func ListLoadbalancers(dcid string) Loadbalancers {
path := lbal_col_path(dcid)
- return is_list(path)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ return toLoadbalancers(do(req))
}
// Createloadbalancer creates a loadbalancer in the datacenter
//from a jason []byte and returns a Instance struct
-func CreateLoadbalancer(dcid string, request LoablanacerCreateRequest) Instance {
+func CreateLoadbalancer(dcid string, request Loadbalancer) Loadbalancer {
obj, _ := json.Marshal(request)
path := lbal_col_path(dcid)
- return is_post(path, obj)
+ url := mk_url(path)
+ req, _ := http.NewRequest("POST", url, bytes.NewBuffer(obj))
+ req.Header.Add("Content-Type", FullHeader)
+ return toLoadbalancer(do(req))
}
// GetLoadbalancer pulls data for the Loadbalancer
// where id = lbalid returns a Instance struct
-func GetLoadbalancer(dcid, lbalid string) Instance {
+func GetLoadbalancer(dcid, lbalid string) Loadbalancer {
path := lbal_path(dcid, lbalid)
- return is_get(path)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ return toLoadbalancer(do(req))
}
-func PatchLoadbalancer(dcid string, lbalid string, obj map[string]string) Instance {
+func PatchLoadbalancer(dcid string, lbalid string, obj LoadbalancerProperties) Loadbalancer {
jason := []byte(MkJson(obj))
path := lbal_path(dcid, lbalid)
- return is_patch(path, jason)
+ url := mk_url(path)
+ req, _ := http.NewRequest("PATCH", url, bytes.NewBuffer(jason))
+ req.Header.Add("Content-Type", PatchHeader)
+ return toLoadbalancer(do(req))
}
func DeleteLoadbalancer(dcid, lbalid string) Resp {
@@ -45,26 +95,51 @@ func DeleteLoadbalancer(dcid, lbalid string) Resp {
return is_delete(path)
}
-func ListBalancedNics(dcid, lbalid string) Collection {
+func ListBalancedNics(dcid, lbalid string) Nics {
path := balnic_col_path(dcid, lbalid)
- return is_list(path)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ return toNics(do(req))
}
-func AssociateNic(dcid string, lbalid string, nicid string) Instance {
- /*var sm StringMap
- sm["id"] = nicid*/
+func AssociateNic(dcid string, lbalid string, nicid string) Nic {
sm := map[string]string{"id": nicid}
jason := []byte(MkJson(sm))
path := balnic_col_path(dcid, lbalid)
- return is_post(path, jason)
+ url := mk_url(path)
+ req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jason))
+ req.Header.Add("Content-Type", FullHeader)
+ return toNic(do(req))
}
-func GetBalancedNic(dcid, lbalid, balnicid string) Instance {
+func GetBalancedNic(dcid, lbalid, balnicid string) Nic {
path := balnic_path(dcid, lbalid, balnicid)
- return is_get(path)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ return toNic(do(req))
}
func DeleteBalancedNic(dcid, lbalid, balnicid string) Resp {
path := balnic_path(dcid, lbalid, balnicid)
return is_delete(path)
}
+
+func toLoadbalancer(resp Resp) Loadbalancer {
+ var server Loadbalancer
+ json.Unmarshal(resp.Body, &server)
+ server.Response = string(resp.Body)
+ server.Headers = &resp.Headers
+ server.StatusCode = resp.StatusCode
+ return server
+}
+
+func toLoadbalancers(resp Resp) Loadbalancers {
+ var col Loadbalancers
+ json.Unmarshal(resp.Body, &col)
+ col.Response = string(resp.Body)
+ col.Headers = &resp.Headers
+ col.StatusCode = resp.StatusCode
+ return col
+}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/location.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/location.go
index 65f8a51cb..279429464 100644
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/location.go
+++ b/vendor/github.com/profitbricks/profitbricks-sdk-go/location.go
@@ -1,11 +1,65 @@
package profitbricks
+import (
+ "encoding/json"
+ "net/http"
+)
+
+type Location struct {
+ Id string `json:"id,omitempty"`
+ Type_ string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+ Metadata DatacenterElementMetadata `json:"metadata,omitempty"`
+ Properties Properties `json:"properties,omitempty"`
+ Response string `json:"Response,omitempty"`
+ Headers *http.Header `json:"headers,omitempty"`
+ StatusCode int `json:"headers,omitempty"`
+}
+
+type Locations struct {
+ Id string `json:"id,omitempty"`
+ Type_ string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+ Items []Location `json:"items,omitempty"`
+ Response string `json:"Response,omitempty"`
+ Headers *http.Header `json:"headers,omitempty"`
+ StatusCode int `json:"headers,omitempty"`
+}
+
+type Properties struct {
+ Name string `json:"name,omitempty"`
+}
+
// ListLocations returns location collection data
-func ListLocations() Collection {
- return is_list(location_col_path())
+func ListLocations() Locations {
+ url := mk_url(location_col_path()) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ return toLocations(do(req))
}
// GetLocation returns location data
-func GetLocation(locid string) Instance {
- return is_get(location_path(locid))
+func GetLocation(locid string) Location {
+ url := mk_url(location_path(locid)) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ return toLocation(do(req))
+}
+
+func toLocation(resp Resp) Location {
+ var obj Location
+ json.Unmarshal(resp.Body, &obj)
+ obj.Response = string(resp.Body)
+ obj.Headers = &resp.Headers
+ obj.StatusCode = resp.StatusCode
+ return obj
+}
+
+func toLocations(resp Resp) Locations {
+ var col Locations
+ json.Unmarshal(resp.Body, &col)
+ col.Response = string(resp.Body)
+ col.Headers = &resp.Headers
+ col.StatusCode = resp.StatusCode
+ return col
}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/AttachedVolumes.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/AttachedVolumes.go
deleted file mode 100644
index bd48f0575..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/AttachedVolumes.go
+++ /dev/null
@@ -1,11 +0,0 @@
-package model
-
-
-
-type AttachedVolumes struct {
- Id string `json:"id,omitempty"`
- Type_ string `json:"type,omitempty"`
- Href string `json:"href,omitempty"`
- Items []Volume `json:"items,omitempty"`
-
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/BalancedNics.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/BalancedNics.go
deleted file mode 100644
index d8b08f476..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/BalancedNics.go
+++ /dev/null
@@ -1,11 +0,0 @@
-package model
-
-
-
-type BalancedNics struct {
- Id string `json:"id,omitempty"`
- Type_ string `json:"type,omitempty"`
- Href string `json:"href,omitempty"`
- Items []Nic `json:"items,omitempty"`
-
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Cdroms.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Cdroms.go
deleted file mode 100644
index afe2715a3..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Cdroms.go
+++ /dev/null
@@ -1,11 +0,0 @@
-package model
-
-
-
-type Cdroms struct {
- Id string `json:"id,omitempty"`
- Type_ string `json:"type,omitempty"`
- Href string `json:"href,omitempty"`
- Items []Image `json:"items,omitempty"`
-
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Datacenter.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Datacenter.go
deleted file mode 100644
index e43c07de5..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Datacenter.go
+++ /dev/null
@@ -1,14 +0,0 @@
-package model
-
-import "net/http"
-
-type Datacenter struct {
- Id string `json:"id,omitempty"`
- Type_ string `json:"type,omitempty"`
- Href string `json:"href,omitempty"`
- Properties DatacenterProperties `json:"properties,omitempty"`
- Entities DatacenterEntities `json:"entities,omitempty"`
- Response string `json:"Response,omitempty"`
- Headers *http.Header `json:"headers,omitempty"`
- StatusCode int `json:"headers,omitempty"`
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/DatacenterElementMetadata.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/DatacenterElementMetadata.go
deleted file mode 100644
index a45261492..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/DatacenterElementMetadata.go
+++ /dev/null
@@ -1,15 +0,0 @@
-package model
-
-import (
- "time"
-)
-
-type DatacenterElementMetadata struct {
- CreatedDate time.Time `json:"createdDate,omitempty"`
- CreatedBy string `json:"createdBy,omitempty"`
- Etag string `json:"etag,omitempty"`
- LastModifiedDate time.Time `json:"lastModifiedDate,omitempty"`
- LastModifiedBy string `json:"lastModifiedBy,omitempty"`
- State string `json:"state,omitempty"`
-
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/DatacenterEntities.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/DatacenterEntities.go
deleted file mode 100644
index b5bc3e092..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/DatacenterEntities.go
+++ /dev/null
@@ -1,11 +0,0 @@
-package model
-
-
-
-type DatacenterEntities struct {
- Servers *Servers `json:"servers,omitempty"`
- Volumes *Volumes `json:"volumes,omitempty"`
- Loadbalancers *Loadbalancers `json:"loadbalancers,omitempty"`
- Lans *Lans `json:"lans,omitempty"`
-
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/DatacenterProperties.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/DatacenterProperties.go
deleted file mode 100644
index 6f61a9d85..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/DatacenterProperties.go
+++ /dev/null
@@ -1,11 +0,0 @@
-package model
-
-
-
-type DatacenterProperties struct {
- Name string `json:"name,omitempty"`
- Description string `json:"description,omitempty"`
- Location string `json:"location,omitempty"`
- Version int32 `json:"version,omitempty"`
-
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Datacenters.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Datacenters.go
deleted file mode 100644
index 5e17b817a..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Datacenters.go
+++ /dev/null
@@ -1,11 +0,0 @@
-package model
-
-
-
-type Datacenters struct {
- Id string `json:"id,omitempty"`
- Type_ string `json:"type,omitempty"`
- Href string `json:"href,omitempty"`
- Items []Datacenter `json:"items,omitempty"`
-
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/FirewallRule.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/FirewallRule.go
deleted file mode 100644
index 6442d32f3..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/FirewallRule.go
+++ /dev/null
@@ -1,12 +0,0 @@
-package model
-
-
-
-type FirewallRule struct {
- Id string `json:"id,omitempty"`
- Type_ string `json:"type,omitempty"`
- Href string `json:"href,omitempty"`
- Metadata DatacenterElementMetadata `json:"metadata,omitempty"`
- Properties FirewallruleProperties `json:"properties,omitempty"`
-
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/FirewallRules.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/FirewallRules.go
deleted file mode 100644
index a52737d28..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/FirewallRules.go
+++ /dev/null
@@ -1,11 +0,0 @@
-package model
-
-
-
-type FirewallRules struct {
- Id string `json:"id,omitempty"`
- Type_ string `json:"type,omitempty"`
- Href string `json:"href,omitempty"`
- Items []FirewallRule `json:"items,omitempty"`
-
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/FirewallruleProperties.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/FirewallruleProperties.go
deleted file mode 100644
index a559cc388..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/FirewallruleProperties.go
+++ /dev/null
@@ -1,16 +0,0 @@
-package model
-
-
-
-type FirewallruleProperties struct {
- Name string `json:"name,omitempty"`
- Protocol string `json:"protocol,omitempty"`
- SourceMac string `json:"sourceMac,omitempty"`
- SourceIp string `json:"sourceIp,omitempty"`
- TargetIp string `json:"targetIp,omitempty"`
- IcmpCode int32 `json:"icmpCode,omitempty"`
- IcmpType int32 `json:"icmpType,omitempty"`
- PortRangeStart int32 `json:"portRangeStart,omitempty"`
- PortRangeEnd int32 `json:"portRangeEnd,omitempty"`
-
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Image.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Image.go
deleted file mode 100644
index 3a98b1a69..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Image.go
+++ /dev/null
@@ -1,12 +0,0 @@
-package model
-
-
-
-type Image struct {
- Id string `json:"id,omitempty"`
- Type_ string `json:"type,omitempty"`
- Href string `json:"href,omitempty"`
- Metadata DatacenterElementMetadata `json:"metadata,omitempty"`
- Properties ImageProperties `json:"properties,omitempty"`
-
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/ImageProperties.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/ImageProperties.go
deleted file mode 100644
index a632df6be..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/ImageProperties.go
+++ /dev/null
@@ -1,24 +0,0 @@
-package model
-
-
-
-type ImageProperties struct {
- Name string `json:"name,omitempty"`
- Description string `json:"description,omitempty"`
- Location string `json:"location,omitempty"`
- Size int `json:"size,omitempty"`
- CpuHotPlug bool `json:"cpuHotPlug,omitempty"`
- CpuHotUnplug bool `json:"cpuHotUnplug,omitempty"`
- RamHotPlug bool `json:"ramHotPlug,omitempty"`
- RamHotUnplug bool `json:"ramHotUnplug,omitempty"`
- NicHotPlug bool `json:"nicHotPlug,omitempty"`
- NicHotUnplug bool `json:"nicHotUnplug,omitempty"`
- DiscVirtioHotPlug bool `json:"discVirtioHotPlug,omitempty"`
- DiscVirtioHotUnplug bool `json:"discVirtioHotUnplug,omitempty"`
- DiscScsiHotPlug bool `json:"discScsiHotPlug,omitempty"`
- DiscScsiHotUnplug bool `json:"discScsiHotUnplug,omitempty"`
- LicenceType string `json:"licenceType,omitempty"`
- ImageType string `json:"imageType,omitempty"`
- Public bool `json:"public,omitempty"`
-
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Images.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Images.go
deleted file mode 100644
index ff933aec6..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Images.go
+++ /dev/null
@@ -1,11 +0,0 @@
-package model
-
-
-
-type Images struct {
- Id string `json:"id,omitempty"`
- Type_ string `json:"type,omitempty"`
- Href string `json:"href,omitempty"`
- Items []Image `json:"items,omitempty"`
-
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Lan.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Lan.go
deleted file mode 100644
index e8bd6834c..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Lan.go
+++ /dev/null
@@ -1,13 +0,0 @@
-package model
-
-
-
-type Lan struct {
- Id string `json:"id,omitempty"`
- Type_ string `json:"type,omitempty"`
- Href string `json:"href,omitempty"`
- Metadata DatacenterElementMetadata `json:"metadata,omitempty"`
- Properties LanProperties `json:"properties,omitempty"`
- Entities LanEntities `json:"entities,omitempty"`
-
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/LanEntities.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/LanEntities.go
deleted file mode 100644
index fa57ff6e0..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/LanEntities.go
+++ /dev/null
@@ -1,8 +0,0 @@
-package model
-
-
-
-type LanEntities struct {
- Nics *LanNics `json:"nics,omitempty"`
-
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/LanNics.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/LanNics.go
deleted file mode 100644
index 8ff9805a4..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/LanNics.go
+++ /dev/null
@@ -1,11 +0,0 @@
-package model
-
-
-
-type LanNics struct {
- Id string `json:"id,omitempty"`
- Type_ string `json:"type,omitempty"`
- Href string `json:"href,omitempty"`
- Items []Nic `json:"items,omitempty"`
-
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/LanProperties.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/LanProperties.go
deleted file mode 100644
index aa3ad3e08..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/LanProperties.go
+++ /dev/null
@@ -1,9 +0,0 @@
-package model
-
-
-
-type LanProperties struct {
- Name string `json:"name,omitempty"`
- Public bool `json:"public,omitempty"`
-
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Lans.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Lans.go
deleted file mode 100644
index d76f4cb4a..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Lans.go
+++ /dev/null
@@ -1,11 +0,0 @@
-package model
-
-
-
-type Lans struct {
- Id string `json:"id,omitempty"`
- Type_ string `json:"type,omitempty"`
- Href string `json:"href,omitempty"`
- Items []Lan `json:"items,omitempty"`
-
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Loadbalancer.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Loadbalancer.go
deleted file mode 100644
index f7d277439..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Loadbalancer.go
+++ /dev/null
@@ -1,13 +0,0 @@
-package model
-
-
-
-type Loadbalancer struct {
- Id string `json:"id,omitempty"`
- Type_ string `json:"type,omitempty"`
- Href string `json:"href,omitempty"`
- Metadata DatacenterElementMetadata `json:"metadata,omitempty"`
- Properties LoadbalancerProperties `json:"properties,omitempty"`
- Entities LoadbalancerEntities `json:"entities,omitempty"`
-
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/LoadbalancerEntities.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/LoadbalancerEntities.go
deleted file mode 100644
index 206b26e0e..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/LoadbalancerEntities.go
+++ /dev/null
@@ -1,8 +0,0 @@
-package model
-
-
-
-type LoadbalancerEntities struct {
- Balancednics *BalancedNics `json:"balancednics,omitempty"`
-
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/LoadbalancerProperties.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/LoadbalancerProperties.go
deleted file mode 100644
index 0d3bc46e7..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/LoadbalancerProperties.go
+++ /dev/null
@@ -1,10 +0,0 @@
-package model
-
-
-
-type LoadbalancerProperties struct {
- Name string `json:"name,omitempty"`
- Ip string `json:"ip,omitempty"`
- Dhcp bool `json:"dhcp,omitempty"`
-
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Loadbalancers.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Loadbalancers.go
deleted file mode 100644
index bddd7bd12..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Loadbalancers.go
+++ /dev/null
@@ -1,11 +0,0 @@
-package model
-
-
-
-type Loadbalancers struct {
- Id string `json:"id,omitempty"`
- Type_ string `json:"type,omitempty"`
- Href string `json:"href,omitempty"`
- Items []Loadbalancer `json:"items,omitempty"`
-
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Nic.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Nic.go
deleted file mode 100644
index 784aeddce..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Nic.go
+++ /dev/null
@@ -1,10 +0,0 @@
-package model
-
-type Nic struct {
- Id string `json:"id,omitempty"`
- Type_ string `json:"type,omitempty"`
- Href string `json:"href,omitempty"`
- // Metadata DatacenterElementMetadata `json:"metadata,omitempty"`
- Properties NicProperties `json:"properties,omitempty"`
- Entities *NicEntities `json:"entities,omitempty"`
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/NicEntities.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/NicEntities.go
deleted file mode 100644
index fa9a4d4b2..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/NicEntities.go
+++ /dev/null
@@ -1,5 +0,0 @@
-package model
-
-type NicEntities struct {
- Firewallrules *FirewallRules `json:"firewallrules,omitempty"`
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/NicProperties.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/NicProperties.go
deleted file mode 100644
index 5235e6c78..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/NicProperties.go
+++ /dev/null
@@ -1,13 +0,0 @@
-package model
-
-
-
-type NicProperties struct {
- Name string `json:"name,omitempty"`
- Mac string `json:"mac,omitempty"`
- Ips []string `json:"ips,omitempty"`
- Dhcp bool `json:"dhcp,omitempty"`
- Lan string `json:"lan,omitempty"`
- FirewallActive bool `json:"firewallActive,omitempty"`
-
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Nics.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Nics.go
deleted file mode 100644
index 0988304b7..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Nics.go
+++ /dev/null
@@ -1,8 +0,0 @@
-package model
-
-type Nics struct {
- Id string `json:"id,omitempty"`
- Type_ string `json:"type,omitempty"`
- Href string `json:"href,omitempty"`
- Items []Nic `json:"items,omitempty"`
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Properties.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Properties.go
deleted file mode 100644
index 1aa485cc6..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Properties.go
+++ /dev/null
@@ -1,5 +0,0 @@
-package model
-
-type Properties struct {
- Name string `json:"name,omitempty"`
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/ResourceReference.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/ResourceReference.go
deleted file mode 100644
index 52cc50d53..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/ResourceReference.go
+++ /dev/null
@@ -1,7 +0,0 @@
-package model
-
-type ResourceReference struct {
- Id string `json:"id,omitempty"`
- Type_ string `json:"type,omitempty"`
- Href string `json:"href,omitempty"`
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Server.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Server.go
deleted file mode 100644
index 6fe9ce436..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Server.go
+++ /dev/null
@@ -1,10 +0,0 @@
-package model
-
-type Server struct {
- Id string `json:"id,omitempty"`
- Type_ string `json:"type,omitempty"`
- Href string `json:"href,omitempty"`
- //Metadata DatacenterElementMetadata `json:"metadata,omitempty"`
- Properties ServerProperties `json:"properties,omitempty"`
- Entities ServerEntities `json:"entities,omitempty"`
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/ServerEntities.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/ServerEntities.go
deleted file mode 100644
index ddb7eb811..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/ServerEntities.go
+++ /dev/null
@@ -1,7 +0,0 @@
-package model
-
-type ServerEntities struct {
- Cdroms *Cdroms `json:"cdroms,omitempty"`
- Volumes *AttachedVolumes `json:"volumes,omitempty"`
- Nics *Nics `json:"nics,omitempty"`
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/ServerProperties.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/ServerProperties.go
deleted file mode 100644
index 0a0bf16f8..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/ServerProperties.go
+++ /dev/null
@@ -1,9 +0,0 @@
-package model
-
-type ServerProperties struct {
- Name string `json:"name,omitempty"`
- Cores int `json:"cores,omitempty"`
- Ram int `json:"ram,omitempty"`
- AvailabilityZone string `json:"availabilityZone,omitempty"`
- VmState string `json:"vmState,omitempty"`
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Servers.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Servers.go
deleted file mode 100644
index 779ef8d4b..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Servers.go
+++ /dev/null
@@ -1,8 +0,0 @@
-package model
-
-type Servers struct {
- Id string `json:"id,omitempty"`
- Type_ string `json:"type,omitempty"`
- Href string `json:"href,omitempty"`
- Items []Server `json:"items,omitempty"`
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Volume.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Volume.go
deleted file mode 100644
index 2ad7c52cf..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Volume.go
+++ /dev/null
@@ -1,8 +0,0 @@
-package model
-
-type Volume struct {
- Id string `json:"id,omitempty"`
- Type_ string `json:"type,omitempty"`
- Href string `json:"href,omitempty"`
- Properties VolumeProperties `json:"properties,omitempty"`
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/VolumeProperties.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/VolumeProperties.go
deleted file mode 100644
index a25d614f8..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/VolumeProperties.go
+++ /dev/null
@@ -1,23 +0,0 @@
-package model
-
-type VolumeProperties struct {
- Name string `json:"name,omitempty"`
- Type_ string `json:"type,omitempty"`
- Size int `json:"size,omitempty"`
- Image string `json:"image,omitempty"`
- ImagePassword string `json:"imagePassword,omitempty"`
- SshKeys []string `json:"sshKeys,omitempty"`
- Bus string `json:"bus,omitempty"`
- LicenceType string `json:"licenceType,omitempty"`
- CpuHotPlug bool `json:"cpuHotPlug,omitempty"`
- CpuHotUnplug bool `json:"cpuHotUnplug,omitempty"`
- RamHotPlug bool `json:"ramHotPlug,omitempty"`
- RamHotUnplug bool `json:"ramHotUnplug,omitempty"`
- NicHotPlug bool `json:"nicHotPlug,omitempty"`
- NicHotUnplug bool `json:"nicHotUnplug,omitempty"`
- DiscVirtioHotPlug bool `json:"discVirtioHotPlug,omitempty"`
- DiscVirtioHotUnplug bool `json:"discVirtioHotUnplug,omitempty"`
- DiscScsiHotPlug bool `json:"discScsiHotPlug,omitempty"`
- DiscScsiHotUnplug bool `json:"discScsiHotUnplug,omitempty"`
- DeviceNumber int64 `json:"deviceNumber,omitempty"`
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Volumes.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Volumes.go
deleted file mode 100644
index a83faf2ca..000000000
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/model/Volumes.go
+++ /dev/null
@@ -1,8 +0,0 @@
-package model
-
-type Volumes struct {
- Id string `json:"id,omitempty"`
- Type_ string `json:"type,omitempty"`
- Href string `json:"href,omitempty"`
- Items []Volume `json:"items,omitempty"`
-}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/nic.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/nic.go
index 3e6b03cce..74764f56b 100644
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/nic.go
+++ b/vendor/github.com/profitbricks/profitbricks-sdk-go/nic.go
@@ -1,46 +1,88 @@
package profitbricks
import (
+ "bytes"
"encoding/json"
+ "net/http"
)
+type Nic struct {
+ Id string `json:"id,omitempty"`
+ Type_ string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+ Metadata *DatacenterElementMetadata `json:"metadata,omitempty"`
+ Properties NicProperties `json:"properties,omitempty"`
+ Entities *NicEntities `json:"entities,omitempty"`
+ Response string `json:"Response,omitempty"`
+ Headers *http.Header `json:"headers,omitempty"`
+ StatusCode int `json:"headers,omitempty"`
+}
+
+type NicProperties struct {
+ Name string `json:"name,omitempty"`
+ Mac string `json:"mac,omitempty"`
+ Ips []string `json:"ips,omitempty"`
+ Dhcp bool `json:"dhcp,omitempty"`
+ Lan int `json:"lan,omitempty"`
+ FirewallActive bool `json:"firewallActive,omitempty"`
+}
+
+type NicEntities struct {
+ Firewallrules *FirewallRules `json:"firewallrules,omitempty"`
+}
+
+type Nics struct {
+ Id string `json:"id,omitempty"`
+ Type_ string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+ Items []Nic `json:"items,omitempty"`
+ Response string `json:"Response,omitempty"`
+ Headers *http.Header `json:"headers,omitempty"`
+ StatusCode int `json:"headers,omitempty"`
+}
+
type NicCreateRequest struct {
NicProperties `json:"properties"`
}
-type NicProperties struct {
- Name string `json:"name,omitempty"`
- Ips []string `json:"ips,omitempty"`
- Dhcp bool `json:"dhcp"`
- Lan string `json:"lan"`
-}
-
// ListNics returns a Nics struct collection
-func ListNics(dcid, srvid string) Collection {
- path := nic_col_path(dcid, srvid)
- return is_list(path)
+func ListNics(dcid, srvid string) Nics {
+ path := nic_col_path(dcid, srvid) + `?depth=` + Depth
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ return toNics(do(req))
}
// CreateNic creates a nic on a server
// from a jason []byte and returns a Instance struct
-func CreateNic(dcid string, srvid string, request NicCreateRequest) Instance {
+func CreateNic(dcid string, srvid string, request Nic) Nic {
obj, _ := json.Marshal(request)
path := nic_col_path(dcid, srvid)
- return is_post(path, obj)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("POST", url, bytes.NewBuffer(obj))
+ req.Header.Add("Content-Type", FullHeader)
+ return toNic(do(req))
}
// GetNic pulls data for the nic where id = srvid returns a Instance struct
-func GetNic(dcid, srvid, nicid string) Instance {
+func GetNic(dcid, srvid, nicid string) Nic {
path := nic_path(dcid, srvid, nicid)
- return is_get(path)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ return toNic(do(req))
}
// PatchNic partial update of nic properties passed in as jason []byte
// Returns Instance struct
-func PatchNic(dcid string, srvid string, nicid string, obj map[string]string) Instance {
+func PatchNic(dcid string, srvid string, nicid string, obj NicProperties) Nic {
jason := []byte(MkJson(obj))
path := nic_path(dcid, srvid, nicid)
- return is_patch(path, jason)
+ url := mk_url(path)
+ req, _ := http.NewRequest("PATCH", url, bytes.NewBuffer(jason))
+ req.Header.Add("Content-Type", PatchHeader)
+ return toNic(do(req))
}
// DeleteNic deletes the nic where id=nicid and returns a Resp struct
@@ -48,3 +90,21 @@ func DeleteNic(dcid, srvid, nicid string) Resp {
path := nic_path(dcid, srvid, nicid)
return is_delete(path)
}
+
+func toNic(resp Resp) Nic {
+ var obj Nic
+ json.Unmarshal(resp.Body, &obj)
+ obj.Response = string(resp.Body)
+ obj.Headers = &resp.Headers
+ obj.StatusCode = resp.StatusCode
+ return obj
+}
+
+func toNics(resp Resp) Nics {
+ var col Nics
+ json.Unmarshal(resp.Body, &col)
+ col.Response = string(resp.Body)
+ col.Headers = &resp.Headers
+ col.StatusCode = resp.StatusCode
+ return col
+}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/req.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/req.go
index b0c9b5958..b5f21c17d 100644
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/req.go
+++ b/vendor/github.com/profitbricks/profitbricks-sdk-go/req.go
@@ -6,7 +6,6 @@ import (
"io/ioutil"
"net/http"
"strings"
- "github.com/profitbricks/profitbricks-sdk-go/model"
)
//FullHeader is the standard header to include with all http requests except is_patch and is_command
@@ -32,10 +31,13 @@ func SetDepth(newdepth string) string {
// returns Endpoint+ path .
func mk_url(path string) string {
if strings.HasPrefix(path, "http") {
+ //REMOVE AFTER TESTING
path := strings.Replace(path, "https://api.profitbricks.com/rest/v2", Endpoint, 1)
+ // END REMOVE
return path
}
if strings.HasPrefix(path, "") {
+ //REMOVE AFTER TESTING
path := strings.Replace(path, "", Endpoint, 1)
return path
}
@@ -68,53 +70,6 @@ func is_delete(path string) Resp {
return do(req)
}
-// is_list performs an http.NewRequest GET and returns a Collection struct
-func is_list(path string) Collection {
- url := mk_url(path) + `?depth=` + Depth
- req, _ := http.NewRequest("GET", url, nil)
- req.Header.Add("Content-Type", FullHeader)
- return toCollection(do(req))
-}
-
-// is_get performs an http.NewRequest GET and returns an Instance struct
-func is_get(path string) Instance {
- url := mk_url(path) + `?depth=` + Depth
- req, _ := http.NewRequest("GET", url, nil)
- req.Header.Add("Content-Type", FullHeader)
- return toInstance(do(req))
-}
-
-// is_patch performs an http.NewRequest PATCH and returns an Instance struct
-func is_patch(path string, jason []byte) Instance {
- url := mk_url(path)
- req, _ := http.NewRequest("PATCH", url, bytes.NewBuffer(jason))
- req.Header.Add("Content-Type", PatchHeader)
- return toInstance(do(req))
-}
-
-// is_put performs an http.NewRequest PUT and returns an Instance struct
-func is_put(path string, jason []byte) Instance {
- url := mk_url(path)
- req, _ := http.NewRequest("PUT", url, bytes.NewBuffer(jason))
- req.Header.Add("Content-Type", FullHeader)
- return toInstance(do(req))
-}
-
-// is_post performs an http.NewRequest POST and returns an Instance struct
-func is_post(path string, jason []byte) Instance {
- url := mk_url(path)
- req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jason))
- req.Header.Add("Content-Type", FullHeader)
- return toInstance(do(req))
-}
-
-func is_composite_post(path string, jason []byte) model.Datacenter {
- url := mk_url(path)+ `?depth=` + Depth
- req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jason))
- req.Header.Add("Content-Type", FullHeader)
- return toDataCenter(do(req))
-}
-
// is_command performs an http.NewRequest POST and returns a Resp struct
func is_command(path string, jason string) Resp {
url := mk_url(path)
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/request.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/request.go
index c73d1c618..023ae1a4a 100644
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/request.go
+++ b/vendor/github.com/profitbricks/profitbricks-sdk-go/request.go
@@ -1,5 +1,43 @@
package profitbricks
-func GetRequestStatus(path string)Instance{
- return is_get(path)
+import (
+ "encoding/json"
+ "net/http"
+)
+
+type RequestStatus struct {
+ Id string `json:"id,omitempty"`
+ Type_ string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+ Metadata RequestStatusMetadata `json:"metadata,omitempty"`
+ Response string `json:"Response,omitempty"`
+ Headers *http.Header `json:"headers,omitempty"`
+ StatusCode int `json:"headers,omitempty"`
+}
+type RequestStatusMetadata struct {
+ Status string `json:"status,omitempty"`
+ Message string `json:"message,omitempty"`
+ Etag string `json:"etag,omitempty"`
+ Targets []RequestTarget `json:"targets,omitempty"`
+}
+
+type RequestTarget struct {
+ Target ResourceReference `json:"target,omitempty"`
+ Status string `json:"status,omitempty"`
+}
+
+func GetRequestStatus(path string) RequestStatus {
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ return toRequestStatus(do(req))
+}
+
+func toRequestStatus(resp Resp) RequestStatus {
+ var server RequestStatus
+ json.Unmarshal(resp.Body, &server)
+ server.Response = string(resp.Body)
+ server.Headers = &resp.Headers
+ server.StatusCode = resp.StatusCode
+ return server
}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/resp.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/resp.go
index d35f57a8c..12d68e0d2 100644
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/resp.go
+++ b/vendor/github.com/profitbricks/profitbricks-sdk-go/resp.go
@@ -4,7 +4,6 @@ import "net/http"
import "fmt"
import (
"encoding/json"
- "github.com/profitbricks/profitbricks-sdk-go/model"
)
func MkJson(i interface{}) string {
@@ -47,23 +46,6 @@ type Id_Type_Href struct {
type MetaData StringIfaceMap
-// toInstance converts a Resp struct into a Instance struct
-func toInstance(resp Resp) Instance {
- var ins Instance
- json.Unmarshal(resp.Body, &ins)
- ins.Resp = resp
- return ins
-}
-
-func toDataCenter(resp Resp) model.Datacenter {
- var dc model.Datacenter
- json.Unmarshal(resp.Body, &dc)
- dc.Response = string(resp.Body)
- dc.Headers = &resp.Headers
- dc.StatusCode = resp.StatusCode
- return dc
-}
-
type Instance struct {
Id_Type_Href
MetaData StringMap `json:"metaData,omitempty"`
@@ -72,44 +54,6 @@ type Instance struct {
Resp Resp `json:"-"`
}
-// Save converts the Instance struct's properties to json
-// and "patch"es them to the rest server
-func (ins *Instance) Save() {
- path := ins.Href
- jason, err := json.MarshalIndent(&ins.Properties, "", " ")
- if err != nil {
- panic(err)
- }
- r := is_patch(path, jason).Resp
- fmt.Println("save status code is ", r.StatusCode)
-}
-
-// ShowProps prints the properties as k,v pairs
-func (ins *Instance) ShowProps() {
- for key, value := range ins.Properties {
- fmt.Println(key, " : ", value)
- }
-}
-func (ins *Instance) SetProp(key, val string) {
- ins.Properties[key] = val
-}
-
-// ShowEnts prints the Entities as k,v pairs
-func (ins *Instance) ShowEnts() {
- for key, value := range ins.Entities {
- v := MkJson(value)
- fmt.Println(key, " : ", v)
- }
-}
-
-// toServers converts a Resp struct into a Collection struct
-func toCollection(resp Resp) Collection {
- var col Collection
- json.Unmarshal(resp.Body, &col)
- col.Resp = resp
- return col
-}
-
type Collection struct {
Id_Type_Href
Items []Instance `json:"items,omitempty"`
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/server.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/server.go
index 8eac6dc54..256d57985 100644
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/server.go
+++ b/vendor/github.com/profitbricks/profitbricks-sdk-go/server.go
@@ -1,46 +1,100 @@
package profitbricks
-import "encoding/json"
+import (
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "net/http"
+)
+
+type Server struct {
+ Id string `json:"id,omitempty"`
+ Type_ string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+ Metadata *DatacenterElementMetadata `json:"metadata,omitempty"`
+ Properties ServerProperties `json:"properties,omitempty"`
+ Entities *ServerEntities `json:"entities,omitempty"`
+ Response string `json:"Response,omitempty"`
+ Headers *http.Header `json:"headers,omitempty"`
+ StatusCode int `json:"headers,omitempty"`
+}
+
+type ServerProperties struct {
+ Name string `json:"name,omitempty"`
+ Cores int `json:"cores,omitempty"`
+ Ram int `json:"ram,omitempty"`
+ AvailabilityZone string `json:"availabilityZone,omitempty"`
+ VmState string `json:"vmState,omitempty"`
+ BootCdrom *ResourceReference `json:"bootCdrom,omitempty"`
+ BootVolume *ResourceReference `json:"bootVolume,omitempty"`
+ CpuFamily string `json:"cpuFamily,omitempty"`
+}
+
+type ServerEntities struct {
+ Cdroms *Cdroms `json:"cdroms,omitempty"`
+ Volumes *Volumes `json:"volumes,omitempty"`
+ Nics *Nics `json:"nics,omitempty"`
+}
+
+type Servers struct {
+ Id string `json:"id,omitempty"`
+ Type_ string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+ Items []Server `json:"items,omitempty"`
+ Response string `json:"Response,omitempty"`
+ Headers *http.Header `json:"headers,omitempty"`
+ StatusCode int `json:"headers,omitempty"`
+}
+
+type ResourceReference struct {
+ Id string `json:"id,omitempty"`
+ Type_ string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+}
type CreateServerRequest struct {
ServerProperties `json:"properties"`
}
-type ServerProperties struct {
- Name string `json:"name,omitempty"`
- Ram int `json:"ram,omitempty"`
- Cores int `json:"cores,omitempty"`
- Availabilityzone string `json:"availabilityzone,omitempty"`
- Licencetype string `json:"licencetype,omitempty"`
- BootVolume *Instance `json:"bootVolume,omitempty"`
- BootCdrom *Instance `json:"bootCdrom,omitempty"`
-}
-
// ListServers returns a server struct collection
-func ListServers(dcid string) Collection {
+func ListServers(dcid string) Servers {
path := server_col_path(dcid)
- return is_list(path)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ resp := do(req)
+ return toServers(resp)
}
// CreateServer creates a server from a jason []byte and returns a Instance struct
-func CreateServer(dcid string, req CreateServerRequest) Instance {
- jason, _ := json.Marshal(req)
+func CreateServer(dcid string, server Server) Server {
+ obj, _ := json.Marshal(server)
path := server_col_path(dcid)
- return is_post(path, jason)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("POST", url, bytes.NewBuffer(obj))
+ req.Header.Add("Content-Type", FullHeader)
+ return toServer(do(req))
}
// GetServer pulls data for the server where id = srvid returns a Instance struct
-func GetServer(dcid, srvid string) Instance {
+func GetServer(dcid, srvid string) Server {
path := server_path(dcid, srvid)
- return is_get(path)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ fmt.Println(path)
+ req.Header.Add("Content-Type", FullHeader)
+ return toServer(do(req))
}
// PatchServer partial update of server properties passed in as jason []byte
// Returns Instance struct
-func PatchServer(dcid string, srvid string, req ServerProperties) Instance {
- jason, _ := json.Marshal(req)
+func PatchServer(dcid string, srvid string, props ServerProperties) Server {
+ jason, _ := json.Marshal(props)
path := server_path(dcid, srvid)
- return is_patch(path, jason)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("PATCH", url, bytes.NewBuffer(jason))
+ req.Header.Add("Content-Type", PatchHeader)
+ return toServer(do(req))
}
// DeleteServer deletes the server where id=srvid and returns Resp struct
@@ -49,20 +103,29 @@ func DeleteServer(dcid, srvid string) Resp {
return is_delete(path)
}
-func ListAttachedCdroms(dcid, srvid string) Collection {
+func ListAttachedCdroms(dcid, srvid string) Images {
path := server_cdrom_col_path(dcid, srvid)
- return is_list(path)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ return toImages(do(req))
}
-func AttachCdrom(dcid string, srvid string, cdid string) Instance {
+func AttachCdrom(dcid string, srvid string, cdid string) Image {
jason := []byte(`{"id":"` + cdid + `"}`)
path := server_cdrom_col_path(dcid, srvid)
- return is_post(path, jason)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jason))
+ req.Header.Add("Content-Type", FullHeader)
+ return toImage(do(req))
}
-func GetAttachedCdrom(dcid, srvid, cdid string) Instance {
+func GetAttachedCdrom(dcid, srvid, cdid string) Volume {
path := server_cdrom_path(dcid, srvid, cdid)
- return is_get(path)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ return toVolume(do(req))
}
func DetachCdrom(dcid, srvid, cdid string) Resp {
@@ -70,20 +133,31 @@ func DetachCdrom(dcid, srvid, cdid string) Resp {
return is_delete(path)
}
-func ListAttachedVolumes(dcid, srvid string) Collection {
+func ListAttachedVolumes(dcid, srvid string) Volumes {
path := server_volume_col_path(dcid, srvid)
- return is_list(path)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ resp := do(req)
+ return toVolumes(resp)
}
-func AttachVolume(dcid string, srvid string, volid string) Instance {
+func AttachVolume(dcid string, srvid string, volid string) Volume {
jason := []byte(`{"id":"` + volid + `"}`)
path := server_volume_col_path(dcid, srvid)
- return is_post(path, jason)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jason))
+ req.Header.Add("Content-Type", FullHeader)
+ return toVolume(do(req))
}
-func GetAttachedVolume(dcid, srvid, volid string) Instance {
+func GetAttachedVolume(dcid, srvid, volid string) Volume {
path := server_volume_path(dcid, srvid, volid)
- return is_get(path)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ resp := do(req)
+ return toVolume(resp)
}
func DetachVolume(dcid, srvid, volid string) Resp {
@@ -91,15 +165,6 @@ func DetachVolume(dcid, srvid, volid string) Resp {
return is_delete(path)
}
-// server_command is a generic function for running server commands
-func server_command(dcid, srvid, cmd string) Resp {
- jason := `
- {}
- `
- path := server_command_path(dcid, srvid, cmd)
- return is_command(path, jason)
-}
-
// StartServer starts a server
func StartServer(dcid, srvid string) Resp {
return server_command(dcid, srvid, "start")
@@ -114,3 +179,30 @@ func StopServer(dcid, srvid string) Resp {
func RebootServer(dcid, srvid string) Resp {
return server_command(dcid, srvid, "reboot")
}
+
+// server_command is a generic function for running server commands
+func server_command(dcid, srvid, cmd string) Resp {
+ jason := `
+ {}
+ `
+ path := server_command_path(dcid, srvid, cmd)
+ return is_command(path, jason)
+}
+
+func toServer(resp Resp) Server {
+ var server Server
+ json.Unmarshal(resp.Body, &server)
+ server.Response = string(resp.Body)
+ server.Headers = &resp.Headers
+ server.StatusCode = resp.StatusCode
+ return server
+}
+
+func toServers(resp Resp) Servers {
+ var col Servers
+ json.Unmarshal(resp.Body, &col)
+ col.Response = string(resp.Body)
+ col.Headers = &resp.Headers
+ col.StatusCode = resp.StatusCode
+ return col
+}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/snapshot.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/snapshot.go
new file mode 100644
index 000000000..a5f54c04f
--- /dev/null
+++ b/vendor/github.com/profitbricks/profitbricks-sdk-go/snapshot.go
@@ -0,0 +1,96 @@
+package profitbricks
+
+import (
+ "bytes"
+ "encoding/json"
+ "net/http"
+)
+
+type Snapshot struct {
+ Id string `json:"id,omitempty"`
+ Type_ string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+ Metadata DatacenterElementMetadata `json:"metadata,omitempty"`
+ Properties SnapshotProperties `json:"properties,omitempty"`
+ Response string `json:"Response,omitempty"`
+ Headers *http.Header `json:"headers,omitempty"`
+ StatusCode int `json:"headers,omitempty"`
+}
+
+type SnapshotProperties struct {
+ Name string `json:"name,omitempty"`
+ Description string `json:"description,omitempty"`
+ Location string `json:"location,omitempty"`
+ Size int `json:"size,omitempty"`
+ CpuHotPlug bool `json:"cpuHotPlug,omitempty"`
+ CpuHotUnplug bool `json:"cpuHotUnplug,omitempty"`
+ RamHotPlug bool `json:"ramHotPlug,omitempty"`
+ RamHotUnplug bool `json:"ramHotUnplug,omitempty"`
+ NicHotPlug bool `json:"nicHotPlug,omitempty"`
+ NicHotUnplug bool `json:"nicHotUnplug,omitempty"`
+ DiscVirtioHotPlug bool `json:"discVirtioHotPlug,omitempty"`
+ DiscVirtioHotUnplug bool `json:"discVirtioHotUnplug,omitempty"`
+ DiscScsiHotPlug bool `json:"discScsiHotPlug,omitempty"`
+ DiscScsiHotUnplug bool `json:"discScsiHotUnplug,omitempty"`
+ LicenceType string `json:"licenceType,omitempty"`
+}
+
+type Snapshots struct {
+ Id string `json:"id,omitempty"`
+ Type_ string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+ Items []Snapshot `json:"items,omitempty"`
+ Response string `json:"Response,omitempty"`
+ Headers *http.Header `json:"headers,omitempty"`
+ StatusCode int `json:"headers,omitempty"`
+}
+
+func ListSnapshots() Snapshots {
+ path := snapshot_col_path()
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ return toSnapshots(do(req))
+}
+
+func GetSnapshot(snapshotId string) Snapshot {
+ path := snapshot_col_path() + slash(snapshotId)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ return toSnapshot(do(req))
+}
+
+func DeleteSnapshot(snapshotId string) Resp {
+ path := snapshot_col_path() + slash(snapshotId)
+ url := mk_url(path)
+ req, _ := http.NewRequest("DELETE", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ return do(req)
+}
+
+func UpdateSnapshot(snapshotId string, request SnapshotProperties) Snapshot {
+ path := snapshot_col_path() + slash(snapshotId)
+ obj, _ := json.Marshal(request)
+ url := mk_url(path)
+ req, _ := http.NewRequest("PATCH", url, bytes.NewBuffer(obj))
+ req.Header.Add("Content-Type", PatchHeader)
+ return toSnapshot(do(req))
+}
+
+func toSnapshot(resp Resp) Snapshot {
+ var lan Snapshot
+ json.Unmarshal(resp.Body, &lan)
+ lan.Response = string(resp.Body)
+ lan.Headers = &resp.Headers
+ lan.StatusCode = resp.StatusCode
+ return lan
+}
+func toSnapshots(resp Resp) Snapshots {
+ var col Snapshots
+ json.Unmarshal(resp.Body, &col)
+ col.Response = string(resp.Body)
+ col.Headers = &resp.Headers
+ col.StatusCode = resp.StatusCode
+ return col
+}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/test_helpers.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/test_helpers.go
index 81e43afb0..35df1f929 100644
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/test_helpers.go
+++ b/vendor/github.com/profitbricks/profitbricks-sdk-go/test_helpers.go
@@ -1,10 +1,13 @@
package profitbricks
-import "fmt"
+import (
+ "fmt"
+ "time"
+)
func mkdcid(name string) string {
- request := CreateDatacenterRequest{
- DCProperties: DCProperties{
+ request := Datacenter{
+ Properties: DatacenterProperties{
Name: name,
Description: "description",
Location: "us/las",
@@ -14,21 +17,14 @@ func mkdcid(name string) string {
fmt.Println("===========================")
fmt.Println("Created a DC " + name)
fmt.Println("Created a DC id " + dc.Id)
- fmt.Println(dc.Resp.StatusCode)
+ fmt.Println(dc.StatusCode)
fmt.Println("===========================")
return dc.Id
}
-func mklocid() string {
- resp := ListLocations()
-
- locid := resp.Items[0].Id
- return locid
-}
-
func mksrvid(srv_dcid string) string {
- var req = CreateServerRequest{
- ServerProperties: ServerProperties{
+ var req = Server{
+ Properties: ServerProperties{
Name: "GO SDK test",
Ram: 1024,
Cores: 2,
@@ -37,16 +33,18 @@ func mksrvid(srv_dcid string) string {
srv := CreateServer(srv_dcid, req)
fmt.Println("===========================")
fmt.Println("Created a server " + srv.Id)
- fmt.Println(srv.Resp.StatusCode)
+ fmt.Println(srv.StatusCode)
fmt.Println("===========================")
+
+ waitTillProvisioned(srv.Headers.Get("Location"))
return srv.Id
}
func mknic(lbal_dcid, serverid string) string {
- var request = NicCreateRequest{
- NicProperties{
+ var request = Nic{
+ Properties: NicProperties{
Name: "GO SDK Original Nic",
- Lan: "1",
+ Lan: 1,
},
}
@@ -55,7 +53,20 @@ func mknic(lbal_dcid, serverid string) string {
fmt.Println("created a nic at server " + serverid)
fmt.Println("created a nic with id " + resp.Id)
- fmt.Println(resp.Resp.StatusCode)
+ fmt.Println(resp.StatusCode)
fmt.Println("===========================")
return resp.Id
}
+
+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++
+ }
+}
diff --git a/vendor/github.com/profitbricks/profitbricks-sdk-go/volume.go b/vendor/github.com/profitbricks/profitbricks-sdk-go/volume.go
index fe3d6529e..2982448d7 100644
--- a/vendor/github.com/profitbricks/profitbricks-sdk-go/volume.go
+++ b/vendor/github.com/profitbricks/profitbricks-sdk-go/volume.go
@@ -1,43 +1,93 @@
package profitbricks
-import "encoding/json"
+import (
+ "bytes"
+ "encoding/json"
+ "net/http"
+)
+
+type Volume struct {
+ Id string `json:"id,omitempty"`
+ Type_ string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+ Metadata *DatacenterElementMetadata `json:"metadata,omitempty"`
+ Properties VolumeProperties `json:"properties,omitempty"`
+ Response string `json:"Response,omitempty"`
+ Headers *http.Header `json:"headers,omitempty"`
+ StatusCode int `json:"headers,omitempty"`
+}
+
+type VolumeProperties struct {
+ Name string `json:"name,omitempty"`
+ Type string `json:"type,omitempty"`
+ Size int `json:"size,omitempty"`
+ Image string `json:"image,omitempty"`
+ ImagePassword string `json:"imagePassword,omitempty"`
+ SshKeys []string `json:"sshKeys,omitempty"`
+ Bus string `json:"bus,omitempty"`
+ LicenceType string `json:"licenceType,omitempty"`
+ CpuHotPlug bool `json:"cpuHotPlug,omitempty"`
+ CpuHotUnplug bool `json:"cpuHotUnplug,omitempty"`
+ RamHotPlug bool `json:"ramHotPlug,omitempty"`
+ RamHotUnplug bool `json:"ramHotUnplug,omitempty"`
+ NicHotPlug bool `json:"nicHotPlug,omitempty"`
+ NicHotUnplug bool `json:"nicHotUnplug,omitempty"`
+ DiscVirtioHotPlug bool `json:"discVirtioHotPlug,omitempty"`
+ DiscVirtioHotUnplug bool `json:"discVirtioHotUnplug,omitempty"`
+ DiscScsiHotPlug bool `json:"discScsiHotPlug,omitempty"`
+ DiscScsiHotUnplug bool `json:"discScsiHotUnplug,omitempty"`
+ DeviceNumber int64 `json:"deviceNumber,omitempty"`
+}
+
+type Volumes struct {
+ Id string `json:"id,omitempty"`
+ Type_ string `json:"type,omitempty"`
+ Href string `json:"href,omitempty"`
+ Items []Volume `json:"items,omitempty"`
+ Response string `json:"Response,omitempty"`
+ Headers *http.Header `json:"headers,omitempty"`
+ StatusCode int `json:"headers,omitempty"`
+}
type CreateVolumeRequest struct {
VolumeProperties `json:"properties"`
}
-type VolumeProperties struct {
- Name string `json:"name,omitempty"`
- Size int `json:"size,omitempty"`
- Bus string `json:",bus,omitempty"`
- Image string `json:"image,omitempty"`
- Type string `json:"type,omitempty"`
- LicenceType string `json:"licenceType,omitempty"`
- ImagePassword string `json:"imagePassword,omitempty"`
- SshKey []string `json:"sshKeys,omitempty"`
-}
-
// ListVolumes returns a Collection struct for volumes in the Datacenter
-func ListVolumes(dcid string) Collection {
+func ListVolumes(dcid string) Volumes {
path := volume_col_path(dcid)
- return is_list(path)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ resp := do(req)
+ return toVolumes(resp)
}
-func GetVolume(dcid string, volumeId string) Instance {
+func GetVolume(dcid string, volumeId string) Volume {
path := volume_path(dcid, volumeId)
- return is_get(path)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("GET", url, nil)
+ req.Header.Add("Content-Type", FullHeader)
+ resp := do(req)
+ return toVolume(resp)
}
-func PatchVolume(dcid string, volid string, request VolumeProperties) Instance {
+func PatchVolume(dcid string, volid string, request VolumeProperties) Volume {
obj, _ := json.Marshal(request)
path := volume_path(dcid, volid)
- return is_patch(path, obj)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("PATCH", url, bytes.NewBuffer(obj))
+ req.Header.Add("Content-Type", PatchHeader)
+ return toVolume(do(req))
}
-func CreateVolume(dcid string, request CreateVolumeRequest) Instance {
+func CreateVolume(dcid string, request Volume) Volume {
obj, _ := json.Marshal(request)
path := volume_col_path(dcid)
- return is_post(path, obj)
+ url := mk_url(path) + `?depth=` + Depth
+ req, _ := http.NewRequest("POST", url, bytes.NewBuffer(obj))
+ req.Header.Add("Content-Type", FullHeader)
+ return toVolume(do(req))
}
func DeleteVolume(dcid, volid string) Resp {
@@ -45,16 +95,37 @@ func DeleteVolume(dcid, volid string) Resp {
return is_delete(path)
}
-func CreateSnapshot(dcid string, volid string, name string) Resp {
+func CreateSnapshot(dcid string, volid string, name string) Snapshot {
var path = volume_path(dcid, volid)
path = path + "/create-snapshot"
-
- return is_command(path, "name=" + name)
+ url := mk_url(path)
+ body := json.RawMessage("name=" + name)
+ req, _ := http.NewRequest("POST", url, bytes.NewBuffer(body))
+ req.Header.Add("Content-Type", CommandHeader)
+ return toSnapshot(do(req))
}
func RestoreSnapshot(dcid string, volid string, snapshotId string) Resp {
var path = volume_path(dcid, volid)
path = path + "/restore-snapshot"
- return is_command(path, "snapshotId=" + snapshotId)
+ return is_command(path, "snapshotId="+snapshotId)
+}
+
+func toVolume(resp Resp) Volume {
+ var server Volume
+ json.Unmarshal(resp.Body, &server)
+ server.Response = string(resp.Body)
+ server.Headers = &resp.Headers
+ server.StatusCode = resp.StatusCode
+ return server
+}
+
+func toVolumes(resp Resp) Volumes {
+ var col Volumes
+ json.Unmarshal(resp.Body, &col)
+ col.Response = string(resp.Body)
+ col.Headers = &resp.Headers
+ col.StatusCode = resp.StatusCode
+ return col
}