<s> '''<STR_LIT>''' <EOL> try : <EOL> import ethtool <EOL> except ImportError : <EOL> ethtool = None <EOL> import os <EOL> import six <EOL> import stat <EOL> from configshell_fb import ExecutionError <EOL> from rtslib_fb import RTSLibBrokenLink , RTSLibError <EOL> from rtslib_fb import MappedLUN , NetworkPortal , NodeACL <EOL> from rtslib_fb import LUN , Target , TPG , StorageObjectFactory <EOL> from . ui_backstore import complete_path <EOL> from . ui_node import UINode , UIRTSLibNode <EOL> auth_params = ( '<STR_LIT>' , '<STR_LIT:password>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> discovery_params = auth_params + ( "<STR_LIT>" , ) <EOL> class UIFabricModule ( UIRTSLibNode ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , fabric_module , parent ) : <EOL> super ( UIFabricModule , self ) . __init__ ( fabric_module . name , <EOL> fabric_module , parent , <EOL> late_params = True ) <EOL> self . refresh ( ) <EOL> if self . rtsnode . has_feature ( '<STR_LIT>' ) : <EOL> for param in discovery_params : <EOL> self . define_config_group_param ( '<STR_LIT>' , <EOL> param , '<STR_LIT:string>' ) <EOL> self . refresh ( ) <EOL> def list_config_groups ( self ) : <EOL> groups = super ( UIFabricModule , self ) . list_config_groups ( ) <EOL> if len ( self . rtsnode . list_parameters ( ) ) : <EOL> groups . append ( '<STR_LIT>' ) <EOL> if len ( self . rtsnode . list_attributes ( ) ) : <EOL> groups . append ( '<STR_LIT>' ) <EOL> return groups <EOL> def list_group_params ( self , group , writable = None ) : <EOL> if group not in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> return super ( UIFabricModule , self ) . list_group_params ( group , <EOL> writable ) <EOL> params_func = getattr ( self . rtsnode , "<STR_LIT>" % group ) <EOL> params = params_func ( ) <EOL> params_ro = params_func ( writable = False ) <EOL> ret_list = [ ] <EOL> for param in params : <EOL> p_writable = param not in params_ro <EOL> if writable is not None and p_writable != writable : <EOL> continue <EOL> ret_list . append ( param ) <EOL> ret_list . sort ( ) <EOL> return ret_list <EOL> def get_group_param ( self , group , param ) : <EOL> if group not in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> return super ( UIFabricModule , self ) . get_group_param ( group , param ) <EOL> if param not in self . list_group_params ( group ) : <EOL> raise ValueError ( "<STR_LIT>" <EOL> % ( param , group ) ) <EOL> description = "<STR_LIT>" % ( param , group ) <EOL> writable = param in self . list_group_params ( group , writable = True ) <EOL> return dict ( name = param , group = group , type = "<STR_LIT:string>" , <EOL> description = description , writable = writable ) <EOL> def ui_getgroup_discovery_auth ( self , auth_attr ) : <EOL> '''<STR_LIT>''' <EOL> if auth_attr == '<STR_LIT>' : <EOL> return self . rtsnode . discovery_enable_auth <EOL> else : <EOL> return getattr ( self . rtsnode , "<STR_LIT>" + auth_attr ) <EOL> def ui_setgroup_discovery_auth ( self , auth_attr , value ) : <EOL> '''<STR_LIT>''' <EOL> self . assert_root ( ) <EOL> if value is None : <EOL> value = '<STR_LIT>' <EOL> if auth_attr == '<STR_LIT>' : <EOL> self . rtsnode . discovery_enable_auth = value <EOL> else : <EOL> setattr ( self . rtsnode , "<STR_LIT>" + auth_attr , value ) <EOL> def refresh ( self ) : <EOL> self . _children = set ( [ ] ) <EOL> for target in self . rtsnode . targets : <EOL> self . shell . log . debug ( "<STR_LIT>" <EOL> % ( target . wwn , target . fabric_module ) ) <EOL> if target . has_feature ( '<STR_LIT>' ) : <EOL> UIMultiTPGTarget ( target , self ) <EOL> else : <EOL> UITarget ( target , self ) <EOL> def summary ( self ) : <EOL> status = None <EOL> msg = [ ] <EOL> fm = self . rtsnode <EOL> if fm . has_feature ( '<STR_LIT>' ) and fm . discovery_enable_auth : <EOL> if not ( fm . discovery_password and fm . discovery_userid ) : <EOL> status = False <EOL> else : <EOL> status = True <EOL> if fm . discovery_authenticate_target : <EOL> msg . append ( "<STR_LIT>" ) <EOL> else : <EOL> msg . append ( "<STR_LIT>" ) <EOL> msg . append ( "<STR_LIT>" % len ( self . _children ) ) <EOL> return ( "<STR_LIT:U+002CU+0020>" . join ( msg ) , status ) <EOL> def ui_command_create ( self , wwn = None ) : <EOL> '''<STR_LIT>''' <EOL> self . assert_root ( ) <EOL> target = Target ( self . rtsnode , wwn , mode = '<STR_LIT>' ) <EOL> wwn = target . wwn <EOL> if self . rtsnode . wwns != None and wwn not in self . rtsnode . wwns : <EOL> self . shell . log . warning ( "<STR_LIT>" ) <EOL> if target . has_feature ( '<STR_LIT>' ) : <EOL> ui_target = UIMultiTPGTarget ( target , self ) <EOL> self . shell . log . info ( "<STR_LIT>" % wwn ) <EOL> return ui_target . ui_command_create ( ) <EOL> else : <EOL> ui_target = UITarget ( target , self ) <EOL> self . shell . log . info ( "<STR_LIT>" % wwn ) <EOL> return self . new_node ( ui_target ) <EOL> def ui_complete_create ( self , parameters , text , current_param ) : <EOL> '''<STR_LIT>''' <EOL> if current_param == '<STR_LIT>' and self . rtsnode . wwns is not None : <EOL> existing_wwns = [ child . wwn for child in self . rtsnode . targets ] <EOL> completions = [ wwn for wwn in self . rtsnode . wwns <EOL> if wwn . startswith ( text ) <EOL> if wwn not in existing_wwns ] <EOL> else : <EOL> completions = [ ] <EOL> if len ( completions ) == <NUM_LIT:1> : <EOL> return [ completions [ <NUM_LIT:0> ] + '<STR_LIT:U+0020>' ] <EOL> else : <EOL> return completions <EOL> def ui_command_delete ( self , wwn ) : <EOL> '''<STR_LIT>''' <EOL> self . assert_root ( ) <EOL> target = Target ( self . rtsnode , wwn , mode = '<STR_LIT>' ) <EOL> target . delete ( ) <EOL> self . shell . log . info ( "<STR_LIT>" % wwn ) <EOL> self . refresh ( ) <EOL> def ui_complete_delete ( self , parameters , text , current_param ) : <EOL> '''<STR_LIT>''' <EOL> if current_param == '<STR_LIT>' : <EOL> wwns = [ child . name for child in self . children ] <EOL> completions = [ wwn for wwn in wwns if wwn . startswith ( text ) ] <EOL> else : <EOL> completions = [ ] <EOL> if len ( completions ) == <NUM_LIT:1> : <EOL> return [ completions [ <NUM_LIT:0> ] + '<STR_LIT:U+0020>' ] <EOL> else : <EOL> return completions <EOL> def ui_command_info ( self ) : <EOL> '''<STR_LIT>''' <EOL> fabric = self . rtsnode <EOL> self . shell . log . info ( "<STR_LIT>" % self . name ) <EOL> self . shell . log . info ( "<STR_LIT>" % self . rtsnode . path ) <EOL> self . shell . log . info ( "<STR_LIT>" % "<STR_LIT:U+002CU+0020>" . join ( fabric . wwn_types ) ) <EOL> if fabric . wwns is not None : <EOL> self . shell . log . info ( "<STR_LIT>" % '<STR_LIT:U+002CU+0020>' . join ( fabric . wwns ) ) <EOL> self . shell . log . info ( "<STR_LIT>" % '<STR_LIT:U+002CU+0020>' . join ( fabric . features ) ) <EOL> self . shell . log . info ( "<STR_LIT>" <EOL> % fabric . kernel_module ) <EOL> def ui_command_version ( self ) : <EOL> '''<STR_LIT>''' <EOL> version = "<STR_LIT>" % ( self . rtsnode . name , self . rtsnode . version ) <EOL> self . shell . con . display ( version . strip ( ) ) <EOL> class UIMultiTPGTarget ( UIRTSLibNode ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , target , parent ) : <EOL> super ( UIMultiTPGTarget , self ) . __init__ ( target . wwn , target , parent ) <EOL> self . refresh ( ) <EOL> def refresh ( self ) : <EOL> self . _children = set ( [ ] ) <EOL> for tpg in self . rtsnode . tpgs : <EOL> UITPG ( tpg , self ) <EOL> def summary ( self ) : <EOL> try : <EOL> self . rtsnode . fabric_module . to_normalized_wwn ( self . rtsnode . wwn ) <EOL> except : <EOL> return ( "<STR_LIT>" , False ) <EOL> return ( "<STR_LIT>" % len ( self . _children ) , None ) <EOL> def ui_command_create ( self , tag = None ) : <EOL> '''<STR_LIT>''' <EOL> self . assert_root ( ) <EOL> if tag : <EOL> if tag . startswith ( "<STR_LIT>" ) : <EOL> tag = tag [ <NUM_LIT:3> : ] <EOL> try : <EOL> tag = int ( tag ) <EOL> except ValueError : <EOL> raise ExecutionError ( "<STR_LIT>" ) <EOL> tpg = TPG ( self . rtsnode , tag , mode = '<STR_LIT>' ) <EOL> if self . shell . prefs [ '<STR_LIT>' ] : <EOL> tpg . enable = True <EOL> if tpg . has_feature ( "<STR_LIT>" ) : <EOL> tpg . set_attribute ( "<STR_LIT>" , <NUM_LIT:0> ) <EOL> self . shell . log . info ( "<STR_LIT>" % tpg . tag ) <EOL> if tpg . has_feature ( "<STR_LIT>" ) and self . shell . prefs [ '<STR_LIT>' ] : <EOL> try : <EOL> NetworkPortal ( tpg , "<STR_LIT>" ) <EOL> self . shell . log . info ( "<STR_LIT>" ) <EOL> self . shell . log . info ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> except RTSLibError : <EOL> self . shell . log . info ( "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> ui_tpg = UITPG ( tpg , self ) <EOL> return self . new_node ( ui_tpg ) <EOL> def ui_command_delete ( self , tag ) : <EOL> '''<STR_LIT>''' <EOL> self . assert_root ( ) <EOL> if tag . startswith ( "<STR_LIT>" ) : <EOL> tag = tag [ <NUM_LIT:3> : ] <EOL> try : <EOL> tag = int ( tag ) <EOL> except ValueError : <EOL> raise ExecutionError ( "<STR_LIT>" ) <EOL> tpg = TPG ( self . rtsnode , tag , mode = '<STR_LIT>' ) <EOL> tpg . delete ( ) <EOL> self . shell . log . info ( "<STR_LIT>" % tag ) <EOL> self . refresh ( ) <EOL> def ui_complete_delete ( self , parameters , text , current_param ) : <EOL> '''<STR_LIT>''' <EOL> if current_param == '<STR_LIT>' : <EOL> tags = [ child . name [ <NUM_LIT:4> : ] for child in self . children ] <EOL> completions = [ tag for tag in tags if tag . startswith ( text ) ] <EOL> else : <EOL> completions = [ ] <EOL> if len ( completions ) == <NUM_LIT:1> : <EOL> return [ completions [ <NUM_LIT:0> ] + '<STR_LIT:U+0020>' ] <EOL> else : <EOL> return completions <EOL> class UITPG ( UIRTSLibNode ) : <EOL> ui_desc_attributes = { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> } <EOL> ui_desc_parameters = { <EOL> '<STR_LIT>' : ( '<STR_LIT:string>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:string>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:string>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:string>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:string>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:string>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:string>' , '<STR_LIT>' ) , <EOL> } <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , tpg , parent ) : <EOL> name = "<STR_LIT>" % tpg . tag <EOL> super ( UITPG , self ) . __init__ ( name , tpg , parent ) <EOL> self . refresh ( ) <EOL> UILUNs ( tpg , self ) <EOL> if tpg . has_feature ( '<STR_LIT>' ) : <EOL> UINodeACLs ( self . rtsnode , self ) <EOL> if tpg . has_feature ( '<STR_LIT>' ) : <EOL> UIPortals ( self . rtsnode , self ) <EOL> if self . rtsnode . has_feature ( '<STR_LIT>' ) and os . path . exists ( self . rtsnode . path + "<STR_LIT>" ) : <EOL> for param in auth_params : <EOL> self . define_config_group_param ( '<STR_LIT>' , param , '<STR_LIT:string>' ) <EOL> def summary ( self ) : <EOL> tpg = self . rtsnode <EOL> status = None <EOL> msg = [ ] <EOL> if tpg . has_feature ( '<STR_LIT>' ) : <EOL> msg . append ( str ( self . rtsnode . nexus ) ) <EOL> if not tpg . enable : <EOL> return ( "<STR_LIT>" , False ) <EOL> if tpg . has_feature ( "<STR_LIT>" ) : <EOL> if "<STR_LIT>" in tpg . list_attributes ( ) and int ( tpg . get_attribute ( "<STR_LIT>" ) ) : <EOL> msg . append ( "<STR_LIT>" ) <EOL> else : <EOL> msg . append ( "<STR_LIT>" ) <EOL> if tpg . has_feature ( "<STR_LIT>" ) : <EOL> if not int ( tpg . get_attribute ( "<STR_LIT>" ) ) : <EOL> msg . append ( "<STR_LIT>" ) <EOL> if int ( tpg . get_attribute ( "<STR_LIT>" ) ) : <EOL> status = True <EOL> else : <EOL> if not int ( tpg . get_attribute ( "<STR_LIT>" ) ) : <EOL> msg . append ( "<STR_LIT>" ) <EOL> else : <EOL> msg . append ( "<STR_LIT>" ) <EOL> status = True <EOL> if not ( tpg . chap_password and tpg . chap_userid ) : <EOL> status = False <EOL> if tpg . authenticate_target : <EOL> msg . append ( "<STR_LIT>" ) <EOL> else : <EOL> msg . append ( "<STR_LIT>" ) <EOL> return ( "<STR_LIT:U+002CU+0020>" . join ( msg ) , status ) <EOL> def ui_getgroup_auth ( self , auth_attr ) : <EOL> return getattr ( self . rtsnode , "<STR_LIT>" + auth_attr ) <EOL> def ui_setgroup_auth ( self , auth_attr , value ) : <EOL> self . assert_root ( ) <EOL> if value is None : <EOL> value = '<STR_LIT>' <EOL> setattr ( self . rtsnode , "<STR_LIT>" + auth_attr , value ) <EOL> def ui_command_enable ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assert_root ( ) <EOL> if self . rtsnode . enable : <EOL> self . shell . log . info ( "<STR_LIT>" ) <EOL> else : <EOL> try : <EOL> self . rtsnode . enable = True <EOL> self . shell . log . info ( "<STR_LIT>" ) <EOL> except RTSLibError : <EOL> raise ExecutionError ( "<STR_LIT>" ) <EOL> def ui_command_disable ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assert_root ( ) <EOL> if self . rtsnode . enable : <EOL> self . rtsnode . enable = False <EOL> self . shell . log . info ( "<STR_LIT>" ) <EOL> else : <EOL> self . shell . log . info ( "<STR_LIT>" ) <EOL> class UITarget ( UITPG ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , target , parent ) : <EOL> super ( UITarget , self ) . __init__ ( TPG ( target , <NUM_LIT:1> ) , parent ) <EOL> self . _name = target . wwn <EOL> self . target = target <EOL> if self . parent . name != "<STR_LIT>" : <EOL> self . rtsnode . enable = True <EOL> def summary ( self ) : <EOL> try : <EOL> self . target . fabric_module . to_normalized_wwn ( self . target . wwn ) <EOL> except : <EOL> return ( "<STR_LIT>" , False ) <EOL> return super ( UITarget , self ) . summary ( ) <EOL> class UINodeACLs ( UINode ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , tpg , parent ) : <EOL> super ( UINodeACLs , self ) . __init__ ( "<STR_LIT>" , parent ) <EOL> self . tpg = tpg <EOL> self . refresh ( ) <EOL> def refresh ( self ) : <EOL> self . _children = set ( [ ] ) <EOL> for name in self . all_names ( ) : <EOL> UINodeACL ( name , self ) <EOL> def summary ( self ) : <EOL> return ( "<STR_LIT>" % len ( self . _children ) , None ) <EOL> def ui_command_create ( self , wwn , add_mapped_luns = None ) : <EOL> '''<STR_LIT>''' <EOL> self . assert_root ( ) <EOL> add_mapped_luns = self . ui_eval_param ( add_mapped_luns , '<STR_LIT:bool>' , <EOL> self . shell . prefs [ '<STR_LIT>' ] ) <EOL> node_acl = NodeACL ( self . tpg , wwn , mode = "<STR_LIT>" ) <EOL> ui_node_acl = UINodeACL ( node_acl . node_wwn , self ) <EOL> self . shell . log . info ( "<STR_LIT>" % node_acl . node_wwn ) <EOL> if add_mapped_luns : <EOL> for lun in self . tpg . luns : <EOL> MappedLUN ( node_acl , lun . lun , lun . lun , write_protect = False ) <EOL> self . shell . log . info ( "<STR_LIT>" % lun . lun ) <EOL> self . refresh ( ) <EOL> return self . new_node ( ui_node_acl ) <EOL> def ui_command_delete ( self , wwn ) : <EOL> '''<STR_LIT>''' <EOL> self . assert_root ( ) <EOL> node_acl = NodeACL ( self . tpg , wwn , mode = '<STR_LIT>' ) <EOL> node_acl . delete ( ) <EOL> self . shell . log . info ( "<STR_LIT>" % wwn ) <EOL> self . refresh ( ) <EOL> def ui_complete_delete ( self , parameters , text , current_param ) : <EOL> '''<STR_LIT>''' <EOL> if current_param == '<STR_LIT>' : <EOL> wwns = [ acl . node_wwn for acl in self . tpg . node_acls ] <EOL> completions = [ wwn for wwn in wwns if wwn . startswith ( text ) ] <EOL> else : <EOL> completions = [ ] <EOL> if len ( completions ) == <NUM_LIT:1> : <EOL> return [ completions [ <NUM_LIT:0> ] + '<STR_LIT:U+0020>' ] <EOL> else : <EOL> return completions <EOL> def find_tagged ( self , name ) : <EOL> for na in self . tpg . node_acls : <EOL> if na . node_wwn == name : <EOL> yield na <EOL> elif na . tag == name : <EOL> yield na <EOL> def all_names ( self ) : <EOL> names = set ( [ ] ) <EOL> for na in self . tpg . node_acls : <EOL> if na . tag : <EOL> names . add ( na . tag ) <EOL> else : <EOL> names . add ( na . node_wwn ) <EOL> return names <EOL> def ui_command_tag ( self , wwn_or_tag , new_tag ) : <EOL> '''<STR_LIT>''' <EOL> if wwn_or_tag == new_tag : <EOL> return <EOL> if '<STR_LIT:.>' in new_tag : <EOL> raise ExecutionError ( "<STR_LIT>" ) <EOL> src = list ( self . find_tagged ( wwn_or_tag ) ) <EOL> if not src : <EOL> raise ExecutionError ( "<STR_LIT>" % wwn_or_tag ) <EOL> old_tag_members = list ( self . find_tagged ( new_tag ) ) <EOL> src_wwns = [ na . node_wwn for na in src ] <EOL> old_tag_members = [ old for old in old_tag_members if old . node_wwn not in src_wwns ] <EOL> for na in src : <EOL> na . tag = new_tag <EOL> if old_tag_members : <EOL> model = old_tag_members [ <NUM_LIT:0> ] <EOL> for mlun in na . mapped_luns : <EOL> mlun . delete ( ) <EOL> for mlun in model . mapped_luns : <EOL> MappedLUN ( na , mlun . mapped_lun , mlun . tpg_lun , mlun . write_protect ) <EOL> if self . parent . rtsnode . has_feature ( "<STR_LIT>" ) : <EOL> for param in auth_params : <EOL> setattr ( na , "<STR_LIT>" + param , getattr ( model , "<STR_LIT>" + param ) ) <EOL> for item in model . list_attributes ( writable = True ) : <EOL> na . set_attribute ( item , model . get_attribute ( item ) ) <EOL> for item in model . list_parameters ( writable = True ) : <EOL> na . set_parameter ( item , model . get_parameter ( item ) ) <EOL> self . refresh ( ) <EOL> def ui_command_untag ( self , wwn_or_tag ) : <EOL> '''<STR_LIT>''' <EOL> for na in list ( self . find_tagged ( wwn_or_tag ) ) : <EOL> na . tag = None <EOL> self . refresh ( ) <EOL> def ui_complete_tag ( self , parameters , text , current_param ) : <EOL> '''<STR_LIT>''' <EOL> if current_param == '<STR_LIT>' : <EOL> completions = [ n for n in self . all_names ( ) if n . startswith ( text ) ] <EOL> else : <EOL> completions = [ ] <EOL> if len ( completions ) == <NUM_LIT:1> : <EOL> return [ completions [ <NUM_LIT:0> ] + '<STR_LIT:U+0020>' ] <EOL> else : <EOL> return completions <EOL> ui_complete_untag = ui_complete_tag <EOL> class UINodeACL ( UIRTSLibNode ) : <EOL> '''<STR_LIT>''' <EOL> ui_desc_attributes = { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> } <EOL> ui_desc_parameters = UITPG . ui_desc_parameters <EOL> def __init__ ( self , name , parent ) : <EOL> self . rtsnodes = list ( parent . find_tagged ( name ) ) <EOL> super ( UINodeACL , self ) . __init__ ( name , self . rtsnodes [ <NUM_LIT:0> ] , parent ) <EOL> del self . rtsnode <EOL> if self . parent . parent . rtsnode . has_feature ( '<STR_LIT>' ) : <EOL> for parameter in auth_params : <EOL> self . define_config_group_param ( '<STR_LIT>' , parameter , '<STR_LIT:string>' ) <EOL> self . refresh ( ) <EOL> def ui_getgroup_auth ( self , auth_attr ) : <EOL> '''<STR_LIT>''' <EOL> return getattr ( self . rtsnodes [ <NUM_LIT:0> ] , "<STR_LIT>" + auth_attr ) <EOL> def ui_setgroup_auth ( self , auth_attr , value ) : <EOL> '''<STR_LIT>''' <EOL> self . assert_root ( ) <EOL> if value is None : <EOL> value = '<STR_LIT>' <EOL> for na in self . rtsnodes : <EOL> setattr ( na , "<STR_LIT>" + auth_attr , value ) <EOL> def refresh ( self ) : <EOL> self . _children = set ( [ ] ) <EOL> for mlun in self . rtsnodes [ <NUM_LIT:0> ] . mapped_luns : <EOL> UIMappedLUN ( mlun , self ) <EOL> def summary ( self ) : <EOL> msg = [ ] <EOL> if self . name != self . rtsnodes [ <NUM_LIT:0> ] . node_wwn : <EOL> if len ( self . rtsnodes ) > <NUM_LIT:1> : <EOL> msg . append ( "<STR_LIT>" % len ( self . rtsnodes ) ) <EOL> else : <EOL> msg . append ( "<STR_LIT>" % self . rtsnodes [ <NUM_LIT:0> ] . node_wwn ) <EOL> status = None <EOL> na = self . rtsnodes [ <NUM_LIT:0> ] <EOL> tpg = self . parent . parent . rtsnode <EOL> if tpg . has_feature ( "<STR_LIT>" ) and int ( tpg . get_attribute ( "<STR_LIT>" ) ) : <EOL> if int ( tpg . get_attribute ( "<STR_LIT>" ) ) : <EOL> msg . append ( "<STR_LIT>" ) <EOL> else : <EOL> status = True <EOL> if not ( na . chap_password and na . chap_userid ) : <EOL> status = False <EOL> if na . authenticate_target : <EOL> msg . append ( "<STR_LIT>" ) <EOL> else : <EOL> msg . append ( "<STR_LIT>" ) <EOL> msg . append ( "<STR_LIT>" % len ( self . _children ) ) <EOL> return ( "<STR_LIT:U+002CU+0020>" . join ( msg ) , status ) <EOL> def ui_command_create ( self , mapped_lun , tpg_lun_or_backstore , write_protect = None ) : <EOL> '''<STR_LIT>''' <EOL> self . assert_root ( ) <EOL> try : <EOL> mapped_lun = int ( mapped_lun ) <EOL> except ValueError : <EOL> raise ExecutionError ( "<STR_LIT>" ) <EOL> try : <EOL> if tpg_lun_or_backstore . startswith ( "<STR_LIT>" ) : <EOL> tpg_lun_or_backstore = tpg_lun_or_backstore [ <NUM_LIT:3> : ] <EOL> tpg_lun = int ( tpg_lun_or_backstore ) <EOL> except ValueError : <EOL> try : <EOL> so = self . get_node ( tpg_lun_or_backstore ) . rtsnode <EOL> except ValueError : <EOL> try : <EOL> so = StorageObjectFactory ( tpg_lun_or_backstore ) <EOL> self . shell . log . info ( "<STR_LIT>" % so . name ) <EOL> except RTSLibError : <EOL> raise ExecutionError ( "<STR_LIT>" ) <EOL> self . get_node ( "<STR_LIT>" ) . refresh ( ) <EOL> ui_tpg = self . parent . parent <EOL> for lun in ui_tpg . rtsnode . luns : <EOL> if so == lun . storage_object : <EOL> tpg_lun = lun . lun <EOL> break <EOL> else : <EOL> lun_object = LUN ( ui_tpg . rtsnode , storage_object = so ) <EOL> self . shell . log . info ( "<STR_LIT>" % lun_object . lun ) <EOL> ui_lun = UILUN ( lun_object , ui_tpg . get_node ( "<STR_LIT>" ) ) <EOL> tpg_lun = ui_lun . rtsnode . lun <EOL> if tpg_lun in ( ml . tpg_lun . lun for ml in self . rtsnodes [ <NUM_LIT:0> ] . mapped_luns ) : <EOL> self . shell . log . warning ( <EOL> "<STR_LIT>" % tpg_lun ) <EOL> for na in self . rtsnodes : <EOL> mlun = MappedLUN ( na , mapped_lun , tpg_lun , write_protect ) <EOL> ui_mlun = UIMappedLUN ( mlun , self ) <EOL> self . shell . log . info ( "<STR_LIT>" % mlun . mapped_lun ) <EOL> return self . new_node ( ui_mlun ) <EOL> def ui_complete_create ( self , parameters , text , current_param ) : <EOL> '''<STR_LIT>''' <EOL> if current_param == '<STR_LIT>' : <EOL> completions = [ ] <EOL> for backstore in self . get_node ( '<STR_LIT>' ) . children : <EOL> for storage_object in backstore . children : <EOL> completions . append ( storage_object . path ) <EOL> completions . extend ( lun . name for lun in self . parent . parent . get_node ( "<STR_LIT>" ) . children ) <EOL> completions . extend ( complete_path ( text , lambda x : stat . S_ISREG ( x ) or stat . S_ISBLK ( x ) ) ) <EOL> completions = [ c for c in completions if c . startswith ( text ) ] <EOL> else : <EOL> completions = [ ] <EOL> if len ( completions ) == <NUM_LIT:1> : <EOL> return [ completions [ <NUM_LIT:0> ] + '<STR_LIT:U+0020>' ] <EOL> else : <EOL> return completions <EOL> def ui_command_delete ( self , mapped_lun ) : <EOL> '''<STR_LIT>''' <EOL> self . assert_root ( ) <EOL> for na in self . rtsnodes : <EOL> mlun = MappedLUN ( na , mapped_lun ) <EOL> mlun . delete ( ) <EOL> self . shell . log . info ( "<STR_LIT>" % mapped_lun ) <EOL> self . refresh ( ) <EOL> def ui_complete_delete ( self , parameters , text , current_param ) : <EOL> '''<STR_LIT>''' <EOL> if current_param == '<STR_LIT>' : <EOL> mluns = [ str ( mlun . mapped_lun ) for mlun in self . rtsnodes [ <NUM_LIT:0> ] . mapped_luns ] <EOL> completions = [ mlun for mlun in mluns if mlun . startswith ( text ) ] <EOL> else : <EOL> completions = [ ] <EOL> if len ( completions ) == <NUM_LIT:1> : <EOL> return [ completions [ <NUM_LIT:0> ] + '<STR_LIT:U+0020>' ] <EOL> else : <EOL> return completions <EOL> def ui_getgroup_attribute ( self , attribute ) : <EOL> return self . rtsnodes [ <NUM_LIT:0> ] . get_attribute ( attribute ) <EOL> def ui_setgroup_attribute ( self , attribute , value ) : <EOL> self . assert_root ( ) <EOL> for na in self . rtsnodes : <EOL> na . set_attribute ( attribute , value ) <EOL> def ui_getgroup_parameter ( self , parameter ) : <EOL> return self . rtsnodes [ <NUM_LIT:0> ] . get_parameter ( parameter ) <EOL> def ui_setgroup_parameter ( self , parameter , value ) : <EOL> self . assert_root ( ) <EOL> for na in self . rtsnodes : <EOL> na . set_parameter ( parameter , value ) <EOL> def ui_command_info ( self ) : <EOL> '''<STR_LIT>''' <EOL> info = self . rtsnodes [ <NUM_LIT:0> ] . dump ( ) <EOL> for item in ( '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" ) : <EOL> if item in info : <EOL> del info [ item ] <EOL> for name , value in sorted ( six . iteritems ( info ) ) : <EOL> if not isinstance ( value , ( dict , list ) ) : <EOL> self . shell . log . info ( "<STR_LIT>" % ( name , value ) ) <EOL> self . shell . log . info ( "<STR_LIT>" ) <EOL> for na in self . parent . find_tagged ( self . name ) : <EOL> self . shell . log . info ( na . node_wwn ) <EOL> class UIMappedLUN ( UIRTSLibNode ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , mapped_lun , parent ) : <EOL> name = "<STR_LIT>" % mapped_lun . mapped_lun <EOL> super ( UIMappedLUN , self ) . __init__ ( name , mapped_lun , parent ) <EOL> self . refresh ( ) <EOL> def summary ( self ) : <EOL> mapped_lun = self . rtsnode <EOL> is_healthy = True <EOL> try : <EOL> tpg_lun = mapped_lun . tpg_lun <EOL> except RTSLibBrokenLink : <EOL> description = "<STR_LIT>" <EOL> is_healthy = False <EOL> else : <EOL> if mapped_lun . write_protect : <EOL> access_mode = '<STR_LIT>' <EOL> else : <EOL> access_mode = '<STR_LIT>' <EOL> description = "<STR_LIT>" % ( tpg_lun . lun , tpg_lun . storage_object . plugin , <EOL> tpg_lun . storage_object . name , access_mode ) <EOL> return ( description , is_healthy ) <EOL> class UILUNs ( UINode ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , tpg , parent ) : <EOL> super ( UILUNs , self ) . __init__ ( "<STR_LIT>" , parent ) <EOL> self . tpg = tpg <EOL> self . refresh ( ) <EOL> def refresh ( self ) : <EOL> self . _children = set ( [ ] ) <EOL> for lun in self . tpg . luns : <EOL> UILUN ( lun , self ) <EOL> def summary ( self ) : <EOL> return ( "<STR_LIT>" % len ( self . _children ) , None ) <EOL> def ui_command_create ( self , storage_object , lun = None , <EOL> add_mapped_luns = None ) : <EOL> '''<STR_LIT>''' <EOL> self . assert_root ( ) <EOL> add_mapped_luns = self . ui_eval_param ( add_mapped_luns , '<STR_LIT:bool>' , <EOL> self . shell . prefs [ '<STR_LIT>' ] ) <EOL> try : <EOL> so = self . get_node ( storage_object ) . rtsnode <EOL> except ValueError : <EOL> try : <EOL> so = StorageObjectFactory ( storage_object ) <EOL> self . shell . log . info ( "<STR_LIT>" % so . name ) <EOL> except RTSLibError : <EOL> raise ExecutionError ( "<STR_LIT>" ) <EOL> self . get_node ( "<STR_LIT>" ) . refresh ( ) <EOL> if so in ( l . storage_object for l in self . parent . rtsnode . luns ) : <EOL> raise ExecutionError ( "<STR_LIT>" % ( so . plugin , so . name ) ) <EOL> if lun and lun . lower ( ) . startswith ( '<STR_LIT>' ) : <EOL> lun = lun [ <NUM_LIT:3> : ] <EOL> lun_object = LUN ( self . tpg , lun , so ) <EOL> self . shell . log . info ( "<STR_LIT>" % lun_object . lun ) <EOL> ui_lun = UILUN ( lun_object , self ) <EOL> if add_mapped_luns : <EOL> for acl in self . tpg . node_acls : <EOL> if lun : <EOL> mapped_lun = lun <EOL> else : <EOL> mapped_lun = <NUM_LIT:0> <EOL> existing_mluns = [ mlun . mapped_lun for mlun in acl . mapped_luns ] <EOL> if mapped_lun in existing_mluns : <EOL> mapped_lun = None <EOL> for possible_mlun in six . moves . range ( LUN . MAX_LUN ) : <EOL> if possible_mlun not in existing_mluns : <EOL> mapped_lun = possible_mlun <EOL> break <EOL> if mapped_lun == None : <EOL> self . shell . log . warning ( <EOL> "<STR_LIT>" <EOL> % ( lun_object . lun , acl . node_wwn ) ) <EOL> else : <EOL> mlun = MappedLUN ( acl , mapped_lun , lun_object , write_protect = False ) <EOL> self . shell . log . info ( "<STR_LIT>" <EOL> % ( mlun . tpg_lun . lun , mlun . mapped_lun , acl . node_wwn ) ) <EOL> self . parent . refresh ( ) <EOL> return self . new_node ( ui_lun ) <EOL> def ui_complete_create ( self , parameters , text , current_param ) : <EOL> '''<STR_LIT>''' <EOL> if current_param == '<STR_LIT>' : <EOL> storage_objects = [ ] <EOL> for backstore in self . get_node ( '<STR_LIT>' ) . children : <EOL> for storage_object in backstore . children : <EOL> storage_objects . append ( storage_object . path ) <EOL> completions = [ so for so in storage_objects if so . startswith ( text ) ] <EOL> completions . extend ( complete_path ( text , lambda x : stat . S_ISREG ( x ) or stat . S_ISBLK ( x ) ) ) <EOL> else : <EOL> completions = [ ] <EOL> if len ( completions ) == <NUM_LIT:1> : <EOL> return [ completions [ <NUM_LIT:0> ] + '<STR_LIT:U+0020>' ] <EOL> else : <EOL> return completions <EOL> def ui_command_delete ( self , lun ) : <EOL> '''<STR_LIT>''' <EOL> self . assert_root ( ) <EOL> if lun . lower ( ) . startswith ( "<STR_LIT>" ) : <EOL> lun = lun [ <NUM_LIT:3> : ] <EOL> try : <EOL> lun_object = LUN ( self . tpg , lun ) <EOL> except : <EOL> raise RTSLibError ( "<STR_LIT>" ) <EOL> lun_object . delete ( ) <EOL> self . shell . log . info ( "<STR_LIT>" % lun ) <EOL> self . parent . refresh ( ) <EOL> def ui_complete_delete ( self , parameters , text , current_param ) : <EOL> '''<STR_LIT>''' <EOL> if current_param == '<STR_LIT>' : <EOL> luns = [ str ( lun . lun ) for lun in self . tpg . luns ] <EOL> completions = [ lun for lun in luns if lun . startswith ( text ) ] <EOL> else : <EOL> completions = [ ] <EOL> if len ( completions ) == <NUM_LIT:1> : <EOL> return [ completions [ <NUM_LIT:0> ] + '<STR_LIT:U+0020>' ] <EOL> else : <EOL> return completions <EOL> class UILUN ( UIRTSLibNode ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , lun , parent ) : <EOL> name = "<STR_LIT>" % lun . lun <EOL> super ( UILUN , self ) . __init__ ( name , lun , parent ) <EOL> self . refresh ( ) <EOL> def summary ( self ) : <EOL> lun = self . rtsnode <EOL> is_healthy = True <EOL> try : <EOL> storage_object = lun . storage_object <EOL> except RTSLibBrokenLink : <EOL> description = "<STR_LIT>" <EOL> is_healthy = False <EOL> else : <EOL> description = "<STR_LIT>" % ( storage_object . plugin , storage_object . name , ) <EOL> if storage_object . udev_path : <EOL> description += "<STR_LIT>" % storage_object . udev_path <EOL> return ( description , is_healthy ) <EOL> class UIPortals ( UINode ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , tpg , parent ) : <EOL> super ( UIPortals , self ) . __init__ ( "<STR_LIT>" , parent ) <EOL> self . tpg = tpg <EOL> self . refresh ( ) <EOL> def refresh ( self ) : <EOL> self . _children = set ( [ ] ) <EOL> for portal in self . tpg . network_portals : <EOL> UIPortal ( portal , self ) <EOL> def summary ( self ) : <EOL> return ( "<STR_LIT>" % len ( self . _children ) , None ) <EOL> def _canonicalize_ip ( self , ip_address ) : <EOL> """<STR_LIT>""" <EOL> if "<STR_LIT:.>" in ip_address : <EOL> return ip_address <EOL> return "<STR_LIT:[>" + ip_address + "<STR_LIT:]>" <EOL> def ui_command_create ( self , ip_address = None , ip_port = None ) : <EOL> '''<STR_LIT>''' <EOL> self . assert_root ( ) <EOL> ip_port = self . ui_eval_param ( ip_port , '<STR_LIT>' , <NUM_LIT> ) <EOL> ip_address = self . ui_eval_param ( ip_address , '<STR_LIT:string>' , "<STR_LIT>" ) <EOL> if ip_port == <NUM_LIT> : <EOL> self . shell . log . info ( "<STR_LIT>" % ip_port ) <EOL> if ip_address == "<STR_LIT>" : <EOL> self . shell . log . info ( "<STR_LIT>" ) <EOL> portal = NetworkPortal ( self . tpg , self . _canonicalize_ip ( ip_address ) , <EOL> ip_port , mode = '<STR_LIT>' ) <EOL> self . shell . log . info ( "<STR_LIT>" <EOL> % ( ip_address , ip_port ) ) <EOL> ui_portal = UIPortal ( portal , self ) <EOL> return self . new_node ( ui_portal ) <EOL> def ui_complete_create ( self , parameters , text , current_param ) : <EOL> '''<STR_LIT>''' <EOL> def list_eth_ips ( ) : <EOL> if not ethtool : <EOL> return [ ] <EOL> devcfgs = ethtool . get_interfaces_info ( ethtool . get_devices ( ) ) <EOL> addrs = set ( ) <EOL> for d in devcfgs : <EOL> if d . ipv4_address : <EOL> addrs . add ( d . ipv4_address ) <EOL> addrs . add ( "<STR_LIT>" ) <EOL> for ip6 in d . get_ipv6_addresses ( ) : <EOL> addrs . add ( ip6 . address ) <EOL> addrs . add ( "<STR_LIT>" ) <EOL> return sorted ( addrs ) <EOL> if current_param == '<STR_LIT>' : <EOL> completions = [ addr for addr in list_eth_ips ( ) <EOL> if addr . startswith ( text ) ] <EOL> else : <EOL> completions = [ ] <EOL> if len ( completions ) == <NUM_LIT:1> : <EOL> return [ completions [ <NUM_LIT:0> ] + '<STR_LIT:U+0020>' ] <EOL> else : <EOL> return completions <EOL> def ui_command_delete ( self , ip_address , ip_port ) : <EOL> '''<STR_LIT>''' <EOL> self . assert_root ( ) <EOL> portal = NetworkPortal ( self . tpg , self . _canonicalize_ip ( ip_address ) , <EOL> ip_port , mode = '<STR_LIT>' ) <EOL> portal . delete ( ) <EOL> self . shell . log . info ( "<STR_LIT>" <EOL> % ( ip_address , ip_port ) ) <EOL> self . refresh ( ) <EOL> def ui_complete_delete ( self , parameters , text , current_param ) : <EOL> '''<STR_LIT>''' <EOL> completions = [ ] <EOL> portals = { } <EOL> all_ports = set ( [ ] ) <EOL> for portal in self . tpg . network_portals : <EOL> all_ports . add ( str ( portal . port ) ) <EOL> portal_ip = portal . ip_address . strip ( '<STR_LIT>' ) <EOL> if not portal_ip in portals : <EOL> portals [ portal_ip ] = [ ] <EOL> portals [ portal_ip ] . append ( str ( portal . port ) ) <EOL> if current_param == '<STR_LIT>' : <EOL> completions = [ addr for addr in portals if addr . startswith ( text ) ] <EOL> if '<STR_LIT>' in parameters : <EOL> port = parameters [ '<STR_LIT>' ] <EOL> completions = [ addr for addr in completions <EOL> if port in portals [ addr ] ] <EOL> elif current_param == '<STR_LIT>' : <EOL> if '<STR_LIT>' in parameters : <EOL> addr = parameters [ '<STR_LIT>' ] <EOL> if addr in portals : <EOL> completions = [ port for port in portals [ addr ] <EOL> if port . startswith ( text ) ] <EOL> else : <EOL> completions = [ port for port in all_ports <EOL> if port . startswith ( text ) ] <EOL> if len ( completions ) == <NUM_LIT:1> : <EOL> return [ completions [ <NUM_LIT:0> ] + '<STR_LIT:U+0020>' ] <EOL> else : <EOL> return completions <EOL> class UIPortal ( UIRTSLibNode ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , portal , parent ) : <EOL> name = "<STR_LIT>" % ( portal . ip_address , portal . port ) <EOL> super ( UIPortal , self ) . __init__ ( name , portal , parent ) <EOL> self . refresh ( ) <EOL> def summary ( self ) : <EOL> if self . rtsnode . iser : <EOL> return ( '<STR_LIT>' , True ) <EOL> return ( '<STR_LIT>' , True ) <EOL> def ui_command_enable_iser ( self , boolean ) : <EOL> '''<STR_LIT>''' <EOL> boolean = self . ui_eval_param ( boolean , '<STR_LIT:bool>' , False ) <EOL> self . rtsnode . iser = boolean <EOL> self . shell . log . info ( "<STR_LIT>" % self . rtsnode . iser ) </s>
