-
Notifications
You must be signed in to change notification settings - Fork 33
/
devenv.py
executable file
·210 lines (191 loc) · 6.01 KB
/
devenv.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env python3
from datetime import datetime
from kqueen.server import create_app
from kqueen.models import Cluster
from kqueen.models import Organization
from kqueen.models import Provisioner
from kqueen.models import User
import requests
import yaml
import os
uuid_organization = '22d8df64-4ac9-4be0-89a7-c45ea0fc85da'
uuid_jenkins = 'c88b05d6-a107-4636-a3cc-eb5c90562f8f'
uuid_local = '2d51891a-adac-4bbc-a725-eed20cc67849'
uuid_gke = '9212695e-3aad-434d-ba26-3403481d37a1'
uuid_aks = 'c02d3b7c-d06e-11e7-973c-68f72873a109'
uuid_provisioner_jenkins = 'e8de24b0-43d1-4a3c-af55-7b1d3f700554'
uuid_provisioner_local = '203c50d6-3d09-4789-8b8b-1ecb00814436'
uuid_provisioner_kubespray = '689de9a2-50e0-4fcd-b6a6-96930b5fadc9'
uuid_provisioner_gke = '516e3a8c-6c4d-49f1-8178-c6f802836618'
uuid_provisioner_aks = 'b72df8cc-d06e-11e7-97cc-68f72873a109'
kubeconfig_url = 'https://ci.mcp.mirantis.net/job/deploy-aws-k8s_ha_calico_sm/17/artifact/kubeconfig'
kubeconfig_file = 'kubeconfig_remote'
app = create_app()
with app.app_context():
# Organization and user
try:
organization = Organization(
id=uuid_organization,
name='DemoOrg',
namespace='demoorg',
created_at=datetime.utcnow()
)
organization.save()
except:
raise Exception('Adding DemoOrg organization failed')
try:
user = User.create(
None,
username='admin',
password='default',
organization=organization,
created_at=datetime.utcnow(),
role='superadmin',
active=True
)
user.save()
except:
raise Exception('Adding admin user failed')
# AWS + Jenkins
try:
provisioner = Provisioner(
user.namespace,
id=uuid_provisioner_jenkins,
name='Jenkins provisioner to AWS',
state='OK',
engine='kqueen.engines.JenkinsEngine',
parameters={
'username': 'demo',
'password': 'Demo123'
},
created_at=datetime.utcnow(),
owner=user
)
provisioner.save(check_status=False)
except:
raise Exception('Adding AWS provisioner failed')
try:
# load kubeconfig file
if os.path.isfile(kubeconfig_file):
print('Loading remote kubeconfig from {}'.format(kubeconfig_file))
kubeconfig = yaml.load(open(kubeconfig_file).read())
else:
print('Loading remote kubeconfig from {}'.format(kubeconfig_url))
kubeconfig = yaml.load(requests.get(kubeconfig_url).text)
cluster = Cluster(
user.namespace,
id=uuid_jenkins,
name='AWS kqueen testing',
state='OK',
provisioner=provisioner,
kubeconfig=kubeconfig,
created_at=datetime.utcnow(),
owner=user,
metadata={}
)
cluster.save()
except:
raise Exception('Adding AWS cluster failed')
# GKE provisioner
try:
provisioner = Provisioner(
user.namespace,
id=uuid_provisioner_gke,
name='Google Kubernetes engine',
state='OK',
engine='kqueen.engines.GceEngine',
created_at=datetime.utcnow(),
owner=user,
parameters={}
)
provisioner.save(check_status=False)
except:
raise Exception('Adding GKE provisioner failed')
try:
cluster = Cluster(
user.namespace,
id=uuid_gke,
state='OK',
name='GKE cluster, paused',
provisioner=provisioner,
created_at=datetime.utcnow(),
owner=user,
metadata={}
)
cluster.save()
except:
raise Exception('Adding GKE provisioner failed')
# AKS provisioner
try:
provisioner = Provisioner(
user.namespace,
id=uuid_provisioner_aks,
name='Azure Kubernetes Service',
state='OK',
engine='kqueen.engines.AksEngine',
created_at=datetime.utcnow(),
owner=user,
parameters={}
)
provisioner.save(check_status=False)
except:
raise Exception('Adding AKS provisioner failed')
try:
cluster = Cluster(
user.namespace,
id=uuid_aks,
state='OK',
name='AKS cluster, paused',
provisioner=provisioner,
created_at=datetime.utcnow(),
owner=user,
metadata={}
)
cluster.save()
except:
raise Exception('Adding AKS cluster failed')
# Local cluster
try:
provisioner = Provisioner(
user.namespace,
id=uuid_provisioner_local,
name='Manual provisioner',
state='OK',
engine='kqueen.engines.ManualEngine',
parameters={},
created_at=datetime.utcnow(),
owner=user
)
provisioner.save(check_status=False)
except:
raise Exception('Adding manual provisioner failed')
try:
cluster = Cluster(
user.namespace,
id=uuid_local,
name='local_cluster',
state='OK',
provisioner=provisioner,
kubeconfig=yaml.load(open('kubeconfig_localhost', 'r').read()),
created_at=datetime.utcnow(),
owner=user,
metadata={}
)
cluster.save()
except:
raise Exception('Adding local cluster failed')
# Dummy Kubespray provisioner
try:
provisioner = Provisioner(
user.namespace,
id=uuid_provisioner_kubespray,
name='Kubespray',
state='OK',
engine='kqueen.engines.ManualEngine',
created_at=datetime.utcnow(),
owner=user,
parameters={}
)
provisioner.save(check_status=False)
except:
raise Exception('Adding manual provisioner failed')