-
Notifications
You must be signed in to change notification settings - Fork 132
/
types_cloud.go
199 lines (168 loc) · 6.21 KB
/
types_cloud.go
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package ovh
import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/ovh/terraform-provider-ovh/ovh/helpers"
)
// Opts
type CloudProjectNetworkPrivateCreateOpts struct {
ServiceName string `json:"serviceName"`
VlanId int `json:"vlanId"`
Name string `json:"name"`
Regions []string `json:"regions"`
}
func (p *CloudProjectNetworkPrivateCreateOpts) String() string {
return fmt.Sprintf("projectId: %s, vlanId:%d, name: %s, regions: %s", p.ServiceName, p.VlanId, p.Name, p.Regions)
}
// Opts
type CloudProjectNetworkPrivateUpdateOpts struct {
Name string `json:"name"`
}
type CloudProjectNetworkPrivateRegion struct {
Status string `json:"status"`
Region string `json:"region"`
OpenStackId string `json:"openstackId"`
}
func (p *CloudProjectNetworkPrivateRegion) String() string {
return fmt.Sprintf("Status:%s, Region: %s", p.Status, p.Region)
}
type CloudProjectNetworkPrivateResponse struct {
Id string `json:"id"`
Status string `json:"status"`
Vlanid int `json:"vlanId"`
Name string `json:"name"`
Type string `json:"type"`
Regions []*CloudProjectNetworkPrivateRegion `json:"regions"`
}
func (p *CloudProjectNetworkPrivateResponse) String() string {
return fmt.Sprintf("Id: %s, Status: %s, Name: %s, Vlanid: %d, Type: %s, Regions: %s", p.Id, p.Status, p.Name, p.Vlanid, p.Type, p.Regions)
}
// Opts
type CloudProjectNetworkPrivatesCreateOpts struct {
ServiceName string `json:"serviceName"`
NetworkId string `json:"networkId"`
Dhcp bool `json:"dhcp"`
NoGateway bool `json:"noGateway"`
Start string `json:"start"`
End string `json:"end"`
Network string `json:"network"`
Region string `json:"region"`
}
func (p *CloudProjectNetworkPrivatesCreateOpts) String() string {
return fmt.Sprintf("PCPNSCreateOpts[projectId: %s, networkId:%s, dhcp: %v, noGateway: %v, network: %s, start: %s, end: %s, region: %s]",
p.ServiceName, p.NetworkId, p.Dhcp, p.NoGateway, p.Network, p.Start, p.End, p.Region)
}
type CloudProjectNetworkPrivatesResponse struct {
Id string `json:"id"`
GatewayIp string `json:"gatewayIp"`
Cidr string `json:"cidr"`
IPPools []*IPPool `json:"ipPools"`
}
func (p *CloudProjectNetworkPrivatesResponse) String() string {
return fmt.Sprintf("PCPNSResponse[Id: %s, GatewayIp: %s, Cidr: %s, IPPools: %s]", p.Id, p.GatewayIp, p.Cidr, p.IPPools)
}
// Opts
type CloudProjectUserCreateOpts struct {
Description *string `json:"description,omitempty"`
Role *string `json:"role,omitempty"`
Roles []string `json:"roles"`
}
func (p *CloudProjectUserCreateOpts) String() string {
return fmt.Sprintf(
"CloudProjectUserCreateOpts[description:%v, role:%v, roles:%s]",
p.Description,
p.Role,
p.Roles,
)
}
func (opts *CloudProjectUserCreateOpts) FromResource(d *schema.ResourceData) *CloudProjectUserCreateOpts {
opts.Description = helpers.GetNilStringPointerFromData(d, "description")
opts.Role = helpers.GetNilStringPointerFromData(d, "role_name")
opts.Roles, _ = helpers.StringsFromSchema(d, "role_names")
return opts
}
type CloudProjectUser struct {
CreationDate string `json:"creationDate"`
Description string `json:"description"`
Id int `json:"id"`
Password string `json:"password"`
Roles []*CloudProjectUserRole `json:"roles"`
Status string `json:"status"`
Username string `json:"username"`
}
func (u *CloudProjectUser) String() string {
return fmt.Sprintf("UserResponse[Id: %v, Username: %s, Status: %s, Description: %s, CreationDate: %s]", u.Id, u.Username, u.Status, u.Description, u.CreationDate)
}
func (u CloudProjectUser) ToMap() map[string]interface{} {
obj := make(map[string]interface{})
obj["creation_date"] = u.CreationDate
obj["description"] = u.Description
// Don't set password as it must be set only at creation time
obj["status"] = u.Status
obj["username"] = u.Username
// Set the roles
var roles []map[string]interface{}
for _, r := range u.Roles {
roles = append(roles, r.ToMap())
}
obj["roles"] = roles
return obj
}
type CloudProjectUserRole struct {
Description string `json:"description"`
Id string `json:"id"`
Name string `json:"name"`
Permissions []string `json:"permissions"`
}
func (r CloudProjectUserRole) ToMap() map[string]interface{} {
obj := make(map[string]interface{})
obj["description"] = r.Description
obj["id"] = r.Id
obj["name"] = r.Name
obj["permissions"] = r.Permissions
return obj
}
type CloudProjectUserOpenstackRC struct {
Content string `json:"content"`
}
type CloudProjectUserS3Credential struct {
Access string `json:"access"`
Secret string `json:"secret"`
ServiceName string `json:"tenantId"`
UserId string `json:"userId"`
}
func (u *CloudProjectUserS3Credential) String() string {
return fmt.Sprintf("CloudProjectUserS3Credential[ServiceName:%s, UserId: %s, Access: %s]", u.ServiceName, u.UserId, u.Access)
}
func (u CloudProjectUserS3Credential) ToMap() map[string]interface{} {
obj := make(map[string]interface{})
obj["access_key_id"] = u.Access
obj["secret_access_key"] = u.Secret
obj["service_name"] = u.ServiceName
obj["internal_user_id"] = u.UserId
return obj
}
type CloudProjectRegionResponse struct {
ContinentCode string `json:"continentCode"`
DatacenterLocation string `json:"datacenterLocation"`
Name string `json:"name"`
Services []CloudServiceStatusResponse `json:"services"`
}
func (r *CloudProjectRegionResponse) String() string {
return fmt.Sprintf("Region: %s, Services: %s", r.Name, r.Services)
}
func (r *CloudProjectRegionResponse) HasServiceUp(service string) bool {
for _, s := range r.Services {
if s.Name == service && s.Status == "UP" {
return true
}
}
return false
}
type CloudServiceStatusResponse struct {
Status string `json:"status"`
Name string `json:"name"`
}
func (s *CloudServiceStatusResponse) String() string {
return fmt.Sprintf("%s: %s", s.Name, s.Status)
}