def process(self): (opts, args) = getopts() chkopts(opts) opts.dest = opts.dest.rstrip('/') self.up_progress(10) tmp_configfiles = { LIGHTTPD_PORT_CONFIG: opts.tmp_port_conf, LIGHTTPD_SSL_CONFIG: opts.tmp_ssl_conf, LIGHTTPD_ACCESS_CONFIG: opts.tmp_access_conf } self.up_progress(10) for srcfile in tmp_configfiles.values(): if os.path.isfile(srcfile) is False: raise KssCommandException( 'Temporary config file is not found. -path=%s' % srcfile) self.up_progress(20) try: for dest, src in tmp_configfiles.items(): copy_file(src, opts.dest + '/' + dest) remove_file(src) self.up_progress(40) except: raise KssCommandException( 'Failed to copy config file -src=%s dest=%s' % (src, dest)) self.logger.info('Applied lighttpd settings.') print >> sys.stdout, _('Applied lighttpd settings.') return True
def process(self): (opts, args) = getopts() chkopts(opts) opts.dest = opts.dest.rstrip('/') self.up_progress(10) tmp_configfiles = { LIGHTTPD_PORT_CONFIG : opts.tmp_port_conf, LIGHTTPD_SSL_CONFIG : opts.tmp_ssl_conf, LIGHTTPD_ACCESS_CONFIG : opts.tmp_access_conf } self.up_progress(10) for srcfile in tmp_configfiles.values(): if os.path.isfile(srcfile) is False: raise KssCommandException( 'Temporary config file is not found. -path=%s' % srcfile) self.up_progress(20) try: for dest, src in tmp_configfiles.items(): copy_file(src, opts.dest + '/' + dest) remove_file(src) self.up_progress(40) except: raise KssCommandException('Failed to copy config file -src=%s dest=%s' % (src, dest)) self.logger.info('Applied lighttpd settings.') print >>sys.stdout, _('Applied lighttpd settings.') return True
def process(self): (opts, args) = getopts() chkopts(opts) self.up_progress(1) uniq_id = time.strftime("%Y%m%d%H%M%S", time.localtime()) if opts.pre_command is not None: if opts.pre_command[0:4] == "b64:": command = base64_decode(opts.pre_command[4:]) else: command = opts.pre_command self.logger.info("execute command - %s" % command) (_ret,_res) = execute_command(command.split()) if _ret != 0: error_msg = "execute error - %s" % command self.logger.error(error_msg) #raise KssCommandOptException("ERROR: %s" % error_msg) dop = DictOp() modules = opts.module.split(":") files = opts.file.split(":") source_files = [] retval = True cnt = 0 for _mod in modules: _file = files[cnt] try: exec("from karesansui.lib.parser.%s import %sParser as Parser" % (_mod,_mod,)) self.up_progress(5) parser = Parser() # 辞書オペレータに追加 self.up_progress(5) if opts.php is True: conf_arr = php_array_to_python_dict(open(_file).read()) else: exec("conf_arr = %s" % open(_file).read()) dop.addconf(_mod,conf_arr) """ 必要ならここで配列操作 通常は、配列操作後の辞書が_fileに書き込まれているので必要ない dop.add (_mod,"foo","bar") dop.delete(_mod,"foo") """ # 設定ファイル一覧に作成(バックアップ用) self.up_progress(5) source_file = parser.source_file() for _afile in source_file: _bak_afile = "%s.%s" % (_afile,uniq_id) copy_file(_afile,_bak_afile) source_files = source_files + source_file # 辞書に戻す self.up_progress(5) conf_arr = dop.getconf(_mod) #dop.preprint_r(_mod) # 設定ファイルに書き込み self.up_progress(5) extra_args = {} extra_args["include"] = opts.include if opts.early_exit is True: retval = retval and parser.write_conf(conf_arr,extra_args=extra_args) else: retval = parser.write_conf(conf_arr,extra_args=extra_args) and retval if opts.delete is True: os.unlink(_file) finally: cnt = cnt + 1 if retval is False: for _afile in source_files: _bak_afile = "%s.%s" % (_afile,uniq_id) os.unlink(_afile) copy_file(_bak_afile,_afile) os.unlink(_bak_afile) raise KssCommandOptException("ERROR: write configure failure") for _afile in source_files: _bak_afile = "%s.%s" % (_afile,uniq_id) os.unlink(_bak_afile) if opts.post_command is not None: if opts.post_command[0:4] == "b64:": command = base64_decode(opts.post_command[4:]) else: command = opts.post_command self.logger.info("execute command - %s" % command) (_ret,_res) = execute_command(command.split()) if _ret != 0: error_msg = "execute error - %s" % command self.logger.error(error_msg) raise KssCommandOptException("ERROR: %s" % error_msg) self.up_progress(10) return True
def process(self): (opts, args) = getopts() chkopts(opts) self.up_progress(10) dev_list = comma_split(opts.dev) if len(dev_list) < 2: # TRANSLATORS: # bondingするためのdeviceが少ないです raise KssCommandOptException('ERROR: Small device for bonding. - dev=%s' % (opts.dev)) interface_list = get_ifconfig_info() for dev in dev_list: if dev not in interface_list: raise KssCommandOptException('ERROR: Bonding target device not found. - dev=%s' % (dev)) if opts.primary not in dev_list: raise KssCommandOptException('ERROR: Primary device not found in bonding device. - primary=%s dev=%s' % (opts.primary, opts.dev)) exist_bond_max_num = -1 exist_bond_list = get_ifconfig_info("regex:^bond") for bond_name in exist_bond_list.keys(): try: num = int(bond_name.replace("bond","")) except ValueError: continue if exist_bond_max_num < num: exist_bond_max_num = num self.up_progress(10) physical_bond_name = "bond%s" % (exist_bond_max_num + 1) bridge_bond_name = "bondbr%s" % (exist_bond_max_num + 1) bond_options = '"mode=%s primary=%s miimon=%s"' % (opts.mode, opts.primary, BONDING_CONFIG_MII_DEFAULT) self.up_progress(10) dop = DictOp() ifcfg_parser = ifcfgParser() modprobe_parser = modprobe_confParser() dop.addconf("ifcfg", ifcfg_parser.read_conf()) if dop.getconf("ifcfg") == {}: raise KssCommandException('Failure read network config file.') dop.addconf("modprobe_conf", modprobe_parser.read_conf()) if dop.getconf("modprobe_conf") == {}: raise KssCommandException('Failure read modprobe config file.') self.up_progress(10) eth_conf_copykey = ["HWADDR", "BOOTPROTO", "ONBOOT", "USERCTL", ] bond_conf_nocopykey = ["TYPE", "HWADDR", "MACADDR", "ETHTOOL_OPTS", "ESSID", "CHANNEL", ] self.up_progress(10) for dev in dev_list: conf = dop.get("ifcfg", dev) if dev == opts.primary: primary_conf = copy.deepcopy(conf) dop.unset("ifcfg", dev) dop.set("ifcfg", [dev, "DEVICE"], conf["DEVICE"]["value"]) for key in eth_conf_copykey: if key in conf: dop.set("ifcfg", [dev, key], conf[key]["value"]) dop.set("ifcfg", [dev, "MASTER"], physical_bond_name) dop.set("ifcfg", [dev, "SLAVE"], "yes") dop.set("ifcfg", [dev, "BOOTPROTO"], "none") if dop.get("ifcfg", "p%s" % (dev)): hwaddr = dop.get("ifcfg", ["p%s" % (dev), "HWADDR"]) if hwaddr: dop.set("ifcfg", [dev, "HWADDR"], hwaddr) dop.unset("ifcfg", "p%s" % (dev)) for key in bond_conf_nocopykey: if key in primary_conf: del primary_conf[key] dop.set("ifcfg", bridge_bond_name, primary_conf) dop.set("ifcfg", [bridge_bond_name, "DEVICE"], bridge_bond_name) dop.set("ifcfg", [bridge_bond_name, "TYPE"], "Bridge") dop.set("ifcfg", [physical_bond_name, "DEVICE"], physical_bond_name) dop.set("ifcfg", [physical_bond_name, "BRIDGE"], bridge_bond_name) dop.set("ifcfg", [physical_bond_name, "BOOTPROTO"], "none") dop.set("ifcfg", [physical_bond_name, "ONBOOT"], dop.get("ifcfg", [bridge_bond_name, "ONBOOT"])) dop.set("ifcfg", [physical_bond_name, "BONDING_OPTS"], bond_options) self.up_progress(10) dop.set("modprobe_conf", ["alias", physical_bond_name], "bonding") for dev in dev_list: if os.path.isfile("%s/ifcfg-%s" % (NETWORK_IFCFG_DIR, dev)): copy_file("%s/ifcfg-%s" % (NETWORK_IFCFG_DIR, dev), VENDOR_DATA_BONDING_EVACUATION_DIR) if os.path.isfile("%s/ifcfg-p%s" % (NETWORK_IFCFG_DIR, dev)): move_file("%s/ifcfg-p%s" % (NETWORK_IFCFG_DIR, dev), VENDOR_DATA_BONDING_EVACUATION_DIR) if ifcfg_parser.write_conf(dop.getconf("ifcfg")) is False: raise KssCommandException('Failure write network config file.') if modprobe_parser.write_conf(dop.getconf("modprobe_conf")) is False: raise KssCommandException('Failure write modprobe config file.') self.up_progress(10) # # Delete bridge device # bridge_list = get_bridge_info() for dev in dev_list: if dev in bridge_list: ifdown_cmd = (NETWORK_IFDOWN_COMMAND, dev, ) (ifdown_rc, ifdown_res) = execute_command(ifdown_cmd) if ifdown_rc != 0: raise KssCommandException('Failure stop interface. interface:%s' % (dev)) for brif in bridge_list[dev]: brctl_delif_cmd = (NETWORK_BRCTL_COMMAND, "delif", dev, brif, ) (brctl_rc, brctl_res) = execute_command(brctl_delif_cmd) if brctl_rc != 0: raise KssCommandException('Failure delete bridge port. bridge:%s port:%s' % (dev, brif)) brctl_delbr_cmd = (NETWORK_BRCTL_COMMAND, "delbr", dev, ) (brctl_rc, brctl_res) = execute_command(brctl_delbr_cmd) if brctl_rc != 0: raise KssCommandException('Failure delete bridge. bridge:%s' % (dev, brif)) self.up_progress(10) # # Restart network # network_restart_cmd = (NETWORK_COMMAND, "restart", ) (net_rc, net_res) = execute_command(network_restart_cmd) if net_rc != 0: raise KssCommandException('Failure restart network.') self.logger.info("Created bonding device. - dev=%s bond=%s" % (opts.dev, bridge_bond_name)) print >>sys.stdout, _("Created bonding device. - dev=%s bond=%s" % (opts.dev, bridge_bond_name)) return True
def process(self): (opts, args) = getopts() chkopts(opts) self.up_progress(10) dev_list = comma_split(opts.dev) if len(dev_list) < 2: # TRANSLATORS: # bondingするためのdeviceが少ないです raise KssCommandOptException( 'ERROR: Small device for bonding. - dev=%s' % (opts.dev)) interface_list = get_ifconfig_info() for dev in dev_list: if dev not in interface_list: raise KssCommandOptException( 'ERROR: Bonding target device not found. - dev=%s' % (dev)) if opts.primary not in dev_list: raise KssCommandOptException( 'ERROR: Primary device not found in bonding device. - primary=%s dev=%s' % (opts.primary, opts.dev)) exist_bond_max_num = -1 exist_bond_list = get_ifconfig_info("regex:^bond") for bond_name in exist_bond_list.keys(): try: num = int(bond_name.replace("bond", "")) except ValueError: continue if exist_bond_max_num < num: exist_bond_max_num = num self.up_progress(10) physical_bond_name = "bond%s" % (exist_bond_max_num + 1) bridge_bond_name = "bondbr%s" % (exist_bond_max_num + 1) bond_options = '"mode=%s primary=%s miimon=%s"' % ( opts.mode, opts.primary, BONDING_CONFIG_MII_DEFAULT) self.up_progress(10) dop = DictOp() ifcfg_parser = ifcfgParser() modprobe_parser = modprobe_confParser() dop.addconf("ifcfg", ifcfg_parser.read_conf()) if dop.getconf("ifcfg") == {}: raise KssCommandException('Failure read network config file.') dop.addconf("modprobe_conf", modprobe_parser.read_conf()) if dop.getconf("modprobe_conf") == {}: raise KssCommandException('Failure read modprobe config file.') self.up_progress(10) eth_conf_copykey = [ "HWADDR", "BOOTPROTO", "ONBOOT", "USERCTL", ] bond_conf_nocopykey = [ "TYPE", "HWADDR", "MACADDR", "ETHTOOL_OPTS", "ESSID", "CHANNEL", ] self.up_progress(10) for dev in dev_list: conf = dop.get("ifcfg", dev) if dev == opts.primary: primary_conf = copy.deepcopy(conf) dop.unset("ifcfg", dev) dop.set("ifcfg", [dev, "DEVICE"], conf["DEVICE"]["value"]) for key in eth_conf_copykey: if key in conf: dop.set("ifcfg", [dev, key], conf[key]["value"]) dop.set("ifcfg", [dev, "MASTER"], physical_bond_name) dop.set("ifcfg", [dev, "SLAVE"], "yes") dop.set("ifcfg", [dev, "BOOTPROTO"], "none") if dop.get("ifcfg", "p%s" % (dev)): hwaddr = dop.get("ifcfg", ["p%s" % (dev), "HWADDR"]) if hwaddr: dop.set("ifcfg", [dev, "HWADDR"], hwaddr) dop.unset("ifcfg", "p%s" % (dev)) for key in bond_conf_nocopykey: if key in primary_conf: del primary_conf[key] dop.set("ifcfg", bridge_bond_name, primary_conf) dop.set("ifcfg", [bridge_bond_name, "DEVICE"], bridge_bond_name) dop.set("ifcfg", [bridge_bond_name, "TYPE"], "Bridge") dop.set("ifcfg", [physical_bond_name, "DEVICE"], physical_bond_name) dop.set("ifcfg", [physical_bond_name, "BRIDGE"], bridge_bond_name) dop.set("ifcfg", [physical_bond_name, "BOOTPROTO"], "none") dop.set("ifcfg", [physical_bond_name, "ONBOOT"], dop.get("ifcfg", [bridge_bond_name, "ONBOOT"])) dop.set("ifcfg", [physical_bond_name, "BONDING_OPTS"], bond_options) self.up_progress(10) dop.set("modprobe_conf", ["alias", physical_bond_name], "bonding") for dev in dev_list: if os.path.isfile("%s/ifcfg-%s" % (NETWORK_IFCFG_DIR, dev)): copy_file("%s/ifcfg-%s" % (NETWORK_IFCFG_DIR, dev), VENDOR_DATA_BONDING_EVACUATION_DIR) if os.path.isfile("%s/ifcfg-p%s" % (NETWORK_IFCFG_DIR, dev)): move_file("%s/ifcfg-p%s" % (NETWORK_IFCFG_DIR, dev), VENDOR_DATA_BONDING_EVACUATION_DIR) if ifcfg_parser.write_conf(dop.getconf("ifcfg")) is False: raise KssCommandException('Failure write network config file.') if modprobe_parser.write_conf(dop.getconf("modprobe_conf")) is False: raise KssCommandException('Failure write modprobe config file.') self.up_progress(10) # # Delete bridge device # bridge_list = get_bridge_info() for dev in dev_list: if dev in bridge_list: ifdown_cmd = ( NETWORK_IFDOWN_COMMAND, dev, ) (ifdown_rc, ifdown_res) = execute_command(ifdown_cmd) if ifdown_rc != 0: raise KssCommandException( 'Failure stop interface. interface:%s' % (dev)) for brif in bridge_list[dev]: brctl_delif_cmd = ( NETWORK_BRCTL_COMMAND, "delif", dev, brif, ) (brctl_rc, brctl_res) = execute_command(brctl_delif_cmd) if brctl_rc != 0: raise KssCommandException( 'Failure delete bridge port. bridge:%s port:%s' % (dev, brif)) brctl_delbr_cmd = ( NETWORK_BRCTL_COMMAND, "delbr", dev, ) (brctl_rc, brctl_res) = execute_command(brctl_delbr_cmd) if brctl_rc != 0: raise KssCommandException( 'Failure delete bridge. bridge:%s' % (dev, brif)) self.up_progress(10) # # Restart network # network_restart_cmd = ( NETWORK_COMMAND, "restart", ) (net_rc, net_res) = execute_command(network_restart_cmd) if net_rc != 0: raise KssCommandException('Failure restart network.') self.logger.info("Created bonding device. - dev=%s bond=%s" % (opts.dev, bridge_bond_name)) print >> sys.stdout, _("Created bonding device. - dev=%s bond=%s" % (opts.dev, bridge_bond_name)) return True