automation: establish an automation framework
This commit is contained in:
parent
1b53bf451c
commit
8abe5d60fa
31 changed files with 586 additions and 274 deletions
|
@ -1,14 +1,14 @@
|
|||
import datetime
|
||||
from typing import Iterable
|
||||
from typing import Iterable, Optional, Any
|
||||
|
||||
from app import app
|
||||
from app.extensions import db
|
||||
from app.models.bridges import BridgeConf, Bridge
|
||||
from app.models.base import Group
|
||||
from app.terraform import BaseAutomation
|
||||
from app.terraform.terraform import TerraformAutomation
|
||||
|
||||
|
||||
class BridgeAutomation(BaseAutomation):
|
||||
class BridgeAutomation(TerraformAutomation):
|
||||
def create_missing(self):
|
||||
bridgeconfs: Iterable[BridgeConf] = BridgeConf.query.filter(
|
||||
BridgeConf.provider == self.provider,
|
||||
|
@ -45,8 +45,12 @@ class BridgeAutomation(BaseAutomation):
|
|||
bridge.destroy()
|
||||
db.session.commit()
|
||||
|
||||
def generate_terraform(self):
|
||||
self.write_terraform_config(
|
||||
def tf_prehook(self) -> Optional[Any]:
|
||||
self.create_missing()
|
||||
self.destroy_expired()
|
||||
|
||||
def tf_generate(self):
|
||||
self.tf_write(
|
||||
self.template,
|
||||
groups=Group.query.all(),
|
||||
bridgeconfs=BridgeConf.query.filter(
|
||||
|
@ -60,8 +64,8 @@ class BridgeAutomation(BaseAutomation):
|
|||
}
|
||||
)
|
||||
|
||||
def import_terraform(self):
|
||||
outputs = self.terraform_output()
|
||||
def tf_posthook(self, *, prehook_result: Any = None) -> None:
|
||||
outputs = self.tf_output()
|
||||
for output in outputs:
|
||||
if output.startswith('bridge_hashed_fingerprint_'):
|
||||
parts = outputs[output]['value'].split(" ")
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
from app import app
|
||||
from app.terraform.bridge import BridgeAutomation
|
||||
|
||||
|
||||
class BridgeAWSAutomation(BridgeAutomation):
|
||||
short_name = "bridge_aws"
|
||||
description = "Deploy Tor bridges on AWS Lightsail"
|
||||
provider = "aws"
|
||||
|
||||
template_parameters = [
|
||||
|
@ -67,18 +67,3 @@ class BridgeAWSAutomation(BridgeAutomation):
|
|||
{% endfor %}
|
||||
{% endfor %}
|
||||
"""
|
||||
|
||||
|
||||
def automate():
|
||||
auto = BridgeAWSAutomation()
|
||||
auto.destroy_expired()
|
||||
auto.create_missing()
|
||||
auto.generate_terraform()
|
||||
auto.terraform_init()
|
||||
auto.terraform_apply()
|
||||
auto.import_terraform()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with app.app_context():
|
||||
automate()
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
from app import app
|
||||
from app.terraform.bridge import BridgeAutomation
|
||||
|
||||
|
||||
class BridgeGandiAutomation(BridgeAutomation):
|
||||
short_name = "bridge_gandi"
|
||||
description = "Deploy Tor bridges on GandiCloud VPS"
|
||||
provider = "gandi"
|
||||
|
||||
template_parameters = [
|
||||
|
@ -78,18 +78,3 @@ class BridgeGandiAutomation(BridgeAutomation):
|
|||
{% endfor %}
|
||||
{% endfor %}
|
||||
"""
|
||||
|
||||
|
||||
def automate():
|
||||
auto = BridgeGandiAutomation()
|
||||
auto.destroy_expired()
|
||||
auto.create_missing()
|
||||
auto.generate_terraform()
|
||||
auto.terraform_init()
|
||||
auto.terraform_apply()
|
||||
auto.import_terraform()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with app.app_context():
|
||||
automate()
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
from app import app
|
||||
from app.terraform.bridge import BridgeAutomation
|
||||
|
||||
|
||||
class BridgeHcloudAutomation(BridgeAutomation):
|
||||
short_name = "bridge_hcloud"
|
||||
description = "Deploy Tor bridges on Hetzner Cloud"
|
||||
provider = "hcloud"
|
||||
|
||||
template_parameters = [
|
||||
|
@ -81,18 +81,3 @@ class BridgeHcloudAutomation(BridgeAutomation):
|
|||
{% endfor %}
|
||||
{% endfor %}
|
||||
"""
|
||||
|
||||
|
||||
def automate():
|
||||
auto = BridgeHcloudAutomation()
|
||||
auto.destroy_expired()
|
||||
auto.create_missing()
|
||||
auto.generate_terraform()
|
||||
auto.terraform_init()
|
||||
auto.terraform_apply()
|
||||
auto.import_terraform()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with app.app_context():
|
||||
automate()
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
from app import app
|
||||
from app.terraform.bridge import BridgeAutomation
|
||||
|
||||
|
||||
class BridgeOvhAutomation(BridgeAutomation):
|
||||
short_name = "bridge_ovh"
|
||||
description = "Deploy Tor bridges on OVH Public Cloud"
|
||||
provider = "ovh"
|
||||
|
||||
template_parameters = [
|
||||
|
@ -104,18 +104,3 @@ class BridgeOvhAutomation(BridgeAutomation):
|
|||
{% endfor %}
|
||||
{% endfor %}
|
||||
"""
|
||||
|
||||
|
||||
def automate():
|
||||
auto = BridgeOvhAutomation()
|
||||
auto.destroy_expired()
|
||||
auto.create_missing()
|
||||
auto.generate_terraform()
|
||||
auto.terraform_init()
|
||||
auto.terraform_apply()
|
||||
auto.import_terraform()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with app.app_context():
|
||||
automate()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue