forked from cloudify-community/eaas-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload-blueprints.py
executable file
·80 lines (71 loc) · 3.38 KB
/
upload-blueprints.py
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python
import os
import subprocess
import threading
def perform(**kwargs):
def _thread_body(blueprint_id, blueprint_path):
print("Uploading blueprint '{}' from {}".format(blueprint_id,
blueprint_path))
subprocess.check_call(
['cfy', 'blueprints', 'upload', blueprint_path, '-b', blueprint_id, '--visibility', 'global'])
def _create_blueprint_tuple(file, env_blueprint, root_dir, env_type, cloud_type=None):
if "standalone" in file and cloud_type:
return ("{}_standalone_{}".format(cloud_type, env_blueprint),
os.path.join(root_dir,
'infra',
env_type,
env_blueprint,
file))
elif "standalone" not in file and cloud_type:
return ("{}_{}".format(cloud_type, env_blueprint),
os.path.join(root_dir,
'infra',
env_type,
env_blueprint,
file))
elif "standalone" in file and not cloud_type:
return ("standalone_{}".format(env_blueprint),
os.path.join(root_dir,
'infra',
env_type,
env_blueprint,
file))
else:
return (env_blueprint,
os.path.join(root_dir,
'infra',
env_type,
env_blueprint,
file))
script_dir = os.path.dirname(os.path.realpath(__file__))
root_dir = os.path.normpath(os.path.join(script_dir, '..'))
blueprints = [
('nginx', os.path.join(root_dir, 'services/nginx.yaml')),
('aws', os.path.join(root_dir, 'environments/aws.yaml')),
('azure', os.path.join(root_dir, 'environments/azure.yaml')),
('eaas', os.path.join(root_dir, 'environments/eaas.yaml')),
('vpc', os.path.join(root_dir, 'infra/vpc/blueprint.yaml')),
('rg', os.path.join(root_dir, 'infra/rg/blueprint.yaml'))
]
for env_type in ['dev', 'prod']:
env_blueprints = os.listdir(os.path.join(root_dir, 'infra', env_type))
for env_blueprint in env_blueprints:
for file in os.listdir(
os.path.join(root_dir, 'infra', env_type, env_blueprint)
):
if file.endswith("blueprint.yaml"):
if file.startswith("aws"):
blueprints.append(_create_blueprint_tuple(file, env_blueprint, root_dir, env_type, "aws"))
elif file.startswith("azure"):
blueprints.append(_create_blueprint_tuple(file, env_blueprint, root_dir, env_type, "azure"))
else:
blueprints.append(_create_blueprint_tuple(file, env_blueprint, root_dir, env_type))
threads = []
for blueprint_id, blueprint_path in blueprints:
thread = threading.Thread(target=_thread_body, args=(blueprint_id, os.path.join(root_dir, blueprint_path)))
thread.start()
threads.append(thread)
for t in threads:
t.join()
if __name__ == '__main__':
perform()