diff --git a/api/client/machine/machine_client.go b/api/client/machine/machine_client.go index 6f581e3d..281bc99f 100644 --- a/api/client/machine/machine_client.go +++ b/api/client/machine/machine_client.go @@ -62,6 +62,8 @@ type ClientService interface { MachineBios(params *MachineBiosParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*MachineBiosOK, error) + MachineCycle(params *MachineCycleParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*MachineCycleOK, error) + MachineDisk(params *MachineDiskParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*MachineDiskOK, error) MachineOff(params *MachineOffParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*MachineOffOK, error) @@ -731,6 +733,44 @@ func (a *Client) MachineBios(params *MachineBiosParams, authInfo runtime.ClientA return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) } +/* + MachineCycle sends a power cycle to the machine +*/ +func (a *Client) MachineCycle(params *MachineCycleParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*MachineCycleOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewMachineCycleParams() + } + op := &runtime.ClientOperation{ + ID: "machineCycle", + Method: "POST", + PathPattern: "/v1/machine/{id}/power/cycle", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"http"}, + Params: params, + Reader: &MachineCycleReader{formats: a.formats}, + AuthInfo: authInfo, + Context: params.Context, + Client: params.HTTPClient, + } + for _, opt := range opts { + opt(op) + } + + result, err := a.transport.Submit(op) + if err != nil { + return nil, err + } + success, ok := result.(*MachineCycleOK) + if ok { + return success, nil + } + // unexpected success response + unexpectedSuccess := result.(*MachineCycleDefault) + return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) +} + /* MachineDisk boots machine from disk */ diff --git a/api/client/machine/machine_cycle_parameters.go b/api/client/machine/machine_cycle_parameters.go new file mode 100644 index 00000000..020fa44d --- /dev/null +++ b/api/client/machine/machine_cycle_parameters.go @@ -0,0 +1,170 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package machine + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "net/http" + "time" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + "github.com/go-openapi/strfmt" + + "github.com/metal-stack/metal-go/api/models" +) + +// NewMachineCycleParams creates a new MachineCycleParams object, +// with the default timeout for this client. +// +// Default values are not hydrated, since defaults are normally applied by the API server side. +// +// To enforce default values in parameter, use SetDefaults or WithDefaults. +func NewMachineCycleParams() *MachineCycleParams { + return &MachineCycleParams{ + timeout: cr.DefaultTimeout, + } +} + +// NewMachineCycleParamsWithTimeout creates a new MachineCycleParams object +// with the ability to set a timeout on a request. +func NewMachineCycleParamsWithTimeout(timeout time.Duration) *MachineCycleParams { + return &MachineCycleParams{ + timeout: timeout, + } +} + +// NewMachineCycleParamsWithContext creates a new MachineCycleParams object +// with the ability to set a context for a request. +func NewMachineCycleParamsWithContext(ctx context.Context) *MachineCycleParams { + return &MachineCycleParams{ + Context: ctx, + } +} + +// NewMachineCycleParamsWithHTTPClient creates a new MachineCycleParams object +// with the ability to set a custom HTTPClient for a request. +func NewMachineCycleParamsWithHTTPClient(client *http.Client) *MachineCycleParams { + return &MachineCycleParams{ + HTTPClient: client, + } +} + +/* MachineCycleParams contains all the parameters to send to the API endpoint + for the machine cycle operation. + + Typically these are written to a http.Request. +*/ +type MachineCycleParams struct { + + // Body. + Body models.V1EmptyBody + + /* ID. + + identifier of the machine + */ + ID string + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithDefaults hydrates default values in the machine cycle params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *MachineCycleParams) WithDefaults() *MachineCycleParams { + o.SetDefaults() + return o +} + +// SetDefaults hydrates default values in the machine cycle params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *MachineCycleParams) SetDefaults() { + // no default values defined for this parameter +} + +// WithTimeout adds the timeout to the machine cycle params +func (o *MachineCycleParams) WithTimeout(timeout time.Duration) *MachineCycleParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the machine cycle params +func (o *MachineCycleParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the machine cycle params +func (o *MachineCycleParams) WithContext(ctx context.Context) *MachineCycleParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the machine cycle params +func (o *MachineCycleParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the machine cycle params +func (o *MachineCycleParams) WithHTTPClient(client *http.Client) *MachineCycleParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the machine cycle params +func (o *MachineCycleParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithBody adds the body to the machine cycle params +func (o *MachineCycleParams) WithBody(body models.V1EmptyBody) *MachineCycleParams { + o.SetBody(body) + return o +} + +// SetBody adds the body to the machine cycle params +func (o *MachineCycleParams) SetBody(body models.V1EmptyBody) { + o.Body = body +} + +// WithID adds the id to the machine cycle params +func (o *MachineCycleParams) WithID(id string) *MachineCycleParams { + o.SetID(id) + return o +} + +// SetID adds the id to the machine cycle params +func (o *MachineCycleParams) SetID(id string) { + o.ID = id +} + +// WriteToRequest writes these params to a swagger request +func (o *MachineCycleParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + if o.Body != nil { + if err := r.SetBodyParam(o.Body); err != nil { + return err + } + } + + // path param id + if err := r.SetPathParam("id", o.ID); err != nil { + return err + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/api/client/machine/machine_cycle_responses.go b/api/client/machine/machine_cycle_responses.go new file mode 100644 index 00000000..29392a87 --- /dev/null +++ b/api/client/machine/machine_cycle_responses.go @@ -0,0 +1,116 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package machine + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + + "github.com/go-openapi/runtime" + "github.com/go-openapi/strfmt" + + "github.com/metal-stack/metal-go/api/models" + "github.com/metal-stack/metal-lib/httperrors" +) + +// MachineCycleReader is a Reader for the MachineCycle structure. +type MachineCycleReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *MachineCycleReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + case 200: + result := NewMachineCycleOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + default: + result := NewMachineCycleDefault(response.Code()) + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + if response.Code()/100 == 2 { + return result, nil + } + return nil, result + } +} + +// NewMachineCycleOK creates a MachineCycleOK with default headers values +func NewMachineCycleOK() *MachineCycleOK { + return &MachineCycleOK{} +} + +/* MachineCycleOK describes a response with status code 200, with default header values. + +OK +*/ +type MachineCycleOK struct { + Payload *models.V1MachineResponse +} + +func (o *MachineCycleOK) Error() string { + return fmt.Sprintf("[POST /v1/machine/{id}/power/cycle][%d] machineCycleOK %+v", 200, o.Payload) +} +func (o *MachineCycleOK) GetPayload() *models.V1MachineResponse { + return o.Payload +} + +func (o *MachineCycleOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(models.V1MachineResponse) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewMachineCycleDefault creates a MachineCycleDefault with default headers values +func NewMachineCycleDefault(code int) *MachineCycleDefault { + return &MachineCycleDefault{ + _statusCode: code, + } +} + +/* MachineCycleDefault describes a response with status code -1, with default header values. + +Error +*/ +type MachineCycleDefault struct { + _statusCode int + + Payload *httperrors.HTTPErrorResponse +} + +// Code gets the status code for the machine cycle default response +func (o *MachineCycleDefault) Code() int { + return o._statusCode +} + +func (o *MachineCycleDefault) Error() string { + return fmt.Sprintf("[POST /v1/machine/{id}/power/cycle][%d] machineCycle default %+v", o._statusCode, o.Payload) +} +func (o *MachineCycleDefault) GetPayload() *httperrors.HTTPErrorResponse { + return o.Payload +} + +func (o *MachineCycleDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(httperrors.HTTPErrorResponse) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} diff --git a/machine.go b/machine.go index 4e0a587d..6ef2c17e 100644 --- a/machine.go +++ b/machine.go @@ -479,6 +479,21 @@ func (d *Driver) MachinePowerReset(machineID string) (*MachinePowerResponse, err return response, nil } +// MachinePowerCycle power-cycles the given machine +func (d *Driver) MachinePowerCycle(machineID string) (*MachinePowerResponse, error) { + machineCycle := machine.NewMachineCycleParams() + machineCycle.ID = machineID + machineCycle.Body = []string{} + + response := &MachinePowerResponse{} + resp, err := d.machine.MachineCycle(machineCycle, nil) + if err != nil { + return response, err + } + response.Machine = resp.Payload + return response, nil +} + // MachineBootBios boots given machine into BIOS func (d *Driver) MachineBootBios(machineID string) (*MachineFirmwareResponse, error) { machineBios := machine.NewMachineBiosParams() diff --git a/metal-api.json b/metal-api.json index 118b7efb..b75ac44e 100644 --- a/metal-api.json +++ b/metal-api.json @@ -6233,6 +6233,52 @@ ] } }, + "/v1/machine/{id}/power/cycle": { + "post": { + "consumes": [ + "application/json" + ], + "operationId": "machineCycle", + "parameters": [ + { + "description": "identifier of the machine", + "in": "path", + "name": "id", + "required": true, + "type": "string" + }, + { + "in": "body", + "name": "body", + "required": true, + "schema": { + "$ref": "#/definitions/v1.EmptyBody" + } + } + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.MachineResponse" + } + }, + "default": { + "description": "Error", + "schema": { + "$ref": "#/definitions/httperrors.HTTPErrorResponse" + } + } + }, + "summary": "sends a power cycle to the machine", + "tags": [ + "machine" + ] + } + }, "/v1/machine/{id}/power/disk": { "post": { "consumes": [ @@ -7964,4 +8010,4 @@ "name": "switch" } ] -} \ No newline at end of file +}