Skip to content

Commit 956895e

Browse files
committed
apiclient: add network configure subcommand
Implements 'apiclient network configure <input-source>' to enable runtime network configuration for Bottlerocket. Supports file://, base64: input sources with client-side URI processing. Content is sent to the API server for further processing. Signed-off-by: Yutong Sun <yutongsu@amazon.com>
1 parent 1c00d2e commit 956895e

File tree

5 files changed

+530
-8
lines changed

5 files changed

+530
-8
lines changed

sources/api/apiclient/README.md

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Current version: 0.1.0
55
## apiclient binary
66

77
The `apiclient` binary provides high-level methods to interact with the Bottlerocket API.
8-
There's a [set](#set-mode) subcommand for changing settings, an [update](#update-mode) subcommand for updating the host, and an [exec](#exec-mode) subcommand for running commands in host containers.
8+
There's a [set](#set-mode) subcommand for changing settings, a [network configure](#network-configure) subcommand for configuring network settings, an [update](#update-mode) subcommand for updating the host, and an [exec](#exec-mode) subcommand for running commands in host containers.
99
There's also a low-level [raw](#raw-mode) subcommand for direct interaction with the HTTP API.
1010

1111
It talks to the Bottlerocket socket by default.
@@ -75,6 +75,53 @@ You can use JSON form to set it:
7575
apiclient set --json '{"motd": "42"}'
7676
```
7777

78+
### Network configure
79+
80+
This allows you to configure network settings by providing a net.toml file which netdog uses for network configuration.
81+
The configuration is written to `/.bottlerocket/net.toml` and will be validated and applied at the next boot by netdog.
82+
83+
The network configure command accepts input from different sources using URI schemes:
84+
85+
#### File URI input
86+
87+
You can specify a local file path using the `file://` URI scheme:
88+
89+
```shell
90+
apiclient network configure file:///path/to/net.toml
91+
```
92+
93+
#### Base64 encoded input
94+
95+
For inline configuration, you can provide base64-encoded content:
96+
97+
```shell
98+
apiclient network configure base64:dmVyc2lvbiA9IDIKCltldGgwXQpkaGNwNCA9IHRydWU=
99+
```
100+
101+
This is particularly useful for automation and configuration management where you want to embed the network configuration directly in scripts or user data.
102+
103+
#### Configuration format
104+
105+
The net.toml file uses the same format that netdog supports. Here's an example:
106+
107+
```toml
108+
version = 2
109+
110+
[eth0]
111+
dhcp4 = true
112+
dhcp6 = false
113+
114+
[eth1]
115+
static4 = ["192.168.1.100/24"]
116+
route = [{to = "default", via = "192.168.1.1"}]
117+
```
118+
119+
After configuring the network settings, you'll need to reboot the system for the changes to take effect:
120+
121+
```shell
122+
apiclient reboot
123+
```
124+
78125
### Update mode
79126

80127
To start, you can check what updates are available:
@@ -329,7 +376,7 @@ The results from each item in the report will be one of:
329376
## apiclient library
330377

331378
The apiclient library provides high-level methods to interact with the Bottlerocket API. See
332-
the documentation for submodules [`apply`], [`exec`], [`get`], [`reboot`], [`report`], [`set`],
379+
the documentation for submodules [`apply`], [`exec`], [`get`], [`network`], [`reboot`], [`report`], [`set`],
333380
and [`update`] for high-level helpers.
334381

335382
For more control, and to handle APIs without high-level wrappers, there are also 'raw' methods

sources/api/apiclient/README.tpl

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Current version: {{version}}
55
## apiclient binary
66

77
The `apiclient` binary provides high-level methods to interact with the Bottlerocket API.
8-
There's a [set](#set-mode) subcommand for changing settings, an [update](#update-mode) subcommand for updating the host, and an [exec](#exec-mode) subcommand for running commands in host containers.
8+
There's a [set](#set-mode) subcommand for changing settings, a [network configure](#network-configure) subcommand for configuring network settings, an [update](#update-mode) subcommand for updating the host, and an [exec](#exec-mode) subcommand for running commands in host containers.
99
There's also a low-level [raw](#raw-mode) subcommand for direct interaction with the HTTP API.
1010

1111
It talks to the Bottlerocket socket by default.
@@ -75,6 +75,53 @@ You can use JSON form to set it:
7575
apiclient set --json '{"motd": "42"}'
7676
```
7777

78+
### Network configure
79+
80+
This allows you to configure network settings by providing a net.toml file which netdog uses for network configuration.
81+
The configuration is written to `/.bottlerocket/net.toml` and will be validated and applied at the next boot by netdog.
82+
83+
The network configure command accepts input from different sources using URI schemes:
84+
85+
#### File URI input
86+
87+
You can specify a local file path using the `file://` URI scheme:
88+
89+
```shell
90+
apiclient network configure file:///path/to/net.toml
91+
```
92+
93+
#### Base64 encoded input
94+
95+
For inline configuration, you can provide base64-encoded content:
96+
97+
```shell
98+
apiclient network configure base64:dmVyc2lvbiA9IDIKCltldGgwXQpkaGNwNCA9IHRydWU=
99+
```
100+
101+
This is particularly useful for automation and configuration management where you want to embed the network configuration directly in scripts or user data.
102+
103+
#### Configuration format
104+
105+
The net.toml file uses the same format that netdog supports. Here's an example:
106+
107+
```toml
108+
version = 2
109+
110+
[eth0]
111+
dhcp4 = true
112+
dhcp6 = false
113+
114+
[eth1]
115+
static4 = ["192.168.1.100/24"]
116+
route = [{to = "default", via = "192.168.1.1"}]
117+
```
118+
119+
After configuring the network settings, you'll need to reboot the system for the changes to take effect:
120+
121+
```shell
122+
apiclient reboot
123+
```
124+
78125
### Update mode
79126

80127
To start, you can check what updates are available:

sources/api/apiclient/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! The apiclient library provides high-level methods to interact with the Bottlerocket API. See
2-
//! the documentation for submodules [`apply`], [`exec`], [`get`], [`reboot`], [`report`], [`set`],
2+
//! the documentation for submodules [`apply`], [`exec`], [`get`], [`network`], [`reboot`], [`report`], [`set`],
33
//! and [`update`] for high-level helpers.
44
//!
55
//! For more control, and to handle APIs without high-level wrappers, there are also 'raw' methods
@@ -23,6 +23,7 @@ pub mod apply;
2323
pub mod ephemeral_storage;
2424
pub mod exec;
2525
pub mod get;
26+
pub mod network;
2627
pub mod reboot;
2728
pub mod report;
2829
pub mod set;

0 commit comments

Comments
 (0)