def NewChunkList(self, chksizes): volumelist = [] serlist = self.mds.GetChunkServers(5) if len(serlist) == 0: logging.error('Currently not ChunkServer is available') return None for size in chksizes: server = serlist[0] addr = server.ServiceAddress port = server.ServicePort chkclient = self.chkpool.get(self.guid, addr, port) chunks = chkclient.NewChunk(size, 1) if chunks == []: pass volume = Object() volume.size = size volume.assembler = 'chunk' volume.guid = Guid.toStr(chunks.guids[0]) volume.parameters = [volume.guid, '', '', addr, str(port)] path, nodename = self.MountChunk(volume) volume.parameters[1] = path volume.parameters[2] = nodename if path == None: for volume in volumelist: self.UnmountChunk(volume) logging.error('Mount chunk failed') return None volumelist.append(volume) return volumelist
def CreateVolume(self, volname, volsize, voltype, chksizes, volnames, params): vollist = [] if len(volnames) > 0: volsize = 0 for name in volnames: try: vol = self.mds.ReadVolumeInfo(name) except IOError as ex: if str(ex).find('No such file or directory') > -1: logging.error('Volume '+name+' does not exist') return False else: raise ex if vol.parameters[2] == 'subvolume': logging.error('volume '+name+' is a subvolume of another volume') return False if vol.parameters[3] == 'inactive': logging.warn('Volume '+name+' is inactive') logging.warn('Mounting volume '+name) if not self.MountVolume(name): logging.error('Mount volume '+name+' failed') return False volsize += vol.size vollist.append(vol) if len(chksizes) == 0 and len(volnames) == 0: totsize = volsize while totsize > CHUNKSIZE: chksizes.append(CHUNKSIZE) totsize -= CHUNKSIZE chksizes.append(totsize) if voltype == 'gfs': temlist = [] for chksize in chksizes: temlist.append(chksize) temlist.append(chksize) temlist.append(chksize) chksizes = temlist if len(chksizes) > 0: vollist = self.NewChunkList(chksizes) if vollist == None: logging.error('New Chunk(s) failed') return False volume = Object() volume.size = volsize volume.assembler = voltype volume.subvolumes = vollist volume.guid = Guid.toStr(Guid.generate()) volume.parameters = [volname, '/dev/mapper/'+volname, 'volume', 'active'] volume.parameters.extend(params) if self.dmclient.MapVolume(volume) == False: logging.error('device mapper: create volume '+volname+' failed') if volume.subvolumes[0].assembler == 'chunk': for subvol in volume.subvolumes: self.DeleteVolumeTree(subvol) return False self.mds.WriteVolumeInfo(volume) for vol in vollist: if vol.assembler != 'chunk': vol.parameters[2] = 'subvolume' vol.parameters[3] = 'active' self.mds.WriteVolumeInfo(vol) return True