def chkopts(opts): if not opts.name: raise KssCommandOptException('ERROR: %s option is required.' % '-n or --name') if opts.passwd_file is not None and not os.path.exists(opts.passwd_file): raise KssCommandOptException('ERROR: %s is not found.' % opts.passwd_file) if opts.passwd != None and opts.passwd_file != None and opts.random_passwd != None: raise KssCommandOptException('ERROR: %s options are conflicted.' % '--passwd, --passwd-file and --random-passwd')
def chkopts(opts): if not opts.module: raise KssCommandOptException( "ERROR: -m or --module option is required.") modules = opts.module.split(":") for _mod in modules: try: exec("from karesansui.lib.parser.%s import %sParser" % ( _mod, _mod, )) except: raise KssCommandOptException("ERROR: module not found. - %s" % opts.module) if not opts.file: opts.file = "/dev/stdout" for _cnt in range(1, len(modules)): opts.file = "%s:/dev/stdout" % opts.file files = opts.file.split(":") if len(modules) != len(files): raise KssCommandOptException( "ERROR: not same number of modules and files. - module:%d file:%d" % ( len(modules), len(files), )) if opts.raw is True and opts.php is True: raise KssCommandOptException( "ERROR: cannot specify --raw and --php option at same time.")
def chkopts(opts): if not opts.name: raise KssCommandOptException('ERROR: %s option is required.' % '-n or --name') if not opts.target: raise KssCommandOptException('ERROR: %s option is required.' % '-t or --target')
def chkopts(opts): reg = re.compile("[^a-zA-Z0-9\./_:-]") if opts.name: if reg.search(opts.name): raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-n or --name', opts.name)) else: raise KssCommandOptException('ERROR: %s option is required.' % '-n or --name')
def chkopts(opts): if not opts.name: raise KssCommandOptException('ERROR: %s option is required.' % '-n or --name') if not opts.old: raise KssCommandOptException('ERROR: %s option is required.' % '-f or --from') if not opts.new: raise KssCommandOptException('ERROR: %s option is required.' % '-t or --to')
def chkopts(opts): if not opts.name: raise KssCommandOptException('ERROR: %s option is required.' % '-n or --name') if opts.bridge is None and opts.network is None: raise KssCommandOptException( 'ERROR: either %s options must be specified.' % '--bridge or --network') """TOOD valid
def chkopts(opts): reg = re.compile("[^a-zA-Z0-9]") if opts.dev: if reg.search(opts.dev): raise KssCommandOptException( 'ERROR: Illigal option value. option=%s value=%s' % ('-d or --dev', opts.dev)) else: raise KssCommandOptException('ERROR: %s option is required.' % '-d or --dev')
def chkopts(opts): reg = re.compile("[^a-zA-Z0-9\._:-]") if opts.iqn: if reg.search(opts.iqn): raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-i or --iqn', opts.iqn)) else: raise KssCommandOptException('ERROR: %s option is required.' % '-i or --iqn') if opts.host: if reg.search(opts.host): raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-t or --target', opts.host))
def chkopts(opts): if not opts.name: raise KssCommandOptException('ERROR: -n or --name option is required.') if opts.passwd_file is not None and not os.path.exists(opts.passwd_file): raise KssCommandOptException('ERROR: %s is not found.' % opts.passwd_file) if opts.uri is not None: if uri_split(opts.uri)["scheme"] is None: raise KssCommandOptException('ERROR: uri %s is invalid.' % opts.uri)
def chkopts(opts): if not opts.name: raise KssCommandOptException('ERROR: %s option is required.' % '-n or --name') if opts.enable is None and opts.disable is None: raise KssCommandOptException( 'ERROR: either %s options must be specified.' % '--enable or --disable') if opts.enable is not None and opts.disable is not None: raise KssCommandOptException('ERROR: %s options are conflicted.' % '--enable and --disable')
def chkopts(opts): reg = re.compile("[^a-zA-Z0-9\./_:-]") if opts.name: if reg.search(opts.name): raise KssCommandOptException( 'ERROR: Illigal option value. option=%s value=%s' % ('-d or --dest-name', opts.name)) else: raise KssCommandOptException('ERROR: %s option is required.' % '-d or --dest-name') if opts.src_name: if reg.search(opts.src_name): raise KssCommandOptException( 'ERROR: Illigal option value. option=%s value=%s' % ('-s or --src-name', opts.src_name)) else: raise KssCommandOptException('ERROR: %s option is required.' % '-s or --src-name') if opts.pool: if reg.search(opts.pool): raise KssCommandOptException( 'ERROR: Illigal option value. option=%s value=%s' % ('-p or --pool', opts.pool)) else: raise KssCommandOptException('ERROR: %s option is required.' % '-p or --pool') if opts.graphics_port: reg = re.compile("^[0-9]{1,5}$") if not reg.match(opts.graphics_port): raise KssCommandOptException( 'ERROR: Illigal option value. option=%s value=%s' % ('-v or --graphics-port', opts.graphics_port)) if int(opts.graphics_port) < PORT_MIN_NUMBER or PORT_MAX_NUMBER < int( opts.graphics_port): raise KssCommandOptException( 'ERROR: Illigal port number. port=%s' % (opts.graphics_port)) if opts.mac: reg = re.compile("^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$") if not reg.match(opts.mac): raise KssCommandOptException('ERROR: Illigal MAC address. mac=%s' % (opts.mac)) if opts.uuid: if not is_uuid(opts.uuid): raise KssCommandOptException('ERROR: Illigal UUID. uuid=%s' % (opts.uuid))
def chkopts(opts): # option check if not opts.dest: raise KssCommandOptException('ERROR: -d or --dest option is required.') elif not opts.tmp_port_conf: raise KssCommandOptException('ERROR: -p or --port option is required.') elif not opts.tmp_ssl_conf: raise KssCommandOptException('ERROR: -s or --ssl option is required.') elif not opts.tmp_access_conf: raise KssCommandOptException( 'ERROR: -a or --access option is required.') # exist check if os.path.isdir(opts.dest) is False: raise KssCommandOptException('ERROR: Not directory dest=%s' % opts.dest) elif os.path.isfile(opts.tmp_port_conf) is False: raise KssCommandOptException( 'ERROR: Not exist temporary file tmp_port_conf=%s' % opts.tmp_port_conf) elif os.path.isfile(opts.tmp_ssl_conf) is False: raise KssCommandOptException( 'ERROR: Not exist temporary file tmp_ssl_conf=%s' % opts.tmp_ssl_conf) elif os.path.isfile(opts.tmp_access_conf) is False: raise KssCommandOptException( 'ERROR: Not exist temporary file tmp_access_conf=%s' % opts.tmp_access_conf)
def chkopts(opts): reg = re.compile("[^a-zA-Z0-9\./_:-]") if opts.dev: if reg.search(opts.dev): raise KssCommandOptException( 'ERROR: Illigal option value. option=%s value=%s' % ('-d or --dev', opts.dev)) else: raise KssCommandOptException('ERROR: %s option is required.' % '-d or --dev') if opts.type not in get_filesystem_info(): raise KssCommandOptException('ERROR: Unknown format type. type=%s' % (opts.type))
def chkopts(opts): try: int(opts.count) except: raise KssCommandOptException( 'ERROR: -c or --count option must be specified as a positive integer.' )
def chkopts(opts): reg = re.compile("[^a-zA-Z0-9\._:-]") if opts.iqn: if reg.search(opts.iqn): raise KssCommandOptException( 'ERROR: Illigal option value. option=%s value=%s' % ('-i or --iqn', opts.iqn))
def chkopts(opts): if not opts.module: raise KssCommandOptException("ERROR: -m or --module option is required.") modules = opts.module.split(":") for _mod in modules: try: exec("from karesansui.lib.parser.%s import %sParser" % (_mod,_mod,)) except: raise KssCommandOptException("ERROR: module not found. - %s" % opts.module) if not opts.file: raise KssCommandOptException("ERROR: -i or --input-file option is required.") files = opts.file.split(":") for _file in files: if not os.path.exists(_file): raise KssCommandOptException("ERROR: file not found. - %s" % _file) if opts.php is True: try: _dict = php_array_to_python_dict(open(_file).read()) except: raise raise KssCommandOptException("ERROR: file format is invalid. - %s" % _file) else: try: exec("%s" % open(_file).read()) except: raise KssCommandOptException("ERROR: file format is invalid. - %s" % _file) if len(modules) != len(files): raise KssCommandOptException("ERROR: not same number of modules and files. - module:%d file:%d" % (len(modules),len(files),))
def chkopts(opts): reg = re.compile("[^a-zA-Z0-9\./_:-]") if opts.host: if reg.search(opts.host): raise KssCommandOptException( 'ERROR: Illigal option value. option=%s value=%s' % ('-t or --target', opts.host)) else: raise KssCommandOptException('ERROR: %s option is required.' % '-t or --target') if opts.auth: if not opts.auth == ISCSI_CONFIG_VALUE_AUTH_METHOD_CHAP and not opts.auth == ISCSI_CONFIG_VALUE_AUTH_METHOD_NONE: raise KssCommandOptException( 'ERROR: %s option is require %s or %s.' % '-a', ISCSI_CONFIG_VALUE_AUTH_METHOD_CHAP, ISCSI_CONFIG_VALUE_AUTH_METHOD_NONE) if opts.auth == ISCSI_CONFIG_VALUE_AUTH_METHOD_CHAP: if opts.user is None: raise KssCommandOptException('ERROR: %s option is required.' % '-u or --user') if opts.password is None and opts.password_file is None: raise KssCommandOptException( 'ERROR: %s option is required.' % '-p or --password or -w or --password-file') if opts.password_file is not None and not is_readable( opts.password_file): raise KssCommandOptException('ERROR: %s is not found.' % opts.password_file) else: raise KssCommandOptException('ERROR: %s option is required.' % '-a or --auth')
def chkopts(opts): reg = re.compile("[^a-zA-Z0-9\./_:-]") if opts.name: if reg.search(opts.name): raise KssCommandOptException( 'ERROR: Illigal option value. option=%s value=%s' % ('-n or --name', opts.name)) else: raise KssCommandOptException('ERROR: %s option is required.' % '-n or --name') if opts.enable is False and opts.disable is False: raise KssCommandOptException( 'ERROR: either %s options must be specified.' % '--enable or --disable') if opts.enable is True and opts.disable is True: raise KssCommandOptException('ERROR: %s options are conflicted.' % '--enable and --disable')
def process(self): (opts, args) = getopts() chkopts(opts) self.up_progress(10) conn = KaresansuiVirtConnection(readonly=False) try: inactive_storage_pools = conn.list_inactive_storage_pool() active_storage_pools = conn.list_active_storage_pool() self.up_progress(10) if not (opts.name in active_storage_pools or \ opts.name in inactive_storage_pools): raise KssCommandOptException( 'Storage pool does not exist. - pool=%s' % opts.name) conn.storage_pool.set_storage_name(opts.name) self.up_progress(10) flag = None if opts.enable: flag = True elif opts.disable: flag = False else: raise KssCommandException( 'ERROR: Execution status information does not exist. enable,disable=%s,%s' \ % (str(opts.enable), str(opts.disable))) self.up_progress(10) if conn.autostart_storage_pool(flag) is False: raise KssCommandException( 'Failed to autostart storage pool(libvirt). - pool=%s' % (opts.name)) ret = conn.is_autostart_storage_pool() if not (ret is flag): raise KssCommandException( 'Auto-start failed to set the storage pool. - pool=%s, autostart=%s' \ % (opts.name, str(ret))) self.up_progress(40) if opts.enable: self.logger.info('Set autostart storage pool. - pool=%s' % (opts.name)) print >> sys.stdout, _( 'Set autostart storage pool. - pool=%s') % (opts.name) elif opts.disable: self.logger.info('Unset autostart storage pool. - pool=%s' % (opts.name)) print >> sys.stdout, _( 'Unset autostart storage pool. - pool=%s') % (opts.name) return True finally: conn.close()
def chkopts(opts): if opts.name is None: raise KssCommandOptException('ERROR: %s option is required.' % '-n or --name') if opts.cidr is None: raise KssCommandOptException('ERROR: %s option is required.' % '-c or --cidr') if opts.dhcp_start is None: raise KssCommandOptException('ERROR: %s option is required.' % '-s or --dhcp-start') if opts.dhcp_end is None: raise KssCommandOptException('ERROR: %s option is required.' % '-e or --dhcp-end') if opts.bridge_name is None: raise KssCommandOptException('ERROR: %s option is required.' % '-b or --bridge_name')
def chkopts(opts): if not opts.name: raise KssCommandOptException('ERROR: %s option is required.' % '-n or --name') if opts.enable is None and opts.disable is None: raise KssCommandOptException( 'ERROR: either %s options must be specified.' % '--enable or --disable') if opts.enable is not None and opts.disable is not None: raise KssCommandOptException('ERROR: %s options are conflicted.' % '--enable and --disable') if opts.passwd_file is not None and not os.path.exists(opts.passwd_file): raise KssCommandOptException('ERROR: %s is not found.' % opts.passwd_file) if opts.uri is not None: if uri_split(opts.uri)["scheme"] is None: raise KssCommandOptException('ERROR: uri %s is invalid.' % opts.uri)
def chkopts(opts): reg = re.compile("[^a-zA-Z0-9,]") if opts.dev: if reg.search(opts.dev): raise KssCommandOptException( 'ERROR: Illigal option value. option=%s value=%s' % ('-d or --dev', opts.dev)) else: raise KssCommandOptException('ERROR: %s option is required.' % '-d or --dev') if opts.primary: if reg.search(opts.primary): raise KssCommandOptException( 'ERROR: Illigal option value. option=%s value=%s' % ('-p or --primary', opts.primary)) else: raise KssCommandOptException('ERROR: %s option is required.' % '-p or --primary') if opts.mode not in BONDING_MODE: raise KssCommandOptException('ERROR: Unknown bonding mode "%s".' % opts.mode)
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) conn = KaresansuiVirtConnection(readonly=False) try: inactive_storage_pools = conn.list_inactive_storage_pool() active_storage_pools = conn.list_active_storage_pool() self.up_progress(10) if opts.name in active_storage_pools or opts.name in inactive_storage_pools: raise KssCommandException( 'Storage pool already exists. - pool=%s' % opts.name) try: if opts.type == STORAGE_POOL_TYPE["TYPE_DIR"]: if conn.create_storage_pool( opts.name, opts.type, opts.target_path, #allocation=opts.allocation, available=opts.available, #capacity=opts.capacity, target_p_group=opts.group, target_p_label=opts.label, target_p_mode=opts.mode, target_p_owner=opts.owner, ) is False: raise KssCommandException('Failed to create storage pools. - pool=%s' \ % opts.name) elif opts.type == STORAGE_POOL_TYPE["TYPE_ISCSI"]: if conn.create_storage_pool( opts.name, opts.type, target_path="/dev/disk/by-path", source_h_name=opts.host_name, source_dev_path=opts.device_path, #allocation=opts.allocation, available=opts.available, #capacity=opts.capacity, target_p_group=opts.group, target_p_label=opts.label, target_p_mode=opts.mode, target_p_owner=opts.owner, ) is False: raise KssCommandException('Failed to create storage pools. - pool=%s' \ % opts.name) elif opts.type == STORAGE_POOL_TYPE["TYPE_FS"]: if conn.create_storage_pool( opts.name, opts.type, opts.target_path, source_dev_path=opts.device_path, #allocation=opts.allocation, available=opts.available, #capacity=opts.capacity, target_p_group=opts.group, target_p_label=opts.label, target_p_mode=opts.mode, target_p_owner=opts.owner, ) is False: raise KssCommandException('Failed to create storage pools. - pool=%s' \ % opts.name) else: raise KssCommandOptException('ERROR: The type that does not exist. type=%s' \ % opts.type) self.up_progress(20) # pool check inactive_storage_pools = conn.list_inactive_storage_pool() active_storage_pools = conn.list_active_storage_pool() if not (opts.name in active_storage_pools or opts.name in inactive_storage_pools): raise KssCommandException( 'Failed to create storage pools. (Unexplained) - pool=%s' \ % opts.name) self.up_progress(20) # pool autostart check flag = True # autostart on if conn.autostart_storage_pool(flag) is False: raise KssCommandException( 'Failed to autostart storage pool(libvirt). - pool=%s' % (opts.name)) ret = conn.is_autostart_storage_pool() if not (ret is flag): raise KssCommandException( 'Auto-start failed to set the storage pool. - pool=%s, autostart=%s' \ % (opts.name, str(ret))) self.logger.info('Created storage pool. - pool=%s' % (opts.name)) print >> sys.stdout, _('Created storage pool. - pool=%s') % ( opts.name) return True except KssCommandException, e: raise e finally: conn.close()
def chkopts(opts): reg = re.compile("[^a-zA-Z0-9\./_:-]") if opts.name: if reg.search(opts.name): raise KssCommandOptException( 'ERROR: Illigal option value. option=%s value=%s' % ('-n or --name', opts.name)) else: raise KssCommandOptException('ERROR: %s option is required.' % '-n or --name') if opts.type: if opts.type not in STORAGE_POOL_TYPE.values(): raise KssCommandOptException( 'ERROR: Type is not available. type=%s' % opts.type) else: raise KssCommandOptException('ERROR: %s option is required.' % '-t or --type') if opts.type == STORAGE_POOL_TYPE["TYPE_DIR"]: # type:dir if not opts.target_path: raise KssCommandOptException('ERROR: %s option is required.' % '-p or --target_path') elif opts.type == STORAGE_POOL_TYPE["TYPE_ISCSI"]: # type:iscsi if not opts.host_name: raise KssCommandOptException('ERROR: %s option is required.' % '-b or --host_name') if not opts.device_path: raise KssCommandOptException('ERROR: %s option is required.' % '-d or --device_path') elif opts.type == STORAGE_POOL_TYPE["TYPE_FS"]: # type:fs if not opts.target_path: raise KssCommandOptException('ERROR: %s option is required.' % '-p or --target_path') if not opts.device_path: raise KssCommandOptException('ERROR: %s option is required.' % '-d or --device_path') else: raise KssCommandOptException( 'ERROR: The type that does not exist. type=%s' % opts.type) if opts.label: if reg.search(opts.label): raise KssCommandOptException( 'ERROR: Illigal option value. option=%s value=%s' % ('-l or --label', opts.label)) reg = re.compile("[^0-9]") if opts.owner: if reg.search(opts.owner): if opts.owner not in [user[0] for user in get_pwd_info()]: raise KssCommandOptException( 'ERROR: Permission user not found. owner=%s' % (opts.owner)) else: if int(opts.owner) not in [user[2] for user in get_pwd_info()]: raise KssCommandOptException( 'ERROR: Permission user not found. owner=%s' % (opts.owner)) if opts.group: if reg.search(opts.group): if opts.group not in [group[0] for group in get_grp_info()]: raise KssCommandOptException( 'ERROR: Permission user not found. group=%s' % (opts.group)) else: if int(opts.group) not in [group[2] for group in get_grp_info()]: raise KssCommandOptException( 'ERROR: Permission user not found. group=%s' % (opts.group)) reg = re.compile("^[0-9]{3,4}$") if opts.mode: if not reg.match(opts.mode): raise KssCommandOptException( 'ERROR: Illigal permission mode. mode=%s' % (opts.mode))
def chkopts(opts): if not opts.name: raise KssCommandOptException('ERROR: -n or --name option is required.') if not opts.id: raise KssCommandOptException('ERROR: -i or --id option is required.')
def chkopts(opts): if not opts.name: raise KssCommandOptException('ERROR: %s option is required.' % '-n or --name') if not opts.disk or not os.path.exists(opts.disk): raise KssCommandOptException('ERROR: disk image not found.')
def chkopts(opts): if not opts.name: raise KssCommandOptException('ERROR: %s option is required.' % '-n or --name') if not opts.mac: KssCommandOptException('ERROR: %s option is required.' % '-m or --mac')
def chkopts(opts): if not opts.exportuuid: raise KssCommandOptException('ERROR: -e or --exportuuid option is required.') if not opts.destuuid: raise KssCommandOptException('ERROR: -d or --destuuid option is required.')
def chkopts(opts): reg = re.compile("[^a-zA-Z0-9\./_:-]") if opts.name: if reg.search(opts.name): raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-n or --name', opts.name)) else: raise KssCommandOptException('ERROR: %s option is required.' % '-n or --name') if opts.pool: if reg.search(opts.pool): raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-p or --pool', opts.pool)) else: raise KssCommandOptException('ERROR: %s option is required.' % '-p or --pool') if opts.volume: if reg.search(opts.volume): raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-v or --volume', opts.volume)) else: raise KssCommandOptException('ERROR: %s option is required.' % '-v or --volume') if opts.type: if opts.type.lower() != "iscsi" and opts.type.lower() != "file": raise KssCommandOptException('ERROR: %s option is require %s or %s.' % ('-t or --type', 'iscsi', 'file')) else: raise KssCommandOptException('ERROR: %s option is required.' % '-t or --type') if opts.bus: if reg.search(opts.bus): raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-b or --bus', opts.bus)) if opts.format: if reg.search(opts.format): raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-f or --format', opts.format)) if opts.target: if reg.search(opts.target): raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-f or --format', opts.target))