def dhcp(request): if request.method == 'GET': #json = serializers.serialize('json', dhcp_config) f = open(DEPLOY_CONF_PATH) lines = f.readlines() for line in lines: temp = line.split() dhcp_config[temp[0]] = temp[1] json = simplejson.dumps(dhcp_config) return HttpResponse(json,mimetype="aplication/json") elif request.method == 'POST': logger.info("post deploy configs") ret = False form = ConfigForm(request.POST) response = HttpResponse() if form.is_valid(): for k in dhcp_config: dhcp_config[k] = form.cleaned_data[k] f = open(DEPLOY_CONF_PATH,'w') for k in dhcp_config: f.write(k+ ' ' + dhcp_config[k]) f.write("\n") f.close() ret = True logger.info("update deploy configs success.") iso_addr = request.POST['iso_addr'] if iso_addr[-4:] == '.iso': iso_addr = ISO_DIR + iso_addr print iso_addr logger.info("sh /opt/openstack/scripts/deploy.sh %s" % iso_addr) #p = os.system("/opt/openstack/scripts/deploy.sh %s" % iso_addr) #if(p!=0): # ret = "sh deploy.sh false,please check the log !" #p = commands.getstatusoutput("sh /opt/openstack/scripts/deploy.sh %s" % iso_addr) #logger.info(str(p[0])+p[1]) #if p[0]!=0: # response.status_code = 500 # time.sleep(10) # ret = "sh /opt/openstack/scripts/deploy.sh false,please check the log !" # f = open(DEPLOY_RESULT_PATH,'w') # f.write('2') # f.close() deploytask.delay(iso_addr) else: response.status_code = 500 ret = str(form.errors) response.write(ret) return response
def dhcp(request): if request.method == 'GET': #json = serializers.serialize('json', dhcp_config) f = open(CONF_PATH,"r") ya = yaml.load(f) f.close() for k in dhcp_config: dhcp_config[k] = ya['cobbler_dhcp'][k] json = simplejson.dumps(dhcp_config) return HttpResponse(json,mimetype="aplication/json") elif request.method == 'POST': logger.info("post deploy configs") ret = False form = ConfigForm(request.POST) response = HttpResponse() if form.is_valid(): for k in dhcp_config: dhcp_config[k] = form.cleaned_data[k] f = open(CONF_PATH,"r") ya = yaml.load(f) f.close() for k in dhcp_config: ya['cobbler_dhcp'][k] = dhcp_config[k] f = open(CONF_PATH,"w") yaml.dump(ya,f,default_flow_style=False) f.close() ret = True logger.info("update deploy configs success.") iso_addr = request.POST['iso_addr'] if iso_addr[-4:] == '.iso': iso_addr = ISO_DIR + iso_addr try: deploytask(iso_addr) except SystemExit: response.status_code = 500 logger.error("Set cobbler error!") ret = str("设置cobbler失败,请检查日志文件") else: response.status_code = 500 ret = str(form.errors) response.write(ret) return response