Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
resmo committed Oct 20, 2023
1 parent ffc3bfe commit d173629
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 25 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ test:

update:
pip-compile -U --no-header --no-annotate --strip-extras --resolver backtracking
pip-sync
3 changes: 2 additions & 1 deletion chaotic/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]()
Expand Down
12 changes: 7 additions & 5 deletions chaotic/app.py
Original file line number Diff line number Diff line change
@@ -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("")
Expand Down
3 changes: 2 additions & 1 deletion chaotic/cloud/cloudscale_ch.py
Original file line number Diff line number Diff line change
@@ -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):

Expand Down
12 changes: 8 additions & 4 deletions chaotic/cloud/cloudstack.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion chaotic/cloud/digitalocean.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import random
import time

import digitalocean

from chaotic.cloud import Chaotic
Expand Down
7 changes: 3 additions & 4 deletions chaotic/cloud/exoscale.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
5 changes: 3 additions & 2 deletions chaotic/cloud/hcloud.py
Original file line number Diff line number Diff line change
@@ -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):

Expand Down
9 changes: 5 additions & 4 deletions chaotic/cloud/proxmox_kvm.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
7 changes: 4 additions & 3 deletions chaotic/cloud/vultr.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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}",
Expand Down

0 comments on commit d173629

Please sign in to comment.