summaryrefslogtreecommitdiff
path: root/vendor/github.com/mitchellh/packer/vendor/github.com/profitbricks/profitbricks-sdk-go/contractresources.go
blob: cd4fa2c3ce2fc2454318b402d78b9a62cfc01ff9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package profitbricks

import (
	"encoding/json"
	"net/http"
	"strconv"
)

type ContractResources struct {
	Id         string                      `json:"id,omitempty"`
	Type_      string                      `json:"type,omitempty"`
	Href       string                      `json:"href,omitempty"`
	Properties ContractResourcesProperties `json:"properties,omitempty"`
	Response   string                      `json:"Response,omitempty"`
	Headers    *http.Header                `json:"headers,omitempty"`
	StatusCode int                         `json:"headers,omitempty"`
}

type ContractResourcesProperties struct {
	PBContractNumber string           `json:"PB-Contract-Number,omitempty"`
	Owner            string           `json:"owner,omitempty"`
	Status           string           `json:"status,omitempty"`
	ResourceLimits   *ResourcesLimits `json:"resourceLimits,omitempty"`
}

type ResourcesLimits struct {
	CoresPerServer        int32 `json:"coresPerServer,omitempty"`
	CoresPerContract      int32 `json:"coresPerContract,omitempty"`
	CoresProvisioned      int32 `json:"coresProvisioned,omitempty"`
	RamPerServer          int32 `json:"ramPerServer,omitempty"`
	RamPerContract        int32 `json:"ramPerContract,omitempty"`
	RamProvisioned        int32 `json:"ramProvisioned,omitempty"`
	HddLimitPerVolume     int64 `json:"hddLimitPerVolume,omitempty"`
	HddLimitPerContract   int64 `json:"hddLimitPerContract,omitempty"`
	HddVolumeProvisioned  int64 `json:"hddVolumeProvisioned,omitempty"`
	SsdLimitPerVolume     int64 `json:"ssdLimitPerVolume,omitempty"`
	SsdLimitPerContract   int64 `json:"ssdLimitPerContract,omitempty"`
	SsdVolumeProvisioned  int64 `json:"ssdVolumeProvisioned,omitempty"`
	ReservableIps         int32 `json:"reservableIps,omitempty"`
	ReservedIpsOnContract int32 `json:"reservedIpsOnContract,omitempty"`
	ReservedIpsInUse      int32 `json:"reservedIpsInUse,omitempty"`
}

func GetContractResources() ContractResources {
	path := contract_resource_path()
	url := mk_url(path) + `?depth=` + Depth + `&pretty=` + strconv.FormatBool(Pretty)
	req, _ := http.NewRequest("GET", url, nil)
	req.Header.Add("Content-Type", FullHeader)
	resp := do(req)
	return toContractResources(resp)
}

func toContractResources(resp Resp) ContractResources {
	var col ContractResources
	json.Unmarshal(resp.Body, &col)
	col.Response = string(resp.Body)
	col.Headers = &resp.Headers
	col.StatusCode = resp.StatusCode
	return col
}