forked from devopsloft/devopsloft
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspin.py
More file actions
executable file
·62 lines (50 loc) · 1.94 KB
/
Copy pathspin.py
File metadata and controls
executable file
·62 lines (50 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
import dotenv
import vagrant
import os
import click
from createPemFiles import SelfSignedCertificate, IsCertExist
def prepareEnvironmentVars(environementName):
# Reads the .env file from the repository
# Returns an array with all the env vars, inclduing modificatoins per env
dotenv.load_dotenv()
envArray = os.environ.copy()
if (environementName == 'dev'):
envArray['WEB_HOST_PORT'] = envArray['DEV_WEB_HOST_PORT']
envArray['WEB_GUEST_PORT'] = envArray['DEV_WEB_GUEST_PORT']
envArray['WEB_HOST_SECURE_PORT'] = envArray['DEV_WEB_HOST_SECURE_PORT']
envArray['WEB_GUEST_SECURE_PORT'] = \
envArray['DEV_WEB_GUEST_SECURE_PORT']
return envArray
def startVagrant(machineName, envVars):
# Starts a Vagrant instance with noisy logs
# Loading the enviornement vars that was created in prepareEnvironmentVars
v = vagrant.Vagrant(quiet_stdout=False, quiet_stderr=False)
v.env = envVars
v.up(vm_name=machineName)
def destroyVagrant(machineName, envVars):
v = vagrant.Vagrant(quiet_stdout=False, quiet_stderr=False)
v.env = envVars
v.destroy(vm_name=machineName)
def updateBox():
v = vagrant.Vagrant(quiet_stdout=False, quiet_stderr=False)
v.box_update()
v.box_prune()
@click.command()
@click.option("-e", "--envioronment", required=False, default="dev",
type=click.Choice(["dev", "prod", "stage"]))
@click.option("-a", "--action", required=False, default="up",
type=click.Choice(["up", "destroy"]))
def main(envioronment, action):
if not (IsCertExist()):
SelfSignedCertificate()
machineName = envioronment
envVars = prepareEnvironmentVars(machineName)
if (action == 'up'):
if (envioronment == 'dev'):
updateBox()
startVagrant(machineName, envVars)
elif (action == 'destroy'):
destroyVagrant(machineName, envVars)
if __name__ == '__main__':
main()