Skip to content

Commit

Permalink
Merge pull request #79 from fintelia/virtual-media
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdoherty4 authored Feb 27, 2023
2 parents 50c4ce3 + 4b94b93 commit e5736f0
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 7 deletions.
16 changes: 16 additions & 0 deletions api/v1alpha1/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,19 @@ type OneTimeBootDeviceAction struct {
// EFIBoot instructs the machine to use EFI boot.
EFIBoot bool `json:"efiBoot,omitempty"`
}

type VirtualMediaKind string

const (
// VirtualMediaCD represents a virtual CD-ROM.
VirtualMediaCD VirtualMediaKind = "CD"
)

// VirtualMediaAction represents a virtual media action.
type VirtualMediaAction struct {
// mediaURL represents the URL of the image to be inserted into the virtual media, or empty to
// eject media.
MediaURL string `json:"mediaURL,omitempty"`

Kind VirtualMediaKind `json:"kind"`
}
4 changes: 2 additions & 2 deletions api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the bmc v1alpha1 API group
//+kubebuilder:object:generate=true
//+groupName=bmc.tinkerbell.org
// +kubebuilder:object:generate=true
// +groupName=bmc.tinkerbell.org
package v1alpha1

import (
Expand Down
3 changes: 3 additions & 0 deletions api/v1alpha1/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ type Action struct {

// OneTimeBootDeviceAction represents a baseboard management one time set boot device operation.
OneTimeBootDeviceAction *OneTimeBootDeviceAction `json:"oneTimeBootDeviceAction,omitempty"`

// VirtualMediaAction represents a baseboard management virtual media insert/eject.
VirtualMediaAction *VirtualMediaAction `json:"virtualMediaAction,omitempty"`
}

// TaskStatus defines the observed state of Task
Expand Down
20 changes: 20 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions config/crd/bases/bmc.tinkerbell.org_jobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ spec:
- cycle
- reset
type: string
virtualMediaAction:
description: VirtualMediaAction represents a baseboard management
virtual media insert/eject.
properties:
kind:
type: string
mediaURL:
description: mediaURL represents the URL of the image to
be inserted into the virtual media, or empty to eject
media.
type: string
required:
- kind
type: object
type: object
minItems: 1
type: array
Expand Down
13 changes: 13 additions & 0 deletions config/crd/bases/bmc.tinkerbell.org_tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,19 @@ spec:
- cycle
- reset
type: string
virtualMediaAction:
description: VirtualMediaAction represents a baseboard management
virtual media insert/eject.
properties:
kind:
type: string
mediaURL:
description: mediaURL represents the URL of the image to be
inserted into the virtual media, or empty to eject media.
type: string
required:
- kind
type: object
type: object
required:
- task
Expand Down
3 changes: 3 additions & 0 deletions controllers/bmc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ type BMCClient interface {
// setPersistent, if true will set the boot device permanently. If false, sets one time boot.
// efiBoot, if true passes efiboot options while setting boot device.
SetBootDevice(ctx context.Context, bootDevice string, setPersistent, efiBoot bool) (bool, error)
// SetVirtualMedia ejects existing virtual media and then if mediaUrl isn't empty, instructs
// the bmc to download virtual media of the specified kind from mediaUrl. Returns true on success.
SetVirtualMedia(ctx context.Context, kind string, mediaUrl string) (bool, error)
}

// BMCClientFactoryFunc defines a func that returns a BMCClient
Expand Down
15 changes: 15 additions & 0 deletions controllers/mocks/bmcclient.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions controllers/task_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ func (r *TaskReconciler) runTask(ctx context.Context, task bmcv1alpha1.Action, b
}
}

if task.VirtualMediaAction != nil {
_, err := bmcClient.SetVirtualMedia(ctx, string(task.VirtualMediaAction.Kind), task.VirtualMediaAction.MediaURL)
if err != nil {
return fmt.Errorf("failed to perform SetVirtualMedia: %v", err)
}
}

return nil
}

Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/tinkerbell/rufio
go 1.18

require (
github.com/bmc-toolbox/bmclib/v2 v2.0.1-0.20230123132352-e982ba834c64
github.com/bmc-toolbox/bmclib/v2 v2.0.1-0.20230212165211-bac64498b8ba
github.com/go-logr/logr v1.2.3
github.com/go-logr/zapr v1.2.3
github.com/golang/mock v1.6.0
Expand Down Expand Up @@ -62,6 +62,7 @@ require (
github.com/stmcginnis/gofish v0.13.1-0.20221107140645-5cc43fad050f // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/exp v0.0.0-20230127130021-4ca2cb1a16b7 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/mod v0.7.0 // indirect
golang.org/x/net v0.3.1-0.20221206200815-1e63c2f08a10 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bmc-toolbox/bmclib/v2 v2.0.1-0.20221202150410-31e3dc1a1588 h1:ORTKFJofbRgy3chz0Cgf6fBfm7PR4OxczqjPd34Loro=
github.com/bmc-toolbox/bmclib/v2 v2.0.1-0.20221202150410-31e3dc1a1588/go.mod h1:2HUSfpk9cdI69955us3orjKGlVr/SKNZg2DQZuNqsjQ=
github.com/bmc-toolbox/bmclib/v2 v2.0.1-0.20230123132352-e982ba834c64 h1:6HH4Qs64xx0adb6MFomY7p6p97/Ko0VXpjVrUph5ZkY=
github.com/bmc-toolbox/bmclib/v2 v2.0.1-0.20230123132352-e982ba834c64/go.mod h1:2HUSfpk9cdI69955us3orjKGlVr/SKNZg2DQZuNqsjQ=
github.com/bmc-toolbox/bmclib/v2 v2.0.1-0.20230212165211-bac64498b8ba h1:7f1/G8FgXc8iS1MbD8t2G/kHAj3DOfWQK3xenuSXH+o=
github.com/bmc-toolbox/bmclib/v2 v2.0.1-0.20230212165211-bac64498b8ba/go.mod h1:MmsiCtKkfgtZ4eTRmL78HADcV8nOY46rHnj5GmUfOhs=
github.com/bmc-toolbox/common v0.0.0-20221115135648-0b584f504396 h1:MAIYVFtt/Hnhx0Cth6T9pnLTJnZKppzi7LHue4KpPtg=
github.com/bmc-toolbox/common v0.0.0-20221115135648-0b584f504396/go.mod h1:SY//n1PJjZfbFbmAsB6GvEKbc7UXz3d30s3kWxfJQ/c=
github.com/bombsimon/logrusr/v2 v2.0.1 h1:1VgxVNQMCvjirZIYaT9JYn6sAVGVEcNtRE0y4mvaOAM=
Expand Down Expand Up @@ -340,6 +338,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20230127130021-4ca2cb1a16b7 h1:o7Ps2IYdzLRolS9/nadqeMSHpa9k8pu8u+VKBFUG7cQ=
golang.org/x/exp v0.0.0-20230127130021-4ca2cb1a16b7/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down

0 comments on commit e5736f0

Please sign in to comment.