idx int64 0 252k | question stringlengths 48 5.28k | target stringlengths 5 1.23k |
|---|---|---|
232,100 | def set_moving_image ( self , image ) : if not isinstance ( image , iio . ANTsImage ) : raise ValueError ( 'image must be ANTsImage type' ) if image . dimension != self . dimension : raise ValueError ( 'image dim (%i) does not match metric dim (%i)' % ( image . dimension , self . dimension ) ) self . _metric . setMovin... | Set Moving ANTsImage for metric |
232,101 | def image_to_cluster_images ( image , min_cluster_size = 50 , min_thresh = 1e-06 , max_thresh = 1 ) : if not isinstance ( image , iio . ANTsImage ) : raise ValueError ( 'image must be ANTsImage type' ) clust = label_clusters ( image , min_cluster_size , min_thresh , max_thresh ) labs = np . unique ( clust [ clust > 0 ]... | Converts an image to several independent images . |
232,102 | def threshold_image ( image , low_thresh = None , high_thresh = None , inval = 1 , outval = 0 , binary = True ) : if high_thresh is None : high_thresh = image . max ( ) + 0.01 if low_thresh is None : low_thresh = image . min ( ) - 0.01 dim = image . dimension outimage = image . clone ( ) args = [ dim , image , outimage... | Converts a scalar image into a binary image by thresholding operations |
232,103 | def symmetrize_image ( image ) : imager = reflect_image ( image , axis = 0 ) imageavg = imager * 0.5 + image for i in range ( 5 ) : w1 = registration ( imageavg , image , type_of_transform = 'SyN' ) w2 = registration ( imageavg , imager , type_of_transform = 'SyN' ) xavg = w1 [ 'warpedmovout' ] * 0.5 + w2 [ 'warpedmovo... | Use registration and reflection to make an image symmetric |
232,104 | def _get_attachments ( self , id ) : uri = '/' . join ( [ self . base_url , self . name , id , 'Attachments' ] ) + '/' return uri , { } , 'get' , None , None , False | Retrieve a list of attachments associated with this Xero object . |
232,105 | def _put_attachment_data ( self , id , filename , data , content_type , include_online = False ) : uri = '/' . join ( [ self . base_url , self . name , id , 'Attachments' , filename ] ) params = { 'IncludeOnline' : 'true' } if include_online else { } headers = { 'Content-Type' : content_type , 'Content-Length' : str ( ... | Upload an attachment to the Xero object . |
232,106 | def page_response ( self , title = '' , body = '' ) : f = StringIO ( ) f . write ( '<!DOCTYPE html>\n' ) f . write ( '<html>\n' ) f . write ( '<head><title>{}</title><head>\n' . format ( title ) ) f . write ( '<body>\n<h2>{}</h2>\n' . format ( title ) ) f . write ( '<div class="content">{}</div>\n' . format ( body ) ) ... | Helper to render an html page with dynamic content |
232,107 | def redirect_response ( self , url , permanent = False ) : if permanent : self . send_response ( 301 ) else : self . send_response ( 302 ) self . send_header ( "Location" , url ) self . end_headers ( ) | Generate redirect response |
232,108 | def _init_credentials ( self , oauth_token , oauth_token_secret ) : "Depending on the state passed in, get self._oauth up and running" if oauth_token and oauth_token_secret : if self . verified : self . _init_oauth ( oauth_token , oauth_token_secret ) else : self . oauth_token = oauth_token self . oauth_token_secret = ... | Depending on the state passed in get self . _oauth up and running |
232,109 | def _init_oauth ( self , oauth_token , oauth_token_secret ) : "Store and initialize a verified set of OAuth credentials" self . oauth_token = oauth_token self . oauth_token_secret = oauth_token_secret self . _oauth = OAuth1 ( self . consumer_key , client_secret = self . consumer_secret , resource_owner_key = self . oau... | Store and initialize a verified set of OAuth credentials |
232,110 | def _process_oauth_response ( self , response ) : "Extracts the fields from an oauth response" if response . status_code == 200 : credentials = parse_qs ( response . text ) self . _init_oauth ( credentials . get ( 'oauth_token' ) [ 0 ] , credentials . get ( 'oauth_token_secret' ) [ 0 ] ) self . oauth_session_handle = c... | Extracts the fields from an oauth response |
232,111 | def state ( self ) : return dict ( ( attr , getattr ( self , attr ) ) for attr in ( 'consumer_key' , 'consumer_secret' , 'callback_uri' , 'verified' , 'oauth_token' , 'oauth_token_secret' , 'oauth_session_handle' , 'oauth_expires_at' , 'oauth_authorization_expires_at' , 'scope' ) if getattr ( self , attr ) is not None ... | Obtain the useful state of this credentials object so that we can reconstruct it independently . |
232,112 | def verify ( self , verifier ) : "Verify an OAuth token" oauth = OAuth1 ( self . consumer_key , client_secret = self . consumer_secret , resource_owner_key = self . oauth_token , resource_owner_secret = self . oauth_token_secret , verifier = verifier , rsa_key = self . rsa_key , signature_method = self . _signature_met... | Verify an OAuth token |
232,113 | def url ( self ) : "Returns the URL that can be visited to obtain a verifier code" query_string = { 'oauth_token' : self . oauth_token } if self . scope : query_string [ 'scope' ] = self . scope url = XERO_BASE_URL + AUTHORIZE_URL + '?' + urlencode ( query_string ) return url | Returns the URL that can be visited to obtain a verifier code |
232,114 | def refresh ( self ) : "Refresh an expired token" oauth = OAuth1 ( self . consumer_key , client_secret = self . consumer_secret , resource_owner_key = self . oauth_token , resource_owner_secret = self . oauth_token_secret , rsa_key = self . rsa_key , signature_method = self . _signature_method ) headers = { 'User-Agent... | Refresh an expired token |
232,115 | def _get_files ( self , folderId ) : uri = '/' . join ( [ self . base_url , self . name , folderId , 'Files' ] ) return uri , { } , 'get' , None , None , False , None | Retrieve the list of files contained in a folder |
232,116 | def handle_cluster_request ( self , tsn , command_id , args ) : if command_id == 0 : if self . _timer_handle : self . _timer_handle . cancel ( ) loop = asyncio . get_event_loop ( ) self . _timer_handle = loop . call_later ( 30 , self . _turn_off ) | Handle the cluster command . |
232,117 | def _parse_attributes ( self , value ) : from zigpy . zcl import foundation as f attributes = { } attribute_names = { 1 : BATTERY_VOLTAGE_MV , 3 : TEMPERATURE , 4 : XIAOMI_ATTR_4 , 5 : XIAOMI_ATTR_5 , 6 : XIAOMI_ATTR_6 , 10 : PATH } result = { } while value : skey = int ( value [ 0 ] ) svalue , value = f . TypeValue . ... | Parse non standard atrributes . |
232,118 | def _calculate_remaining_battery_percentage ( self , voltage ) : min_voltage = 2500 max_voltage = 3000 percent = ( voltage - min_voltage ) / ( max_voltage - min_voltage ) * 200 return min ( 200 , percent ) | Calculate percentage . |
232,119 | def battery_reported ( self , voltage , rawVoltage ) : self . _update_attribute ( BATTERY_PERCENTAGE_REMAINING , voltage ) self . _update_attribute ( self . BATTERY_VOLTAGE_ATTR , int ( rawVoltage / 100 ) ) | Battery reported . |
232,120 | async def configure_reporting ( self , attribute , min_interval , max_interval , reportable_change ) : result = await super ( ) . configure_reporting ( PowerConfigurationCluster . BATTERY_VOLTAGE_ATTR , self . FREQUENCY , self . FREQUENCY , self . MINIMUM_CHANGE ) return result | Configure reporting . |
232,121 | def update ( self , ** kwargs ) : inherit_device_group = self . __dict__ . get ( 'inheritedDevicegroup' , False ) if inherit_device_group == 'true' : self . __dict__ . pop ( 'deviceGroup' ) return self . _update ( ** kwargs ) | Update the object removing device group if inherited |
232,122 | def sync_to ( self ) : device_group_collection = self . _meta_data [ 'container' ] cm = device_group_collection . _meta_data [ 'container' ] sync_cmd = 'config-sync to-group %s' % self . name cm . exec_cmd ( 'run' , utilCmdArgs = sync_cmd ) | Wrapper method that synchronizes configuration to DG . |
232,123 | def _create ( self , ** kwargs ) : try : return super ( Service , self ) . _create ( ** kwargs ) except HTTPError as ex : if "The configuration was updated successfully but could not be " "retrieved" not in ex . response . text : raise if 'partition' not in kwargs : kwargs [ 'partition' ] = 'Common' kwargs_copy = kwarg... | Create service on device and create accompanying Python object . |
232,124 | def _build_service_uri ( self , base_uri , partition , name ) : name = name . replace ( '/' , '~' ) return '%s~%s~%s.app~%s' % ( base_uri , partition , name , name ) | Build the proper uri for a service resource . |
232,125 | def delete ( self , ** kwargs ) : if 'id' not in kwargs : delete_uri = self . _meta_data [ 'uri' ] if delete_uri . endswith ( '/' ) : delete_uri = delete_uri [ 0 : - 1 ] kwargs [ 'id' ] = os . path . basename ( delete_uri ) uid = uuid . UUID ( kwargs [ 'id' ] , version = 4 ) if uid . hex != kwargs [ 'id' ] . replace ( ... | Deletes a member from a license pool |
232,126 | def _set_attributes ( self , ** kwargs ) : self . devices = kwargs [ 'devices' ] [ : ] self . partition = kwargs [ 'partition' ] self . device_group_name = 'device_trust_group' self . device_group_type = 'sync-only' | Set attributes for instance in one place |
232,127 | def validate ( self ) : self . _populate_domain ( ) missing = [ ] for domain_device in self . domain : for truster , trustees in iteritems ( self . domain ) : if domain_device not in trustees : missing . append ( ( domain_device , truster , trustees ) ) if missing : msg = '' for item in missing : msg += '\n%r is not tr... | Validate that devices are each trusted by one another |
232,128 | def _populate_domain ( self ) : self . domain = { } for device in self . devices : device_name = get_device_info ( device ) . name ca_devices = device . tm . cm . trust_domains . trust_domain . load ( name = 'Root' ) . caDevices self . domain [ device_name ] = [ d . replace ( '/%s/' % self . partition , '' ) for d in c... | Populate TrustDomain s domain attribute . |
232,129 | def create ( self , ** kwargs ) : self . _set_attributes ( ** kwargs ) for device in self . devices [ 1 : ] : self . _add_trustee ( device ) pollster ( self . validate ) ( ) | Add trusted peers to the root bigip device . |
232,130 | def teardown ( self ) : for device in self . devices : self . _remove_trustee ( device ) self . _populate_domain ( ) self . domain = { } | Teardown trust domain by removing trusted devices . |
232,131 | def _add_trustee ( self , device ) : device_name = get_device_info ( device ) . name if device_name in self . domain : msg = 'Device: %r is already in this trust domain.' % device_name raise DeviceAlreadyInTrustDomain ( msg ) self . _modify_trust ( self . devices [ 0 ] , self . _get_add_trustee_cmd , device ) | Add a single trusted device to the trust domain . |
232,132 | def _remove_trustee ( self , device ) : trustee_name = get_device_info ( device ) . name name_object_map = get_device_names_to_objects ( self . devices ) delete_func = self . _get_delete_trustee_cmd for truster in self . domain : if trustee_name in self . domain [ truster ] and truster != trustee_name : truster_obj = n... | Remove a trustee from the trust domain . |
232,133 | def _modify_trust ( self , truster , mod_peer_func , trustee ) : iapp_name = 'trusted_device' mod_peer_cmd = mod_peer_func ( trustee ) iapp_actions = self . iapp_actions . copy ( ) iapp_actions [ 'definition' ] [ 'implementation' ] = mod_peer_cmd self . _deploy_iapp ( iapp_name , iapp_actions , truster ) self . _delete... | Modify a trusted peer device by deploying an iapp . |
232,134 | def _delete_iapp ( self , iapp_name , deploying_device ) : iapp = deploying_device . tm . sys . application iapp_serv = iapp . services . service . load ( name = iapp_name , partition = self . partition ) iapp_serv . delete ( ) iapp_tmpl = iapp . templates . template . load ( name = iapp_name , partition = self . parti... | Delete an iapp service and template on the root device . |
232,135 | def _deploy_iapp ( self , iapp_name , actions , deploying_device ) : tmpl = deploying_device . tm . sys . application . templates . template serv = deploying_device . tm . sys . application . services . service tmpl . create ( name = iapp_name , partition = self . partition , actions = actions ) pollster ( deploying_de... | Deploy iapp to add trusted device |
232,136 | def _get_add_trustee_cmd ( self , trustee ) : trustee_info = pollster ( get_device_info ) ( trustee ) username = trustee . _meta_data [ 'username' ] password = trustee . _meta_data [ 'password' ] return 'tmsh::modify cm trust-domain Root ca-devices add ' '\\{ %s \\} name %s username %s password %s' % ( trustee_info . m... | Get tmsh command to add a trusted device . |
232,137 | def load ( self , ** kwargs ) : kwargs [ 'transform_name' ] = True kwargs = self . _mutate_name ( kwargs ) return self . _load ( ** kwargs ) | Loads a given resource |
232,138 | 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 : ] ) : if char == '\\' and not in_escape : in_escape = True elif char == '\\' and in_escape : in_escape = False if not in_escape : if ch... | Get end of section s content . |
232,139 | 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 . |
232,140 | 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 fou... | Find template name . |
232,141 | 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 . |
232,142 | 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 . templ... | Add the found and required sections to the templ_dict . |
232,143 | 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 ... | Add the found external sections to the templ_dict . |
232,144 | 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 . |
232,145 | 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 ... | Turns a string representation of a TCL list into a Python list . |
232,146 | 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 . |
232,147 | 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 . |
232,148 | 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 ) ... | wrapped by create override that in subclasses to customize |
232,149 | def peer ( opt_peer , opt_username , opt_password , scope = "module" ) : p = BigIP ( opt_peer , opt_username , opt_password ) return p | peer bigip fixture |
232,150 | 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 |
232,151 | 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 |
232,152 | 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 |
232,153 | def refresh ( self , ** kwargs ) : self . resource . refresh ( ** kwargs ) self . rdict = self . resource . entries self . _update_stats ( ) | Refreshes stats attached to an object |
232,154 | 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 |
232,155 | 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 ( interv... | Poll with a given callable for a specified number of times . |
232,156 | 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 |
232,157 | 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 . |
232,158 | 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 . s... | If command result exists run these checks . |
232,159 | 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 . |
232,160 | 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... | Create a new method as command has specific requirements . |
232,161 | 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 . |
232,162 | 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 . |
232,163 | 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 |
232,164 | 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 . |
232,165 | 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 ... | Due to a password decryption bug |
232,166 | 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 . endswi... | Use this to decide which format is called for by the kind . |
232,167 | 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 . |
232,168 | 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 |
232,169 | 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 . |
232,170 | 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 self . ... | Validate parameters that will be passed to the requests verbs . |
232,171 | 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 : ... | Check for mutually exclusive attributes in kwargs . |
232,172 | 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 = 'Attem... | Wrapped with modify override in a subclass to customize . |
232,173 | 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 . |
232,174 | 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_u... | Retrieve the appropriate request items for put or patch calls . |
232,175 | def _prepare_request_json ( self , kwargs ) : kwargs = self . _check_for_python_keywords ( 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 . |
232,176 | 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 ... | Iterate over list to find dicts and check for python keywords . |
232,177 | 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 ) el... | When Python keywords seen mutate to remove trailing underscore . |
232,178 | 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 = "Devi... | Call this from _local_update to validate response keys |
232,179 | 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 . |
232,180 | 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' % re... | wrapped with update override that in a subclass to customize |
232,181 | 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/' ) : uri = self . _meta_data [ 'uri' ] [ 0 : - 1 ] else : uri = self . _meta_data [ 'uri' ] ... | wrapped by refresh override that in a subclass to customize |
232,182 | def _produce_instance ( self , response ) : new_instance = self . _stamp_out_core ( ) new_instance . _local_update ( response . json ( ) ) if hasattr ( new_instance , 'selfLink' ) : if new_instance . kind != new_instance . _meta_data [ 'required_json_kind' ] and new_instance . kind != "tm:transaction:commandsstate" and... | Generate a new self which is an instance of the self . |
232,183 | 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 s... | Ensure only one key with a boolean value is present in dict . |
232,184 | def get_collection ( self , ** kwargs ) : list_of_contents = [ ] self . refresh ( ** kwargs ) if 'items' in self . __dict__ : for item in self . items : if 'kind' not in item : list_of_contents . append ( item ) continue kind = item [ 'kind' ] if kind in self . _meta_data [ 'attribute_registry' ] : instance = self . _m... | Get an iterator of Python Resource objects that represent URIs . |
232,185 | 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... | wrapped with delete_collection override that in a sublcass to customize |
232,186 | def _activate_URI ( self , selfLinkuri ) : uri = urlparse . urlsplit ( str ( self . _meta_data [ 'bigip' ] . _meta_data [ 'uri' ] ) ) attribute_reg = self . _meta_data . get ( 'attribute_registry' , { } ) attrs = list ( itervalues ( attribute_reg ) ) attrs = self . _assign_stats ( attrs ) ( scheme , domain , path , qar... | Call this with a selfLink after it s returned in _create or _load . |
232,187 | 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 . |
232,188 | 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 ' 'paramet... | Helper function to do operation on sets |
232,189 | 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 . |
232,190 | 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 ( ... | wrapped with load override that in a subclass to customize |
232,191 | 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' ] force = self . _check_force_arg ( kwargs . pop ( 'force' , True ) ) if not force : self . _check_generation ( ) r... | wrapped with delete override that in a subclass to customize |
232,192 | 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 . ... | Wrapped with delete override that in a subclass to customize |
232,193 | def exists ( self , ** kwargs ) : r 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 = kw... | r Check for the existence of the ASM object on the BIG - IP |
232,194 | 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 ) _create_uri = self . _meta_data [ 'container' ] . _meta_data [... | wrapped by fetch override that in subclasses to customize |
232,195 | 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 |
232,196 | 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 |
232,197 | 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 : logg... | Filter version - specific optional parameters |
232,198 | 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' ) : ... | Allow creation of draft policy and ability to publish a draft |
232,199 | 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' ) a... | Modify only draft or legacy policies |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.