mirror of
https://github.com/compute-blade-community/compute-blade-agent.git
synced 2026-04-29 12:43:20 +02:00
781ded8e43
This PR introduces a comprehensive set of new subcommands to bladectl, expanding its capabilities for querying and managing compute blade state. It also includes an internal refactor to simplify interface management across the gRPC API.
* `get`
* `fan`: Returns current fan speed.
* `identify`: Indicates whether the identify mode is active.
* `stealth`: Shows if stealth mode is currently enabled.
* `status`: Prints a full blade status report.
* `temperature`: Retrieves current SoC temperature.
* `critical`: Shows whether critical mode is active.
* `power`: Reports the current power source (e.g., PoE+ or USB).
* `set`
* `stealth`: Enables stealth mode.
* `remove`
* `stealth`: Disables stealth mode.
* `describe`
* `fan`: Outputs the current fan curve configuration.
* `monitor`: plot some charts about the state of the compute-blade-agent
* **gRPC API refactor**: The gRPC service definitions previously located in `internal/api` have been folded into `internal/agent`. This eliminates redundant interface declarations and ensures that all ComputeBladeAgent implementations are directly compatible with the gRPC API.
This reduces duplication and improves long-term maintainability and clarity of the interface contract.
```bash
bladectl set fan --percent 90 --blade 1 --blade 2
bladectl unset identify --blade 1 --blade 2 --blade 3 --blade 4
bladectl set stealth --blade 1 --blade 2 --blade 3 --blade 4
bladectl get status --blade 1 --blade 2 --blade 3 --blade 4
┌───────┬─────────────┬────────────────────┬───────────────┬──────────────┬──────────┬───────────────┬──────────────┐
│ BLADE │ TEMPERATURE │ FAN SPEED OVERRIDE │ FAN SPEED │ STEALTH MODE │ IDENTIFY │ CRITICAL MODE │ POWER STATUS │
├───────┼─────────────┼────────────────────┼───────────────┼──────────────┼──────────┼───────────────┼──────────────┤
│ 1 │ 50°C │ 90% │ 5825 RPM(90%) │ Active │ Off │ Off │ poe+ │
│ 2 │ 48°C │ 90% │ 5825 RPM(90%) │ Active │ Off │ Off │ poe+ │
│ 3 │ 49°C │ Not set │ 4643 RPM(56%) │ Active │ Off │ Off │ poe+ │
│ 4 │ 49°C │ Not set │ 4774 RPM(58%) │ Active │ Off │ Off │ poe+ │
└───────┴─────────────┴────────────────────┴───────────────┴──────────────┴──────────┴───────────────┴──────────────┘
bladectl rm stealth --blade 1 --blade 2 --blade 3 --blade 4
bladectl rm fan --blade 1 --blade 2 --blade 3 --blade 4
bladectl get status --blade 1 --blade 2 --blade 3 --blade 4
┌───────┬─────────────┬────────────────────┬───────────────┬──────────────┬──────────┬───────────────┬──────────────┐
│ BLADE │ TEMPERATURE │ FAN SPEED OVERRIDE │ FAN SPEED │ STEALTH MODE │ IDENTIFY │ CRITICAL MODE │ POWER STATUS │
├───────┼─────────────┼────────────────────┼───────────────┼──────────────┼──────────┼───────────────┼──────────────┤
│ 1 │ 51°C │ Not set │ 5177 RPM(66%) │ Off │ Off │ Off │ poe+ │
│ 2 │ 49°C │ Not set │ 5177 RPM(58%) │ Off │ Off │ Off │ poe+ │
│ 3 │ 50°C │ Not set │ 4659 RPM(60%) │ Off │ Off │ Off │ poe+ │
│ 4 │ 48°C │ Not set │ 4659 RPM(54%) │ Off │ Off │ Off │ poe+ │
└───────┴─────────────┴────────────────────┴───────────────┴──────────────┴──────────┴───────────────┴──────────────┘
```
when having multiple compute-blades in your bladeconfig:
```yaml
blades:
- name: 1
blade:
server: blade-pi1:8081
cert:
certificate-authority-data: <redacted>
client-certificate-data: <redacted>
client-key-data: <redacted>
- name: 2
blade:
server: blade-pi2:8081
cert:
certificate-authority-data: <redacted>
client-certificate-data: <redacted>
client-key-data: <redacted>
- name: 3
blade:
server: blade-pi3:8081
cert:
certificate-authority-data: <redacted>
client-certificate-data: <redacted>
client-key-data: <redacted>
- name: 4
blade:
server: blade-pi4:8081
cert:
certificate-authority-data: <redacted>
client-certificate-data: <redacted>
client-key-data: <redacted>
- name: 4
blade:
server: blade-pi4:8081
cert:
certificate-authority-data: <redacted>
client-certificate-data: <redacted>
client-key-data: <redacted>
current-blade: 1
```
Fixes #4, #9 (partially), should help with #5
* test: improve unit-testing
* fix: pin github.com/warthog618/gpiod
---------
Co-authored-by: Cedric Kienzler <cedric@specht-labs.de>
95 lines
2.6 KiB
Go
95 lines
2.6 KiB
Go
package hal
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/compute-blade-community/compute-blade-agent/pkg/hal/led"
|
|
)
|
|
|
|
type FanUnitKind uint8
|
|
type ComputeModule uint8
|
|
type PowerStatus uint8
|
|
|
|
func (p PowerStatus) String() string {
|
|
switch p {
|
|
case PowerPoe802at:
|
|
return "poe+"
|
|
case PowerPoeOrUsbC:
|
|
return "poeOrUsbC"
|
|
default:
|
|
return "undefined"
|
|
}
|
|
}
|
|
|
|
const (
|
|
FanUnitKindStandard = iota
|
|
FanUnitKindStandardNoRPM
|
|
FanUnitKindSmart
|
|
)
|
|
|
|
const (
|
|
PowerPoeOrUsbC = iota
|
|
PowerPoe802at
|
|
)
|
|
|
|
type LedIndex uint8
|
|
|
|
const (
|
|
LedTop LedIndex = iota
|
|
LedEdge
|
|
)
|
|
|
|
type ComputeBladeHalOpts struct {
|
|
RpmReportingStandardFanUnit bool `mapstructure:"rpm_reporting_standard_fan_unit"`
|
|
}
|
|
|
|
// ComputeBladeHal abstracts hardware details of the Compute Blade and provides a simple interface
|
|
type ComputeBladeHal interface {
|
|
// Run starts background tasks and returns when the context is cancelled or an error occurs
|
|
Run(ctx context.Context) error
|
|
// Close closes the ComputeBladeHal
|
|
Close() error
|
|
// SetFanSpeed sets the fan speed in percent
|
|
SetFanSpeed(speed uint8) error
|
|
// GetFanRPM returns the current fan speed in percent (based on moving average)
|
|
GetFanRPM() (float64, error)
|
|
// SetStealthMode enables/disables stealth mode of the blade (turning on/off the LEDs)
|
|
SetStealthMode(enabled bool) error
|
|
// StealthModeActive returns if stealth mode of the blade is currently active
|
|
StealthModeActive() bool
|
|
// SetLed sets the color of the LEDs
|
|
SetLed(idx LedIndex, color led.Color) error
|
|
// GetPowerStatus returns the current power status of the blade
|
|
GetPowerStatus() (PowerStatus, error)
|
|
// GetTemperature returns the current temperature of the SoC in °C
|
|
GetTemperature() (float64, error)
|
|
// WaitForEdgeButtonPress returns a channel emitting edge button press events
|
|
WaitForEdgeButtonPress(ctx context.Context) error
|
|
}
|
|
|
|
// FanUnit abstracts the fan unit
|
|
type FanUnit interface {
|
|
// Kind returns the kind of the fan FanUnit
|
|
Kind() FanUnitKind
|
|
|
|
// Run the client with event loop
|
|
Run(context.Context) error
|
|
|
|
// SetFanSpeedPercent sets the fan speed in percent.
|
|
SetFanSpeedPercent(context.Context, uint8) error
|
|
|
|
// SetLed sets the LED color. Noop if the LED is not available.
|
|
SetLed(context.Context, led.Color) error
|
|
|
|
// FanSpeedRPM returns the current fan speed in rotations per minute.
|
|
FanSpeedRPM(context.Context) (float64, error)
|
|
|
|
// WaitForButtonPress blocks until the button is pressed. Noop if the button is not available.
|
|
WaitForButtonPress(context.Context) error
|
|
|
|
// AirFlowTemperature returns the temperature of the air flow. Noop if the sensor is not available.
|
|
AirFlowTemperature(context.Context) (float32, error)
|
|
|
|
Close() error
|
|
}
|