a B:f9:@s ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddlm Z m Z ddlmZddlZddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"ddl#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.gdZ/ej0re1Z2zddl3m4Z4Wn e5yLddl6m4Z4Yn0da7dkdd Z8d d Z9d d Z:ddZ;ddZddZ?ddZ@ddZAddZBdlddZCd d!ZDd"d#ZEGd$d%d%eFZGdmd(d)ZHd*d+ZIGd,d-d-ZJd.d/ZKgd0ZLd1ZMd2d3NeMZOd4ZPd5d3NePZQd6d7gZRd8d3NeRZSeTd9d:eSeRe>d;ZUgd<ZVd=d3NeVd>d?ZWeTd9d:eWeVe>d;ZXd@ZYeTdAdBdCdDZZeZ[Z\dEe\dF<eTdGdHdIdDZ]e][Z^dJe^dF<eTdKdLdMdDZ_e_[Z`dNe`dF<eTdOdPdQdDZaea[ZbdRebdF<eTdSdTdUdDZcec[ZddVeddF<eTdWdXdYe;dZZeeTd[d\d]dDZfeTd^d_d`dDZgeTdadbdcdDZheTdddedfdDZieTdgdheYdDZjeTdidjdkdDZkeTdldmdndoZleTdpdqdrdoZmeTdsdtdueAdvZneTdwdxeTdydzd{NeLd|d}eLe>d~geTe\eTe^eTe`eTeieTedeTebeTeheTekgdeTddeTddddDgdeTddeTeZgdeTdddeTddeTddddoeTejeTe]geTdeOdeMe>dgdeTddeTddddoeTddddddeTddd{Ne)joe)joe>dgeTddeYdgdeTddeTeZgdeTddeTe_gdeTddeTe_eTdgddeYdDgdeTddeTe_eTddddDeTddeQePdgeTdGddgdeTddeTddddDeTddddDeTdddddgdeTdddded?eTeageTd3dgd@dAgdeTdBdCeTeaeTdDdEdFdDeTdGdHdIdDgeTd(d*dgdeTdJdKggdeTdLdMggdeTdNdOeTe_gdeTdPdQeTe_eTeUgdeTdRdSeTe_eTeUgdeTdTdUeTe_eTeXgdeTdVdWeTelgdeTdXdYeTelgdeTdZd[eTelgdeTd\d]eTelgdeTd^d_eTemeTengdf5ZqeTd`dadbdcdddedfdddddddddddddddddddddJdgdNdPdRdTdVdXdZd\dh%ZrGdidjdjesZtdS(nN)ArgumentParserArgumentTypeError)RawTextHelpFormatter)ClientPoolVERSIONLsmErrorDiskVolume JobStatus ErrorNumber BlockRange uri_parseProxysize_human_2_size_bytes AccessGroup FileSystem NfsExport TargetPort LocalDiskBattery) DisplayDataPlugDataoutvol_provision_str_to_typevol_rep_type_str_to_typeVolumeRAIDInfo PoolRAIDInfoVcrCap LocalDiskInfoVolumeRAMCacheInfoLocalLedSlotInfo)local-disk-listlocal-disk-ident-led-onlocal-disk-ident-led-offlocal-disk-fault-led-onlocal-disk-fault-led-offlocal-led-slot-listlocal-led-slot-set) OrderedDictcCsd}d}zFzt}||Wntyb}z*tjt|tjd}WYd}~nd}~0ty}z@tjt|dtj|j t j krd}nd}WYd}~njd}~0t yd}YnNt y}z|j }WYd}~n.d}~0ddl}|jtjdd}Yn0W|rFz||WntyDYn0t|n6|r|z||WntyzYn0t|0dS) z+ Common command line code, called. rN )file)CmdLineprocessArgErrorsysstderrwritestrflushrcoder ZPERMISSION_DENIEDKeyboardInterrupt SystemExit traceback print_excstdoutshutdown Exceptionexit)cZerr_exitcliZaeleZser;rD8/usr/lib64/python3.9/site-packages/lsm/lsmcli/cmdline.pycmd_line_wrapper8sF      rFc Cs\tj}t|}z0ttjtjd}Wt|tj |nt|tj |0|S)Nr.) r3stdinfilenotermiosZ tcgetattrttyZsetrawreadZ tcsetattrZ TCSADRAIN)fdprevZchrDrDrEgetches  $rNcCs,t|\}}}|r||fStd|dS)z If init_id is a WWPN, convert it into LSM standard version: (?:[0-9a-f]{2}:){7}[0-9a-f]{2} Return (converted_init_id, lsm_init_type) z,--init "%s" is not a valid WWPN or iSCSI IQNN)rinitiator_id_verifyr2)init_idvalidZconverted_init_typeconverted_init_idrDrDrEparse_convert_initps rScCs(t|\}}}|r|Std|dS)z Call back from validating an initiator :param init_id: Initiator to validate :return: Value of initiator or raises an exception z!"%s" is invalid WWPN or iSCSI IQNN)rrOr)rPrQ_rRrDrDrE _check_inits rUcCsHz$t|d}|dkr td||WStyBtd|Yn0dS)z Call back for validating a positive integer :param num: Number string to check :return: Numeric value, else exception rz,invalid: require positive integer value '%d'z*invalid: not a positive integer value '%s'N)longr ValueError)ZnumrcrDrDrE_check_positive_integers  rZZchild_cCs|SN)upper)srDrDrE_uppersr^c Cs|sdS|d}t|dkr"dSd|vr.dS|D]t}dt|krNdksVndSt|dkrt|ddkrtdSzt|d d krWdSWq2tyYdS0q2d S) z Check if a string represents a valid ip4 address :param address: String representing address :return: True if valid address, else false F.r-/rr.0rVT)splitlenintrX)addresspartsirDrDrE_valid_ip4_addresss$     rjcsdd}|sdSd|vrdSt|ddkr2dS|d}t|dksTt|dkrXdSd |d vrt|s|td dS|d d gd|vrd d|D}|d d}|rt|dkst|dkrtdd|Dotfddd|DSdS)z Check if a string represents a valid ipv6 address :param address: String representing address :return: True if valid address, else false zABCDEFabcdef0123456789:Fr`z::r*:ra r_zNot valid ipv suffixrbcSsg|]}|dkr|qS)rD).0prDrDrE z&_valid_ip6_address..Tcss|]}t|dkVqdS)r-N)reroxrDrDrE rrz%_valid_ip6_address..c3s|]}|vVqdSr[rDrtallowedrDrErvrrrn) rerdrjpopprintextendappendalljoin)rgZ has_zerosrhrDrwrE_valid_ip6_addresss2    rcCsttjtjtjtjd}|d}|D](}||vr*t d|t |fq*t |t t |krt |dkr|t dt |dkr|ddd|dddkrt d ||d||dBS||dSn t d |dS) N)ZIDENT_ONZ IDENT_OFFZFAULT_ONZ FAULT_OFFrkz&Invalid state '%s', valid choices = %sr*z(Maximum number of LED state values is 2!rr-r.z0States which counteract one another are invalid!z&Repeated same LED state is invalid! %s) dictr ZLED_STATUS_IDENT_ONZLED_STATUS_IDENT_OFFZLED_STATUS_FAULT_ONZLED_STATUS_FAULT_OFFr\rdkeysrlistreset)stateZ valid_optionsZt_statesr]rDrDrE_check_led_states0    rcstdtjtd}t|r$dSt|r0dSt|dkr@dS||rNdS|ddkrf|dd}tfd d |dDS) z Checks to see if the supplied string is a valid ip4/6 or hostname :param ip_hn: String representing address user inputted :return: True if valid IP address or hostname z(?!-)[A-Z0-9-]{1,63}(?.) recompile IGNORECASErjrrerr}rd)Zip_hnZ digits_onlyrDrwrE_is_valid_network_name s     rFc Cspd}|r t}|jddddtjdtfd|jdd td d |tjd |jd dd tdd|dd |jdddd|dd|jdddd|dd|jddd d|dd d!|jd"d#dd$|d%d&d'|jd(d)dd*|d%d+d'|jd,d-d d.|d/td0|jd1dd2|d3d|jd4dd5|d%d6d'|jd7d8dd9|d%d:d'|rlt }d;|d.|<|j fi|dz %splugin_exe)rtypemetavardesthelpz-uz--urizz%suriz,Uniform resource identifier (env LSMCLI_URI)z-Pz--prompt store_truez%spromptz)Prompt for password (env LSMCLI_PASSWORD))rrrz-Hz--humanz%shumanz:Print sizes in human readable format (e.g., MiB, GiB, TiB)z-tz--tersez%ssepzz;Print output in terse form with "SEP" as a record separator)rrrrz-ez--enumz%senumFz3Display enumerated types as numbers instead of text)rrdefaultrz-fz--forcez%sforcez3Bypass confirmation prompt for data loss operationsz-wz--waitz%swaitz+Command timeout value in ms (default = 30s))rrrrz--headerz%sheaderzInclude the header with tersez-bz%s_asynczmRun the command async. Instead of waiting for completion. Command will exit(7) and job id written to stdout.z-sz--scriptz%sscriptzMDisplaying data in script friendly way with additional information(if exists)i0uN) _CHILD_OPTION_DST_PREFIX add_argumentr3argvrr6argparseSUPPRESSrZr set_defaults)Z arg_parseris_childprefixZ default_dictrDrDrE_add_common_options)s  rc Cs`i}tD]N}zt|}|||<Wq tyX}z|jtjkrDWYd}~q d}~00q |Sr[)rr vpd83_getrr8r NO_SUPPORT)lookupdZvpdlsm_errrDrDrE_sd_paths_caches    rc Csvg|_tdurtaz*t|jdkr<|jtvr> %szutf-8r+zPLUGIN EC>> %d)rr=readlinerzdecoderstripZpollwait)instanceoutputlinerDrDrEr szPluginFork.read_stdoutcCsB|jr|j|jr.t|jt|j|jr>|j}dSr[) rrrrremovermdirrrr~)rrYrDrDrErs   zPluginFork.closeN)rrr__doc__r staticmethodrrrDrDrDrErs 0 rcCs&t|}t|jtjd<||_dS)NZLSMCLI_DEBUG_FD)rr6rrHrr plugin_fork)rrZfdatarDrDrE_fork_exec_plugin$sr) VOLUMESPOOLSFS SNAPSHOTSEXPORTSNFS_CLIENT_AUTH ACCESS_GROUPSSYSTEMSDISKSPLUGINS TARGET_PORTS BATTERIES)DEFAULTZTHINZFULLzprovisioning type: , )CLONECOPYZ MIRROR_ASYNCZ MIRROR_SYNCzreplication type: ENABLEZDISABLEzPolicy: z--policyz)rrrchoicesr)WBAUTOZWTzWrite cache polices: z' which stand for "write back", "auto", z"write through"z7Can use B, KiB, MiB, GiB, TiB, PiB postfix (IEC sizing)z--syszz System ID)rrrzmSearch by System ID. Only supported for: (VOLUMES, POOLS, FS, DISKS, ACCESS_GROUPS, TARGET_PORTS, BATTERIES)rz--poolz zPool IDz;Search by Pool ID. Only supported for: (VOLUMES, POOLS, FS)z--volzz Volume IDzASearch by Volume ID. Only supported for: (VOLUMES, ACCESS_GROUPS)z--fszzFile System IDz=Search by FS ID. Only supported for: (FS, SNAPSHOTS, EXPORTS)z--agzzAccess Group IDzGSearch by Access Group ID. Only supported for: (ACCESS_GROUPS, VOLUMES)z--initz z Initiator ID)rrrrz--snapz z Snapshot IDz--exportz z Export IDz --nfs-exportzz6Search by NFS Export ID. Only supported for: (EXPORTS)z--diskz z.Search by Disk ID. Only supported for: (DISKS)z--sizezz--tgtzz=Search by target port ID. Only supported for: (TARGET_PORTS)z--pathzLocal disk pathz )rrrz--slotzLED slot identifierz z--statez[LED slot value state (IDENT_[ON|OFF] or [FAULT_[ON|OFF], or combination separated with ':')z)rrrrrzList records of different typesz--typezList records of type: z z3 When listing SNAPSHOTS, it requires --fs .z)rrrrr)rrroptionalz job-statusz Retrieve information about a jobz--jobzz job status id)rrr capabilitieszRetrieves array capabilitiesz plugin-infoz(Retrieves plugin description and version)rr volume-createzCreates a volume (logical unit)z--namez volume namezz--provisioningr)rrrrrzvolume-raid-createz(Creates a RAIDed volume on hardware RAIDzz>Free disks for new RAIDed volume. This is repeatable argument.r|)rrrrz --raid-typez@RAID type for the new RAID group. Should be one of these: %s)rrrrz --strip-sizez Strip size. zvolume-raid-create-capz=Query capability of creating a RAIDed volume on hardware RAID volume-deletezDeletes a volume given its idz volume-resizezRe-sizes a volumez z New size. %szvolume-replicatez:Creates a new volume and replicates provided volume to it.zz"The name for New replicated volumez --rep-typez )rrrrz[Pool ID to contain the new volume. By default, new volume will be created in the same pool.zvolume-replicate-rangez3Replicates a portion of a volume to existing volumez --src-volz zSource volume idz --dst-volz zDestination volume idz zReplication type: CLONE, COPYrrz --src-startzz>Source volume start block number. This is repeatable argument.)rrrrrz --dst-startzzCDestination volume start block number. This is repeatable argument.z--countz z;Number of blocks to replicate. This is repeatable argument.z!volume-replicate-range-block-sizez2Size of each replicated block on a system in byteszvolume-dependantsz>Returns True if volume has a dependant child, like replicationzvolume-dependants-rmzRemoves volume dependencieszvolume-access-groupz4Lists the access group(s) that have access to volumez volume-maskz>Grants access to an access group to a volume, like LUN Maskingz volume-unmaskz7Revoke the access of specified access group to a volumez volume-enablezEnable block access of a volumezvolume-disablez Disable block access of a volumezvolume-raid-infozQuery volume RAID informationzvolume-ident-led-onz!Enable the IDENT LED for a volumezTargeted volume. zvolume-ident-led-offz"Disable the IDENT LED for a volumezsystem-read-cache-pct-updatez,Change the read cache percentage of a systemzTargeted system. z --read-pctzRead cache percentage. )rrrzpool-member-infoz!Query Pool membership informationzaccess-group-createzCreate an access groupz z$Human readable name for access groupzaccess-group-addz+Add an initiator into existing access groupzaccess-group-removez.Remove an initiator from existing access groupzaccess-group-deletezDeletes an access groupzaccess-group-volumeszBLists the volumes that the access group has been granted access toz iscsi-chapz5Configures iSCSI inbound/outbound CHAP authenticationz --in-userz zInbound chap user namez --in-passz zInbound chap passwordz --out-userz zOutbound chap user namez --out-passz zOutbound chap password fs-createzCreates a file systemz zname of the file system fs-deletezDelete a filesystem fs-resizezRe-sizes a filesystemz fs-exportzExport a filesystem via NFS.z --exportpathz z(NFS server export path. e.g. '/foo/bar'.z --anonuidz z%UID(User ID) to map to anonymous user)rrrrrz --anongidz z&GID(Group ID) to map to anonymous userz --auth-typez zNFS client authentication typez --root-hostz z9The host/IP has root access. This is repeatable argument.)rrrrrrz --ro-hostz zrThe host/IP has readonly access. This is repeatable argument. At least one '--ro-host' or '--rw-host' is required.z --rw-hostz zsThe host/IP has readwrite access. This is repeatable argument. At least one '--ro-host' or '--rw-host' is required.z fs-unexportzRemove an NFS exportzfs-clonezCreates a file system clonez--src-fsz z&The ID of existing source file system.z --dst-namez z3The name for newly created destination file system.z--backing-snapshotz zbacking snapshot idzfs-snap-createzCreates a snapshotz z'The human friendly name of new snapshotzfs-snap-deletezDeletes a snapshotfs-snap-restorez;Restores a FS or specified files to previous snapshot statez--filez zkOnly restore provided file Without this argument, all files will be restored This is a repeatable argument.)rrrrrz--fileaszzGstore restore file name to another name. This is a repeatable argument.z fs-dependantszHReturns True if filesystem has a child dependency(clone/snapshot) existsz-For file check This is a repeatable argument.)rrrrrfs-dependants-rmz Removes file system dependencieszHFile or files to remove dependencies for. This is a repeatable argument.)rrrrz file-clonez,Creates a clone of a file (thin provisioned)z--srczzCsource file to clone (relative path) This is a repeatable argument.z--dstzz@Destination file (relative path), this is a repeatable argument.r"zQuery local disk informationr'z#Query slots with LED identificationzvolume-cache-infoz"Query volume RAM cache informationzvolume-phy-disk-cache-updatez)Update volume physical disk cache settingzvolume-read-cache-policy-updatezUpdate volume read cache policyz volume-write-cache-policy-updatez Update volume write cache policyr#z/Turn on the identification LED for a local diskr$z0Turn off the identification LED for a local diskr%z&Turn on the fault LED for a local diskr&z'Turn off the fault LED for a local diskr(z#Sets the state of the specified LEDzlist --type systemszlist --type poolszlist --type volumeszlist --type diskszlist --type access_groupszlist --type fszlist --type target_portszlist --type batteries)%ZlsZlplvZldZlaZlfltrArpZvcZvrcZvrccZvdZvrZvmZvuveviZacZaaarZadZvriZvilonZviloffZsrcpuZpmiZldlZlbZvciZvpdcuZvrcpuZvwcpuZldilonZldiloffZldflonZldfloffc@s`eZdZdZddZddZddZedd Zed d Z d d Z ddZ eddZ ddZ ddZddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zed.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Z d:d;Z!dd?Z#d@dAZ$dBdCZ%dDdEZ&edFdGZ'dHdIZ(dJdKZ)dLdMZ*dNdOZ+dPdQZ,dRdSZ-dTdUZ.dVdWZ/dXdYZ0dZd[Z1d\d]Z2d^d_Z3d`daZ4dbdcZ5dddeZ6dfdgZ7dhdiZ8djdkZ9dldmZ:dndoZ;dpdqZddwdxZ?ddydzZ@d{d|ZAd}d~ZBddZCddZDddZEddZFddZGddZHddZIddZJddZKdvS)r0z' Command line interface class. cCsL|jjsD|rdnd}td|t}|dkr6dStddSndSdS) z1 Give the user a chance to bail. ZwillZmayzxWarning: You are about to do an operation that %s cause data to be lost! Press [Y|y] to continue, any other key to abortYTzOperation aborted!FN)rforcerrNr\)rZdeletingrZpressedrDrDrEconfirm_prompts  zCmdLine.confirm_promptc Csld}t|dkrdStj}d}|jjr*d}|jjr6d}|jjrDtj}tj|||jj |jj |jj||ddS)NFrT) display_wayZ flag_humanZ flag_enumZsplitterflag_with_headerZflag_dsp_all_data) rerZDISPLAY_WAY_DEFAULTrsepheaderZscriptZDISPLAY_WAY_SCRIPT display_dataZhumanenum)rZobjectsZ display_allrrrDrDrEr2s& zCmdLine.display_datacCsHg}d}t|}|D]"}||\}}|t||q||dS)Nz<}{>)rZavailable_pluginsrdr|rr)rrrZpluginsrpdescrrDrDrEdisplay_available_pluginsKs z!CmdLine.display_available_pluginscCsDg}tjddD],}|tvr4|t|dq||q|S)ab Walk the command line argument list and build up a new command line with the appropriate substitutions which is then passed to argparse, so that we can avoid adding more sub parsers and do all argument parsing before the need to talk to the library :return copy of command line args with alias expansion: r.N )r3raliasesr{rdr|)rYrirDrDrE handle_aliasVs  zCmdLine.handle_aliascCs.d}ttD]\}}|d||7}q|S)Nzcommand aliases: z {0:<18} Alias of '{1}' )sortedr itemsformat)rYkvrDrDrEalias_help_textgszCmdLine.alias_help_textcCstdd}t|ddtdtdtd}t|dd|jdd }d|_tD]}|j|d |d |gtd }| d }| dgD](}|d }|d =|j |fddi|q| d}| dgD]2}|d } |d =t | t s| f} |j | i|q|jt||d dddqNttjdkr8|td||_|jtd} t| D]R\} } | trZ| ttd} t| | dust| | durZt| | | qZ| S)z3 Command line interface parameters F)add_helpT)rz^The libStorageMgmt command line interface. Run %(prog)s -h for more on each command.zh Copyright 2012-2022 Red Hat, Inc. Please report bugs to ) descriptionepilogformatter_classZcommand)rrr)rparentsrzcmd required argumentsrrequiredzcmd optional argumentsr-rT)funcr.rN)rrr0rradd_subparsersrcmds add_parseradd_argument_groupgetr isinstancetuplergetattrreplacerer3r print_usager@parser parse_argsr varsr startswithrsetattr)rZ parent_parserr&Z subparserscmdZ sub_parsergroupargrflagsZ known_argsrrZroot_krDrDrErBos^         z CmdLine.clicCs:|jjr"t|jj|jntd|jdS)zD Dump the supported nfs client authentication types rN)rrrr~rAZ export_authrrDrDrE!display_nfs_client_authenticationsz)CmdLine.display_nfs_client_authenticationc Csd}d}|jdf|jdf|jdf|jdf|jdf|jdf|jdf|jdff}|D].}|d rP|rvtd ||d fqP|\}}qP||fS) NZ system_idpool_id volume_iddisk_idaccess_group_idfs_id nfs_export_id tgt_port_idrz,Search key specified more than once (%s, %s)r.) r3poolvoldiskagfsZ nfs_exportZtgtr2)r search_key search_valueZ search_argsZsarDrDrE_get_search_key_values&   zCmdLine._get_search_key_valuecCst|\}}|jdkrg}|dkr(d}|dkrZt|j|jddd}|r|j|}n*|rv|tj vrvt d|n|j ||}| t d d |DnT|jd kr|d krd}|r|tj vrt d || |j||n |jdkr8|dkrd}|r |tj vr t d|| |j||n|jdkr|jdurXt d|rt|dkrtt d|t|j|jd}| |j|nV|jdkr|dkrd}|r|tj vrt d|| |j||n|jdkr|rt d|n|jdkr|dkr.d}|dkrtt|j |jddd}|rh| |j|S| gSn|r|tj vrt d|| |j||nJ|jdkr|rt d| |jn|jdkr4|dkrd}|r|tj vrt d || t d!d |j||Dn|jd"kr|d#krNd}|rl|tj vrlt d$|| |j||nr|jd%kr|rt d&|nN|jd'kr|r|tj vrt d(|| |j ||nt d)|jdS)*Nrr1rr3 Access GroupF)rz3Search key '%s' is not supported by volume listing.css|]}t|VqdSr[rrorrDrDrErvrrzCmdLine.list..rr0z1Search key '%s' is not supported by pool listing.rr4rz--fs requiredz5Search key '%s' is not supported by snapshot listing. File Systemrr5z6Search key '%s' is not supported by NFS Export listingrzCNFS client authentication type listing with search is not supportedrr z8Search key '%s' is not supported by Access Group listingrz+System listing with search is not supportedrr2z0Search key '%s' is not supported by disk listingcss|]}t|VqdSr[r@rorrDrDrErv-srr6z7Search key '%s' is not supported by target port listingrz,Plugins listing with search is not supportedrz3Search key '%s' is not supported by battery listingzunsupported listing type=%s)!r0r>rrrA access_groupsr:"volumes_accessible_by_access_groupr ZSUPPORTED_SEARCH_KEYSr2volumesrrrpoolsrr; fs_snapshotsrexportsr/r8access_groups_granted_to_volumersystemsr disksrZ target_portsr rZ batteries)rrr<r=Zlsm_volslsm_agr;lsm_volrDrDrErs                          z CmdLine.listcCsFt|j|jd}t|j\}}|j|j|||}||gdSNSystem) rrArKr3rSinitaccess_group_createrr)rrsystemrP init_typeZ access_grouprDrDrErRFs  zCmdLine.access_group_createcCsJt|j|jd}t|j\}}|r6|j|||S|j|||SdSNr?)rrArDr:rSrQZaccess_group_initiator_addZaccess_group_initiator_delete)rroprMrPrTrDrDrE_add_rm_access_grp_initMs zCmdLine._add_rm_access_grp_initcCs|||dgdS)NTrrWrrrDrDrEaccess_group_addYszCmdLine.access_group_addcCs|||dgdS)NFrXrYrDrDrEaccess_group_remove]szCmdLine.access_group_removecCs@|j}t||jd}|j|}|tdd|DdS)Nr?css|]}t|VqdSr[r@rArDrDrErvdrrz/CmdLine.access_group_volumes..)rArDrr:rErr)rraglr,ZvolsrDrDrEaccess_group_volumes`s  zCmdLine.access_group_volumescCst|j\}}|tjkr&td|j|jjr>|jjs>td|jjrV|jjsVtd|jjrn|jj sntd|jj r|jjstd|jjr|jj r|jjr|jjstd|j ||j|jj|jj|jj dS)Nz$--init "%s" is not a valid iSCSI IQNz--in-user requires --in-passz--in-pass requires --in-userz--out-user requires --out-passz--out-pass requires --out-userz?out-user and out-password only supported if inbound is supplied) rSrQrZINIT_TYPE_ISCSI_IQNr2rZin_userZin_passZout_userZout_passrAZiscsi_chap_auth)rrrPrTrDrDrE iscsi_chapfs,  zCmdLine.iscsi_chapcCs.t|j|jd}|j|}||dSNr )rrArFr8rJr)rrr8groupsrDrDrEvolume_access_groups zCmdLine.volume_access_groupcCs$|j}t||jd}|j|SrU)rArDrr:access_group_delete)rrr\r,rDrDrErbs zCmdLine.access_group_deletecCs8t|j|jd}|dr4|d|j|ddS)NrBTr)rrAr;r _wait_for_it fs_deleterrr;rDrDrErds zCmdLine.fs_deletec CsLt|j|jd}|jdg|j||j||jR}| |gdS)Nrr) rrArGr7rc fs_creater_sizesizer)rrrpr;rDrDrErfs  zCmdLine.fs_createcCslt|j|jd}||j}||jkr6ttjd| drh|j dg|j ||R}| |gdS)NrBSpecified size same as currentFr) rrAr;rgrhZ total_spacerr NO_STATE_CHANGErrc fs_resizer)rrr;rhrDrDrErks   zCmdLine.fs_resizecCsdt|j|jd}d}|jr4t|j||jd}|jdg|j||j|R}| |gdS)NzSource File SystemSnapshotfs_clone) rrAr;src_fsbacking_snapshotrHrcrmZdst_namer)rrrnssr;rDrDrErmszCmdLine.fs_clonec Cs\t|j|jd}|jjr4t|j||jd}nd}|d|j||j|j |ddS)NrBrl fs_file_clone) rrAr;rrorHrcrqsrcdstrrr;rprDrDrE file_cloneszCmdLine.file_clonecCs t|}|dkrtd||S)Nrz$Incorrect size argument format: '%s')rr2)r]Z size_bytesrDrDrErgs z CmdLine._sizecCs>|jjdur|jj}nd}|r$d}nd}td|||fdS)Nrk SUPPORTED UNSUPPORTED%s%s%s)rrr)rcapvalr]rrDrDrE_cps  z CmdLine._cpc Cst|j|jd}|j|}t|}t|d}tj }|j j dur\|j j }t }|D] }d||<qf|D]}||vrxd||<qxt |g|dS)NrPTrvrw)rrArKr3rr Z get_supportedvaluesrZDEFAULT_SPLITTERrrr)Zdisplay_data_script_way) rrr]ryZsup_capsZall_capsrZcap_datarrDrDrErs    zCmdLine.capabilitiescCs>|j\}}|jr*td||j|fntd||fdS)NrxzDescription: %s Version: %s)rA plugin_inforr)rrrrrDrDrEr}szCmdLine.plugin_infoc CsXt|j|jd}|jdg|j||j||jt |j R}| t |gdS)Nrr) rrArGr7rc volume_createrrgrhrZ provisioningrr)rrrpr8rDrDrEr~szCmdLine.volume_createcCsBt|j|jd}|jdg|j||jR}||gdS)NrBzsnapshot-create)rrAr;rcZfs_snapshot_createrrrtrDrDrEfs_snap_creates zCmdLine.fs_snap_createc Cst|j|jd}t|j||jd}|jj}t|dkrBd}d}|jjrzd}|jjrzt|jjt|jjkrzt d| dr| d|j ||||jj|ddS)NrBrlrTFz&number of --file not equal to --fileasr) rrAr;rHsnaprr/reZfileasr2rrcZfs_snapshot_restore)rrr;rpfilesZflag_all_filesrDrDrEfs_snap_restore s&  zCmdLine.fs_snap_restorecCs8t|j|jd}|dr4|d|j|ddS)Nr Tr)rrArFr8rrc volume_deleterrrrDrDrEr$s zCmdLine.volume_deletecCsPt|j|jd}t|j||jd}|drL|d|j||ddS)NrBrlTfs_snap_delete)rrAr;rHrrrcZfs_snapshot_deletertrDrDrEr*s  zCmdLine.fs_snap_deletecCs|s|S|jjr$t||tj|j|\}}}|tj krLt dq$|tj krf|j ||St|dt|q$dS)Ng?z job error code= )rZ_asyncrr>r JOB_STARTEDrA job_statusr Z INPROGRESStimesleepCOMPLETEjob_freer2r6)rrjobrr]percentrDrDrErc7s     zCmdLine._wait_for_itcCs^|j|j\}}}|tjkrB|r2|t|g|j|jntt || t j dSr[) rArrr rrrrrr6r>r r)rrr]rrrDrDrErPs  zCmdLine.job_statuscCsd}|jrt|j|jd}t|j|jd}t|j}|tj krRt d||j dg|j ||||j R}|t|gdS)Nrr invalid replication type= %szreplicate volume)r7rrArGrFr8rrep_typer REPLICATE_UNKNOWNr2rcvolume_replicaterrr)rrrprrr8rDrDrEr]s   zCmdLine.volume_replicatecCs@dd}|jddd||d|jddd||ddS) Nc Sstdt|D]n}t||d|}||dj}t|||}||j}|||krtd||||d|||dfqdS)Nr.z._overlapcSs|jSr[) src_blockrurDrDrE}rrz(CmdLine._check_overlap..)keyrcSs|jSr[) dest_blockrrDrDrErrrr)sort)rangesrrDrDrE_check_overlapns   zCmdLine._check_overlapc Csdt|j|jd}t|j|jd}t|j}|tjkrHt d||j }|j }|j }t |rt |t |krt |ksnt dg}tt |D]} t|| } t|| } t|| } | dkrt d| dkrt d| dkrt d| | |jkr t d | | |jkr$t d |t| | | qt||d r`|j||||dS) Nz Source VolumezDestination Volumerz@Differing numbers of src_start, dest_start, and count parametersrz--count: value < 0z--src-start: value < 0z--dst_start: value < 0z#--src-start + --count > source sizez(--dst-start + --count > destination sizeF)rrArFZsrc_volZdst_volrrr rr2 src_start dst_startcountrerrW num_of_blocksr|r r0rrvolume_replicate_range) rrrrrsrZ src_startsZ dst_startsZcountsrbrrrrDrDrErsB         zCmdLine.volume_replicate_rangecCs(t|j|jd}t|j|dSrO)rrArKr3r!volume_replicate_range_block_size)rrr]rDrDrErsz)CmdLine.volume_replicate_range_block_sizecCs:t|j|jd}t|j|jd}|j||dS)Nr r?)rrArFr8rDr: volume_mask)rrr8r:rDrDrErszCmdLine.volume_maskcCs6t|j|jd}t|j|jd}|j||S)Nr?r )rrArDr:rFr8 volume_unmask)rrr:r8rDrDrErszCmdLine.volume_unmaskcCsvt|j|jd}||j}||j|jkr.zDisk ID %s not foundrcss|] }|jVqdSr[)rrCrDrDrErv rrz-CmdLine.volume_raid_create..cSsg|]}|jtj@s|jqSrD)statusr Z STATUS_FREErrCrDrDrErq sr.zDisk %s is not free)rZraid_type_str_to_lsm raid_typerArLrer9rr ZNOT_FOUND_DISKr~rZ DISK_NOT_FREE strip_sizerr ZVCR_STRIP_SIZE_DEFAULTrrvolume_raid_creater)rrrZ all_lsm_disksZ lsm_disksZ busy_disksrrDrrErs4      zCmdLine.volume_raid_createcCs:t|j|jd}|t|jg|j|RgdSrO)rrArKr3rrrZvolume_raid_create_cap_get)rrZlsm_sysrDrDrEvolume_raid_create_capszCmdLine.volume_raid_create_capcCs$t|j|jd}|j|dSr_)rrArFr8volume_ident_led_onrrZ lsm_volumerDrDrEr$szCmdLine.volume_ident_led_oncCs$t|j|jd}|j|dSr_)rrArFr8volume_ident_led_offrrDrDrEr)szCmdLine.volume_ident_led_offc Cst|j|jd}zt|j}Wn4tyV}zttj t |WYd}~n d}~00|j ||t|j|jd}| |gdSrO) rrArKr3rfread_pctrXrr ZINVALID_ARGUMENTr6system_read_cache_pct_updater)rrZ lsm_systemrrrDrDrEr.s&z$CmdLine.system_read_cache_pct_updatecCs0t|j|jd}|j||j}t|dS)NrB)rrAr;Zfs_child_dependencyr/r)rrr;rYrDrDrE fs_dependants:szCmdLine.fs_dependantscCs2t|j|jd}|d|j||jddS)NrBr)rrAr;rcZfs_child_dependency_rmr/rerDrDrEfs_dependants_rm@szCmdLine.fs_dependants_rmc Csd}tjdd}tj|s$dSt|p}|D]Z}|drFq2z2dd|dd D\}}||vrvt|||Wq2t yYq20q2Wdn1s0YdS) zo Set uri from config file. Will be overridden by cmdline option or env var if present. )uri~z/.lsmcliN#cSsg|] }|qSrD)striprtrDrDrErqXrrz,CmdLine._read_configfile..=r.) rr expanduserexistsopenlstripr)rdr*rX)rZallowed_config_optionsZ config_pathfrrrzrDrDrE_read_configfileEs   zCmdLine._read_configfilecCs|jjjddtvrdSdS)zU Return True if current command is one of _CONNECTION_FREE_COMMANDS. rTrTF)rrrr$_CONNECTION_FREE_COMMANDSrrDrDrEis_connection_free_cmd^s zCmdLine.is_connection_free_cmdcCs4d|_d|_d|_d|_d|_||_d|_t|jj |_ |j rL|j dkrTt d| r`dS| tddurtd|_td|_|jjdur|jj|_|jdurd|jvr|jjdkrd|_d|_nt d|jjrt|_|jdurt|j}|d durt d |jjr0t||jjdS) Nrz0[-w|--wait] requires a non-zero positive integerZ LSMCLI_URIZLSMCLI_PASSWORDrrzsim://z"--uri missing or export LSMCLI_URIusernamez+password specified with no user name in uri)rrAr&Z unknown_argsrrBrcleanuprfrtmor2rrrgetenvpasswordrpromptgetpassrrr)rurDrDrErhs>          zCmdLine.__init__NcCs:|jr||jdur(|jd|_|r6t|dSr[)rrrr3r@)rZecrDrDrEr>s  zCmdLine.shutdowncCs|r|j|jn||rJt||_|j|j|j|j|jj |_ n4tt |j|j|j|_t drttd|jj|_ |j|j|dS)z- Process the parsed command. ZLSM_DEBUG_PLUGINz8Attach debugger to plug-in, press when ready...N)rrrrrAZplugin_registerrrrZplugin_unregisterrrrrinputrr>)rrBrDrDrEr1s    zCmdLine.processc Csg}tjtjtjtjtjtjtjd}tD]}dt j t j dt j t j t jd}|D]l}z|||||<WqXty}z:|jtjkrtjd||j||j|jfWYd}~qXd}~00qX|t||d|d|d|d|d|d |d q.||dS) N)rrpm link_type serial_num led_status link_speed health_statusrnzWARN: %s('%s'): %d %s rrrrrrr)rrZrpm_getZ link_type_getZserial_num_getZled_status_getZlink_speed_getZhealth_status_getrr ZRPM_NO_SUPPORTZLINK_TYPE_NO_SUPPORTZLED_STATUS_UNKNOWNZLINK_SPEED_UNKNOWNZHEALTH_STATUS_UNKNOWNrrr8r rr3r4r5rrr|rr)rrZ local_disksZ func_dictZ disk_pathZ info_dictrrrDrDrElocal_disk_listsH      zCmdLine.local_disk_listc Csbg}t8}|D]"}|t|||qWdn1sJ0Y||dSr[)rled_slots_openr|r!rrZdevicer)rrZlocal_led_slotsslotsr]rDrDrElocal_led_slot_lists $zCmdLine.local_led_slot_listcCs:t|j|jd}|t|jg|j|RgdSr_)rrArFr8rr rvolume_cache_inforrDrDrErszCmdLine.volume_cache_infocCs`t|j|jd}|jdkr&tj}ntj}|j||| t |j g|j |RgdSNr r) rrArFr8policyr ZREAD_CACHE_POLICY_ENABLEDZREAD_CACHE_POLICY_DISABLEDZ!volume_physical_disk_cache_updaterr rrrrrNrrDrDrEvolume_phy_disk_cache_updates z$CmdLine.volume_phy_disk_cache_updatecCs`t|j|jd}|jdkr&tj}ntj}|j||| t |j g|j |RgdSr) rrArFr8rr ZPHYSICAL_DISK_CACHE_ENABLEDZPHYSICAL_DISK_CACHE_DISABLEDvolume_read_cache_policy_updaterr rrrrDrDrEr s z'CmdLine.volume_read_cache_policy_updatecCsrt|j|jd}|jdkr&tj}n|jdkr8tj}ntj}|j ||| t |j g|j |RgdS)Nr rr)rrArFr8rr ZWRITE_CACHE_POLICY_WRITE_BACKZWRITE_CACHE_POLICY_AUTOZ WRITE_CACHE_POLICY_WRITE_THROUGH volume_write_cache_policy_updaterr rrrrDrDrEr s  z(CmdLine.volume_write_cache_policy_updatecCst|jdSr[)rZ ident_led_onrrYrDrDrElocal_disk_ident_led_on szCmdLine.local_disk_ident_led_oncCst|jdSr[)rZ ident_led_offrrYrDrDrElocal_disk_ident_led_off sz CmdLine.local_disk_ident_led_offcCst|jdSr[)rZ fault_led_onrrYrDrDrElocal_disk_fault_led_on# szCmdLine.local_disk_fault_led_oncCst|jdSr[)rZ fault_led_offrrYrDrDrElocal_disk_fault_led_off& sz CmdLine.local_disk_fault_led_offcCsptF}|D]0}||jkr||jWddSqWdn1sT0Ytd|jdS)NzLED slot id '%s' not found!)rrrZslotZ state_setrr2)rrrr]rDrDrElocal_led_slot_set) s   2zCmdLine.local_led_slot_set)N)N)Lrrrrrrr rr rrBr/r>rrRrWrZr[r]r^rarbrdrfrkrmrurgr{rr}r~rrrrrcrrrrrrrrrrrrrrrrrrrrrrrrrrr>r1rrrrrrrrrrrrDrDrDrEr0s    A  q          1   4  &    r0)N)F)rT)urrrrr3rrrrrJrIrrrrZsixZlsmrrrrr r r r r rrrrrrrrrZlsm.lsmcli.data_displayrrrrrrrrrr r!rZPY3rfrW collectionsr) ImportErrorZ ordereddictrrFrNrSrUrZrr^rjrrrrrrr?r2rrrrZ list_choicesZprovision_typesr~Zprovision_helpZreplicate_typesZreplicate_helpZ policy_typesZ policy_helprZ policy_optZwrite_cache_policy_typesZwrite_cache_policy_helpZwrite_cache_policy_optZ size_helpZ sys_id_optcopyZsys_id_filter_optZ pool_id_optZpool_id_filter_optZ vol_id_optZvol_id_filter_optZ fs_id_optZfs_id_filter_optZ ag_id_optZag_id_filter_optZ init_id_optZ snap_id_optZ export_id_optZnfs_export_id_filter_optZdisk_id_filter_optZsize_optZtgt_id_filter_optZlocal_disk_path_optZlocal_disk_led_slot_optZlocal_disk_led_slot_state_optZVOL_CREATE_RAID_TYPES_STRZANON_UID_GID_NArr objectr0rDrDrDrEs P4 -  * h   L        "        0  R+