diff --git a/Makefile b/Makefile index 68ff600..cac499b 100644 --- a/Makefile +++ b/Makefile @@ -19,3 +19,4 @@ test: update: pip-compile -U --no-header --no-annotate --strip-extras --resolver backtracking + pip-sync diff --git a/chaotic/__init__.py b/chaotic/__init__.py index ef7ee56..62f867d 100644 --- a/chaotic/__init__.py +++ b/chaotic/__init__.py @@ -1,3 +1,4 @@ +from chaotic.cloud import Chaotic from chaotic.cloud.cloudscale_ch import CloudscaleChChaotic from chaotic.cloud.cloudstack import CloudStackChaotic from chaotic.cloud.digitalocean import DigitaloceanChaotic @@ -22,7 +23,7 @@ class ChaoticFactory: "vultr": VultrChaotic, } - def get_instance(self, name: str) -> object: + def get_instance(self, name: str) -> Chaotic: log.info(f"Instantiate {name}") try: return self.CLOUD_CLASSES[name]() diff --git a/chaotic/app.py b/chaotic/app.py index 1a07a15..18c73ff 100644 --- a/chaotic/app.py +++ b/chaotic/app.py @@ -1,17 +1,19 @@ +import json import os import sys -from requests.models import Response -import yaml -import json import time -import schedule from argparse import ArgumentParser + import requests +import schedule +import yaml +from requests.models import Response +from chaotic import ChaoticFactory +from chaotic.cloud import Chaotic from chaotic.log import log from chaotic.version import __version__ -from chaotic import ChaoticFactory def app() -> None: print("") diff --git a/chaotic/cloud/cloudscale_ch.py b/chaotic/cloud/cloudscale_ch.py index df526c9..174860f 100644 --- a/chaotic/cloud/cloudscale_ch.py +++ b/chaotic/cloud/cloudscale_ch.py @@ -1,12 +1,13 @@ import os import random import time + from cloudscale import Cloudscale, CloudscaleApiException from chaotic.cloud import Chaotic from chaotic.log import log -CLOUDSCALE_API_TOKEN: str = os.getenv('CLOUDSCALE_API_TOKEN') +CLOUDSCALE_API_TOKEN: str = os.getenv('CLOUDSCALE_API_TOKEN', "") class CloudscaleChChaotic(Chaotic): diff --git a/chaotic/cloud/cloudstack.py b/chaotic/cloud/cloudstack.py index ebdc931..9d7cc8d 100644 --- a/chaotic/cloud/cloudstack.py +++ b/chaotic/cloud/cloudstack.py @@ -1,14 +1,15 @@ import os import random import time + from cs import CloudStack from chaotic.cloud import Chaotic from chaotic.log import log -CLOUDSTACK_API_ENDPOINT: str = os.getenv('CLOUDSTACK_API_ENDPOINT') -CLOUDSTACK_API_KEY: str = os.getenv('CLOUDSTACK_API_KEY') -CLOUDSTACK_API_SECRET: str = os.getenv('CLOUDSTACK_API_SECRET') +CLOUDSTACK_API_ENDPOINT: str = os.getenv('CLOUDSTACK_API_ENDPOINT', "") +CLOUDSTACK_API_KEY: str = os.getenv('CLOUDSTACK_API_KEY', "") +CLOUDSTACK_API_SECRET: str = os.getenv('CLOUDSTACK_API_SECRET', "") class CloudStackChaotic(Chaotic): @@ -21,7 +22,10 @@ def __init__(self) -> None: ) def action(self) -> None: - tag = self.configs.get('tag') + tag = self.configs.get("tag") + if not tag: + return + log.info(f"Querying with tag: {tag['key']}={tag['value']}") instances = self.cs.listVirtualMachines( diff --git a/chaotic/cloud/digitalocean.py b/chaotic/cloud/digitalocean.py index 5a7156c..e6f233a 100644 --- a/chaotic/cloud/digitalocean.py +++ b/chaotic/cloud/digitalocean.py @@ -1,6 +1,6 @@ -import os import random import time + import digitalocean from chaotic.cloud import Chaotic diff --git a/chaotic/cloud/exoscale.py b/chaotic/cloud/exoscale.py index 8c68775..cd4cc4d 100644 --- a/chaotic/cloud/exoscale.py +++ b/chaotic/cloud/exoscale.py @@ -1,14 +1,13 @@ import os -import random -import time + from cs import CloudStack from chaotic.cloud.cloudstack import CloudStackChaotic from chaotic.log import log EXOSCALE_API_ENDPOINT: str = "https://api.exoscale.com/compute" -EXOSCALE_API_KEY: str = os.getenv('EXOSCALE_API_KEY') -EXOSCALE_API_SECRET: str = os.getenv('EXOSCALE_API_SECRET') +EXOSCALE_API_KEY: str = os.getenv('EXOSCALE_API_KEY', "") +EXOSCALE_API_SECRET: str = os.getenv('EXOSCALE_API_SECRET', "") class ExoscaleChaotic(CloudStackChaotic): diff --git a/chaotic/cloud/hcloud.py b/chaotic/cloud/hcloud.py index 86dc76b..7b94595 100644 --- a/chaotic/cloud/hcloud.py +++ b/chaotic/cloud/hcloud.py @@ -1,12 +1,13 @@ import os import random import time -from hcloud import Client, APIException + +from hcloud import Client from chaotic.cloud import Chaotic from chaotic.log import log -HCLOUD_API_TOKEN: str = os.getenv('HCLOUD_API_TOKEN') +HCLOUD_API_TOKEN: str = os.getenv("HCLOUD_API_TOKEN", "") class HcloudChaotic(Chaotic): diff --git a/chaotic/cloud/proxmox_kvm.py b/chaotic/cloud/proxmox_kvm.py index bd41a33..985f12a 100644 --- a/chaotic/cloud/proxmox_kvm.py +++ b/chaotic/cloud/proxmox_kvm.py @@ -1,15 +1,16 @@ import os import random import time + from proxmoxer import ProxmoxAPI from chaotic.cloud import Chaotic from chaotic.log import log -PROXMOX_API_HOST = os.getenv('PROXMOX_API_HOST') -PROXMOX_API_USER = os.getenv('PROXMOX_API_USER', 'root@pam') -PROXMOX_API_PASSWORD = os.getenv('PROXMOX_API_PASSWORD') -PROXMOX_API_VERIFY_SSL = bool(os.getenv('PROXMOX_API_VERIFY_SSL', False)) +PROXMOX_API_HOST: str = os.getenv("PROXMOX_API_HOST", "") +PROXMOX_API_USER: str = os.getenv("PROXMOX_API_USER", 'root@pam') +PROXMOX_API_PASSWORD: str = os.getenv("ROXMOX_API_PASSWORD", "") +PROXMOX_API_VERIFY_SSL: bool = bool(os.getenv('PROXMOX_API_VERIFY_SSL', False)) class ProxmoxKvmChaotic(Chaotic): diff --git a/chaotic/cloud/vultr.py b/chaotic/cloud/vultr.py index 3188894..53e5015 100644 --- a/chaotic/cloud/vultr.py +++ b/chaotic/cloud/vultr.py @@ -1,13 +1,14 @@ import os import random import time +from typing import List, Optional + import requests -from typing import List from chaotic.cloud import Chaotic from chaotic.log import log -VULTR_API_KEY: str = os.getenv('VULTR_API_KEY') +VULTR_API_KEY: str = os.getenv('VULTR_API_KEY', "") class Vultr: @@ -17,7 +18,7 @@ class Vultr: def __init__(self, api_key: str) -> None: self.api_key = api_key - def query_api(self, method: str, path: str, params: dict = None, json: dict = None) -> requests.Response: + def query_api(self, method: str, path: str, params: Optional[dict] = None, json: Optional[dict] = None) -> requests.Response: r = requests.request( method=method, url=f"{self.VULTR_API_URL}/{path}",