Beispiel #1
0
 def get_object(self, obj_or_param) :
     """
     return an object, regardless of what was the input (object or unique parameters)
     unique paramter is name_or_id (either volume name or volume id)
     """
     if isinstance(obj_or_param, Volume) :
          this_Volume = obj_or_param
     else : 
          this_Volume = Volume()
          if misc.is_name(obj_or_param) :
              this_Volume.name = obj_or_param
          else :
              this_Volume.vid = obj_or_param
     return this_Volume
Beispiel #2
0
def get_volume_list(rc, output, outerr, parseParamList, Logger) :
    if rc :
        raise FileServerLLAError("Error",outerr)
        
    # first line gives Name, ID, Type, Used and Status 
    volList = [] 
    dateT=datetime.datetime(1970, 1, 1)
    i = 0
    while i < len(output):
        while output[i] != "BEGIN_OF_ENTRY":
             i = i+1  
             if i >= len(output): break
        if i >= len(output): break
        #Beginnig block
        splits = output[i].split()
        if splits[0] == "BEGIN_OF_ENTRY":
                vol = Volume()
                splits = output[i+1].split()
                # Invalid volume, something wrong
                if splits[0] != 'name':
                    #vol['valid'] = False 
                    if  splits[0] == 'id':
                        vol.vid  = int(splits[1])
                    
                    splits = output[i+2].split()
                    if  splits[0] == 'serv':
                        vol.servername = splits[1] 
                    
                    splits = output[i+3].split()   
                    if  splits[0] == 'part':
                         vol.part = misc.canonicalize_partition(splits[1]) 
                         
                    splits = output[i+4].split()
                    if  splits[0] == 'status':
                        vol.status = splits[1] 
                    
                    while output[i] != "END_OF_ENTRY":
                        i = i+1  
                        
                # Valid volume                           
                else:  
                    vol.vid = "UNSET"
                    try: 
                      vol.name     = splits[1]
                      splits = output[i+2].split()
                      vol.vid      = int(splits[1])
                      splits = output[i+3].split()
                    except :
                        # XXX Here we need a flag to show that parsing was not complete
                        # or a list of Volumes which need to be reparsed.
                        # this will be in the return-code
                        while output[i] != "END_OF_ENTRY":
                            i = i+1
                        Logger.error("Cannot parse name of volume with id=%s! Skipping." % vol.vid)
                        continue
                    
                    if len(splits) > 2:
                       vol.servername     = splits[2]
                    else:
                       #Only ip is available 
                       vol.servername     = splits[1] 
                    splits = output[i+4].split()
                    vol.partition = misc.canonicalize_partition(splits[1])
                    splits = output[i+5].split()
                    vol.status     = splits[1]
                    if vol.status != "OK" : 
                        while output[i] != "END_OF_ENTRY":
                            i = i+1
                        continue
                    splits = output[i+6].split()
                    vol.backup_id = int(splits[1])
                    splits = output[i+7].split()
                    vol.parent_id = int(splits[1])
                    splits = output[i+8].split()
                    vol.clone_id = int(splits[1])
                    splits = output[i+9].split()
                    vol.in_use    = splits[1]
                    splits = output[i+10].split()
                    vol.needs_salvage = splits[1]
                    splits = output[i+11].split()
                    vol.destroy_me = splits[1]
                    splits = output[i+12].split()
                    vol.type = splits[1]
                    splits = output[i+13].split()
                    vol.creation_date  =  dateT.fromtimestamp(float(splits[1]))
                    splits = output[i+14].split()
                    vol.access_date = dateT.fromtimestamp(float(splits[1]))
                    splits = output[i+15].split()
                    vol.update_date = dateT.fromtimestamp(float(splits[1]))
                    splits = output[i+16].split()
                    vol.backup_date = dateT.fromtimestamp(float(splits[1]))
                    splits = output[i+17].split()
                    vol.copy_date = dateT.fromtimestamp(float(splits[1]))
                    splits = output[i+18].split()
                    vol.flags = splits[1]
                    splits = output[i+19].split()
                    vol.diskused = int(splits[1])
                    splits = output[i+20].split()
                    vol.maxquota = int(splits[1])
                    splits = output[i+21].split()
                    vol.minquota = int(splits[1])
                    splits = output[i+22].split()
                    vol.filecount = int(splits[1])
                    splits = output[i+23].split()
                    vol.day_use = int(splits[1])
                    splits = output[i+24].split()
                    vol.week_use = int(splits[1])
                    splits = output[i+25].split()
                    vol.spare2 = splits[1]
                    splits = output[i+26].split()
                    vol.spare3 = splits[1]
                    i = i+26
                volList.append(vol)
    return volList