idx
int64
0
63k
question
stringlengths
53
5.28k
target
stringlengths
5
805
41,800
def get_svnpath ( ) : svnpathtmp = __file__ splitsvnpath = svnpathtmp . split ( '/' ) if len ( splitsvnpath ) == 1 : svnpath = os . path . abspath ( '.' ) + '/../../' else : svnpath = '' for i in range ( len ( splitsvnpath ) - 3 ) : svnpath += splitsvnpath [ i ] + '/' return svnpath
This subroutine gives back the path of the whole svn tree installation which is necessary for the script to run .
41,801
def reset_filter ( self ) : self . header_desc = self . _header_desc self . header_data = self . _header_data self . header_style = self . _header_style self . desc = self . _desc self . data = self . _data self . style = self . _style self . descdict = self . _descdict self . datadict = self . _datadict self . styledi...
Resets the filter and goes back to initialized value . This routine also resets the style if you have changed it .
41,802
def info ( self , graintype = True , group = True , reference = False , phase = True ) : gtype_info = [ ] group_info = [ ] ref_info = [ ] phase_info = [ ] print ( 'There are ' + str ( len ( self . data ) ) + ' grains in your database.\n' ) if graintype : for i in range ( len ( self . desc ) ) : gtype_tmp = self . desc ...
This routine gives you informations what kind of grains are currently available in your filtered version . It gives you the type of grains available . More to be implemented upon need .
41,803
def _filter_desc ( self , indexing ) : if len ( indexing ) > 0 : desc_tmp = np . zeros ( ( len ( indexing ) , len ( self . header_desc ) ) , dtype = '|S1024' ) data_tmp = np . zeros ( ( len ( indexing ) , len ( self . header_data ) ) ) style_tmp = np . zeros ( ( len ( indexing ) , len ( self . header_style ) ) , dtype ...
Private function to filter data goes with filter_desc
41,804
def filter_data ( self , isos , limit , delta = True ) : dat_index , delta_b , ratio_b = self . check_availability ( isos ) if dat_index == - 1 : print ( 'Isotopes selected are not available. Check i.datadict (where i is your instance) for availability of isotopes.' ) return None if limit [ 0 : 1 ] == '>' : comperator ...
This subroutine filters isotopic values according to the limit you give . You can filter in ratio or in delta space .
41,805
def check_availability ( self , isos ) : iso1name = iso_name_converter ( isos [ 0 ] ) iso2name = iso_name_converter ( isos [ 1 ] ) ratio = iso1name + '/' + iso2name ratio_inv = iso2name + '/' + iso1name delta = 'd(' + iso1name + '/' + iso2name + ')' delta_inv = 'd(' + iso2name + '/' + iso1name + ')' index = - 1 try : i...
This routine checks if the requested set of isotopes is available in the dataset .
41,806
def ratio_to_delta ( self , isos_ss , ratio , oneover = False ) : if type ( isos_ss ) == float : ss_ratio = isos_ss elif type ( isos_ss ) == list : ss_ratio = self . inut . isoratio_init ( isos_ss ) else : print ( 'Check input of isos_ss into ratio_to_delta routine' ) return None if oneover : ratio = old_div ( 1 , rati...
Transforms an isotope ratio into a delta value
41,807
def with_filter ( self , filter ) : res = copy . deepcopy ( self ) old_filter = self . _filter def new_filter ( request ) : return filter ( request , old_filter ) res . _filter = new_filter return res
Returns a new service which will process requests with the specified filter . Filtering operations can include logging automatic retrying etc ... The filter is a lambda which receives the HTTPRequest and another lambda . The filter can perform any pre - processing on the request pass it off to the next lambda and then ...
41,808
def _validate_snmp ( self ) : cred = self . snmp_credentials if cred is not None : if cred . get ( 'snmp_inspection' ) is True : if not all ( [ cred . get ( 'auth_user' ) , cred . get ( 'auth_prot_pp' ) , cred . get ( 'auth_priv_pp' ) ] ) : msg = self . _ ( 'Either few or all mandatory ' 'SNMP credentials ' 'are missin...
Validates SNMP credentials .
41,809
def _call_method ( self , method_name , * args , ** kwargs ) : if self . use_redfish_only : if method_name in SUPPORTED_REDFISH_METHODS : the_operation_object = self . redfish else : raise NotImplementedError ( ) else : the_operation_object = self . ribcl if 'Gen10' in self . model : if method_name in SUPPORTED_REDFISH...
Call the corresponding method using RIBCL RIS or REDFISH
41,810
def set_vm_status ( self , device = 'FLOPPY' , boot_option = 'BOOT_ONCE' , write_protect = 'YES' ) : return self . _call_method ( 'set_vm_status' , device , boot_option , write_protect )
Sets the Virtual Media drive status and allows the
41,811
def get_essential_properties ( self ) : data = self . _call_method ( 'get_essential_properties' ) if ( data [ 'properties' ] [ 'local_gb' ] == 0 ) : cred = self . snmp_credentials if cred and cred . get ( 'snmp_inspection' ) : disksize = snmp . get_local_gb ( self . host , cred ) if disksize : data [ 'properties' ] [ '...
Get the essential scheduling properties
41,812
def get_server_capabilities ( self ) : capabilities = self . _call_method ( 'get_server_capabilities' ) if ( 'Gen10' not in self . model ) : major_minor = ( self . _call_method ( 'get_ilo_firmware_version_as_major_minor' ) ) nic_capacity = ipmi . get_nic_capacity ( self . ipmi_host_info , major_minor ) if nic_capacity ...
Get hardware properties which can be used for scheduling
41,813
def _read_mesafile ( filename , data_rows = 0 , only = 'all' ) : f = open ( filename , 'r' ) vv = [ ] v = [ ] lines = [ ] line = '' for i in range ( 0 , 6 ) : line = f . readline ( ) lines . extend ( [ line ] ) hval = lines [ 2 ] . split ( ) hlist = lines [ 1 ] . split ( ) header_attr = { } for a , b in zip ( hlist , h...
private routine that is not directly called by the user
41,814
def _profiles_index ( self ) : prof_ind_name = self . prof_ind_name f = open ( self . sldir + '/' + prof_ind_name , 'r' ) line = f . readline ( ) numlines = int ( line . split ( ) [ 0 ] ) print ( str ( numlines ) + ' in profiles.index file ...' ) model = [ ] log_file_num = [ ] for line in f : model . append ( int ( lin...
read profiles . index and make hash array
41,815
def _log_file_ind ( self , inum ) : self . _profiles_index ( ) if inum <= 0 : print ( "Smallest argument is 1" ) return inum_max = len ( self . log_ind ) inum -= 1 if inum > inum_max : print ( 'There are only ' + str ( inum_max ) + ' profile file available.' ) log_data_number = - 1 return log_data_number else : log_dat...
Information about available profile . data or log . data files .
41,816
def get ( self , str_name ) : column_array = self . data [ : , self . cols [ str_name ] - 1 ] . astype ( 'float' ) return column_array
return a column of data with the name str_name .
41,817
def write_LEAFS_model ( self , nzn = 30000000 , dr = 5.e4 , rhostrip = 5.e-4 ) : from scipy import interpolate ye = self . get ( 'ye' ) newye = [ ] rho = 10. ** self . get ( 'logRho' ) [ : : - 1 ] idx = np . abs ( rho - rhostrip ) . argmin ( ) + 1 rho = rho [ : idx ] rhoc = rho [ 0 ] rad = 10. ** self . get ( 'logR' ) ...
write an ascii file that will be read by Sam s version of inimod . F90 in order to make an initial model for LEAFS
41,818
def energy_profile ( self , ixaxis ) : mass = self . get ( 'mass' ) radius = self . get ( 'radius' ) * ast . rsun_cm eps_nuc = self . get ( 'eps_nuc' ) eps_neu = self . get ( 'non_nuc_neu' ) if ixaxis == 'mass' : xaxis = mass xlab = 'Mass / M$_\odot$' else : xaxis = old_div ( radius , 1.e8 ) xlab = 'Radius (Mm)' pl . p...
Plot radial profile of key energy generations eps_nuc eps_neu etc .
41,819
def _read_starlog ( self ) : sldir = self . sldir slname = self . slname slaname = slname + 'sa' if not os . path . exists ( sldir + '/' + slaname ) : print ( 'No ' + self . slname + 'sa file found, create new one from ' + self . slname ) _cleanstarlog ( sldir + '/' + slname ) else : if self . clean_starlog : print ( '...
read history . data or star . log file again
41,820
def hrd ( self , ifig = None , label = None , colour = None , s2ms = False , dashes = None , ** kwargs ) : if ifig is not None : pl . figure ( ifig ) if s2ms : h1 = self . get ( 'center_h1' ) idx = np . where ( h1 [ 0 ] - h1 >= 3.e-3 ) [ 0 ] [ 0 ] skip = idx else : skip = 0 x = self . get ( 'log_Teff' ) [ skip : ] y = ...
Plot an HR diagram
41,821
def hrd_key ( self , key_str ) : pyl . plot ( self . data [ : , self . cols [ 'log_Teff' ] - 1 ] , self . data [ : , self . cols [ 'log_L' ] - 1 ] , label = key_str ) pyl . legend ( ) pyl . xlabel ( 'log Teff' ) pyl . ylabel ( 'log L' ) x1 , x2 = pl . xlim ( ) if x2 > x1 : self . _xlimrev ( )
plot an HR diagram
41,822
def hrd_new ( self , input_label = "" , skip = 0 ) : xl_old = pyl . gca ( ) . get_xlim ( ) if input_label == "" : my_label = "M=" + str ( self . header_attr [ 'initial_mass' ] ) + ", Z=" + str ( self . header_attr [ 'initial_z' ] ) else : my_label = "M=" + str ( self . header_attr [ 'initial_mass' ] ) + ", Z=" + str ( ...
plot an HR diagram with options to skip the first N lines and add a label string
41,823
def xche4_teff ( self , ifig = None , lims = [ 1. , 0. , 3.4 , 4.7 ] , label = None , colour = None , s2ms = True , dashes = None ) : fsize = 18 params = { 'axes.labelsize' : fsize , 'font.family' : 'Times New Roman' , 'figure.facecolor' : 'white' , 'text.fontsize' : fsize , 'legend.fontsize' : fsize , 'xtick.labelsize...
Plot effective temperature against central helium abundance .
41,824
def tcrhoc ( self , ifig = None , lims = [ 3. , 10. , 8. , 10. ] , label = None , colour = None , dashes = None ) : if ifig is not None : pl . figure ( ifig ) if label is not None : if colour is not None : line , = pl . plot ( self . get ( 'log_center_Rho' ) , self . get ( 'log_center_T' ) , label = label , color = col...
Central temperature again central density plot
41,825
def mdot_t ( self , ifig = None , lims = [ 7.4 , 2.6 , - 8.5 , - 4.5 ] , label = None , colour = None , s2ms = False , dashes = None ) : fsize = 18 params = { 'axes.labelsize' : fsize , 'font.family' : 'Times New Roman' , 'figure.facecolor' : 'white' , 'text.fontsize' : fsize , 'legend.fontsize' : fsize , 'xtick.labels...
Plot mass loss history as a function of log - time - left
41,826
def t_surfabu ( self , num_frame , xax , t0_model = 0 , title = 'surface abundance' , t_eps = 1.e-3 , plot_CO_ratio = False ) : if num_frame >= 0 : pyl . figure ( num_frame ) if xax == 'time' : xaxisarray = self . get ( 'star_age' ) [ t0_model : ] elif xax == 'model' : xaxisarray = self . get ( 'model_number' ) [ t0_mo...
t_surfabu plots surface abundance evolution as a function of time .
41,827
def t_lumi ( self , num_frame , xax ) : pyl . figure ( num_frame ) if xax == 'time' : xaxisarray = self . get ( 'star_age' ) elif xax == 'model' : xaxisarray = self . get ( 'model_number' ) else : print ( 'kippenhahn_error: invalid string for x-axis selction. needs to be "time" or "model"' ) logLH = self . get ( 'log_L...
Luminosity evolution as a function of time or model .
41,828
def t_surf_parameter ( self , num_frame , xax ) : pyl . figure ( num_frame ) if xax == 'time' : xaxisarray = self . get ( 'star_age' ) elif xax == 'model' : xaxisarray = self . get ( 'model_number' ) else : print ( 'kippenhahn_error: invalid string for x-axis selction. needs to be "time" or "model"' ) logL = self . get...
Surface parameter evolution as a function of time or model .
41,829
def find_first_TP ( self ) : star_mass = self . get ( 'star_mass' ) he_lumi = self . get ( 'log_LHe' ) h_lumi = self . get ( 'log_LH' ) mx2_bot = self . get ( 'mx2_bot' ) * star_mass try : h1_boundary_mass = self . get ( 'h1_boundary_mass' ) he4_boundary_mass = self . get ( 'he4_boundary_mass' ) except : try : h1_bound...
Find first TP of the TPAGB phase and returns the model number at its LHe maximum .
41,830
def calc_DUP_parameter ( self , modeln , label , fig = 10 , color = 'r' , marker_type = '*' , h_core_mass = False ) : number_DUP = ( old_div ( len ( modeln ) , 2 ) - 1 ) try : h1_bnd_m = self . get ( 'h1_boundary_mass' ) except : try : h1_bnd_m = self . get ( 'he_core_mass' ) except : pass star_mass = self . get ( 'sta...
Method to calculate the DUP parameter evolution for different TPs specified specified by their model number .
41,831
def _create_usm_user_obj ( snmp_cred ) : auth_protocol = snmp_cred . get ( 'auth_protocol' ) priv_protocol = snmp_cred . get ( 'priv_protocol' ) auth_user = snmp_cred . get ( 'auth_user' ) auth_prot_pp = snmp_cred . get ( 'auth_prot_pp' ) auth_priv_pp = snmp_cred . get ( 'auth_priv_pp' ) if ( ( not auth_protocol ) and ...
Creates the UsmUserData obj for the given credentials .
41,832
def _parse_mibs ( iLOIP , snmp_credentials ) : result = { } usm_user_obj = _create_usm_user_obj ( snmp_credentials ) try : for ( errorIndication , errorStatus , errorIndex , varBinds ) in hlapi . nextCmd ( hlapi . SnmpEngine ( ) , usm_user_obj , hlapi . UdpTransportTarget ( ( iLOIP , 161 ) , timeout = 3 , retries = 3 )...
Parses the MIBs .
41,833
def _get_disksize_MiB ( iLOIP , cred ) : result = _parse_mibs ( iLOIP , cred ) disksize = { } for uuid in sorted ( result ) : for key in result [ uuid ] : if key . find ( 'PhyDrvSize' ) >= 0 : disksize [ uuid ] = dict ( ) for suffix in sorted ( result [ uuid ] [ key ] ) : size = result [ uuid ] [ key ] [ suffix ] disks...
Reads the dictionary of parsed MIBs and gets the disk size .
41,834
def get_local_gb ( iLOIP , snmp_credentials ) : disk_sizes = _get_disksize_MiB ( iLOIP , snmp_credentials ) max_size = 0 for uuid in disk_sizes : for key in disk_sizes [ uuid ] : if int ( disk_sizes [ uuid ] [ key ] ) > max_size : max_size = int ( disk_sizes [ uuid ] [ key ] ) max_size_gb = max_size / 1024 return max_s...
Gets the maximum disk size among all disks .
41,835
def summary ( self ) : mac_dict = { } for eth in self . get_members ( ) : if eth . mac_address is not None : if ( eth . status is not None and eth . status . health == sys_cons . HEALTH_OK and eth . status . state == sys_cons . HEALTH_STATE_ENABLED ) : mac_dict . update ( { 'Port ' + eth . identity : eth . mac_address ...
property to return the summary MAC addresses and state
41,836
def _update_physical_disk_details ( raid_config , server ) : raid_config [ 'physical_disks' ] = [ ] physical_drives = server . get_physical_drives ( ) for physical_drive in physical_drives : physical_drive_dict = physical_drive . get_physical_drive_dict ( ) raid_config [ 'physical_disks' ] . append ( physical_drive_dic...
Adds the physical disk details to the RAID configuration passed .
41,837
def validate ( raid_config ) : raid_schema_fobj = open ( RAID_CONFIG_SCHEMA , 'r' ) raid_config_schema = json . load ( raid_schema_fobj ) try : jsonschema . validate ( raid_config , raid_config_schema ) except json_schema_exc . ValidationError as e : raise exception . InvalidInputError ( e . message ) for logical_disk ...
Validates the RAID configuration provided .
41,838
def _select_controllers_by ( server , select_condition , msg ) : all_controllers = server . controllers supported_controllers = [ c for c in all_controllers if select_condition ( c ) ] if not supported_controllers : reason = ( "None of the available SSA controllers %(controllers)s " "have %(msg)s" % { 'controllers' : '...
Filters out the hpssa controllers based on the condition .
41,839
def create_configuration ( raid_config ) : server = objects . Server ( ) select_controllers = lambda x : not x . properties . get ( 'HBA Mode Enabled' , False ) _select_controllers_by ( server , select_controllers , 'RAID enabled' ) validate ( raid_config ) logical_disks_sorted = ( sorted ( ( x for x in raid_config [ '...
Create a RAID configuration on this server .
41,840
def _sort_shared_logical_disks ( logical_disks ) : is_shared = ( lambda x : True if ( 'share_physical_disks' in x and x [ 'share_physical_disks' ] ) else False ) num_of_disks = ( lambda x : x [ 'number_of_physical_disks' ] if 'number_of_physical_disks' in x else constants . RAID_LEVEL_MIN_DISKS [ x [ 'raid_level' ] ] )...
Sort the logical disks based on the following conditions .
41,841
def delete_configuration ( ) : server = objects . Server ( ) select_controllers = lambda x : not x . properties . get ( 'HBA Mode Enabled' , False ) _select_controllers_by ( server , select_controllers , 'RAID enabled' ) for controller in server . controllers : if controller . raid_arrays : controller . delete_all_logi...
Delete a RAID configuration on this server .
41,842
def get_configuration ( ) : server = objects . Server ( ) logical_drives = server . get_logical_drives ( ) raid_config = { } raid_config [ 'logical_disks' ] = [ ] for logical_drive in logical_drives : logical_drive_dict = logical_drive . get_logical_drive_dict ( ) raid_config [ 'logical_disks' ] . append ( logical_driv...
Get the current RAID configuration .
41,843
def erase_devices ( ) : server = objects . Server ( ) for controller in server . controllers : drives = [ x for x in controller . unassigned_physical_drives if ( x . get_physical_drive_dict ( ) . get ( 'erase_status' , '' ) == 'OK' ) ] if drives : controller . erase_devices ( drives ) while not has_erase_completed ( ) ...
Erase all the drives on this server .
41,844
def _parse_queue_message_from_headers ( response ) : headers = _parse_response_for_dict ( response ) message = QueueMessage ( ) message . pop_receipt = headers . get ( 'x-ms-popreceipt' ) message . time_next_visible = parser . parse ( headers . get ( 'x-ms-time-next-visible' ) ) return message
Extracts pop receipt and time next visible from headers .
41,845
def volumes ( self ) : return sys_volumes . VolumeCollection ( self . _conn , utils . get_subresource_path_by ( self , 'Volumes' ) , redfish_version = self . redfish_version )
This property prepares the list of volumes
41,846
def _drives_list ( self ) : drives_list = [ ] for member in self . drives : drives_list . append ( sys_drives . Drive ( self . _conn , member . get ( '@odata.id' ) , self . redfish_version ) ) return drives_list
Gets the list of drives
41,847
def has_ssd ( self ) : for member in self . _drives_list ( ) : if member . media_type == constants . MEDIA_TYPE_SSD : return True return False
Return true if any of the drive is ssd
41,848
def has_rotational ( self ) : for member in self . _drives_list ( ) : if member . media_type == constants . MEDIA_TYPE_HDD : return True return False
Return true if any of the drive is HDD
41,849
def has_nvme_ssd ( self ) : for member in self . _drives_list ( ) : if ( member . media_type == constants . MEDIA_TYPE_SSD and member . protocol == constants . PROTOCOL_NVMe ) : return True return False
Return True if the drive is SSD and protocol is NVMe
41,850
def create_table_service ( self ) : try : from . . table . tableservice import TableService return TableService ( self . account_name , self . account_key , sas_token = self . sas_token , is_emulated = self . is_emulated ) except ImportError : raise Exception ( 'The package azure-storage-table is required. ' + 'Please ...
Creates a TableService object with the settings specified in the CloudStorageAccount .
41,851
def get_queue_service_properties ( self , timeout = None ) : request = HTTPRequest ( ) request . method = 'GET' request . host = self . _get_host ( ) request . path = _get_path ( ) request . query = [ ( 'restype' , 'service' ) , ( 'comp' , 'properties' ) , ( 'timeout' , _int_to_str ( timeout ) ) , ] response = self . _...
Gets the properties of a storage account s Queue service including logging analytics and CORS rules .
41,852
def get_queue_acl ( self , queue_name , timeout = None ) : _validate_not_none ( 'queue_name' , queue_name ) request = HTTPRequest ( ) request . method = 'GET' request . host = self . _get_host ( ) request . path = _get_path ( queue_name ) request . query = [ ( 'comp' , 'acl' ) , ( 'timeout' , _int_to_str ( timeout ) ) ...
Returns details about any stored access policies specified on the queue that may be used with Shared Access Signatures .
41,853
def get_allowed_reset_keys_values ( self ) : reset_keys_action = self . _get_reset_keys_action_element ( ) if not reset_keys_action . allowed_values : LOG . warning ( 'Could not figure out the allowed values for the ' 'reset keys in secure boot %s' , self . path ) return set ( mappings . SECUREBOOT_RESET_KEYS_MAP_REV )...
Get the allowed values for resetting the system .
41,854
def reset_keys ( self , target_value ) : valid_keys_resets = self . get_allowed_reset_keys_values ( ) if target_value not in valid_keys_resets : msg = ( 'The parameter "%(parameter)s" value "%(target_value)s" is ' 'invalid. Valid values are: %(valid_keys_reset_values)s' % { 'parameter' : 'target_value' , 'target_value'...
Resets the secure boot keys .
41,855
def _parse_response_for_dict ( response ) : if response is None : return None http_headers = [ 'server' , 'date' , 'location' , 'host' , 'via' , 'proxy-connection' , 'connection' ] return_dict = _HeaderDict ( ) if response . headers : for name , value in response . headers : if not name . lower ( ) in http_headers : re...
Extracts name - values from response header . Filter out the standard http headers .
41,856
def iscsi_settings ( self ) : return ISCSISettings ( self . _conn , utils . get_subresource_path_by ( self , [ "@Redfish.Settings" , "SettingsObject" ] ) , redfish_version = self . redfish_version )
Property to provide reference to iSCSI settings instance
41,857
def update_iscsi_settings ( self , iscsi_data ) : self . _conn . patch ( self . path , data = iscsi_data )
Update iscsi data
41,858
def array_controllers ( self ) : return array_controller . HPEArrayControllerCollection ( self . _conn , utils . get_subresource_path_by ( self , [ 'Links' , 'ArrayControllers' ] ) , redfish_version = self . redfish_version )
This property gets the list of instances for array controllers
41,859
def wait_for_operation_to_complete ( has_operation_completed , retries = 10 , delay_bw_retries = 5 , delay_before_attempts = 10 , failover_exc = exception . IloError , failover_msg = ( "Operation did not complete even after multiple " "attempts." ) , is_silent_loop_exit = False ) : retry_count = retries time . sleep ( ...
Attempts the provided operation for a specified number of times .
41,860
def wait_for_ilo_after_reset ( ilo_object ) : is_ilo_up_after_reset = lambda : ilo_object . get_product_name ( ) is not None is_ilo_up_after_reset . __name__ = 'is_ilo_up_after_reset' wait_for_operation_to_complete ( is_ilo_up_after_reset , failover_exc = exception . IloConnectionError , failover_msg = 'iLO is not up a...
Continuously polls for iLO to come up after reset .
41,861
def wait_for_ribcl_firmware_update_to_complete ( ribcl_object ) : def is_ilo_reset_initiated ( ) : try : LOG . debug ( ribcl_object . _ ( 'Checking for iLO reset...' ) ) ribcl_object . get_product_name ( ) return False except exception . IloError : LOG . debug ( ribcl_object . _ ( 'iLO is being reset...' ) ) return Tru...
Continuously checks for iLO firmware update to complete .
41,862
def get_filename_and_extension_of ( target_file ) : base_target_filename = os . path . basename ( target_file ) file_name , file_ext_with_dot = os . path . splitext ( base_target_filename ) return file_name , file_ext_with_dot
Gets the base filename and extension of the target file .
41,863
def add_exec_permission_to ( target_file ) : mode = os . stat ( target_file ) . st_mode os . chmod ( target_file , mode | stat . S_IXUSR )
Add executable permissions to the file
41,864
def get_major_minor ( ilo_ver_str ) : if not ilo_ver_str : return None try : pattern = re . search ( ILO_VER_STR_PATTERN , ilo_ver_str ) if pattern : matched = pattern . group ( 0 ) if matched : return matched return None except Exception : return None
Extract the major and minor number from the passed string
41,865
def get_supported_boot_modes ( supported_boot_mode_constant ) : boot_mode_bios = 'false' boot_mode_uefi = 'false' if ( supported_boot_mode_constant == constants . SUPPORTED_BOOT_MODE_LEGACY_BIOS_ONLY ) : boot_mode_bios = 'true' elif ( supported_boot_mode_constant == constants . SUPPORTED_BOOT_MODE_UEFI_ONLY ) : boot_mo...
Retrieves the server supported boot modes
41,866
def refresh ( self ) : config = self . _get_all_details ( ) raid_info = _convert_to_dict ( config ) self . controllers = [ ] for key , value in raid_info . items ( ) : self . controllers . append ( Controller ( key , value , self ) ) self . last_updated = time . time ( )
Refresh the server and it s child objects .
41,867
def get_controller_by_id ( self , id ) : for controller in self . controllers : if controller . id == id : return controller return None
Get the controller object given the id .
41,868
def get_logical_drives ( self ) : logical_drives = [ ] for controller in self . controllers : for array in controller . raid_arrays : for logical_drive in array . logical_drives : logical_drives . append ( logical_drive ) return logical_drives
Get all the RAID logical drives in the Server .
41,869
def get_physical_drives ( self ) : physical_drives = [ ] for controller in self . controllers : for physical_drive in controller . unassigned_physical_drives : physical_drives . append ( physical_drive ) for array in controller . raid_arrays : for physical_drive in array . physical_drives : physical_drives . append ( p...
Get all the RAID physical drives on the Server .
41,870
def get_logical_drive_by_wwn ( self , wwn ) : disk = [ x for x in self . get_logical_drives ( ) if x . wwn == wwn ] if disk : return disk [ 0 ] return None
Get the logical drive object given the wwn .
41,871
def get_physical_drive_by_id ( self , id ) : for phy_drive in self . unassigned_physical_drives : if phy_drive . id == id : return phy_drive for array in self . raid_arrays : for phy_drive in array . physical_drives : if phy_drive . id == id : return phy_drive return None
Get a PhysicalDrive object for given id .
41,872
def create_logical_drive ( self , logical_drive_info ) : cmd_args = [ ] if 'array' in logical_drive_info : cmd_args . extend ( [ 'array' , logical_drive_info [ 'array' ] ] ) cmd_args . extend ( [ 'create' , "type=logicaldrive" ] ) if 'physical_disks' in logical_drive_info : phy_drive_ids = ',' . join ( logical_drive_in...
Create a logical drive on the controller .
41,873
def _get_erase_command ( self , drive , pattern ) : cmd_args = [ ] cmd_args . append ( "pd %s" % drive ) cmd_args . extend ( [ 'modify' , 'erase' , pattern ] ) if pattern != 'erasepattern=zero' : cmd_args . append ( 'unrestricted=off' ) cmd_args . append ( 'forced' ) return cmd_args
Return the command arguments based on the pattern .
41,874
def erase_devices ( self , drives ) : for drive in drives : pattern = 'overwrite' if ( drive . disk_type == constants . DISK_TYPE_HDD ) else 'block' cmd_args = self . _get_erase_command ( drive . id , 'erasepattern=%s' % pattern ) stdout = self . execute_cmd ( * cmd_args ) LOG . debug ( "Sanitize disk erase invoked wit...
Perform Erase on all the drives in the controller .
41,875
def can_accomodate ( self , logical_disk ) : raid_level = constants . RAID_LEVEL_INPUT_TO_HPSSA_MAPPING . get ( logical_disk [ 'raid_level' ] , logical_disk [ 'raid_level' ] ) args = ( "array" , self . id , "create" , "type=logicaldrive" , "raid=%s" % raid_level , "size=?" ) if logical_disk [ 'size_gb' ] != "MAX" : des...
Check if this RAID array can accomodate the logical disk .
41,876
def get_physical_drive_dict ( self ) : if isinstance ( self . parent , RaidArray ) : controller = self . parent . parent . id status = 'active' else : controller = self . parent . id status = 'ready' return { 'size_gb' : self . size_gb , 'controller' : controller , 'id' : self . id , 'disk_type' : self . disk_type , 'i...
Returns a dictionary of with the details of the physical drive .
41,877
def send_stream ( stream , filename , size , mtime , mimetype = None , restricted = True , as_attachment = False , etag = None , content_md5 = None , chunk_size = None , conditional = True , trusted = False ) : chunk_size = chunk_size_or_default ( chunk_size ) if mimetype is None and filename : mimetype = mimetypes . g...
Send the contents of a file to the client .
41,878
def sanitize_mimetype ( mimetype , filename = None ) : if mimetype in MIMETYPE_WHITELIST : return mimetype if mimetype in MIMETYPE_PLAINTEXT or ( filename and filename . lower ( ) in MIMETYPE_TEXTFILES ) : return 'text/plain' return 'application/octet-stream'
Sanitize a MIME type so the browser does not render the file .
41,879
def make_path ( base_uri , path , filename , path_dimensions , split_length ) : assert len ( path ) > path_dimensions * split_length uri_parts = [ ] for i in range ( path_dimensions ) : uri_parts . append ( path [ 0 : split_length ] ) path = path [ split_length : ] uri_parts . append ( path ) uri_parts . append ( filen...
Generate a path as base location for file instance .
41,880
def populate_from_path ( bucket , source , checksum = True , key_prefix = '' , chunk_size = None ) : from . models import FileInstance , ObjectVersion def create_file ( key , path ) : key = key_prefix + key if checksum : file_checksum = compute_md5_checksum ( open ( path , 'rb' ) , chunk_size = chunk_size ) file_instan...
Populate a bucket from all files in path .
41,881
def set_options ( self , options ) : self . wipe = options . get ( "wipe" ) self . test_run = options . get ( "test_run" ) self . quiet = options . get ( "test_run" ) self . container_name = options . get ( "container" ) self . verbosity = int ( options . get ( "verbosity" ) ) self . syncmedia = options . get ( "syncme...
Sets instance variables based on an options dict
41,882
def match_cloud ( self , includes , excludes ) : cloud_objs = [ cloud_obj . name for cloud_obj in self . container . get_objects ( ) ] includes_pattern = r"|" . join ( [ fnmatch . translate ( x ) for x in includes ] ) excludes_pattern = r"|" . join ( [ fnmatch . translate ( x ) for x in excludes ] ) or r"$." excludes =...
Returns the cloud objects that match the include and exclude patterns .
41,883
def upload_files ( self , abspaths , relpaths , remote_objects ) : for relpath in relpaths : abspath = [ p for p in abspaths if p [ len ( self . file_root ) : ] == relpath ] [ 0 ] cloud_datetime = remote_objects [ relpath ] if relpath in remote_objects else None local_datetime = datetime . datetime . utcfromtimestamp (...
Determines files to be uploaded and call upload_file on each .
41,884
def upload_file ( self , abspath , cloud_filename ) : if not self . test_run : content = open ( abspath , "rb" ) content_type = get_content_type ( cloud_filename , content ) headers = get_headers ( cloud_filename , content_type ) if headers . get ( "Content-Encoding" ) == "gzip" : content = get_gzipped_contents ( conte...
Uploads a file to the container .
41,885
def delete_extra_files ( self , relpaths , cloud_objs ) : for cloud_obj in cloud_objs : if cloud_obj not in relpaths : if not self . test_run : self . delete_cloud_obj ( cloud_obj ) self . delete_count += 1 if not self . quiet or self . verbosity > 1 : print ( "Deleted: {0}" . format ( cloud_obj ) )
Deletes any objects from the container that do not exist locally .
41,886
def delete_cloud_obj ( self , cloud_obj ) : self . _connection . delete_object ( container = self . container_name , obj = cloud_obj , )
Deletes an object from the container .
41,887
def wipe_container ( self ) : if self . test_run : print ( "Wipe would delete {0} objects." . format ( len ( self . container . object_count ) ) ) else : if not self . quiet or self . verbosity > 1 : print ( "Deleting {0} objects..." . format ( len ( self . container . object_count ) ) ) self . _connection . delete_all...
Completely wipes out the contents of the container .
41,888
def print_tally ( self ) : self . update_count = self . upload_count - self . create_count if self . test_run : print ( "Test run complete with the following results:" ) print ( "Skipped {0}. Created {1}. Updated {2}. Deleted {3}." . format ( self . skip_count , self . create_count , self . update_count , self . delete...
Prints the final tally to stdout .
41,889
def handle ( self , * args , ** options ) : self . _connection = Auth ( ) . _get_connection ( ) if len ( args ) == 0 : containers = self . _connection . list_containers ( ) if not containers : print ( "No containers were found for this account." ) elif len ( args ) == 1 : containers = self . _connection . list_containe...
Lists all the items in a container to stdout .
41,890
def progress_updater ( size , total ) : current_task . update_state ( state = state ( 'PROGRESS' ) , meta = dict ( size = size , total = total ) )
Progress reporter for checksum verification .
41,891
def verify_checksum ( file_id , pessimistic = False , chunk_size = None , throws = True , checksum_kwargs = None ) : f = FileInstance . query . get ( uuid . UUID ( file_id ) ) if pessimistic : f . clear_last_check ( ) db . session . commit ( ) f . verify_checksum ( progress_callback = progress_updater , chunk_size = ch...
Verify checksum of a file instance .
41,892
def schedule_checksum_verification ( frequency = None , batch_interval = None , max_count = None , max_size = None , files_query = None , checksum_kwargs = None ) : assert max_count is not None or max_size is not None frequency = timedelta ( ** frequency ) if frequency else timedelta ( days = 30 ) if batch_interval : b...
Schedule a batch of files for checksum verification .
41,893
def migrate_file ( src_id , location_name , post_fixity_check = False ) : location = Location . get_by_name ( location_name ) f_src = FileInstance . get ( src_id ) f_dst = FileInstance . create ( ) db . session . commit ( ) try : f_dst . copy_contents ( f_src , progress_callback = progress_updater , default_location = ...
Task to migrate a file instance to a new location .
41,894
def remove_file_data ( file_id , silent = True ) : try : f = FileInstance . get ( file_id ) if not f . writable : return f . delete ( ) db . session . commit ( ) f . storage ( ) . delete ( ) except IntegrityError : if not silent : raise
Remove file instance and associated data .
41,895
def merge_multipartobject ( upload_id , version_id = None ) : mp = MultipartObject . query . filter_by ( upload_id = upload_id ) . one_or_none ( ) if not mp : raise RuntimeError ( 'Upload ID does not exists.' ) if not mp . completed : raise RuntimeError ( 'MultipartObject is not completed.' ) try : obj = mp . merge_par...
Merge multipart object .
41,896
def remove_expired_multipartobjects ( ) : delta = current_app . config [ 'FILES_REST_MULTIPART_EXPIRES' ] expired_dt = datetime . utcnow ( ) - delta file_ids = [ ] for mp in MultipartObject . query_expired ( expired_dt ) : file_ids . append ( str ( mp . file_id ) ) mp . delete ( ) for fid in file_ids : remove_file_data...
Remove expired multipart objects .
41,897
def pyfs_storage_factory ( fileinstance = None , default_location = None , default_storage_class = None , filestorage_class = PyFSFileStorage , fileurl = None , size = None , modified = None , clean_dir = True ) : assert fileinstance or ( fileurl and size ) if fileinstance : fileurl = None size = fileinstance . size mo...
Get factory function for creating a PyFS file storage instance .
41,898
def _get_fs ( self , create_dir = True ) : filedir = dirname ( self . fileurl ) filename = basename ( self . fileurl ) return ( opener . opendir ( filedir , writeable = True , create_dir = create_dir ) , filename )
Return tuple with filesystem and filename .
41,899
def open ( self , mode = 'rb' ) : fs , path = self . _get_fs ( ) return fs . open ( path , mode = mode )
Open file .