Skip to content

Commit fc8b79d

Browse files
authored
Merge pull request #60 from opencredo/master
Allow empty boolean values and add fields to create server networking
2 parents 56b37fe + b224805 commit fc8b79d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+5558
-4330
lines changed

upcloud/hosts_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func TestUnmarshalHosts(t *testing.T) {
7373
ID: 7653311107,
7474
Description: "My Host #1",
7575
Zone: "private-zone-id",
76-
WindowsEnabled: false,
76+
WindowsEnabled: False,
7777
Stats: []Stat{
7878
{
7979
Name: "cpu_idle",
@@ -91,7 +91,7 @@ func TestUnmarshalHosts(t *testing.T) {
9191
ID: 8055964291,
9292
Description: "My Host #2",
9393
Zone: "private-zone-id",
94-
WindowsEnabled: false,
94+
WindowsEnabled: False,
9595
Stats: []Stat{
9696
{
9797
Name: "cpu_idle",
@@ -147,7 +147,7 @@ func TestUnmarshalHost(t *testing.T) {
147147
ID: 7653311107,
148148
Description: "My Host #1",
149149
Zone: "private-zone-id",
150-
WindowsEnabled: false,
150+
WindowsEnabled: False,
151151
Stats: []Stat{
152152
{
153153
Name: "cpu_idle",

upcloud/ip_address_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func TestUnmarshalIPAddresses(t *testing.T) {
7979
Family: IPAddressFamilyIPv4,
8080
PTRRecord: "",
8181
ServerUUID: "0053cd80-5945-4105-9081-11192806a8f7",
82+
Floating: False,
8283
MAC: "mm:mm:mm:mm:mm:m1",
8384
Zone: "fi-hel2",
8485
},
@@ -88,17 +89,18 @@ func TestUnmarshalIPAddresses(t *testing.T) {
8889
Family: IPAddressFamilyIPv4,
8990
PTRRecord: "",
9091
ServerUUID: "006b6701-55d2-4374-ac40-56cc1501037f",
92+
Floating: False,
9193
MAC: "mm:mm:mm:mm:mm:m2",
9294
Zone: "de-fra1",
9395
},
9496
{
9597
Access: IPAddressAccessPublic,
9698
Address: "x.x.x.x",
9799
Family: IPAddressFamilyIPv4,
98-
PartOfPlan: true,
100+
PartOfPlan: True,
99101
PTRRecord: "x-x-x-x.zone.upcloud.host",
100102
ServerUUID: "0053cd80-5945-4105-9081-11192806a8f7",
101-
Floating: true,
103+
Floating: True,
102104
MAC: "mm:mm:mm:mm:mm:m1",
103105
Zone: "de-fra1",
104106
},
@@ -108,6 +110,7 @@ func TestUnmarshalIPAddresses(t *testing.T) {
108110
Family: IPAddressFamilyIPv6,
109111
PTRRecord: "xxxx-xxxx-xxxx-xxxx.v6.zone.upcloud.host",
110112
ServerUUID: "006b6701-55d2-4374-ac40-56cc1501037f",
113+
Floating: False,
111114
MAC: "mm:mm:mm:mm:mm:m3",
112115
Zone: "fi-hel1",
113116
},
@@ -116,7 +119,7 @@ func TestUnmarshalIPAddresses(t *testing.T) {
116119
Address: "y.y.y.y",
117120
Family: IPAddressFamilyIPv4,
118121
PTRRecord: "y.y.y.y.zone.host.upcloud.com",
119-
Floating: true,
122+
Floating: True,
120123
Zone: "nl-ams1",
121124
},
122125
}

upcloud/network_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ func TestUnmarshalNetworks(t *testing.T) {
8383
IPNetworks: []IPNetwork{
8484
{
8585
Address: "80.69.172.0/22",
86-
DHCP: true,
87-
DHCPDefaultRoute: true,
86+
DHCP: True,
87+
DHCPDefaultRoute: True,
8888
DHCPDns: []string{
8989
"94.237.127.9",
9090
"94.237.40.9",
@@ -112,8 +112,8 @@ func TestUnmarshalNetworks(t *testing.T) {
112112
IPNetworks: []IPNetwork{
113113
{
114114
Address: "80.69.173.0/22",
115-
DHCP: false,
116-
DHCPDefaultRoute: false,
115+
DHCP: False,
116+
DHCPDefaultRoute: False,
117117
DHCPDns: []string{
118118
"94.237.17.9",
119119
"94.237.4.9",
@@ -193,8 +193,8 @@ func TestUnmarshalNetwork(t *testing.T) {
193193
IPNetworks: []IPNetwork{
194194
{
195195
Address: "172.16.0.0/22",
196-
DHCP: true,
197-
DHCPDefaultRoute: false,
196+
DHCP: True,
197+
DHCPDefaultRoute: False,
198198
DHCPDns: []string{
199199
"172.16.0.10",
200200
"172.16.1.10",
@@ -296,9 +296,9 @@ func TestUnmarshalServerNetworks(t *testing.T) {
296296
},
297297
MAC: "de:ff:ff:ff:66:89",
298298
Network: "037fcf2a-6745-45dd-867e-f9479ea8c044",
299-
SourceIPFiltering: true,
299+
SourceIPFiltering: True,
300300
Type: NetworkTypePublic,
301-
Bootable: false,
301+
Bootable: False,
302302
},
303303
{
304304
Index: 3,
@@ -310,9 +310,9 @@ func TestUnmarshalServerNetworks(t *testing.T) {
310310
},
311311
MAC: "de:ff:ff:ff:ed:85",
312312
Network: "03c93fd8-cc60-4849-91b8-6e404b228e2a",
313-
SourceIPFiltering: true,
313+
SourceIPFiltering: True,
314314
Type: NetworkTypeUtility,
315-
Bootable: false,
315+
Bootable: False,
316316
},
317317
{
318318
Index: 4,
@@ -324,9 +324,9 @@ func TestUnmarshalServerNetworks(t *testing.T) {
324324
},
325325
MAC: "de:ff:ff:ff:cc:20",
326326
Network: "0374ce47-4303-4490-987d-32dc96cfd79b",
327-
SourceIPFiltering: true,
327+
SourceIPFiltering: True,
328328
Type: NetworkTypePrivate,
329-
Bootable: false,
329+
Bootable: False,
330330
},
331331
},
332332
}
@@ -369,14 +369,14 @@ func TestUnmarshalInterface(t *testing.T) {
369369
{
370370
Address: "10.0.0.20",
371371
Family: IPAddressFamilyIPv4,
372-
Floating: false,
372+
Floating: False,
373373
},
374374
},
375375
MAC: "de:ff:ff:ff:86:cf",
376376
Network: "0374ce47-4303-4490-987d-32dc96cfd79b",
377-
SourceIPFiltering: true,
377+
SourceIPFiltering: True,
378378
Type: NetworkTypePrivate,
379-
Bootable: false,
379+
Bootable: False,
380380
}
381381

382382
assert.Equal(t, testIface, iface)

upcloud/request/ip_address_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestMarshalAssignIPAddressRequest(t *testing.T) {
2424
Family: upcloud.IPAddressFamilyIPv4,
2525
ServerUUID: "009d64ef-31d1-4684-a26b-c86c955cbf46",
2626
MAC: "foo_mac",
27-
Floating: true,
27+
Floating: upcloud.True,
2828
Zone: "foo_zone",
2929
}
3030

upcloud/request/network.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ type CreateNetworkInterfaceRequest struct {
131131
ServerUUID string `json:"-"`
132132

133133
Type string `json:"type"`
134-
NetworkUUID string `json:"network"`
134+
NetworkUUID string `json:"network,omitempty"`
135135
Index int `json:"index,omitempty"`
136136
IPAddresses CreateNetworkInterfaceIPAddressSlice `json:"ip_addresses"`
137137
SourceIPFiltering upcloud.Boolean `json:"source_ip_filtering,omitempty"`

upcloud/request/network_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ func TestMarshalCreateNetworkRequest(t *testing.T) {
3535
IPNetworks: []upcloud.IPNetwork{
3636
{
3737
Address: "172.16.0.0/22",
38-
DHCP: true,
39-
DHCPDefaultRoute: false,
38+
DHCP: upcloud.True,
39+
DHCPDefaultRoute: upcloud.False,
4040
DHCPDns: []string{
4141
"172.16.0.10",
4242
"172.16.1.10",
@@ -86,7 +86,7 @@ func TestMarshalModifyNetworkRequest(t *testing.T) {
8686
Name: "My private network",
8787
IPNetworks: []upcloud.IPNetwork{
8888
{
89-
DHCP: false,
89+
DHCP: upcloud.False,
9090
Family: upcloud.IPAddressFamilyIPv4,
9191
},
9292
},
@@ -139,7 +139,7 @@ func TestMarshalCreateNetworkInterfaceRequest(t *testing.T) {
139139
ServerUUID: "foo",
140140
Type: upcloud.IPAddressAccessPrivate,
141141
NetworkUUID: "0374ce47-4303-4490-987d-32dc96cfd79b",
142-
SourceIPFiltering: true,
142+
SourceIPFiltering: upcloud.True,
143143
IPAddresses: []CreateNetworkInterfaceIPAddress{
144144
{
145145
Address: "10.0.0.20",
@@ -191,7 +191,7 @@ func TestMarshalModifyNetworkInterfaceRequest(t *testing.T) {
191191

192192
Type: upcloud.IPAddressAccessPrivate,
193193
NetworkUUID: "0374ce47-4303-4490-987d-32dc96cfd79b",
194-
SourceIPFiltering: true,
194+
SourceIPFiltering: upcloud.True,
195195
IPAddresses: []CreateNetworkInterfaceIPAddress{
196196
{
197197
Address: "10.0.0.20",

upcloud/request/server.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@ func (s CreateServerStorageDeviceSlice) MarshalJSON() ([]byte, error) {
8181
// CreateServerInterface represents a server network interface
8282
// that is needed during server creation.
8383
type CreateServerInterface struct {
84-
IPAddresses CreateServerIPAddressSlice `json:"ip_addresses"`
85-
Type string `json:"type"`
84+
IPAddresses CreateServerIPAddressSlice `json:"ip_addresses"`
85+
Type string `json:"type"`
86+
Network string `json:"network,omitempty"`
87+
SourceIPFiltering upcloud.Boolean `json:"source_ip_filtering,omitempty"`
88+
Bootable upcloud.Boolean `json:"bootable,omitempty"`
8689
}
8790

8891
// CreateServerInterfaceSlice is a slice of CreateServerInterfaces.

upcloud/request/server_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestCreateServerRequest(t *testing.T) {
3535
},
3636
},
3737
SimpleBackup: "0430,monthlies",
38-
Metadata: true,
38+
Metadata: upcloud.True,
3939
Networking: &CreateServerNetworking{
4040
Interfaces: []CreateServerInterface{
4141
{
@@ -71,7 +71,7 @@ func TestCreateServerRequest(t *testing.T) {
7171
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDJfx4OmD8D6mnPA0BPk2DVlbggEkMvB2cecSttauZuaYX7Vju6PvG+kXrUbTvO09oLQMoNYAk3RinqQLXo9eF7bzZIsgB4ZmKGau84kOpYjguhimkKtZiVTKF53G2pbnpiZUN9wfy3xK2mt/MkacjZ1Tp7lAgRGTfWDoTfQa88kzOJGNPWXd12HIvFtd/1KoS9vm5O0nDLV+5zSBLxEYNDmBlIGu1Y3XXle5ygL1BhfGvqOQnv/TdRZcrOgVGWHADvwEid91/+IycLNMc37uP7TdS6vOihFBMytfmFXAqt4+3AzYNmyc+R392RorFzobZ1UuEFm3gUod2Wvj8pY8d/ negge@palinski",
7272
},
7373
},
74-
RemoteAccessEnabled: true,
74+
RemoteAccessEnabled: upcloud.True,
7575
RemoteAccessType: upcloud.RemoteAccessTypeVNC,
7676
RemoteAccessPassword: "abcdefgh",
7777
}
@@ -129,7 +129,7 @@ func TestCreateServerRequest(t *testing.T) {
129129
}
130130
}
131131
`
132-
actualJSON, err := json.MarshalIndent(&request, "", " ")
132+
actualJSON, err := json.Marshal(&request)
133133
assert.NoError(t, err)
134134
assert.JSONEq(t, expectedJSON, string(actualJSON))
135135
assert.Equal(t, "/server", request.RequestURL())
@@ -263,7 +263,7 @@ func TestModifyServerRequest(t *testing.T) {
263263
CoreNumber: 8,
264264
MemoryAmount: 16384,
265265
Plan: "custom",
266-
Metadata: true,
266+
Metadata: upcloud.True,
267267
}
268268

269269
expectedJSON := `

upcloud/server_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,14 @@ func TestUnmarshalServerDetails(t *testing.T) {
253253
assert.Equal(t, 0, serverDetails.StorageDevices[0].BootDisk)
254254
assert.Equal(t, "UTC", serverDetails.Timezone)
255255
assert.Equal(t, VideoModelCirrus, serverDetails.VideoModel)
256-
assert.True(t, bool(serverDetails.RemoteAccessEnabled))
256+
assert.True(t, serverDetails.RemoteAccessEnabled.Bool())
257257
assert.Equal(t, "fi-hel1.vnc.upcloud.com", serverDetails.RemoteAccessHost)
258258
assert.Equal(t, "aabbccdd", serverDetails.RemoteAccessPassword)
259259
assert.Equal(t, 3000, serverDetails.RemoteAccessPort)
260260
assert.Equal(t, RemoteAccessTypeVNC, serverDetails.RemoteAccessType)
261261
assert.Equal(t, "server1.example.com", serverDetails.Hostname)
262262
assert.Equal(t, "0100,dailies", serverDetails.SimpleBackup)
263-
assert.True(t, bool(serverDetails.Metadata))
263+
assert.True(t, serverDetails.Metadata.Bool())
264264

265265
networkingTestData := []ServerInterface{
266266
{
@@ -269,41 +269,41 @@ func TestUnmarshalServerDetails(t *testing.T) {
269269
{
270270
Address: "94.237.0.207",
271271
Family: IPAddressFamilyIPv4,
272-
Floating: false,
272+
Floating: False,
273273
},
274274
},
275275
MAC: "de:ff:ff:ff:66:89",
276276
Network: "037fcf2a-6745-45dd-867e-f9479ea8c044",
277277
Type: NetworkTypePublic,
278-
Bootable: false,
278+
Bootable: False,
279279
},
280280
{
281281
Index: 2,
282282
IPAddresses: []IPAddress{
283283
{
284284
Address: "10.6.3.95",
285285
Family: IPAddressFamilyIPv4,
286-
Floating: false,
286+
Floating: False,
287287
},
288288
},
289289
MAC: "de:ff:ff:ff:ed:85",
290290
Network: "03000000-0000-4000-8045-000000000000",
291291
Type: NetworkTypeUtility,
292-
Bootable: false,
292+
Bootable: False,
293293
},
294294
{
295295
Index: 3,
296296
IPAddresses: []IPAddress{
297297
{
298298
Address: "xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx",
299299
Family: "IPv6",
300-
Floating: false,
300+
Floating: False,
301301
},
302302
},
303303
MAC: "de:ff:ff:ff:cc:20",
304304
Network: "03c93fd8-cc60-4849-91b8-6e404b228e2a",
305305
Type: NetworkTypePublic,
306-
Bootable: false,
306+
Bootable: False,
307307
},
308308
}
309309

0 commit comments

Comments
 (0)