Пример #1
0
def add_to_config(id):
    data = {}
    body = request.body.getvalue().decode('utf-8')
    save = request.headers.get('action')
    hap_configs_dir = funct.get_config_var('configs',
                                           'haproxy_save_configs_dir')
    login = request.headers.get('login')

    if save == '':
        save = 'save'
    elif save == 'restart':
        save = ''

    try:
        servers = check_permit_to_server(id)

        for s in servers:
            ip = s[2]
        cfg = '/tmp/' + ip + '.cfg'
        cfg_for_save = hap_configs_dir + ip + "-" + funct.get_data(
            'config') + ".cfg"
        out = funct.get_config(ip, cfg)
        try:
            with open(cfg, "a") as conf:
                conf.write('\n' + body + '\n')
            return_mess = 'section was added to the config'
            os.system("/bin/cp %s %s" % (cfg, cfg_for_save))
            funct.logging('localhost',
                          " section was added via REST API",
                          login=login)
            out = funct.upload_and_restart(ip, cfg, just_save=save)

            if out:
                return_mess = out
        except IOError:
            return_mess = "cannot upload config"

        data = {id: return_mess}
    except:
        data = {}
        data[id] = {"error": "Cannot find the server"}
        return dict(error=data)

    return dict(config=data)
Пример #2
0
                    stderr = "Error: %s - %s." % (e.filename, e.strerror)
        print(
            '<meta http-equiv="refresh" content="10; url=versions.py?service=%s&serv=%s&open=open">'
            % (service, form.getvalue('serv')))

if serv is not None and form.getvalue('config') is not None:
    configver = configs_dir + configver
    save = form.getvalue('save')
    aftersave = 1
    try:
        funct.logging(serv, "configver.py upload old config %s" % configver)
    except:
        pass
    if service == 'keepalived':
        stderr = funct.upload_and_restart(serv,
                                          configver,
                                          just_save=save,
                                          keepalived=1)
    elif service == 'nginx':
        stderr = funct.master_slave_upload_and_restart(serv,
                                                       configver,
                                                       just_save=save,
                                                       nginx=1)
    else:
        stderr = funct.master_slave_upload_and_restart(serv,
                                                       configver,
                                                       just_save=save)

template = template.render(h2=1,
                           title=title,
                           role=role,
                           action=action,
Пример #3
0
        pass

    config = form.getvalue('config')
    oldcfg = form.getvalue('oldconfig')
    save = form.getvalue('save')
    aftersave = 1
    try:
        with open(cfg, "a") as conf:
            conf.write(config)
    except IOError:
        error = "Can't read import config file"

    MASTERS = sql.is_master(serv)
    for master in MASTERS:
        if master[0] != None:
            funct.upload_and_restart(master[0], cfg, just_save=save)

    stderr = funct.upload_and_restart(serv, cfg, just_save=save)

    funct.diff_config(oldcfg, cfg)

    if save:
        c = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
        c["restart"] = form.getvalue('serv')
        print(c)

    os.system("/bin/rm -f " + hap_configs_dir + "*.old")

print('Content-type: text/html\n')
template = template.render(h2=1,
                           title="Working with HAProxy configs",
Пример #4
0
            '<a class="accordion-expand-all ui-button ui-widget ui-corner-all" href="#">Expand all</a>'
            '</p></center>')
        funct.show_config(configver)
        print('<center><p>')
        funct.get_button("Just save", value="save")
        funct.get_button("Upload and restart")
        print('</p></form></center>')

if form.getvalue('serv') is not None and form.getvalue('config') is not None:
    configver = form.getvalue('configver')
    configver = hap_configs_dir + configver
    save = form.getvalue('save')

    funct.logging(serv, "configver.py upload old config %s" % configver)

    print("<center><b>Uploaded old config ver: %s </b></br></br></center>" %
          configver)

    MASTERS = sql.is_master(serv)
    for master in MASTERS:
        if master[0] != None:
            funct.upload_and_restart(master[0], configver, just_save=save)

    funct.upload_and_restart(serv, configver, just_save=save)

    print(
        '</br><a href="viewsttats.py?serv=%s" target="_blank" title="View stats">Go to view stats</a> <br />'
        % serv)

funct.footer()
Пример #5
0
if serv is not None and form.getvalue('config') is not None:
	import sys
	funct.check_is_server_in_group(serv)

	config = form.getvalue('config')
	oldcfg = form.getvalue('oldconfig')
	save = form.getvalue('save')

	try:
		with open(cfg, "a") as conf:
			conf.write(config)
	except IOError:
		print("error: Cannot read imported config file")

	if service == 'keepalived':
		stderr = funct.upload_and_restart(serv, cfg, just_save=save, keepalived=1, oldcfg=oldcfg)
	elif service == 'nginx':
		stderr = funct.master_slave_upload_and_restart(serv, cfg, just_save=save, nginx=1, oldcfg=oldcfg, config_file_name=config_file_name)
	else:
		stderr = funct.master_slave_upload_and_restart(serv, cfg, just_save=save, oldcfg=oldcfg)

	funct.diff_config(oldcfg, cfg)

	os.system("/bin/rm -f " + configs_dir + "*.old")

	if stderr:
		print(stderr)
	else:
		if save == 'test':
			print('Config is ok')
		else:
Пример #6
0
		for j in i:	
			j = j.strip('\t\n\r')
			servers_split += "    server " + j + check + "\n"
	else:
		servers_split = ""
	
	config_add = name + "\n" + bind +  mode  + "\n" + balance + options_split + backend + servers_split + "\n"
	cfg = hap_configs_dir + serv + "-" + funct.get_data('config') + ".cfg"
	
	funct.get_config(serv, cfg)
	try:
		with open(cfg, "a") as conf:
			conf.write(config_add)			
	except IOError:
		print("Can't read import config file")
	
	funct.logging(serv, "add.py add new %s" % name)
	print('<div class="line3">')
	
	MASTERS = sql.is_master(serv)
	for master in MASTERS:
		if master[0] != None:
			funct.upload_and_restart(master[0], cfg)
	
	funct.upload_and_restart(serv, cfg)
	print('<meta http-equiv="refresh" content="0; url=add.py?add=%s&conf=%s">' % (name, config_add))
		
	print('</div>')

	
Пример #7
0
    config_add = name + "\n" + bind + mode + "\n" + balance + options_split + backend + servers_split + "\n"

    os.chdir(config.get('configs', 'haproxy_save_configs_dir'))

    cfg = hap_configs_dir + serv + "-" + funct.get_data('config') + ".cfg"

    funct.get_config(serv, cfg)
    try:
        with open(cfg, "a") as conf:
            conf.write(config_add)
    except IOError:
        print("Can't read import config file")

    funct.logging(serv, "add.py add new %s" % name)
    print('<div class="line3">')
    if funct.upload_and_restart(serv, cfg):
        print(
            '<meta http-equiv="refresh" content="30; url=add.py?add=%s&conf=%s">'
            % (name, config_add))

    print('</div>')

if form.getvalue('add') is not None:
    print('<h3 class="addSuc">  ' + form.getvalue('add') +
          ' was successfully added</h3>')
    print('<div class="line3">')
    print(form.getvalue('conf'))
    print('</div>')

print(
    '<div id="tabs">'
Пример #8
0
        configver = form.getvalue('configver')
        funct.logging(serv, "open old config %s" % configver)

        print("<h3>Config from %s, and version is: %s</h3>" %
              (serv, configver))
        print('<form action="configver.py#conf" method="post">')
        print('<input type="hidden" value="%s" name="serv">' % serv)
        print('<input type="hidden" value="%s" name="configver">' % configver)
        print('<input type="hidden" value="1" name="config">')
        print('<a name="conf"></a></center>')
        funct.show_config(configver)
        print('<center><p>')
        funct.mode_admin("Upload and restart")
        print('</p></form></center>')

if form.getvalue('serv') is not None and form.getvalue('config') is not None:
    configver = form.getvalue('configver')
    configver = hap_configs_dir + configver

    funct.logging(serv, "configver.py upload old config %s" % configver)

    print("<b>Uploaded old config ver: %s </b></br></br>" % configver)

    funct.upload_and_restart(serv, configver)

    print(
        '</br><a href="viewsttats.py?serv=%s" target="_blank" title="View stats">Go to view stats</a> <br />'
        % serv)

funct.footer()
Пример #9
0
	print('<p>')
	funct.get_button("Just save", value="save")
	funct.get_button("Save and restart")
	print('</p></form>')
	conf.close

	os.system("/bin/mv %s %s.old" % (cfg, cfg))	

if form.getvalue('serv') is not None and form.getvalue('config') is not None:
	funct.logging(serv, "keepalivedconfig.py edited config")
	config = form.getvalue('config')
	oldcfg = form.getvalue('oldconfig')
	save = form.getvalue('save')

	try:
		with open(cfg, "a") as conf:
			conf.write(config)
	except IOError:
		print("Can't read import config file")

	print('<center><br><div class="alert alert-info">New config was saved as: %s </div></center>' % cfg)
			
	funct.upload_and_restart(serv, cfg, just_save=save, keepalived=1)
	
	
	os.system("/bin/diff -ub %s %s >> %s/config_edit-%s.log" % (oldcfg, cfg, log_path, funct.get_data('logs')))
	os.system("/bin/rm -f kp_config/*.old")

	print('</br><a href="viewsttats.py?serv=%s" target="_blank" title="View stats">Go to view stats</a> <br />' % serv)
	
funct.footer()