forked from clan/clan-core
Merge pull request 'cli-prep' (#53) from cli-prep into main
This commit is contained in:
commit
2c4667b1f5
@ -3,11 +3,12 @@ import argparse
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from . import admin, ssh
|
from . import admin, ssh
|
||||||
|
from .errors import ClanError
|
||||||
|
|
||||||
has_argcomplete = True
|
has_argcomplete = True
|
||||||
try:
|
try:
|
||||||
import argcomplete
|
import argcomplete
|
||||||
except ImportError: # pragma: no cover
|
except ImportError:
|
||||||
has_argcomplete = False
|
has_argcomplete = False
|
||||||
|
|
||||||
|
|
||||||
@ -30,8 +31,12 @@ def main() -> None:
|
|||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if hasattr(args, "func"):
|
if hasattr(args, "func"):
|
||||||
args.func(args) # pragma: no cover
|
try:
|
||||||
|
args.func(args)
|
||||||
|
except ClanError as e:
|
||||||
|
print(f"{sys.argv[0]}: {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__": # pragma: no cover
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
@ -18,7 +18,7 @@ def create(args: argparse.Namespace) -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def edit(args: argparse.Namespace) -> None: # pragma: no cover
|
def edit(args: argparse.Namespace) -> None:
|
||||||
# TODO add some cli options to change certain options without relying on a text editor
|
# TODO add some cli options to change certain options without relying on a text editor
|
||||||
clan_flake = f"{args.folder}/flake.nix"
|
clan_flake = f"{args.folder}/flake.nix"
|
||||||
if os.path.isfile(clan_flake):
|
if os.path.isfile(clan_flake):
|
||||||
@ -34,7 +34,7 @@ def edit(args: argparse.Namespace) -> None: # pragma: no cover
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def rebuild(args: argparse.Namespace) -> None: # pragma: no cover
|
def rebuild(args: argparse.Namespace) -> None:
|
||||||
# TODO get clients from zerotier cli?
|
# TODO get clients from zerotier cli?
|
||||||
if args.host:
|
if args.host:
|
||||||
print(f"would redeploy {args.host} from clan {args.folder}")
|
print(f"would redeploy {args.host} from clan {args.folder}")
|
||||||
@ -42,7 +42,7 @@ def rebuild(args: argparse.Namespace) -> None: # pragma: no cover
|
|||||||
print(f"would redeploy all hosts from clan {args.folder}")
|
print(f"would redeploy all hosts from clan {args.folder}")
|
||||||
|
|
||||||
|
|
||||||
def destroy(args: argparse.Namespace) -> None: # pragma: no cover
|
def destroy(args: argparse.Namespace) -> None:
|
||||||
# TODO get clan folder & hosts from somwhere (maybe ~/.config/clan/$name /)
|
# TODO get clan folder & hosts from somwhere (maybe ~/.config/clan/$name /)
|
||||||
# send some kind of kill signal, then remove the folder
|
# send some kind of kill signal, then remove the folder
|
||||||
if args.yes:
|
if args.yes:
|
||||||
@ -53,14 +53,14 @@ def destroy(args: argparse.Namespace) -> None: # pragma: no cover
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def backup(args: argparse.Namespace) -> None: # pragma: no cover
|
def backup(args: argparse.Namespace) -> None:
|
||||||
if args.host:
|
if args.host:
|
||||||
print(f"would backup {args.host} from clan {args.folder}")
|
print(f"would backup {args.host} from clan {args.folder}")
|
||||||
else:
|
else:
|
||||||
print(f"would backup all hosts from clan {args.folder}")
|
print(f"would backup all hosts from clan {args.folder}")
|
||||||
|
|
||||||
|
|
||||||
def git(args: argparse.Namespace) -> None: # pragma: no cover
|
def git(args: argparse.Namespace) -> None:
|
||||||
subprocess.Popen(
|
subprocess.Popen(
|
||||||
[
|
[
|
||||||
"git",
|
"git",
|
||||||
|
@ -53,7 +53,7 @@ def qrcode_scan(pictureFile: str) -> str:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def main(args: argparse.Namespace) -> None: # pragma: no cover
|
def main(args: argparse.Namespace) -> None:
|
||||||
if args.json:
|
if args.json:
|
||||||
with open(args.json) as file:
|
with open(args.json) as file:
|
||||||
ssh_data = json.load(file)
|
ssh_data = json.load(file)
|
||||||
|
@ -62,7 +62,7 @@ class ZerotierController:
|
|||||||
resp = urllib.request.urlopen(req)
|
resp = urllib.request.urlopen(req)
|
||||||
return json.load(resp)
|
return json.load(resp)
|
||||||
|
|
||||||
def status(self) -> dict[str, Any]: # pragma: no cover
|
def status(self) -> dict[str, Any]:
|
||||||
return self._http_request("/status")
|
return self._http_request("/status")
|
||||||
|
|
||||||
def create_network(self, data: dict[str, Any] = {}) -> dict[str, Any]:
|
def create_network(self, data: dict[str, Any] = {}) -> dict[str, Any]:
|
||||||
@ -75,9 +75,7 @@ class ZerotierController:
|
|||||||
def get_network(self, id: str) -> dict[str, Any]:
|
def get_network(self, id: str) -> dict[str, Any]:
|
||||||
return self._http_request(f"/controller/network/{id}")
|
return self._http_request(f"/controller/network/{id}")
|
||||||
|
|
||||||
def update_network(
|
def update_network(self, id: str, new_config: dict[str, Any]) -> dict[str, Any]:
|
||||||
self, id: str, new_config: dict[str, Any]
|
|
||||||
) -> dict[str, Any]: # pragma: no cover
|
|
||||||
return self._http_request(
|
return self._http_request(
|
||||||
f"/controller/network/{id}", method="POST", data=new_config
|
f"/controller/network/{id}", method="POST", data=new_config
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user