From 7e20aba8c05cff6b266fa3eeeede50bcc177377b Mon Sep 17 00:00:00 2001 From: Gerrit Date: Wed, 18 Aug 2021 15:20:26 +0200 Subject: [PATCH] Add allocation roles. (#70) --- api/models/datastore_machine_search_query.go | 3 ++ api/models/v1_firewall_find_request.go | 3 ++ api/models/v1_machine_allocation.go | 53 ++++++++++++++++++++ api/models/v1_machine_find_request.go | 3 ++ metal-api.json | 18 +++++++ test/mocks/image/ClientService.go | 30 +++++++++++ 6 files changed, 110 insertions(+) diff --git a/api/models/datastore_machine_search_query.go b/api/models/datastore_machine_search_query.go index c69a787f..1966ed98 100644 --- a/api/models/datastore_machine_search_query.go +++ b/api/models/datastore_machine_search_query.go @@ -29,6 +29,9 @@ type DatastoreMachineSearchQuery struct { // allocation project AllocationProject string `json:"allocation_project,omitempty"` + // allocation role + AllocationRole string `json:"allocation_role,omitempty"` + // allocation succeeded AllocationSucceeded bool `json:"allocation_succeeded,omitempty"` diff --git a/api/models/v1_firewall_find_request.go b/api/models/v1_firewall_find_request.go index e51d83f8..7b8c37ca 100644 --- a/api/models/v1_firewall_find_request.go +++ b/api/models/v1_firewall_find_request.go @@ -29,6 +29,9 @@ type V1FirewallFindRequest struct { // allocation project AllocationProject string `json:"allocation_project,omitempty"` + // allocation role + AllocationRole string `json:"allocation_role,omitempty"` + // allocation succeeded AllocationSucceeded bool `json:"allocation_succeeded,omitempty"` diff --git a/api/models/v1_machine_allocation.go b/api/models/v1_machine_allocation.go index 764de8f2..54ec4f14 100644 --- a/api/models/v1_machine_allocation.go +++ b/api/models/v1_machine_allocation.go @@ -7,6 +7,7 @@ package models import ( "context" + "encoding/json" "strconv" "github.com/go-openapi/errors" @@ -62,6 +63,11 @@ type V1MachineAllocation struct { // Required: true Reinstall *bool `json:"reinstall"` + // the role of the machine + // Required: true + // Enum: [firewall machine] + Role *string `json:"role"` + // the public ssh keys to access the machine with // Required: true SSHPubKeys []string `json:"ssh_pub_keys"` @@ -118,6 +124,10 @@ func (m *V1MachineAllocation) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateRole(formats); err != nil { + res = append(res, err) + } + if err := m.validateSSHPubKeys(formats); err != nil { res = append(res, err) } @@ -266,6 +276,49 @@ func (m *V1MachineAllocation) validateReinstall(formats strfmt.Registry) error { return nil } +var v1MachineAllocationTypeRolePropEnum []interface{} + +func init() { + var res []string + if err := json.Unmarshal([]byte(`["firewall","machine"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + v1MachineAllocationTypeRolePropEnum = append(v1MachineAllocationTypeRolePropEnum, v) + } +} + +const ( + + // V1MachineAllocationRoleFirewall captures enum value "firewall" + V1MachineAllocationRoleFirewall string = "firewall" + + // V1MachineAllocationRoleMachine captures enum value "machine" + V1MachineAllocationRoleMachine string = "machine" +) + +// prop value enum +func (m *V1MachineAllocation) validateRoleEnum(path, location string, value string) error { + if err := validate.EnumCase(path, location, value, v1MachineAllocationTypeRolePropEnum, true); err != nil { + return err + } + return nil +} + +func (m *V1MachineAllocation) validateRole(formats strfmt.Registry) error { + + if err := validate.Required("role", "body", m.Role); err != nil { + return err + } + + // value enum + if err := m.validateRoleEnum("role", "body", *m.Role); err != nil { + return err + } + + return nil +} + func (m *V1MachineAllocation) validateSSHPubKeys(formats strfmt.Registry) error { if err := validate.Required("ssh_pub_keys", "body", m.SSHPubKeys); err != nil { diff --git a/api/models/v1_machine_find_request.go b/api/models/v1_machine_find_request.go index 31231e2e..c1901d5c 100644 --- a/api/models/v1_machine_find_request.go +++ b/api/models/v1_machine_find_request.go @@ -29,6 +29,9 @@ type V1MachineFindRequest struct { // allocation project AllocationProject string `json:"allocation_project,omitempty"` + // allocation role + AllocationRole string `json:"allocation_role,omitempty"` + // allocation succeeded AllocationSucceeded bool `json:"allocation_succeeded,omitempty"` diff --git a/metal-api.json b/metal-api.json index ef1c89f8..998c1789 100644 --- a/metal-api.json +++ b/metal-api.json @@ -55,6 +55,9 @@ "allocation_project": { "type": "string" }, + "allocation_role": { + "type": "string" + }, "allocation_succeeded": { "type": "boolean" }, @@ -925,6 +928,9 @@ "allocation_project": { "type": "string" }, + "allocation_role": { + "type": "string" + }, "allocation_succeeded": { "type": "boolean" }, @@ -1821,6 +1827,14 @@ "description": "indicates whether to reinstall the machine", "type": "boolean" }, + "role": { + "description": "the role of the machine", + "enum": [ + "firewall", + "machine" + ], + "type": "string" + }, "ssh_pub_keys": { "description": "the public ssh keys to access the machine with", "items": { @@ -1845,6 +1859,7 @@ "networks", "project", "reinstall", + "role", "ssh_pub_keys", "succeeded" ] @@ -2064,6 +2079,9 @@ "allocation_project": { "type": "string" }, + "allocation_role": { + "type": "string" + }, "allocation_succeeded": { "type": "boolean" }, diff --git a/test/mocks/image/ClientService.go b/test/mocks/image/ClientService.go index 657f3a07..ea5988df 100644 --- a/test/mocks/image/ClientService.go +++ b/test/mocks/image/ClientService.go @@ -164,6 +164,36 @@ func (_m *ClientService) ListImages(params *image.ListImagesParams, authInfo run return r0, r1 } +// QueryImagesByID provides a mock function with given fields: params, authInfo, opts +func (_m *ClientService) QueryImagesByID(params *image.QueryImagesByIDParams, authInfo runtime.ClientAuthInfoWriter, opts ...image.ClientOption) (*image.QueryImagesByIDOK, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, params, authInfo) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 *image.QueryImagesByIDOK + if rf, ok := ret.Get(0).(func(*image.QueryImagesByIDParams, runtime.ClientAuthInfoWriter, ...image.ClientOption) *image.QueryImagesByIDOK); ok { + r0 = rf(params, authInfo, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*image.QueryImagesByIDOK) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(*image.QueryImagesByIDParams, runtime.ClientAuthInfoWriter, ...image.ClientOption) error); ok { + r1 = rf(params, authInfo, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // SetTransport provides a mock function with given fields: transport func (_m *ClientService) SetTransport(transport runtime.ClientTransport) { _m.Called(transport)