Skip to content

Commit c325aec

Browse files
authored
Finish refactor of main. Align setup, new & init commands (#536)
* refactor setup and create commands * tidy up main * align init behaviour with create * update docs * rename create -> new * move auth into users.py
1 parent 242620b commit c325aec

File tree

6 files changed

+666
-658
lines changed

6 files changed

+666
-658
lines changed

docs/quickstart.md

+13-3
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,23 @@ pip install -e .
2828

2929
## Running
3030

31-
To get started simply run:
31+
To get started first check you have all the necessary requirements:
3232

3333
```bash
34-
warnet quickstart
34+
warnet setup
3535
```
3636

37-
This will check you have the required dependencies and guide you through setting up and deploying your first network.
37+
Then create your first network:
38+
39+
```bash
40+
# Create a new network in the current directory
41+
warnet init
42+
43+
# Or in a directory of choice
44+
warnet new <directory>
45+
```
46+
47+
Follow the guide to configure network variables.
3848

3949
## fork-observer
4050

docs/warnet.md

+11-18
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,14 @@ options:
2121
|-------------|--------|------------|-----------|
2222
| kube_config | String | yes | |
2323

24-
### `warnet create`
25-
Create a new warnet project in the specified directory
26-
27-
options:
28-
| name | type | required | default |
29-
|-----------|--------|------------|-----------|
30-
| directory | Path | yes | |
31-
3224
### `warnet deploy`
3325
Deploy a warnet with topology loaded from \<directory>
3426

3527
options:
3628
| name | type | required | default |
3729
|-----------|--------|------------|-----------|
3830
| directory | Path | yes | |
31+
| debug | Bool | | False |
3932

4033
### `warnet down`
4134
Bring down a running warnet
@@ -45,9 +38,13 @@ Bring down a running warnet
4538
Initialize a warnet project in the current directory
4639

4740

48-
### `warnet quickstart`
49-
Setup warnet
41+
### `warnet new`
42+
Create a new warnet project in the specified directory
5043

44+
options:
45+
| name | type | required | default |
46+
|-----------|--------|------------|-----------|
47+
| directory | Path | yes | |
5148

5249
### `warnet run`
5350
Run a scenario from a file
@@ -58,6 +55,10 @@ options:
5855
| scenario_file | Path | yes | |
5956
| additional_args | String | | |
6057

58+
### `warnet setup`
59+
Setup warnet
60+
61+
6162
### `warnet status`
6263
Display the unified status of the Warnet network and active scenarios
6364

@@ -72,14 +73,6 @@ options:
7273

7374
## Admin
7475

75-
### `warnet admin create`
76-
Create a new warnet project in the specified directory
77-
78-
options:
79-
| name | type | required | default |
80-
|-----------|--------|------------|-----------|
81-
| directory | Func | yes | |
82-
8376
### `warnet admin init`
8477
Initialize a warnet project in the current directory
8578

src/warnet/control.py

+49
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import time
55

66
import click
7+
import inquirer
78
import yaml
9+
from inquirer.themes import GreenPassion
810
from rich import print
911
from rich.console import Console
1012
from rich.prompt import Confirm, Prompt
@@ -248,3 +250,50 @@ def run(scenario_file: str, additional_args: tuple[str]):
248250
print(f"Failed to start scenario: {scenario_name}")
249251

250252
os.unlink(temp_file_path)
253+
254+
255+
@click.command()
256+
@click.argument("pod_name", type=str, default="")
257+
@click.option("--follow", "-f", is_flag=True, default=False, help="Follow logs")
258+
def logs(pod_name: str, follow: bool):
259+
"""Show the logs of a pod"""
260+
follow_flag = "--follow" if follow else ""
261+
namespace = get_default_namespace()
262+
263+
if pod_name:
264+
try:
265+
command = f"kubectl logs pod/{pod_name} -n {namespace} {follow_flag}"
266+
stream_command(command)
267+
return
268+
except Exception as e:
269+
print(f"Could not find the pod {pod_name}: {e}")
270+
271+
try:
272+
pods = run_command(f"kubectl get pods -n {namespace} -o json")
273+
pods = json.loads(pods)
274+
pod_list = [item["metadata"]["name"] for item in pods["items"]]
275+
except Exception as e:
276+
print(f"Could not fetch any pods in namespace {namespace}: {e}")
277+
return
278+
279+
if not pod_list:
280+
print(f"Could not fetch any pods in namespace {namespace}")
281+
return
282+
283+
q = [
284+
inquirer.List(
285+
name="pod",
286+
message="Please choose a pod",
287+
choices=pod_list,
288+
)
289+
]
290+
selected = inquirer.prompt(q, theme=GreenPassion())
291+
if selected:
292+
pod_name = selected["pod"]
293+
try:
294+
command = f"kubectl logs pod/{pod_name} -n {namespace} {follow_flag}"
295+
stream_command(command)
296+
except Exception as e:
297+
print(f"Please consider waiting for the pod to become available. Encountered: {e}")
298+
else:
299+
pass # cancelled by user

0 commit comments

Comments
 (0)