-
Notifications
You must be signed in to change notification settings - Fork 23
Add chassismanager package. #324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Chounoki
wants to merge
1
commit into
openconfig:main
Choose a base branch
from
Chounoki:pr1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Copyright 2023 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
|
||
| go_library( | ||
| name = "chassismanager", | ||
| srcs = ["chassismanager.go"], | ||
| importpath = "github.com/openconfig/bootz/server/chassismanager", | ||
| visibility = ["//visibility:public"], | ||
| deps = [ | ||
| "//common/types", | ||
| "//proto:bootz", | ||
| "//server/proto:config", | ||
| "@com_github_golang_glog//:glog", | ||
| ], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // Copyright 2023 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| // Package chassismanager is a chassis manager that manages chassis. | ||
| // The implementation here is an in-memory implementation primarily used for testing and qualification. | ||
| // For production usecase, you should replace this implementation with your own one. | ||
| package chassismanager | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| log "github.com/golang/glog" | ||
| "github.com/openconfig/bootz/common/types" | ||
|
|
||
| bpb "github.com/openconfig/bootz/proto/bootz" | ||
| cpb "github.com/openconfig/bootz/server/proto/config" | ||
| ) | ||
|
|
||
| // InMemoryChassisManager provides a simple in memory handler for chassis. | ||
| type InMemoryChassisManager struct { | ||
| chassis map[string]*cpb.Chassis | ||
| } | ||
|
|
||
| // ResolveChassis fills the chassis information based on the matched inventory. | ||
| func (m *InMemoryChassisManager) ResolveChassis(ctx context.Context, chassis *types.Chassis) error { | ||
| if chassis == nil { | ||
| return fmt.Errorf("chassis cannot be nil") | ||
| } | ||
| found, ok := m.chassis[chassis.ActiveSerial] | ||
| if !ok { | ||
| return fmt.Errorf("chassis with serial number %v not found", chassis.ActiveSerial) | ||
| } | ||
| chassis.Hostname = found.GetHostname() | ||
| chassis.BootMode = found.GetBootMode() | ||
| chassis.StreamingSupported = found.GetStreamingSupported() | ||
| chassis.Manufacturer = found.GetManufacturer() | ||
|
Chounoki marked this conversation as resolved.
|
||
| return nil | ||
| } | ||
|
|
||
| // GenerateBootstrapData generates the bootstrap data response for the provided serial number. | ||
| func (m *InMemoryChassisManager) GenerateBootstrapData(ctx context.Context, _ *types.Chassis, serial string) (*bpb.BootstrapDataResponse, error) { | ||
| found, ok := m.chassis[serial] | ||
| if !ok { | ||
| return nil, fmt.Errorf("chassis with serial number %v not found", serial) | ||
| } | ||
| return &bpb.BootstrapDataResponse{ | ||
| SerialNum: serial, | ||
| IntendedImage: found.GetIntendedImage(), | ||
| BootPasswordHash: found.GetBootPasswordHash(), | ||
| BootConfig: found.GetBootConfig(), | ||
| Credentials: found.GetCredentials(), | ||
| Pathz: found.GetPathz(), | ||
| Authz: found.GetAuthz(), | ||
| CertzProfiles: found.GetCertzProfiles(), | ||
| }, nil | ||
|
Chounoki marked this conversation as resolved.
|
||
| } | ||
|
|
||
| // UpdateStatus updates the status for each control card on the chassis. | ||
| func (m *InMemoryChassisManager) UpdateStatus(ctx context.Context, req *bpb.ReportStatusRequest) error { | ||
| if len(req.GetStates()) == 0 { | ||
| return fmt.Errorf("no control card or fixed chassis states provided") | ||
| } | ||
| // We only do the logging. | ||
| log.Infof("Bootstrap Status: %v: Status message: %v", req.GetStatus(), req.GetStatusMessage()) | ||
| for _, v := range req.GetStates() { | ||
| log.Infof("Control card %v changed status to %v", v.GetSerialNumber(), v.GetStatus()) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // New returns a new in-memory chassis manager. | ||
| func New(config *cpb.Config) *InMemoryChassisManager { | ||
| // For fast lookup, we build a map indexed by the control card serial number, which means modular chassis with dual control cards are indexed twice. | ||
| chassis := make(map[string]*cpb.Chassis) | ||
| for _, c := range config.GetChassis() { | ||
| for _, cc := range c.GetControlCards() { | ||
| chassis[cc.GetSerialNumber()] = c | ||
| } | ||
| } | ||
| return &InMemoryChassisManager{chassis: chassis} | ||
| } | ||
|
Chounoki marked this conversation as resolved.
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.