Skip to content

Commit

Permalink
Add install flavours to order struct
Browse files Browse the repository at this point in the history
  • Loading branch information
TransIP committed May 1, 2020
1 parent 7e609de commit bf26697
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ analyze:lint:
image: golangci/golangci-lint:v1.19
script:
- golangci-lint run
tags:
- k8s

lint:golint:
stage: lint
Expand Down
7 changes: 5 additions & 2 deletions vps/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestRepository_GetByName(t *testing.T) {
}

func TestRepository_Order(t *testing.T) {
const expectedRequestBody = `{"productName":"vps-bladevps-x8","operatingSystem":"ubuntu-18.04","availabilityZone":"ams0","addons":["vpsAddon-1-extra-cpu-core"],"hostname":"server01.example.com","description":"example vps description","base64InstallText":"testtext123"}`
const expectedRequestBody = `{"productName":"vps-bladevps-x8","operatingSystem":"ubuntu-18.04","availabilityZone":"ams0","description":"example vps description","addons":["vpsAddon-1-extra-cpu-core"],"installFlavour":"cloudinit","hostname":"server01.example.com","username":"bob","sshKeys":["ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDf2pxWX/yhUBDyk2LPhvRtI0LnVO8PyR5Zt6AHrnhtLGqK+8YG9EMlWbCCWrASR+Q1hFQG example"],"base64InstallText":"testtext123"}`
server := mockServer{t: t, expectedURL: "/vps", expectedMethod: "POST", statusCode: 201, expectedRequest: expectedRequestBody}
client, tearDown := server.getClient()
defer tearDown()
Expand All @@ -199,7 +199,10 @@ func TestRepository_Order(t *testing.T) {
OperatingSystem: "ubuntu-18.04",
AvailabilityZone: "ams0",
Addons: []string{"vpsAddon-1-extra-cpu-core"},
InstallFlavour: InstallFlavourCloudInit,
Hostname: "server01.example.com",
Username: "bob",
SSHKeys: []string{"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDf2pxWX/yhUBDyk2LPhvRtI0LnVO8PyR5Zt6AHrnhtLGqK+8YG9EMlWbCCWrASR+Q1hFQG example"},
Description: "example vps description",
Base64InstallText: "testtext123",
}
Expand All @@ -209,7 +212,7 @@ func TestRepository_Order(t *testing.T) {
}

func TestRepository_OrderMultiple(t *testing.T) {
const expectedRequestBody = `{"vpss":[{"productName":"vps-bladevps-x8","operatingSystem":"ubuntu-18.04","availabilityZone":"ams0","addons":["vpsAddon-1-extra-cpu-core"],"hostname":"server01.example.com","description":"webserver01","base64InstallText":"testtext123"},{"productName":"vps-bladevps-x8","operatingSystem":"ubuntu-18.04","availabilityZone":"ams0","hostname":"server01.example.com","description":"backupserver01"}]}`
const expectedRequestBody = `{"vpss":[{"productName":"vps-bladevps-x8","operatingSystem":"ubuntu-18.04","availabilityZone":"ams0","description":"webserver01","addons":["vpsAddon-1-extra-cpu-core"],"hostname":"server01.example.com","base64InstallText":"testtext123"},{"productName":"vps-bladevps-x8","operatingSystem":"ubuntu-18.04","availabilityZone":"ams0","description":"backupserver01","hostname":"server01.example.com"}]}`
server := mockServer{t: t, expectedURL: "/vps", expectedMethod: "POST", statusCode: 201, expectedRequest: expectedRequestBody}
client, tearDown := server.getClient()
defer tearDown()
Expand Down
38 changes: 27 additions & 11 deletions vps/vps.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,22 @@ type revertSnapshotRequest struct {
}

// installRequest struct contains a list with OperatingSystems in it,
// this is solely used for marshalling
// this is used for marshalling and aliased by InstallOptions
type installRequest struct {
OperatingSystemName string `json:"operatingSystemName"`
InstallFlavour InstallFlavour `json:"installFlavour,omitempty"`
Hostname string `json:"hostname,omitempty"`
Username string `json:"username,omitempty"`
SSHKeys []string `json:"sshKeys,omitempty"`
Base64InstallText string `json:"base64InstallText,omitempty"`
// The name of the operating system to install
OperatingSystemName string `json:"operatingSystemName"`
// Install flavour to use for providing the operating system (optional)
// If the field is left empty, the default install flavour for the operating system will be used
InstallFlavour InstallFlavour `json:"installFlavour,omitempty"`
// The name for the host, only needed for the preinstallable and cloudinit install flavours
Hostname string `json:"hostname,omitempty"`
// Username used for account creating during cloudinit installation (max 32 chars)
Username string `json:"username,omitempty"`
// Array of public SSH keys to use for account creating during installation
// (currently only supported with the cloudinit flavour)
SSHKeys []string `json:"sshKeys,omitempty"`
// Base64 encoded preseed / kickstart / cloudinit instructions, when installing unattended
Base64InstallText string `json:"base64InstallText,omitempty"`
}

// InstallOptions can be used to provide options to
Expand Down Expand Up @@ -420,13 +428,21 @@ type Order struct {
OperatingSystem string `json:"operatingSystem"`
// The name of the availability zone where the vps should be created
AvailabilityZone string `json:"availabilityZone,omitempty"`
// The description of the VPS
Description string `json:"description,omitempty"`
// Array with additional addons
Addons []string `json:"addons,omitempty"`
// The name for the host, only needed for installing a preinstallable control panel image
// Install flavour to use for providing the operating system (optional)
// If the field is left empty, the default install flavour for the operating system will be used
InstallFlavour InstallFlavour `json:"installFlavour,omitempty"`
// The name for the host, only needed for the preinstallable and cloudinit install flavours
Hostname string `json:"hostname,omitempty"`
// The description of the VPS
Description string `json:"description,omitempty"`
// Base64 encoded preseed / kickstart instructions, when installing unattended
// Username used for account creating during cloudinit installation (max 32 chars)
Username string `json:"username,omitempty"`
// Array of public SSH keys to use for account creating during installation
// (currently only supported with the cloudinit flavour)
SSHKeys []string `json:"sshKeys,omitempty"`
// Base64 encoded preseed / kickstart / cloudinit instructions, when installing unattended
Base64InstallText string `json:"base64InstallText,omitempty"`
}

Expand Down

0 comments on commit bf26697

Please sign in to comment.