-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
executable file
·250 lines (200 loc) · 8.65 KB
/
gui.py
File metadata and controls
executable file
·250 lines (200 loc) · 8.65 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
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#!/usr/bin/env python
import uuid
from PyQt6.QtWidgets import (QApplication, QCheckBox, QComboBox, QDialog, QGroupBox, QHBoxLayout, QLabel, QLineEdit,
QPushButton, QStyleFactory, QVBoxLayout)
from configuration import Configuration
from server_providers import ServerProvider
from dns_providers import DnsProvider
from prepare_server_and_run_ansible import Server
class WidgetGallery(QDialog):
config = Configuration.from_manifest("empty.yml")
def onClick(self):
server_provider = ServerProvider(self.config)
server_info = server_provider.fetch_provisioned_server()
if server_info != None:
print(f"Server {server_info.ipv4} ({server_info.ipv6}) already provisioned")
else:
print(f"Provisioning server...")
server_info = server_provider.provision_server()
print(f"Server {server_info.ipv4} ({server_info.ipv6}) successfully provisioned")
self.config.render_ansible_vars()
dns_provider = DnsProvider(self.config, server_info)
dns_provider.render_dns_config()
s = Server(server_info.ipv4)
s.prepare_server_and_run_ansible()
print(f"Server {server_info.ipv4} ({server_info.ipv6}) is now set up")
print("Setting up DNS")
s.run_dnscontrol()
hostnames = dns_provider.get_hostnames()
for hostname in hostnames:
print(f"Waiting for DNS update for {hostname}")
s.wait_for_dns(hostname, [server_info.ipv4, server_info.ipv6])
print(f"DNS record successfully updated")
print(f"Restarting services")
s.restart_reverse_proxy()
print(f"\n-----\n")
print(f"Server Info:")
print(f" IPv4: {server_info.ipv4}")
print(f" IPv6: {server_info.ipv6}")
print(f"")
print(f"Deployed Web Apps:")
for hostname in hostnames:
print(f" https://{hostname}")
def __init__(self, parent=None):
super(WidgetGallery, self).__init__(parent)
styleComboBox = QComboBox()
styleComboBox.addItems(QStyleFactory.keys())
self.deploymentIdLineEdit = QLineEdit('')
self.deploymentIdLineEdit.setReadOnly(True)
self.deploymentIdLineEdit.textChanged.connect(self.config.set_uuid)
deploymentIdLabel = QLabel("&Deployment ID:")
deploymentIdLabel.setBuddy(self.deploymentIdLineEdit)
deploymentIdButton = QPushButton("Regenerate")
deploymentIdButton.clicked.connect(self.regenerateDeploymentId)
deployButton = QPushButton("Deploy")
deployButton.clicked.connect(self.onClick)
mainLayout = QVBoxLayout()
deploymentIdLayout = QVBoxLayout()
deploymentIdLayout.addWidget(deploymentIdLabel)
deploymentIdLayout.addWidget(self.deploymentIdLineEdit)
deploymentIdLayout.addWidget(deploymentIdButton)
mainLayout.addLayout(deploymentIdLayout)
apiSettingsLayout = QHBoxLayout()
apiSettingsLayout.addWidget(self.createProviderGroupBox())
apiSettingsLayout.addWidget(self.createDNSGroupBox())
mainLayout.addLayout(apiSettingsLayout)
mainLayout.addWidget(self.createServerGroupBox())
mainLayout.addWidget(self.createWordPressGroupBox())
mainLayout.addWidget(deployButton)
self.setLayout(mainLayout)
self.setWindowTitle("CMS Cloud Manager")
def regenerateDeploymentId(self):
self.deploymentIdLineEdit.setText(uuid.uuid4().hex)
def changeStyle(self, styleName):
QApplication.setStyle(QStyleFactory.create(styleName))
self.changePalette()
def createProviderGroupBox(self):
groupBox = QGroupBox("Provider Settings")
providerComboBox = QComboBox()
providerComboBox.addItem("hetzner-cloud")
providerComboBox.textActivated.connect(self.config.set_server_provider_type)
providerLabel = QLabel("&Provider:")
providerLabel.setBuddy(providerComboBox)
apiTokenLineEdit = QLineEdit('')
apiTokenLineEdit.setEchoMode(QLineEdit.EchoMode.Password)
apiTokenLineEdit.textChanged.connect(self.config.set_server_provider_api_key)
apiTokenLabel = QLabel("&API Token:")
apiTokenLabel.setBuddy(apiTokenLineEdit)
layout = QVBoxLayout()
layout.addWidget(providerLabel)
layout.addWidget(providerComboBox)
layout.addWidget(apiTokenLabel)
layout.addWidget(apiTokenLineEdit)
layout.addStretch(1)
groupBox.setLayout(layout)
return groupBox
def createDNSGroupBox(self):
groupBox = QGroupBox("DNS Settings")
providerComboBox = QComboBox()
providerComboBox.addItem("hetzner")
providerComboBox.setEnabled(False)
providerComboBox.textActivated.connect(self.config.set_dns_provider_type)
providerLabel = QLabel("&Provider:")
providerLabel.setBuddy(providerComboBox)
apiTokenLineEdit = QLineEdit('')
apiTokenLineEdit.setEchoMode(QLineEdit.EchoMode.Password)
apiTokenLineEdit.setEnabled(False)
apiTokenLineEdit.textChanged.connect(self.config.set_dns_provider_api_key)
apiTokenLabel = QLabel("&API Token:")
apiTokenLabel.setBuddy(apiTokenLineEdit)
enableDnsSettings = QCheckBox("&Enable DNS Management")
enableDnsSettings.toggled.connect(providerComboBox.setEnabled)
enableDnsSettings.toggled.connect(apiTokenLineEdit.setEnabled)
layout = QVBoxLayout()
layout.addWidget(enableDnsSettings)
layout.addWidget(providerLabel)
layout.addWidget(providerComboBox)
layout.addWidget(apiTokenLabel)
layout.addWidget(apiTokenLineEdit)
layout.addStretch(1)
groupBox.setLayout(layout)
return groupBox
def createServerGroupBox(self):
groupBox = QGroupBox("Server Settings")
nameLineEdit = QLineEdit('')
nameLineEdit.textChanged.connect(self.config.set_server_name)
nameLabel = QLabel("&Name:")
nameLabel.setBuddy(nameLineEdit)
instanceComboBox = QComboBox()
instanceComboBox.addItem("cx22")
instanceComboBox.addItem("cx32")
instanceComboBox.addItem("cx42")
instanceComboBox.addItem("cx52")
instanceComboBox.textActivated.connect(self.config.set_instance)
instanceLabel = QLabel("&Instance Type:")
instanceLabel.setBuddy(instanceComboBox)
osComboBox = QComboBox()
osComboBox.addItem("ubuntu")
osComboBox.addItem("debian")
osComboBox.textActivated.connect(self.config.set_image)
osLabel = QLabel("&Operating System:")
osLabel.setBuddy(osComboBox)
sshKeyLineEdit = QLineEdit('')
sshKeyLineEdit.textChanged.connect(self.config.set_ssh_pub_key)
sshKeyLabel = QLabel("&SSH Key:")
sshKeyLabel.setBuddy(sshKeyLineEdit)
leMailLineEdit = QLineEdit('')
leMailLineEdit.textChanged.connect(self.config.set_lets_encrypt_email)
leMailLabel = QLabel("&Let's Encrypt E-Mail:")
leMailLabel.setBuddy(leMailLineEdit)
layout = QVBoxLayout()
layout.addWidget(nameLabel)
layout.addWidget(nameLineEdit)
layout.addWidget(instanceLabel)
layout.addWidget(instanceComboBox)
layout.addWidget(osLabel)
layout.addWidget(osComboBox)
layout.addWidget(sshKeyLabel)
layout.addWidget(sshKeyLineEdit)
layout.addWidget(leMailLabel)
layout.addWidget(leMailLineEdit)
layout.addStretch(1)
groupBox.setLayout(layout)
return groupBox
def configureWordpress(self, hostname):
components = []
components.append({
"name": "watchtower",
"type": "watchtower",
})
components.append({
"name": "reverse-proxy",
"type": "reverse-proxy",
})
components.append({
"name": "wordpress",
"type": "wordpress",
"config": {
"hostname": hostname,
},
})
self.config.set_components(components)
def createWordPressGroupBox(self):
groupBox = QGroupBox("WordPress Settings")
hostnameLineEdit = QLineEdit('')
hostnameLineEdit.textChanged.connect(self.configureWordpress)
hostnameLabel = QLabel("&Hostname:")
hostnameLabel.setBuddy(hostnameLineEdit)
layout = QVBoxLayout()
layout.addWidget(hostnameLabel)
layout.addWidget(hostnameLineEdit)
layout.addStretch(1)
groupBox.setLayout(layout)
return groupBox
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
gallery = WidgetGallery()
gallery.setMinimumSize(600, 400)
gallery.show()
sys.exit(app.exec())