1 | #!/usr/bin/env python
|
---|
2 | # -*- coding: utf-8 -*-
|
---|
3 | #
|
---|
4 |
|
---|
5 | from PyQt4 import QtGui, QtCore
|
---|
6 | from PyQt4.QtCore import *
|
---|
7 | from PyQt4.QtGui import *
|
---|
8 |
|
---|
9 | import socket
|
---|
10 | import string
|
---|
11 | import random
|
---|
12 | import Ui_deploywizard
|
---|
13 |
|
---|
14 | import time, difflib
|
---|
15 |
|
---|
16 | import xmlrpclib
|
---|
17 | import sys
|
---|
18 | import htmldiffview
|
---|
19 |
|
---|
20 | #server_url = 'https://localhost:4443'
|
---|
21 |
|
---|
22 |
|
---|
23 |
|
---|
24 |
|
---|
25 | class deploywizard(QtGui.QWizard, Ui_deploywizard.Ui_Wizard,):
|
---|
26 |
|
---|
27 | def __init__(self, serverproxy, cfgstring, daemontype, parent = None):
|
---|
28 | super(deploywizard, self).__init__()
|
---|
29 | self.setupUi(self)
|
---|
30 | self.serverproxy = serverproxy
|
---|
31 | self.diffhtml = ''
|
---|
32 | self.cfgstring = cfgstring
|
---|
33 | self.daemontype = daemontype
|
---|
34 |
|
---|
35 |
|
---|
36 |
|
---|
37 | self.connect(self.pushButton, QtCore.SIGNAL('clicked()'), self.showHTMLDiff)
|
---|
38 | self.connect(self.pushButton_2, QtCore.SIGNAL('clicked()'), self.do_deployment)
|
---|
39 |
|
---|
40 | def initializePage(self, pagenumber):
|
---|
41 | if pagenumber == 1:
|
---|
42 |
|
---|
43 | oldconf = self.serverproxy.get_conf('dir').splitlines(True)
|
---|
44 |
|
---|
45 | newconf = self.cfgstring.splitlines(True)
|
---|
46 | diffunified = difflib.unified_diff(oldconf, newconf, 'old', 'new', n=0)
|
---|
47 | self.diffhtml = difflib.HtmlDiff(2,50).make_file(oldconf, newconf, 'old',
|
---|
48 | 'new', context=True, numlines=3)
|
---|
49 | t = ''
|
---|
50 | for line in diffunified:
|
---|
51 | t += line
|
---|
52 | self.textBrowser.setText(t)
|
---|
53 |
|
---|
54 | #elif pagenumber == 2:
|
---|
55 |
|
---|
56 |
|
---|
57 | def showHTMLDiff(self):
|
---|
58 | dialog = htmldiffview.htmldiffdialog(self)
|
---|
59 | dialog.webView.setHtml(self.diffhtml)
|
---|
60 | dialog.exec_()
|
---|
61 |
|
---|
62 | def do_deployment(self):
|
---|
63 | t = 'Deploying the configuration file...\n'; self.textBrowser_2.setText(t)
|
---|
64 | t += 'transferring file to target system...\n'; self.textBrowser_2.setText(t)
|
---|
65 |
|
---|
66 | self.serverproxy.set_conf('dir', self.cfgstring)
|
---|
67 | t += 'transfer completed\n'; self.textBrowser_2.setText(t)
|
---|
68 | t += 'restarting daemon...\n'; self.textBrowser_2.setText(t)
|
---|
69 |
|
---|
70 | if self.daemontype == 'director':
|
---|
71 | t += 'reLOADing director daemon...\n'; self.textBrowser_2.setText(t)
|
---|
72 | result, out, err = self.serverproxy.reload_director()
|
---|
73 | t += out;self.textBrowser_2.setText(t)
|
---|
74 | if result != 0: # we cannot reload, so we try to restart
|
---|
75 | t += 'reload failed, restarting...\n'; self.textBrowser_2.setText(t)
|
---|
76 | t += self.serverproxy.restart_daemon(self.daemontype)[1]
|
---|
77 | else:
|
---|
78 | t += self.serverproxy.restart_daemon(self.daemontype)[1]
|
---|
79 |
|
---|
80 | t += 'checking for daemon running\n'; self.textBrowser_2.setText(t)
|
---|
81 |
|
---|
82 | if self.serverproxy.check_for_process('bacula-dir'):
|
---|
83 | t += 'OK, is running'; self.textBrowser_2.setText(t)
|
---|
84 | else:
|
---|
85 | t += 'ERROR, is not running, rolling back...\n'; self.textBrowser_2.setText(t)
|
---|
86 |
|
---|
87 | if __name__ == "__main__":
|
---|
88 |
|
---|
89 | class SafeTransportWithCert(xmlrpclib.SafeTransport):
|
---|
90 | # __cert_file = DFLT_CERTFILE
|
---|
91 | # __key_file = DFLT_KEYFILE
|
---|
92 | __cert_file = '../../certs/client-cert.pem' # Replace with your PEM formatted key file
|
---|
93 | __key_file = '../../certs/client-cert.pem' # Replace with your PEM formatted certificate file
|
---|
94 |
|
---|
95 | def make_connection(self,host):
|
---|
96 | host_with_cert = (host, {
|
---|
97 | 'key_file' : self.__key_file,
|
---|
98 | 'cert_file' : self.__cert_file
|
---|
99 | } )
|
---|
100 | return xmlrpclib.SafeTransport.make_connection(
|
---|
101 | self,host_with_cert)
|
---|
102 |
|
---|
103 |
|
---|
104 | import sys
|
---|
105 | print "started"
|
---|
106 |
|
---|
107 | server_url = 'https://bacula-old:4443'
|
---|
108 | transport = SafeTransportWithCert()
|
---|
109 | serverproxy = xmlrpclib.ServerProxy(server_url,
|
---|
110 | transport = transport)
|
---|
111 |
|
---|
112 |
|
---|
113 | app = QtGui.QApplication(sys.argv)
|
---|
114 | app.setOrganizationDomain("dass-it.de")
|
---|
115 | app.setOrganizationName("dassIT GmbH")
|
---|
116 | app.setApplicationName("deploywizard")
|
---|
117 | app.setWindowIcon(QIcon(":/icons/dassit_logo.png"))
|
---|
118 | testconf = open('../configs/bacula-dir.conf','r').read().decode('UTF-8')
|
---|
119 | wizard = deploywizard(serverproxy,testconf,'director')
|
---|
120 | wizard.exec_()
|
---|
121 |
|
---|
122 |
|
---|