def set_server_conf(config, input, session): if os.path.exists(LIGHTTPD_CONF_TEMP_DIR) is False: os.mkdir(LIGHTTPD_CONF_TEMP_DIR) tmp_file_names = {} # port.conf try: port_conf_path = LIGHTTPD_CONF_TEMP_DIR + "/kss_port_" + uniq_filename() port_conf = LighttpdPortConf(port_conf_path) port_conf.write(input) tmp_file_names["port"] = port_conf_path except AttributeError: raise KaresansuiGadgetException( "Failed to write configuration value input.port=%s at %s" % (input.port, port_conf_path) ) # access.conf try: access_conf_path = LIGHTTPD_CONF_TEMP_DIR + "/kss_access_" + uniq_filename() access_conf = LighttpdAccessConf(access_conf_path) access_conf.write(input) tmp_file_names["access"] = access_conf_path except AttributeError: raise KaresansuiGadgetException( "Failed to write configuration value input.access=%s, input.access_ipaddress=%s, input.ip_list=%s at %s" % (input.access, input.network, input.access_ipaddress, access_conf_path) ) # ssl.conf try: ssl_conf_path = LIGHTTPD_CONF_TEMP_DIR + "/kss_ssl_" + uniq_filename() ssl_conf = LighttpdSslConf(ssl_conf_path) ssl_conf.write(input) tmp_file_names["ssl"] = ssl_conf_path except AttributeError: raise KaresansuiGadgetException( "Failed to write configuration value input.ssl_status=%s at %s" % (input.ssl_status, ssl_conf_path) ) config["application.uniqkey"] = input.uniqkey # check temporary files for key in ("port", "access", "ssl"): if not tmp_file_names.has_key(key): raise KaresansuiGadgetException("Failed to make temporary file for %s", key) elif os.path.isfile(tmp_file_names[key]) is False: raise KaresansuiGadgetException("Not exist temporary file for %s", key) return tmp_file_names
def _POST(self, *param, **params): if not validates_icon(self): self.logger.debug("Create Icon is failed, Invalid input value") return web.badrequest(add_prefix(self.view.alert, "400")) icon_filevalue = self.input.multi_icon.value icon_filename = "%s.%s" % (uniq_filename(), imghdr.what(None, icon_filevalue)) if is_path(icon_filename) is True: return web.badrequest("Not to include the path.") icon_realpath = ICON_DIR_TPL % (karesansui.dirname, icon_filename) icon_webpath = ICON_DIR_TPL % (web.ctx.homepath, icon_filename) if os.path.exists(icon_realpath): web.conflict(icon_webpath, add_prefix("icon already exists", "409")) try: create_file(icon_realpath, icon_filevalue) except IOError, ioe: self.logger.error("Failed to write icon file. - filename=%s" % icon_filename) return web.internalerror( add_prefix("Failed to create icon file.", "500"))
def sync_config_generator(param, domname=None): domain_type = param.get_domain_type() tmp_prefix = KVM_KARESANSUI_TMP_DIR if domain_type == "xen": tmp_prefix = XEN_KARESANSUI_TMP_DIR elif domain_type == "kvm": tmp_prefix = KVM_KARESANSUI_TMP_DIR if os.path.exists(tmp_prefix) is False: os.makedirs(tmp_prefix) uniq = uniq_filename() tmp_dir = "%s/%s" % (tmp_prefix, uniq) tmp_xml_dir = "%s/%s/xml" % (tmp_prefix, uniq) if os.path.exists(tmp_dir) is False: os.makedirs(tmp_dir) if os.path.exists(tmp_xml_dir) is False: os.makedirs(tmp_xml_dir) # config config_generator = ConfigGenerator(domain_type) cfg = config_generator.generate(param) # xml config xml_generator = XMLConfigGenerator() cfgxml = xml_generator.generate(param) try: config_generator.writecfg(cfg, tmp_dir) xml_generator.writecfg(cfgxml, tmp_xml_dir) except: config_generator.removecfg(tmp_dir) xml_generator.removecfg(tmp_xml_dir) raise KaresansuiConfigParamException("Failed to update tmp configuration files. - domname=" + str(domname)) try: config_generator.copycfg(tmp_dir) xml_generator.copycfg(tmp_xml_dir) except: raise KaresansuiConfigParamException("Failed to update configuration files. - domname=" + str(domname)) if os.path.exists(tmp_dir): shutil.rmtree(tmp_dir) if os.path.exists(tmp_xml_dir): shutil.rmtree(tmp_xml_dir) return True
def _POST(self, *param, **params): if not validates_icon(self): self.logger.debug("Create Icon is failed, Invalid input value") return web.badrequest(add_prefix(self.view.alert, "400")) icon_filevalue = self.input.multi_icon.value icon_filename = "%s.%s" % (uniq_filename(), imghdr.what(None, icon_filevalue)) if is_path(icon_filename) is True: return web.badrequest("Not to include the path.") icon_realpath = ICON_DIR_TPL % (karesansui.dirname, icon_filename) icon_webpath = ICON_DIR_TPL % (web.ctx.homepath, icon_filename) if os.path.exists(icon_realpath): web.conflict(icon_webpath, add_prefix("icon already exists", "409")) try: create_file(icon_realpath, icon_filevalue) except IOError, ioe: self.logger.error("Failed to write icon file. - filename=%s" % icon_filename) return web.internalerror(add_prefix("Failed to create icon file.", "500"))