idx int64 0 251k | question stringlengths 53 3.53k | target stringlengths 5 1.23k | len_question int64 20 893 | len_target int64 3 238 |
|---|---|---|---|---|
231,200 | def _get_section_end_index ( self , section , section_start ) : brace_count = 0 in_quote = False in_escape = False for index , char in enumerate ( self . template_str [ section_start : ] ) : # This check is to look for items inside of an escape sequence. # # For example, in the iApp team's iApps, there is a proc called # "iapp_get_items" which has a line that looks like this. # # set val [string map {\" ""} $val] # # This will cause this parser to fail because of the unbalanced # quotes. Therefore, this conditional takes this into consideration # if char == '\\' and not in_escape : in_escape = True elif char == '\\' and in_escape : in_escape = False if not in_escape : if char == '"' and not in_quote : in_quote = True elif char == '"' and in_quote : in_quote = False if char == '{' and not in_quote : brace_count += 1 elif char == '}' and not in_quote : brace_count -= 1 if brace_count is 0 : return index + section_start if brace_count is not 0 : raise CurlyBraceMismatchException ( 'Curly braces mismatch in section %s.' % section ) | Get end of section s content . | 297 | 7 |
231,201 | def _get_section_start_index ( self , section ) : sec_start_re = r'%s\s*\{' % section found = re . search ( sec_start_re , self . template_str ) if found : return found . end ( ) - 1 raise NonextantSectionException ( 'Section %s not found in template' % section ) | Get start of a section s content . | 81 | 8 |
231,202 | def _get_template_name ( self ) : start_pattern = r"sys application template\s+" r"(\/[\w\.\-]+\/)?" r"(?P<name>[\w\.\-]+)\s*\{" template_start = re . search ( start_pattern , self . template_str ) if template_start : return template_start . group ( 'name' ) raise NonextantTemplateNameException ( 'Template name not found.' ) | Find template name . | 102 | 4 |
231,203 | def _get_template_attr ( self , attr ) : attr_re = r'{0}\s+.*' . format ( attr ) attr_found = re . search ( attr_re , self . template_str ) if attr_found : attr_value = attr_found . group ( 0 ) . replace ( attr , '' , 1 ) return attr_value . strip ( ) | Find the attribute value for a specific attribute . | 93 | 9 |
231,204 | def _add_sections ( self ) : for section in self . template_sections : try : sec_start = self . _get_section_start_index ( section ) except NonextantSectionException : if section in self . sections_not_required : continue raise sec_end = self . _get_section_end_index ( section , sec_start ) section_value = self . template_str [ sec_start + 1 : sec_end ] . strip ( ) section , section_value = self . _transform_key_value ( section , section_value , self . section_map ) self . templ_dict [ 'actions' ] [ 'definition' ] [ section ] = section_value self . template_str = self . template_str [ : sec_start + 1 ] + self . template_str [ sec_end : ] | Add the found and required sections to the templ_dict . | 183 | 13 |
231,205 | def _add_cli_scripts ( self ) : pattern = r"cli script\s+" r"(\/[\w\.\-]+\/)?" r"(?P<name>[\w\.\-]+)\s*\{" sections = re . finditer ( pattern , self . template_str ) for section in sections : if 'scripts' not in self . templ_dict : self . templ_dict [ 'scripts' ] = [ ] try : sec_start = self . _get_section_start_index ( section . group ( 'name' ) ) except NonextantSectionException : continue sec_end = self . _get_section_end_index ( section . group ( 'name' ) , sec_start ) section_value = self . template_str [ sec_start + 1 : sec_end ] . strip ( ) self . templ_dict [ 'scripts' ] . append ( dict ( name = section . group ( 'name' ) , script = section_value ) ) self . template_str = self . template_str [ : sec_start + 1 ] + self . template_str [ sec_end : ] | Add the found external sections to the templ_dict . | 248 | 12 |
231,206 | def _add_attrs ( self ) : for attr in self . template_attrs : attr_value = self . _get_template_attr ( attr ) if not attr_value : continue attr , attr_value = self . _transform_key_value ( attr , attr_value , self . attr_map ) self . templ_dict [ attr ] = attr_value | Add the found and required attrs to the templ_dict . | 93 | 14 |
231,207 | def _parse_tcl_list ( self , attr , list_str ) : list_str = list_str . strip ( ) if not list_str : return [ ] if list_str [ 0 ] != '{' and list_str [ - 1 ] != '}' : if list_str . find ( 'none' ) >= 0 : return list_str if not re . search ( self . tcl_list_patterns [ attr ] , list_str ) : raise MalformedTCLListException ( 'TCL list for "%s" is malformed. ' % attr ) list_str = list_str . strip ( '{' ) . strip ( '}' ) list_str = list_str . strip ( ) return list_str . split ( ) | Turns a string representation of a TCL list into a Python list . | 171 | 15 |
231,208 | def _transform_key_value ( self , key , value , map_dict ) : if key in self . tcl_list_patterns : value = self . _parse_tcl_list ( key , value ) if key in map_dict : key = map_dict [ key ] return key , value | Massage keys and values for iapp dict to look like JSON . | 67 | 15 |
231,209 | def parse_template ( self ) : self . templ_dict = { 'actions' : { 'definition' : { } } } self . templ_dict [ 'name' ] = self . _get_template_name ( ) self . _add_cli_scripts ( ) self . _add_sections ( ) self . _add_attrs ( ) return self . templ_dict | Parse the template string into a dict . | 85 | 9 |
231,210 | def _create ( self , * * kwargs ) : if 'uri' in self . _meta_data : error = "There was an attempt to assign a new uri to this " "resource, the _meta_data['uri'] is %s and it should" " not be changed." % ( self . _meta_data [ 'uri' ] ) raise URICreationCollision ( error ) self . _check_exclusive_parameters ( * * kwargs ) requests_params = self . _handle_requests_params ( kwargs ) self . _minimum_one_is_missing ( * * kwargs ) self . _check_create_parameters ( * * kwargs ) kwargs = self . _check_for_python_keywords ( kwargs ) # Reduce boolean pairs as specified by the meta_data entry below for key1 , key2 in self . _meta_data [ 'reduction_forcing_pairs' ] : kwargs = self . _reduce_boolean_pair ( kwargs , key1 , key2 ) # Make convenience variable with short names for this method. _create_uri = self . _meta_data [ 'container' ] . _meta_data [ 'uri' ] session = self . _meta_data [ 'bigip' ] . _meta_data [ 'icr_session' ] kwargs = self . _prepare_request_json ( kwargs ) # Invoke the REST operation on the device. response = session . post ( _create_uri , json = kwargs , * * requests_params ) # Make new instance of self result = self . _produce_instance ( response ) return result | wrapped by create override that in subclasses to customize | 373 | 11 |
231,211 | def peer ( opt_peer , opt_username , opt_password , scope = "module" ) : p = BigIP ( opt_peer , opt_username , opt_password ) return p | peer bigip fixture | 41 | 4 |
231,212 | def exists ( self , * * kwargs ) : kwargs . pop ( 'partition' , None ) kwargs [ 'transform_name' ] = True return self . _exists ( * * kwargs ) | Providing a partition is not necessary on topology ; causes errors | 50 | 13 |
231,213 | def _key_dot_replace ( self , rdict ) : temp_dict = { } for key , value in iteritems ( rdict ) : if isinstance ( value , dict ) : value = self . _key_dot_replace ( value ) temp_dict [ key . replace ( '.' , '_' ) ] = value return temp_dict | Replace fullstops in returned keynames | 76 | 9 |
231,214 | def _get_nest_stats ( self ) : for x in self . rdict : check = urlparse ( x ) if check . scheme : nested_dict = self . rdict [ x ] [ 'nestedStats' ] tmp_dict = nested_dict [ 'entries' ] return self . _key_dot_replace ( tmp_dict ) return self . _key_dot_replace ( self . rdict ) | Helper method to deal with nestedStats | 92 | 7 |
231,215 | def refresh ( self , * * kwargs ) : self . resource . refresh ( * * kwargs ) self . rdict = self . resource . entries self . _update_stats ( ) | Refreshes stats attached to an object | 42 | 8 |
231,216 | def load ( self , * * kwargs ) : if LooseVersion ( self . tmos_ver ) == LooseVersion ( '11.6.0' ) : return self . _load_11_6 ( * * kwargs ) else : return super ( Rule , self ) . _load ( * * kwargs ) | Custom load method to address issue in 11 . 6 . 0 Final | 73 | 13 |
231,217 | def poll_for_exceptionless_callable ( callable , attempts , interval ) : @ wraps ( callable ) def poll ( * args , * * kwargs ) : for attempt in range ( attempts ) : try : return callable ( * args , * * kwargs ) except Exception as ex : if attempt == attempts - 1 : raise MaximumAttemptsReached ( ex ) time . sleep ( interval ) continue return poll | Poll with a given callable for a specified number of times . | 91 | 13 |
231,218 | def exists ( self , * * kwargs ) : if LooseVersion ( self . tmos_ver ) == LooseVersion ( '11.6.0' ) : return self . _exists_11_6 ( * * kwargs ) else : return super ( Network , self ) . _exists ( * * kwargs ) | Some objects when deleted still return when called by their | 75 | 10 |
231,219 | def _is_allowed_command ( self , command ) : cmds = self . _meta_data [ 'allowed_commands' ] if command not in self . _meta_data [ 'allowed_commands' ] : error_message = "The command value {0} does not exist. " "Valid commands are {1}" . format ( command , cmds ) raise InvalidCommand ( error_message ) | Checking if the given command is allowed on a given endpoint . | 88 | 13 |
231,220 | def _check_command_result ( self ) : if self . commandResult . startswith ( '/bin/bash' ) : raise UtilError ( '%s' % self . commandResult . split ( ' ' , 1 ) [ 1 ] ) if self . commandResult . startswith ( '/bin/mv' ) : raise UtilError ( '%s' % self . commandResult . split ( ' ' , 1 ) [ 1 ] ) if self . commandResult . startswith ( '/bin/ls' ) : raise UtilError ( '%s' % self . commandResult . split ( ' ' , 1 ) [ 1 ] ) if self . commandResult . startswith ( '/bin/rm' ) : raise UtilError ( '%s' % self . commandResult . split ( ' ' , 1 ) [ 1 ] ) if 'invalid option' in self . commandResult : raise UtilError ( '%s' % self . commandResult ) if 'Invalid option' in self . commandResult : raise UtilError ( '%s' % self . commandResult ) if 'usage: /usr/bin/get_dossier' in self . commandResult : raise UtilError ( '%s' % self . commandResult ) | If command result exists run these checks . | 272 | 8 |
231,221 | def exec_cmd ( self , command , * * kwargs ) : self . _is_allowed_command ( command ) self . _check_command_parameters ( * * kwargs ) return self . _exec_cmd ( command , * * kwargs ) | Wrapper method that can be changed in the inheriting classes . | 59 | 13 |
231,222 | def _exec_cmd ( self , command , * * kwargs ) : kwargs [ 'command' ] = command self . _check_exclusive_parameters ( * * kwargs ) requests_params = self . _handle_requests_params ( kwargs ) session = self . _meta_data [ 'bigip' ] . _meta_data [ 'icr_session' ] response = session . post ( self . _meta_data [ 'uri' ] , json = kwargs , * * requests_params ) new_instance = self . _stamp_out_core ( ) new_instance . _local_update ( response . json ( ) ) if 'commandResult' in new_instance . __dict__ : new_instance . _check_command_result ( ) return new_instance | Create a new method as command has specific requirements . | 178 | 10 |
231,223 | def get_device_info ( self , bigip ) : coll = bigip . tm . cm . devices . get_collection ( ) device = [ device for device in coll if device . selfDevice == 'true' ] assert len ( device ) == 1 return device [ 0 ] | Get device information about a specific BigIP device . | 60 | 10 |
231,224 | def _check_existence_by_collection ( self , container , item_name ) : coll = container . get_collection ( ) for item in coll : if item . name == item_name : return True return False | Check existnce of item based on get collection call . | 46 | 11 |
231,225 | def _return_object ( self , container , item_name ) : coll = container . get_collection ( ) for item in coll : if item . name == item_name : return item | Helper method to retrieve the object | 40 | 6 |
231,226 | def exec_cmd ( self , command , * * kwargs ) : if command == 'load' : if kwargs : kwargs = dict ( options = [ kwargs ] ) return self . _exec_cmd ( command , * * kwargs ) | Normal save and load only need the command . | 58 | 9 |
231,227 | def update ( self , * * kwargs ) : tmos_version = self . _meta_data [ 'bigip' ] . tmos_version if LooseVersion ( tmos_version ) > LooseVersion ( '12.0.0' ) : msg = "Update() is unsupported for User on version %s. " "Utilize Modify() method instead" % tmos_version raise UnsupportedOperation ( msg ) else : self . _update ( * * kwargs ) | Due to a password decryption bug | 108 | 7 |
231,228 | def _process_config_with_kind ( self , raw_conf ) : kind = raw_conf [ u"kind" ] org_match = re . match ( self . OC_pattern , kind ) if org_match : return self . _format_org_collection ( org_match , kind , raw_conf ) elif 'collectionstate' in kind : return self . _format_collection ( kind , raw_conf ) elif kind . endswith ( 'stats' ) : return self . _format_stats ( kind , raw_conf ) elif kind . endswith ( 'state' ) : return self . _format_resource ( kind , raw_conf ) | Use this to decide which format is called for by the kind . | 146 | 13 |
231,229 | def _missing_required_parameters ( rqset , * * kwargs ) : key_set = set ( list ( iterkeys ( kwargs ) ) ) required_minus_received = rqset - key_set if required_minus_received != set ( ) : return list ( required_minus_received ) | Helper function to do operation on sets . | 70 | 8 |
231,230 | def _format_collection_name ( self ) : base_uri = self . _format_resource_name ( ) if base_uri [ - 2 : ] == '_s' : endind = 2 else : endind = 1 return base_uri [ : - endind ] | Formats a name from Collection format | 60 | 7 |
231,231 | def _check_command_parameters ( self , * * kwargs ) : rset = self . _meta_data [ 'required_command_parameters' ] check = _missing_required_parameters ( rset , * * kwargs ) if check : error_message = 'Missing required params: %s' % check raise MissingRequiredCommandParameter ( error_message ) | Params given to exec_cmd should satisfy required params . | 83 | 12 |
231,232 | def _handle_requests_params ( self , kwargs ) : requests_params = kwargs . pop ( 'requests_params' , { } ) for param in requests_params : if param in kwargs : error_message = 'Requests Parameter %r collides with a load' ' parameter of the same name.' % param raise RequestParamKwargCollision ( error_message ) # If we have an icontrol version we need to add 'ver' to params if self . _meta_data [ 'icontrol_version' ] : params = requests_params . pop ( 'params' , { } ) params . update ( { 'ver' : self . _meta_data [ 'icontrol_version' ] } ) requests_params . update ( { 'params' : params } ) return requests_params | Validate parameters that will be passed to the requests verbs . | 183 | 12 |
231,233 | def _check_exclusive_parameters ( self , * * kwargs ) : if len ( self . _meta_data [ 'exclusive_attributes' ] ) > 0 : attr_set = set ( list ( iterkeys ( kwargs ) ) ) ex_set = set ( self . _meta_data [ 'exclusive_attributes' ] [ 0 ] ) common_set = sorted ( attr_set . intersection ( ex_set ) ) if len ( common_set ) > 1 : cset = ', ' . join ( common_set ) error = 'Mutually exclusive arguments submitted. ' 'The following arguments cannot be set ' 'together: "%s".' % cset raise ExclusiveAttributesPresent ( error ) | Check for mutually exclusive attributes in kwargs . | 156 | 10 |
231,234 | def _modify ( self , * * patch ) : requests_params , patch_uri , session , read_only = self . _prepare_put_or_patch ( patch ) self . _check_for_boolean_pair_reduction ( patch ) read_only_mutations = [ ] for attr in read_only : if attr in patch : read_only_mutations . append ( attr ) if read_only_mutations : msg = 'Attempted to mutate read-only attribute(s): %s' % read_only_mutations raise AttemptedMutationOfReadOnly ( msg ) patch = self . _prepare_request_json ( patch ) response = session . patch ( patch_uri , json = patch , * * requests_params ) self . _local_update ( response . json ( ) ) | Wrapped with modify override in a subclass to customize . | 183 | 11 |
231,235 | def _check_for_boolean_pair_reduction ( self , kwargs ) : if 'reduction_forcing_pairs' in self . _meta_data : for key1 , key2 in self . _meta_data [ 'reduction_forcing_pairs' ] : kwargs = self . _reduce_boolean_pair ( kwargs , key1 , key2 ) return kwargs | Check if boolean pairs should be reduced in this resource . | 93 | 11 |
231,236 | def _prepare_put_or_patch ( self , kwargs ) : requests_params = self . _handle_requests_params ( kwargs ) update_uri = self . _meta_data [ 'uri' ] session = self . _meta_data [ 'bigip' ] . _meta_data [ 'icr_session' ] read_only = self . _meta_data . get ( 'read_only_attributes' , [ ] ) return requests_params , update_uri , session , read_only | Retrieve the appropriate request items for put or patch calls . | 117 | 12 |
231,237 | def _prepare_request_json ( self , kwargs ) : # Check for python keywords in dict kwargs = self . _check_for_python_keywords ( kwargs ) # Check for the key 'check' in kwargs if 'check' in kwargs : od = OrderedDict ( ) od [ 'check' ] = kwargs [ 'check' ] kwargs . pop ( 'check' ) od . update ( kwargs ) return od return kwargs | Prepare request args for sending to device as JSON . | 111 | 11 |
231,238 | def _iter_list_for_dicts ( self , check_list ) : list_copy = copy . deepcopy ( check_list ) for index , elem in enumerate ( check_list ) : if isinstance ( elem , dict ) : list_copy [ index ] = self . _check_for_python_keywords ( elem ) elif isinstance ( elem , list ) : list_copy [ index ] = self . _iter_list_for_dicts ( elem ) else : list_copy [ index ] = elem return list_copy | Iterate over list to find dicts and check for python keywords . | 125 | 14 |
231,239 | def _check_for_python_keywords ( self , kwargs ) : kwargs_copy = copy . deepcopy ( kwargs ) for key , val in iteritems ( kwargs ) : if isinstance ( val , dict ) : kwargs_copy [ key ] = self . _check_for_python_keywords ( val ) elif isinstance ( val , list ) : kwargs_copy [ key ] = self . _iter_list_for_dicts ( val ) else : if key . endswith ( '_' ) : strip_key = key . rstrip ( '_' ) if keyword . iskeyword ( strip_key ) : kwargs_copy [ strip_key ] = val kwargs_copy . pop ( key ) return kwargs_copy | When Python keywords seen mutate to remove trailing underscore . | 178 | 11 |
231,240 | def _check_keys ( self , rdict ) : if '_meta_data' in rdict : error_message = "Response contains key '_meta_data' which is " "incompatible with this API!!\n Response json: %r" % rdict raise DeviceProvidesIncompatibleKey ( error_message ) for x in rdict : if not re . match ( tokenize . Name , x ) : error_message = "Device provided %r which is disallowed" " because it's not a valid Python 2.7 identifier." % x raise DeviceProvidesIncompatibleKey ( error_message ) elif keyword . iskeyword ( x ) : # If attribute is keyword, append underscore to attribute name rdict [ x + '_' ] = rdict [ x ] rdict . pop ( x ) elif x . startswith ( '__' ) : error_message = "Device provided %r which is disallowed" ", it mangles into a Python non-public attribute." % x raise DeviceProvidesIncompatibleKey ( error_message ) return rdict | Call this from _local_update to validate response keys | 231 | 11 |
231,241 | def _local_update ( self , rdict ) : sanitized = self . _check_keys ( rdict ) temp_meta = self . _meta_data self . __dict__ = sanitized self . _meta_data = temp_meta | Call this with a response dictionary to update instance attrs . | 53 | 12 |
231,242 | def _update ( self , * * kwargs ) : requests_params , update_uri , session , read_only = self . _prepare_put_or_patch ( kwargs ) read_only_mutations = [ ] for attr in read_only : if attr in kwargs : read_only_mutations . append ( attr ) if read_only_mutations : msg = 'Attempted to mutate read-only attribute(s): %s' % read_only_mutations raise AttemptedMutationOfReadOnly ( msg ) # Get the current state of the object on BIG-IP® and check the # generation Use pop here because we don't want force in the data_dict force = self . _check_force_arg ( kwargs . pop ( 'force' , True ) ) if not force : # generation has a known server-side error self . _check_generation ( ) kwargs = self . _check_for_boolean_pair_reduction ( kwargs ) # Save the meta data so we can add it back into self after we # load the new object. temp_meta = self . __dict__ . pop ( '_meta_data' ) # Need to remove any of the Collection objects from self.__dict__ # because these are subCollections and _meta_data and # other non-BIG-IP® attrs are not removed from the subCollections # See issue #146 for details tmp = dict ( ) for key , value in iteritems ( self . __dict__ ) : # In Python2 versions we were changing a dictionary in place, # but this cannot be done with an iterator as an error is raised. # So instead we create a temporary holder for the modified dict # and then re-assign it afterwards. if isinstance ( value , Collection ) : pass else : tmp [ key ] = value self . __dict__ = tmp data_dict = self . to_dict ( ) # Remove any read-only attributes from our data_dict before we update # the data dict with the attributes. If they pass in read-only attrs # in the method call we are going to let BIG-IP® let them know about it # when it fails for attr in read_only : data_dict . pop ( attr , '' ) data_dict . update ( kwargs ) data_dict = self . _prepare_request_json ( data_dict ) # Handles ConnectionAborted errors # # @see https://github.com/F5Networks/f5-ansible/issues/317 # @see https://github.com/requests/requests/issues/2364 for _ in range ( 0 , 30 ) : try : response = session . put ( update_uri , json = data_dict , * * requests_params ) self . _meta_data = temp_meta self . _local_update ( response . json ( ) ) break except iControlUnexpectedHTTPError : response = session . get ( update_uri , * * requests_params ) self . _meta_data = temp_meta self . _local_update ( response . json ( ) ) raise except ConnectionError as ex : if 'Connection aborted' in str ( ex ) : time . sleep ( 1 ) continue else : raise | wrapped with update override that in a subclass to customize | 709 | 11 |
231,243 | def _refresh ( self , * * kwargs ) : requests_params = self . _handle_requests_params ( kwargs ) refresh_session = self . _meta_data [ 'bigip' ] . _meta_data [ 'icr_session' ] if self . _meta_data [ 'uri' ] . endswith ( '/stats/' ) : # Slicing off the trailing slash here for Stats enpoints because # iWorkflow doesn't consider those `stats` URLs valid if they # include the trailing slash. # # Other than that, functionality does not change uri = self . _meta_data [ 'uri' ] [ 0 : - 1 ] else : uri = self . _meta_data [ 'uri' ] response = refresh_session . get ( uri , * * requests_params ) self . _local_update ( response . json ( ) ) | wrapped by refresh override that in a subclass to customize | 195 | 11 |
231,244 | def _produce_instance ( self , response ) : new_instance = self . _stamp_out_core ( ) # Post-process the response new_instance . _local_update ( response . json ( ) ) # Allow for example files, which are KindTypeMismatches if hasattr ( new_instance , 'selfLink' ) : if new_instance . kind != new_instance . _meta_data [ 'required_json_kind' ] and new_instance . kind != "tm:transaction:commandsstate" and 'example' not in new_instance . selfLink . split ( '/' ) [ - 1 ] : error_message = "For instances of type '%r' the corresponding" " kind must be '%r' but creation returned JSON with kind: %r" % ( new_instance . __class__ . __name__ , new_instance . _meta_data [ 'required_json_kind' ] , new_instance . kind ) raise KindTypeMismatch ( error_message ) else : if new_instance . kind != new_instance . _meta_data [ 'required_json_kind' ] and new_instance . kind != "tm:transaction:commandsstate" : error_message = "For instances of type '%r' the corresponding" " kind must be '%r' but creation returned JSON with kind: %r" % ( new_instance . __class__ . __name__ , new_instance . _meta_data [ 'required_json_kind' ] , new_instance . kind ) raise KindTypeMismatch ( error_message ) # Update the object to have the correct functional uri. new_instance . _activate_URI ( new_instance . selfLink ) return new_instance | Generate a new self which is an instance of the self . | 381 | 13 |
231,245 | def _reduce_boolean_pair ( self , config_dict , key1 , key2 ) : if key1 in config_dict and key2 in config_dict and config_dict [ key1 ] == config_dict [ key2 ] : msg = 'Boolean pair, %s and %s, have same value: %s. If both ' 'are given to this method, they cannot be the same, as this ' 'method cannot decide which one should be True.' % ( key1 , key2 , config_dict [ key1 ] ) raise BooleansToReduceHaveSameValue ( msg ) elif key1 in config_dict and not config_dict [ key1 ] : config_dict [ key2 ] = True config_dict . pop ( key1 ) elif key2 in config_dict and not config_dict [ key2 ] : config_dict [ key1 ] = True config_dict . pop ( key2 ) return config_dict | Ensure only one key with a boolean value is present in dict . | 207 | 14 |
231,246 | def get_collection ( self , * * kwargs ) : list_of_contents = [ ] self . refresh ( * * kwargs ) if 'items' in self . __dict__ : for item in self . items : # It's possible to have non-"kind" JSON returned. We just # append the corresponding dict. PostProcessing is the caller's # responsibility. if 'kind' not in item : list_of_contents . append ( item ) continue kind = item [ 'kind' ] if kind in self . _meta_data [ 'attribute_registry' ] : # If it has a kind, it must be registered. instance = self . _meta_data [ 'attribute_registry' ] [ kind ] ( self ) instance . _local_update ( item ) instance . _activate_URI ( instance . selfLink ) list_of_contents . append ( instance ) else : error_message = '%r is not registered!' % kind raise UnregisteredKind ( error_message ) return list_of_contents | Get an iterator of Python Resource objects that represent URIs . | 225 | 12 |
231,247 | def _delete_collection ( self , * * kwargs ) : error_message = "The request must include \"requests_params\": {\"params\": \"options=<glob pattern>\"} as kwarg" try : if kwargs [ 'requests_params' ] [ 'params' ] . split ( '=' ) [ 0 ] != 'options' : raise MissingRequiredRequestsParameter ( error_message ) except KeyError : raise requests_params = self . _handle_requests_params ( kwargs ) delete_uri = self . _meta_data [ 'uri' ] session = self . _meta_data [ 'bigip' ] . _meta_data [ 'icr_session' ] session . delete ( delete_uri , * * requests_params ) | wrapped with delete_collection override that in a sublcass to customize | 172 | 15 |
231,248 | def _activate_URI ( self , selfLinkuri ) : # netloc local alias uri = urlparse . urlsplit ( str ( self . _meta_data [ 'bigip' ] . _meta_data [ 'uri' ] ) ) # attrs local alias attribute_reg = self . _meta_data . get ( 'attribute_registry' , { } ) attrs = list ( itervalues ( attribute_reg ) ) attrs = self . _assign_stats ( attrs ) ( scheme , domain , path , qarg , frag ) = urlparse . urlsplit ( selfLinkuri ) path_uri = urlparse . urlunsplit ( ( scheme , uri . netloc , path , '' , '' ) ) if not path_uri . endswith ( '/' ) : path_uri = path_uri + '/' qargs = urlparse . parse_qs ( qarg ) self . _meta_data . update ( { 'uri' : path_uri , 'creation_uri_qargs' : qargs , 'creation_uri_frag' : frag , 'allowed_lazy_attributes' : attrs } ) | Call this with a selfLink after it s returned in _create or _load . | 257 | 17 |
231,249 | def _check_create_parameters ( self , * * kwargs ) : rset = self . _meta_data [ 'required_creation_parameters' ] check = _missing_required_parameters ( rset , * * kwargs ) if check : error_message = 'Missing required params: %s' % check raise MissingRequiredCreationParameter ( error_message ) | Params given to create should satisfy required params . | 84 | 10 |
231,250 | def _minimum_one_is_missing ( self , * * kwargs ) : rqset = self . _meta_data [ 'minimum_additional_parameters' ] if rqset : kwarg_set = set ( iterkeys ( kwargs ) ) if kwarg_set . isdisjoint ( rqset ) : args = sorted ( rqset ) error_message = 'This resource requires at least one of the ' 'mandatory additional ' 'parameters to be provided: %s' % ', ' . join ( args ) raise MissingRequiredCreationParameter ( error_message ) | Helper function to do operation on sets | 134 | 7 |
231,251 | def _check_load_parameters ( self , * * kwargs ) : rset = self . _meta_data [ 'required_load_parameters' ] check = _missing_required_parameters ( rset , * * kwargs ) if check : check . sort ( ) error_message = 'Missing required params: %s' % check raise MissingRequiredReadParameter ( error_message ) | Params given to load should at least satisfy required params . | 88 | 12 |
231,252 | def _load ( self , * * kwargs ) : if 'uri' in self . _meta_data : error = "There was an attempt to assign a new uri to this " "resource, the _meta_data['uri'] is %s and it should" " not be changed." % ( self . _meta_data [ 'uri' ] ) raise URICreationCollision ( error ) requests_params = self . _handle_requests_params ( kwargs ) self . _check_load_parameters ( * * kwargs ) kwargs [ 'uri_as_parts' ] = True refresh_session = self . _meta_data [ 'bigip' ] . _meta_data [ 'icr_session' ] base_uri = self . _meta_data [ 'container' ] . _meta_data [ 'uri' ] kwargs . update ( requests_params ) for key1 , key2 in self . _meta_data [ 'reduction_forcing_pairs' ] : kwargs = self . _reduce_boolean_pair ( kwargs , key1 , key2 ) kwargs = self . _check_for_python_keywords ( kwargs ) response = refresh_session . get ( base_uri , * * kwargs ) # Make new instance of self return self . _produce_instance ( response ) | wrapped with load override that in a subclass to customize | 305 | 11 |
231,253 | def _delete ( self , * * kwargs ) : requests_params = self . _handle_requests_params ( kwargs ) delete_uri = self . _meta_data [ 'uri' ] session = self . _meta_data [ 'bigip' ] . _meta_data [ 'icr_session' ] # Check the generation for match before delete force = self . _check_force_arg ( kwargs . pop ( 'force' , True ) ) if not force : self . _check_generation ( ) response = session . delete ( delete_uri , * * requests_params ) if response . status_code == 200 : self . __dict__ = { 'deleted' : True } | wrapped with delete override that in a subclass to customize | 156 | 11 |
231,254 | def _delete ( self , * * kwargs ) : requests_params = self . _handle_requests_params ( kwargs ) delete_uri = self . _meta_data [ 'uri' ] session = self . _meta_data [ 'bigip' ] . _meta_data [ 'icr_session' ] response = session . delete ( delete_uri , * * requests_params ) if response . status_code == 200 or 201 : self . __dict__ = { 'deleted' : True } | Wrapped with delete override that in a subclass to customize | 114 | 11 |
231,255 | def exists ( self , * * kwargs ) : requests_params = self . _handle_requests_params ( kwargs ) self . _check_load_parameters ( * * kwargs ) kwargs [ 'uri_as_parts' ] = True session = self . _meta_data [ 'bigip' ] . _meta_data [ 'icr_session' ] uri = self . _meta_data [ 'container' ] . _meta_data [ 'uri' ] endpoint = kwargs . pop ( 'id' , '' ) # Popping name kwarg as it will cause the uri to be invalid kwargs . pop ( 'name' , '' ) base_uri = uri + endpoint + '/' kwargs . update ( requests_params ) try : session . get ( base_uri , * * kwargs ) except HTTPError as err : if err . response . status_code == 404 : return False else : raise return True | r Check for the existence of the ASM object on the BIG - IP | 215 | 15 |
231,256 | def _fetch ( self ) : if 'uri' in self . _meta_data : error = "There was an attempt to assign a new uri to this " "resource, the _meta_data['uri'] is %s and it should" " not be changed." % ( self . _meta_data [ 'uri' ] ) raise URICreationCollision ( error ) # Make convenience variable with short names for this method. _create_uri = self . _meta_data [ 'container' ] . _meta_data [ 'uri' ] session = self . _meta_data [ 'bigip' ] . _meta_data [ 'icr_session' ] # Invoke the REST operation on the device. response = session . post ( _create_uri , json = { } ) # Make new instance of self return self . _produce_instance ( response ) | wrapped by fetch override that in subclasses to customize | 190 | 11 |
231,257 | def _check_device_number ( self , devices ) : if len ( devices ) < 2 or len ( devices ) > 4 : msg = 'The number of devices to cluster is not supported.' raise ClusterNotSupported ( msg ) | Check if number of devices is between 2 and 4 | 48 | 10 |
231,258 | def manage_extant ( self , * * kwargs ) : self . _check_device_number ( kwargs [ 'devices' ] ) self . trust_domain = TrustDomain ( devices = kwargs [ 'devices' ] , partition = kwargs [ 'device_group_partition' ] ) self . device_group = DeviceGroup ( * * kwargs ) self . cluster = Cluster ( * * kwargs ) | Manage an existing cluster | 96 | 5 |
231,259 | def _filter_version_specific_options ( self , tmos_ver , * * kwargs ) : if LooseVersion ( tmos_ver ) < LooseVersion ( '12.1.0' ) : for k , parms in self . _meta_data [ 'optional_parameters' ] . items ( ) : for r in kwargs . get ( k , [ ] ) : for parm in parms : value = r . pop ( parm , None ) if value is not None : logger . info ( "Policy parameter %s:%s is invalid for v%s" , k , parm , tmos_ver ) | Filter version - specific optional parameters | 142 | 6 |
231,260 | def _create ( self , * * kwargs ) : tmos_ver = self . _meta_data [ 'bigip' ] . _meta_data [ 'tmos_version' ] legacy = kwargs . pop ( 'legacy' , False ) publish = kwargs . pop ( 'publish' , False ) self . _filter_version_specific_options ( tmos_ver , * * kwargs ) if LooseVersion ( tmos_ver ) < LooseVersion ( '12.1.0' ) : return super ( Policy , self ) . _create ( * * kwargs ) else : if legacy : return super ( Policy , self ) . _create ( legacy = True , * * kwargs ) else : if 'subPath' not in kwargs : msg = "The keyword 'subPath' must be specified when " "creating draft policy in TMOS versions >= 12.1.0. " "Try and specify subPath as 'Drafts'." raise MissingRequiredCreationParameter ( msg ) self = super ( Policy , self ) . _create ( * * kwargs ) if publish : self . publish ( ) return self | Allow creation of draft policy and ability to publish a draft | 254 | 11 |
231,261 | def _modify ( self , * * patch ) : legacy = patch . pop ( 'legacy' , False ) tmos_ver = self . _meta_data [ 'bigip' ] . _meta_data [ 'tmos_version' ] self . _filter_version_specific_options ( tmos_ver , * * patch ) if 'Drafts' not in self . _meta_data [ 'uri' ] and LooseVersion ( tmos_ver ) >= LooseVersion ( '12.1.0' ) and not legacy : msg = 'Modify operation not allowed on a published policy.' raise OperationNotSupportedOnPublishedPolicy ( msg ) super ( Policy , self ) . _modify ( * * patch ) | Modify only draft or legacy policies | 158 | 7 |
231,262 | def _update ( self , * * kwargs ) : legacy = kwargs . pop ( 'legacy' , False ) tmos_ver = self . _meta_data [ 'bigip' ] . _meta_data [ 'tmos_version' ] self . _filter_version_specific_options ( tmos_ver , * * kwargs ) if 'Drafts' not in self . _meta_data [ 'uri' ] and LooseVersion ( tmos_ver ) >= LooseVersion ( '12.1.0' ) and not legacy : msg = 'Update operation not allowed on a published policy.' raise OperationNotSupportedOnPublishedPolicy ( msg ) super ( Policy , self ) . _update ( * * kwargs ) | Update only draft or legacy policies | 163 | 6 |
231,263 | def publish ( self , * * kwargs ) : assert 'Drafts' in self . _meta_data [ 'uri' ] assert self . status . lower ( ) == 'draft' base_uri = self . _meta_data [ 'container' ] . _meta_data [ 'uri' ] requests_params = self . _handle_requests_params ( kwargs ) session = self . _meta_data [ 'bigip' ] . _meta_data [ 'icr_session' ] if 'command' not in kwargs : kwargs [ 'command' ] = 'publish' if 'Drafts' not in self . name : kwargs [ 'name' ] = self . fullPath session . post ( base_uri , json = kwargs , * * requests_params ) get_kwargs = { 'name' : self . name , 'partition' : self . partition , 'uri_as_parts' : True } response = session . get ( base_uri , * * get_kwargs ) json_data = response . json ( ) self . _local_update ( json_data ) self . _activate_URI ( json_data [ 'selfLink' ] ) | Publishing a draft policy is only applicable in TMOS 12 . 1 and up . | 265 | 17 |
231,264 | def draft ( self , * * kwargs ) : tmos_ver = self . _meta_data [ 'bigip' ] . _meta_data [ 'tmos_version' ] legacy = kwargs . pop ( 'legacy' , False ) if LooseVersion ( tmos_ver ) < LooseVersion ( '12.1.0' ) or legacy : raise DraftPolicyNotSupportedInTMOSVersion ( "Drafting on this version of BIG-IP is not supported" ) kwargs = dict ( createDraft = True ) super ( Policy , self ) . _modify ( * * kwargs ) get_kwargs = { 'name' : self . name , 'partition' : self . partition , 'uri_as_parts' : True , 'subPath' : 'Drafts' } base_uri = self . _meta_data [ 'container' ] . _meta_data [ 'uri' ] session = self . _meta_data [ 'bigip' ] . _meta_data [ 'icr_session' ] response = session . get ( base_uri , * * get_kwargs ) json_data = response . json ( ) self . _local_update ( json_data ) self . _activate_URI ( json_data [ 'selfLink' ] ) | Allows for easily re - drafting a policy | 285 | 8 |
231,265 | def delete ( self , * * kwargs ) : if 'uuid' not in kwargs : kwargs [ 'uuid' ] = str ( self . uuid ) requests_params = self . _handle_requests_params ( kwargs ) kwargs = self . _check_for_python_keywords ( kwargs ) kwargs = self . _prepare_request_json ( kwargs ) delete_uri = self . _meta_data [ 'uri' ] session = self . _meta_data [ 'bigip' ] . _meta_data [ 'icr_session' ] # Check the generation for match before delete force = self . _check_force_arg ( kwargs . pop ( 'force' , True ) ) if not force : self . _check_generation ( ) response = session . delete ( delete_uri , json = kwargs , * * requests_params ) if response . status_code == 200 : self . __dict__ = { 'deleted' : True } | Deletes a member from an unmanaged license pool | 227 | 10 |
231,266 | def exec_cmd ( self , command , * * kwargs ) : kwargs = self . _reduce_boolean_pair ( kwargs , 'online' , 'offline' ) if 'offline' in kwargs : self . _meta_data [ 'exclusive_attributes' ] . append ( ( 'offline' , 'standby' ) ) if 'online' in kwargs : self . _meta_data [ 'exclusive_attributes' ] . append ( ( 'online' , 'standby' ) ) self . _is_allowed_command ( command ) self . _check_command_parameters ( * * kwargs ) return self . _exec_cmd ( command , * * kwargs ) | Defining custom method to append exclusive_attributes . | 163 | 11 |
231,267 | def toggle_standby ( self , * * kwargs ) : trafficgroup = kwargs . pop ( 'trafficgroup' ) state = kwargs . pop ( 'state' ) if kwargs : raise TypeError ( 'Unexpected **kwargs: %r' % kwargs ) arguments = { 'standby' : state , 'traffic-group' : trafficgroup } return self . exec_cmd ( 'run' , * * arguments ) | Toggle the standby status of a traffic group . | 101 | 10 |
231,268 | def update ( self , * * kwargs ) : if 'useProxyServer' in kwargs and kwargs [ 'useProxyServer' ] == 'enabled' : if 'proxyServerPool' not in kwargs : error = 'Missing proxyServerPool parameter value.' raise MissingUpdateParameter ( error ) if hasattr ( self , 'useProxyServer' ) : if getattr ( self , 'useProxyServer' ) == 'enabled' and 'proxyServerPool' not in self . __dict__ : error = 'Missing proxyServerPool parameter value.' raise MissingUpdateParameter ( error ) self . _update ( * * kwargs ) return self | When setting useProxyServer to enable we need to supply | 140 | 11 |
231,269 | def _check_tagmode_and_tmos_version ( self , * * kwargs ) : tmos_version = self . _meta_data [ 'bigip' ] . _meta_data [ 'tmos_version' ] if LooseVersion ( tmos_version ) < LooseVersion ( '11.6.0' ) : msg = "The parameter, 'tagMode', is not allowed against the " "following version of TMOS: %s" % ( tmos_version ) if 'tagMode' in kwargs or hasattr ( self , 'tagMode' ) : raise TagModeDisallowedForTMOSVersion ( msg ) | Raise an exception if tagMode in kwargs and tmos version < 11 . 6 . 0 | 144 | 21 |
231,270 | def load ( self , * * kwargs ) : tmos_v = self . _meta_data [ 'bigip' ] . _meta_data [ 'tmos_version' ] if self . _check_existence_by_collection ( self . _meta_data [ 'container' ] , kwargs [ 'name' ] ) : if LooseVersion ( tmos_v ) == LooseVersion ( '11.5.4' ) : return self . _load_11_5_4 ( * * kwargs ) else : return self . _load ( * * kwargs ) msg = 'The Policy named, {}, does not exist on the device.' . format ( kwargs [ 'name' ] ) raise NonExtantVirtualPolicy ( msg ) | Override load to retrieve object based on exists above . | 169 | 10 |
231,271 | def _load_11_5_4 ( self , * * kwargs ) : if 'uri' in self . _meta_data : error = "There was an attempt to assign a new uri to this " "resource, the _meta_data['uri'] is %s and it should" " not be changed." % ( self . _meta_data [ 'uri' ] ) raise URICreationCollision ( error ) requests_params = self . _handle_requests_params ( kwargs ) self . _check_load_parameters ( * * kwargs ) kwargs [ 'uri_as_parts' ] = True refresh_session = self . _meta_data [ 'bigip' ] . _meta_data [ 'icr_session' ] base_uri = self . _meta_data [ 'container' ] . _meta_data [ 'uri' ] kwargs . update ( requests_params ) for key1 , key2 in self . _meta_data [ 'reduction_forcing_pairs' ] : kwargs = self . _reduce_boolean_pair ( kwargs , key1 , key2 ) kwargs = self . _check_for_python_keywords ( kwargs ) try : response = refresh_session . get ( base_uri , * * kwargs ) except HTTPError as err : if err . response . status_code != 404 : raise if err . response . status_code == 404 : return self . _return_object ( self . _meta_data [ 'container' ] , kwargs [ 'name' ] ) # Make new instance of self return self . _produce_instance ( response ) | Custom _load method to accommodate for issue in 11 . 5 . 4 | 371 | 14 |
231,272 | def create ( self , * * kwargs ) : tmos_v = self . _meta_data [ 'bigip' ] . _meta_data [ 'tmos_version' ] if LooseVersion ( tmos_v ) == LooseVersion ( '11.5.4' ) or LooseVersion ( tmos_v ) == LooseVersion ( '12.1.1' ) : if 'uri' in self . _meta_data : error = "There was an attempt to assign a new uri to this " "resource, the _meta_data['uri'] is %s and it should" " not be changed." % ( self . _meta_data [ 'uri' ] ) raise URICreationCollision ( error ) self . _check_exclusive_parameters ( * * kwargs ) requests_params = self . _handle_requests_params ( kwargs ) self . _check_create_parameters ( * * kwargs ) # Reduce boolean pairs as specified by the meta_data entry below for key1 , key2 in self . _meta_data [ 'reduction_forcing_pairs' ] : kwargs = self . _reduce_boolean_pair ( kwargs , key1 , key2 ) # Make convenience variable with short names for this method. _create_uri = self . _meta_data [ 'container' ] . _meta_data [ 'uri' ] session = self . _meta_data [ 'bigip' ] . _meta_data [ 'icr_session' ] # We using try/except just in case some HF will fix # this in 11.5.4 try : response = session . post ( _create_uri , json = kwargs , * * requests_params ) except HTTPError as err : if err . response . status_code != 404 : raise if err . response . status_code == 404 : return self . _return_object ( self . _meta_data [ 'container' ] , kwargs [ 'name' ] ) # Make new instance of self return self . _produce_instance ( response ) else : return self . _create ( * * kwargs ) | Custom _create method to accommodate for issue 11 . 5 . 4 and 12 . 1 . 1 | 476 | 19 |
231,273 | def get_collection ( self , * * kwargs ) : list_of_contents = [ ] self . refresh ( * * kwargs ) if 'items' in self . __dict__ : for item in self . items : # It's possible to have non-"kind" JSON returned. We just # append the corresponding dict. PostProcessing is the caller's # responsibility. if 'kind' not in item : list_of_contents . append ( item ) continue kind = item [ 'kind' ] if kind in self . _meta_data [ 'attribute_registry' ] : # If it has a kind, it must be registered. instance = self . _meta_data [ 'attribute_registry' ] [ kind ] ( self ) instance . _local_update ( item ) instance . _activate_URI ( instance . selfLink ) list_of_contents . append ( instance ) else : error_message = '%r is not registered!' % kind raise UnregisteredKind ( error_message ) if 'policiesReference' in self . __dict__ and 'items' not in self . __dict__ : for item in self . policiesReference [ 'items' ] : kind = item [ 'kind' ] if kind in self . _meta_data [ 'attribute_registry' ] : # If it has a kind, it must be registered. instance = self . _meta_data [ 'attribute_registry' ] [ kind ] ( self ) instance . _local_update ( item ) instance . _activate_URI ( instance . selfLink ) list_of_contents . append ( instance ) else : error_message = '%r is not registered!' % kind raise UnregisteredKind ( error_message ) return list_of_contents | We need special get collection method to address issue in 11 . 5 . 4 | 379 | 15 |
231,274 | def get_device_names_to_objects ( devices ) : name_to_object = { } for device in devices : device_name = get_device_info ( device ) . name name_to_object [ device_name ] = device return name_to_object | Map a list of devices to their hostnames . | 59 | 10 |
231,275 | def create ( self , * * kwargs ) : if LooseVersion ( self . tmos_v ) < LooseVersion ( '12.0.0' ) : return self . _create ( * * kwargs ) else : new_instance = self . _create ( * * kwargs ) tmp_name = str ( new_instance . id ) tmp_path = new_instance . _meta_data [ 'container' ] . _meta_data [ 'uri' ] finalurl = tmp_path + tmp_name new_instance . _meta_data [ 'uri' ] = finalurl return new_instance | Custom create method for v12 . x and above . | 136 | 11 |
231,276 | def _format_monitor_parameter ( param ) : if '{' in param and '}' : tmp = param . strip ( '}' ) . split ( '{' ) monitor = '' . join ( tmp ) . rstrip ( ) return monitor else : return param | This is a workaround for a known issue ID645289 which affects | 59 | 13 |
231,277 | def create ( self , * * kwargs ) : if 'monitor' in kwargs : value = self . _format_monitor_parameter ( kwargs [ 'monitor' ] ) kwargs [ 'monitor' ] = value return super ( Pool , self ) . _create ( * * kwargs ) | Custom create method to implement monitor parameter formatting . | 69 | 9 |
231,278 | def update ( self , * * kwargs ) : if 'monitor' in kwargs : value = self . _format_monitor_parameter ( kwargs [ 'monitor' ] ) kwargs [ 'monitor' ] = value elif 'monitor' in self . __dict__ : value = self . _format_monitor_parameter ( self . __dict__ [ 'monitor' ] ) self . __dict__ [ 'monitor' ] = value return super ( Pool , self ) . _update ( * * kwargs ) | Custom update method to implement monitor parameter formatting . | 116 | 9 |
231,279 | def modify ( self , * * patch ) : if 'monitor' in patch : value = self . _format_monitor_parameter ( patch [ 'monitor' ] ) patch [ 'monitor' ] = value return super ( Pool , self ) . _modify ( * * patch ) | Custom modify method to implement monitor parameter formatting . | 60 | 9 |
231,280 | def exists ( self , * * kwargs ) : requests_params = self . _handle_requests_params ( kwargs ) self . _check_load_parameters ( * * kwargs ) kwargs [ 'uri_as_parts' ] = True session = self . _meta_data [ 'bigip' ] . _meta_data [ 'icr_session' ] base_uri = self . _meta_data [ 'container' ] . _meta_data [ 'uri' ] kwargs . update ( requests_params ) try : response = session . get ( base_uri , * * kwargs ) except HTTPError as err : if err . response . status_code == 404 : return False else : raise rdict = response . json ( ) if "address" not in rdict : # We can add 'or' conditions to be more restrictive. return False # Only after all conditions are met... return True | Check for the existence of the named object on the BigIP | 204 | 12 |
231,281 | def exec_cmd ( self , command , * * kwargs ) : self . _is_allowed_command ( command ) self . _check_command_parameters ( * * kwargs ) if command == 'load' : kwargs [ 'command' ] = command self . _check_exclusive_parameters ( * * kwargs ) requests_params = self . _handle_requests_params ( kwargs ) session = self . _meta_data [ 'bigip' ] . _meta_data [ 'icr_session' ] try : session . post ( self . _meta_data [ 'uri' ] , json = kwargs , * * requests_params ) except HTTPError as err : if err . response . status_code != 502 : raise return else : return self . _exec_cmd ( command , * * kwargs ) | Due to ID476518 the load command need special treatment . | 188 | 13 |
231,282 | def load ( self , * * kwargs ) : # Check if we are using 12.1.0 version or above when using this method self . _is_version_supported_method ( '12.1.0' ) newinst = self . _stamp_out_core ( ) newinst . _refresh ( * * kwargs ) return newinst | Method to list the UCS on the system | 79 | 8 |
231,283 | def _set_attributes ( self , * * kwargs ) : try : self . devices = kwargs [ 'devices' ] [ : ] self . name = kwargs [ 'device_group_name' ] self . type = kwargs [ 'device_group_type' ] self . partition = kwargs [ 'device_group_partition' ] except KeyError as ex : raise MissingRequiredDeviceGroupParameter ( ex ) | Set instance attributes based on kwargs | 97 | 8 |
231,284 | def validate ( self , * * kwargs ) : self . _set_attributes ( * * kwargs ) self . _check_type ( ) self . dev_group_uri_res = self . _get_device_group ( self . devices [ 0 ] ) if self . dev_group_uri_res . type != self . type : msg = 'Device group type found: %r does not match expected ' 'device group type: %r' % ( self . dev_group_uri_res . type , self . type ) raise UnexpectedDeviceGroupType ( msg ) queried_device_names = self . _get_device_names_in_group ( ) given_device_names = [ ] for device in self . devices : device_name = get_device_info ( device ) . name given_device_names . append ( device_name ) if sorted ( queried_device_names ) != sorted ( given_device_names ) : msg = 'Given devices does not match queried devices.' raise UnexpectedDeviceGroupDevices ( msg ) self . ensure_all_devices_in_sync ( ) | Validate device group state among given devices . | 244 | 9 |
231,285 | def _check_type ( self ) : if self . type not in self . available_types : msg = 'Unsupported cluster type was given: %s' % self . type raise DeviceGroupNotSupported ( msg ) elif self . type == 'sync-only' and self . name != 'device_trust_group' : msg = "Management of sync-only device groups only supported for " "built-in device group named 'device_trust_group'" raise DeviceGroupNotSupported ( msg ) | Check that the device group type is correct . | 106 | 9 |
231,286 | def create ( self , * * kwargs ) : self . _set_attributes ( * * kwargs ) self . _check_type ( ) pollster ( self . _check_all_devices_in_sync ) ( ) dg = self . devices [ 0 ] . tm . cm . device_groups . device_group dg . create ( name = self . name , partition = self . partition , type = self . type ) for device in self . devices : self . _add_device_to_device_group ( device ) device . tm . sys . config . exec_cmd ( 'save' ) self . ensure_all_devices_in_sync ( ) | Create the device service cluster group and add devices to it . | 149 | 12 |
231,287 | def teardown ( self ) : self . ensure_all_devices_in_sync ( ) for device in self . devices : self . _delete_device_from_device_group ( device ) self . _sync_to_group ( device ) pollster ( self . _ensure_device_active ) ( device ) self . ensure_all_devices_in_sync ( ) dg = pollster ( self . _get_device_group ) ( self . devices [ 0 ] ) dg . delete ( ) pollster ( self . _check_devices_active_licensed ) ( ) pollster ( self . _check_all_devices_in_sync ) ( ) | Teardown device service cluster group . | 146 | 8 |
231,288 | def _get_device_group ( self , device ) : return device . tm . cm . device_groups . device_group . load ( name = self . name , partition = self . partition ) | Get the device group through a device . | 43 | 8 |
231,289 | def _add_device_to_device_group ( self , device ) : device_name = get_device_info ( device ) . name dg = pollster ( self . _get_device_group ) ( device ) dg . devices_s . devices . create ( name = device_name , partition = self . partition ) pollster ( self . _check_device_exists_in_device_group ) ( device_name ) | Add device to device service cluster group . | 96 | 8 |
231,290 | def _check_device_exists_in_device_group ( self , device_name ) : dg = self . _get_device_group ( self . devices [ 0 ] ) dg . devices_s . devices . load ( name = device_name , partition = self . partition ) | Check whether a device exists in the device group | 64 | 9 |
231,291 | def _delete_device_from_device_group ( self , device ) : device_name = get_device_info ( device ) . name dg = pollster ( self . _get_device_group ) ( device ) device_to_remove = dg . devices_s . devices . load ( name = device_name , partition = self . partition ) device_to_remove . delete ( ) | Remove device from device service cluster group . | 87 | 8 |
231,292 | def _ensure_device_active ( self , device ) : act = device . tm . cm . devices . device . load ( name = get_device_info ( device ) . name , partition = self . partition ) if act . failoverState != 'active' : msg = "A device in the cluster was not in the 'Active' state." raise UnexpectedDeviceGroupState ( msg ) | Ensure a single device is in an active state | 85 | 10 |
231,293 | def _sync_to_group ( self , device ) : config_sync_cmd = 'config-sync to-group %s' % self . name device . tm . cm . exec_cmd ( 'run' , utilCmdArgs = config_sync_cmd ) | Sync the device to the cluster group | 58 | 7 |
231,294 | def _check_all_devices_in_sync ( self ) : if len ( self . _get_devices_by_failover_status ( 'In Sync' ) ) != len ( self . devices ) : msg = "Expected all devices in group to have 'In Sync' status." raise UnexpectedDeviceGroupState ( msg ) | Wait until all devices have failover status of In Sync . | 72 | 12 |
231,295 | def _get_devices_by_failover_status ( self , status ) : devices_with_status = [ ] for device in self . devices : if ( self . _check_device_failover_status ( device , status ) ) : devices_with_status . append ( device ) return devices_with_status | Get a list of bigips by failover status . | 69 | 11 |
231,296 | def _check_device_failover_status ( self , device , status ) : sync_status = device . tm . cm . sync_status sync_status . refresh ( ) current_status = ( sync_status . entries [ self . sync_status_entry ] [ 'nestedStats' ] [ 'entries' ] [ 'status' ] [ 'description' ] ) if status == current_status : return True return False | Determine if a device has a specific failover status . | 93 | 13 |
231,297 | def _get_devices_by_activation_state ( self , state ) : devices_with_state = [ ] for device in self . devices : act = device . tm . cm . devices . device . load ( name = get_device_info ( device ) . name , partition = self . partition ) if act . failoverState == state : devices_with_state . append ( device ) return devices_with_state | Get a list of bigips by activation statue . | 91 | 10 |
231,298 | def _set_attr_reg ( self ) : tmos_v = self . _meta_data [ 'bigip' ] . _meta_data [ 'tmos_version' ] attributes = self . _meta_data [ 'attribute_registry' ] v12kind = 'tm:asm:policies:blocking-settings:blocking-settingcollectionstate' v11kind = 'tm:asm:policies:blocking-settings' builderv11 = 'tm:asm:policies:policy-builder:pbconfigstate' builderv12 = 'tm:asm:policies:policy-builder:policy-builderstate' if LooseVersion ( tmos_v ) < LooseVersion ( '12.0.0' ) : attributes [ v11kind ] = Blocking_Settings attributes [ builderv11 ] = Policy_Builder else : attributes [ v12kind ] = Blocking_Settings attributes [ builderv12 ] = Policy_Builder | Helper method . | 208 | 3 |
231,299 | def create ( self , * * kwargs ) : for x in range ( 0 , 30 ) : try : return self . _create ( * * kwargs ) except iControlUnexpectedHTTPError as ex : if self . _check_exception ( ex ) : continue else : raise | Custom creation logic to handle edge cases | 62 | 7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.