SwitchResource¶
SwitchResource
¶
Multi-port KVM switch and EDID management for PiKVM.
Source code in src/aiopikvm/resources/switch.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |
get_state()
async
¶
Get the current switch state.
Returns:
| Type | Description |
|---|---|
SwitchState
|
Current switch state with active port and port list. |
set_active(port)
async
¶
Set the active port.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port
|
int | float
|
Port number, counted from |
required |
Source code in src/aiopikvm/resources/switch.py
get_edids()
async
¶
Get the EDID catalogue.
There is no endpoint of its own for this: the catalogue is part of the switch state, and this is a shortcut to it.
Returns:
| Type | Description |
|---|---|
dict[str, EDID]
|
Every stored EDID, keyed by id. |
Source code in src/aiopikvm/resources/switch.py
create_edid(name, data)
async
¶
Store a new EDID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Human-readable name. |
required |
data
|
str
|
EDID blob as an uppercase hex string, 256 or 512 characters (128 or 256 bytes). |
required |
Returns:
| Type | Description |
|---|---|
str
|
The id kvmd generated for it, which is what
|
Raises:
| Type | Description |
|---|---|
ResponseError
|
If kvmd does not answer with the new id. |
Source code in src/aiopikvm/resources/switch.py
change_edid(edid_id, *, name=None, data=None)
async
¶
Rename a stored EDID or replace its contents.
This edits the EDID itself. Assigning one to a port is
set_port_params()
with edid_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edid_id
|
str
|
Id of the EDID to change. The built-in |
required |
name
|
str | None
|
New name, if it should change. |
None
|
data
|
str | None
|
New EDID blob as hex, if it should change. |
None
|
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
If neither name nor data is given — kvmd answers such a call with success and changes nothing. |
Source code in src/aiopikvm/resources/switch.py
remove_edid(edid_id)
async
¶
Remove a stored EDID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edid_id
|
str
|
Id of the EDID to remove. The built-in |
required |
Source code in src/aiopikvm/resources/switch.py
set_active_prev()
async
¶
set_active_next()
async
¶
set_beacon(state, *, port=None, uplink=None, downlink=None)
async
¶
Light or extinguish one beacon.
Exactly one target must be given. kvmd checks them in the order
port, uplink, downlink and falls through to downlink
when none is present, which answers 400.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
bool
|
Whether the beacon is lit. |
required |
port
|
int | float | None
|
Port number, or |
None
|
uplink
|
int | None
|
Unit whose uplink beacon to control, counted from |
None
|
downlink
|
int | None
|
Unit whose downlink beacon to control, counted from
|
None
|
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
If not exactly one of port, uplink or downlink is given. |
Source code in src/aiopikvm/resources/switch.py
set_port_params(port, *, edid_id=None, dummy=None, name=None, atx_click_power_delay=None, atx_click_power_long_delay=None, atx_click_reset_delay=None)
async
¶
Configure port parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port
|
int | float
|
Port number ( |
required |
edid_id
|
str | None
|
EDID profile identifier. |
None
|
dummy
|
bool | None
|
Pretend host has display attached. |
None
|
name
|
str | None
|
Port name (ASCII letters and numbers). |
None
|
atx_click_power_delay
|
float | None
|
ATX power click delay in seconds ( |
None
|
atx_click_power_long_delay
|
float | None
|
ATX long power click delay in seconds
( |
None
|
atx_click_reset_delay
|
float | None
|
ATX reset click delay in seconds ( |
None
|
Source code in src/aiopikvm/resources/switch.py
set_colors(*, inactive=None, active=None, flashing=None, beacon=None, bootloader=None)
async
¶
Set the indicator colours, one per port role.
Every colour is RRGGBB:BB:IIII in hex — colour, brightness and
blink interval in milliseconds — or the string "default" to go
back to the built-in value. Roles left out keep their current colour.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inactive
|
str | None
|
Ports that are not selected. |
None
|
active
|
str | None
|
The selected port. |
None
|
flashing
|
str | None
|
A port whose unit is being flashed. |
None
|
beacon
|
str | None
|
A port with its beacon lit. |
None
|
bootloader
|
str | None
|
A unit sitting in the bootloader. |
None
|
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
If no role is given at all. |
Source code in src/aiopikvm/resources/switch.py
reset(unit, *, bootloader=False)
async
¶
Reboot a switch unit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
int
|
Unit number ( |
required |
bootloader
|
bool
|
Enter reflashing mode after reboot. |
False
|
Source code in src/aiopikvm/resources/switch.py
atx_power(port, action)
async
¶
ATX power control for a specific port.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port
|
int | float
|
Port number ( |
required |
action
|
ATXAction
|
Power action, one of
|
required |
Raises:
| Type | Description |
|---|---|
APIError
|
If kvmd does not know the action (HTTP 400). |
Source code in src/aiopikvm/resources/switch.py
atx_click(port, button)
async
¶
Simulate an ATX button click for a specific port.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port
|
int | float
|
Port number ( |
required |
button
|
ATXButton
|
Button to press, one of
|
required |
Raises:
| Type | Description |
|---|---|
APIError
|
If kvmd does not know the button (HTTP 400). |
Source code in src/aiopikvm/resources/switch.py
ATXAction = Literal['on', 'off', 'off_hard', 'reset_hard']
¶
The power actions taken by
SwitchResource.atx_power().
"on" and "off" are short presses of the power switch, the second
leaving the OS to decide what a press means; "off_hard" holds it down
instead, and "reset_hard" presses the reset switch.
Every one of the four is conditional on the power state kvmd reads from the
host's power LED: "on" acts only on a host it believes to be off, the
other three only on one it believes to be on. A command that fails the test is
dropped and the call still answers success, so where that LED is miswired or
unread all four are unpredictable — a stuck-on reading lets the three
off-and-reset actions fire at any moment, and a stuck-off one lets "on".
SwitchResource.atx_click()
presses a switch unconditionally, which is the way to reach a host whose LED
kvmd cannot read.
This is kvmd's ATX vocabulary rather than the switch's own: the same validator
serves /api/atx/power, where
ATXResource spells each value out as a
method of its own. kvmd lowercases the value before it looks, so only the
canonical spelling is typed.
ATXButton = Literal['power', 'power_long', 'reset']
¶
The buttons pressed by
SwitchResource.atx_click().
"power" is a short press and "power_long" the same switch held down
for several seconds; "reset" is the other front-panel switch. Unlike every
value of ATXAction, none of these
looks at what state the host is in.
Shared with /api/atx/click and lowercased on the way in, exactly as
ATXAction is.