Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions machine/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,9 @@ def get(config_file_name: str) -> Config:
if not provider_name:
found = [p for p in KNOWN_PROVIDERS if p in config]
if len(found) == 0:
fatal_error(
"No provider section found in config file. Expected one of: " + ", ".join(KNOWN_PROVIDERS)
)
fatal_error("No provider section found in config file. Expected one of: " + ", ".join(KNOWN_PROVIDERS))
if len(found) > 1:
fatal_error(
"Multiple provider sections found in config file. Please add a 'provider:' key to select one."
)
fatal_error("Multiple provider sections found in config file. Please add a 'provider:' key to select one.")
provider_name = found[0]

if provider_name not in config:
Expand Down
3 changes: 1 addition & 2 deletions machine/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ def _resolve_config_dir():
return _new_config_dir
if old_path.exists():
print(
f"Warning: config directory {_old_config_dir} is deprecated, "
f"please move it to {_new_config_dir}",
f"Warning: config directory {_old_config_dir} is deprecated, please move it to {_new_config_dir}",
file=sys.stderr,
)
return _old_config_dir
Expand Down
10 changes: 2 additions & 8 deletions machine/providers/digitalocean.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ def get_ssh_key(self, name) -> SSHKey:

def list_ssh_keys(self) -> list:
keys = self._manager.get_all_sshkeys()
return [
SSHKey(id=str(k.id), name=k.name, fingerprint=k.fingerprint, public_key=k.public_key)
for k in keys
]
return [SSHKey(id=str(k.id), name=k.name, fingerprint=k.fingerprint, public_key=k.public_key) for k in keys]

def create_dns_record(self, zone, record_type, name, data, ttl, tag=None) -> str:
domain = digitalocean.Domain(token=self.token, name=zone)
Expand All @@ -126,10 +123,7 @@ def delete_dns_record(self, zone, record_name) -> bool:
def get_dns_records(self, zone) -> list:
domain = digitalocean.Domain(token=self.token, name=zone)
records = domain.get_records()
return [
DNSRecord(id=str(r.id), name=r.name, type=r.type, data=r.data, ttl=r.ttl)
for r in records
]
return [DNSRecord(id=str(r.id), name=r.name, type=r.type, data=r.data, ttl=r.ttl) for r in records]

def list_domains(self) -> list:
domains = self._manager.get_all_domains()
Expand Down
9 changes: 8 additions & 1 deletion machine/providers/vultr.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
from machine.provider import CloudProvider, VM, SSHKey, DNSRecord


# fmt: off
# Kept as a grid rather than one region per line, which is how it reads on
# Vultr's own region list and keeps the whole set visible at a glance.
VALID_REGIONS = [
"ewr", "ord", "dfw", "sea", "lax", "atl", "ams", "lhr", "fra",
"sjc", "syd", "nrt", "cdg", "icn", "mia", "sgp", "sto",
"mex", "mad", "sao", "del", "hnl", "yto", "blr", "jnb",
"bom", "tlv",
]
# fmt: on

# Overall budget for destroy_vm, and for confirming a single accepted delete.
# The overall budget stays well inside the callers' expectations of a command
Expand Down Expand Up @@ -158,7 +162,10 @@ def create_dns_record(self, zone, record_type, name, data, ttl, tag=None) -> str
try:
result = self._client.post(
f"/domains/{zone}/records",
type=record_type, name=name, data=data, ttl=ttl,
type=record_type,
name=name,
data=data,
ttl=ttl,
)
except VultrException:
info(f"Warning: DNS zone '{zone}' not found in Vultr, DNS record not set")
Expand Down
4 changes: 1 addition & 3 deletions machine/subcommands/destroy.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ def command(context, confirm, delete_dns, all, machine_ids):
fatal_error(f'ERROR: Cannot destroy machine "{name}" (id: {vm.id}), it was not created by this tool.')

if not is_same_session(command_context, vm) and not all:
fatal_error(
f'ERROR: Cannot destroy machine "{name}" (id: {vm.id}), it was created by a different session.'
)
fatal_error(f'ERROR: Cannot destroy machine "{name}" (id: {vm.id}), it was created by a different session.')

if confirm:
output(
Expand Down
20 changes: 15 additions & 5 deletions sh/lint.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
#!/bin/bash

if [[ "$1" == "--fix" ]]; then
uv run ruff format machine/
uv run ruff check --fix machine/
# A bash script exits with the status of its last command, so without this the
# format check's result was discarded and only `ruff check` decided the outcome.
# Both checks still run to completion on failure, so one invocation reports all
# the work that needs doing rather than stopping at the first problem.
set -uo pipefail

status=0

if [[ "${1:-}" == "--fix" ]]; then
uv run ruff format machine/ || status=1
uv run ruff check --fix machine/ || status=1
else
uv run ruff format --check machine/
uv run ruff check machine/
uv run ruff format --check machine/ || status=1
uv run ruff check machine/ || status=1
fi

exit "${status}"
Loading