Beispiel #1
0
 def list_volumes(vpool_guid=None):
     """
     List all known volumes on a specific vpool or on all
     """
     if vpool_guid is not None:
         vpool = VPool(vpool_guid)
         storagedriver_client = StorageDriverClient().load(vpool)
         response = storagedriver_client.list_volumes()
     else:
         response = []
         for vpool in VPoolList.get_vpools():
             storagedriver_client = StorageDriverClient().load(vpool)
             response.extend(storagedriver_client.list_volumes())
     return response
Beispiel #2
0
 def reload_client(self):
     """
     Reloads the StorageDriver Client
     """
     if self.vpool:
         self._frozen = False
         self.storagedriver_client = StorageDriverClient().load(self.vpool)
         self._frozen = True
Beispiel #3
0
 def move_away(storagerouter_guid):
     """
     Moves away all vDisks from all Storage Drivers this Storage Router is serving
     """
     storagedrivers = StorageRouter(storagerouter_guid).storagedrivers
     if len(storagedrivers) > 0:
         storagedriver_client = StorageDriverClient().load(
             storagedrivers[0].vpool)
         for storagedriver in storagedrivers:
             storagedriver_client.mark_node_offline(
                 str(storagedriver.storagedriver_id))
Beispiel #4
0
    def _info(self):
        """
        Fetches the info (see Volume Driver API) for the vDisk.
        """
        if self.volume_id and self.vpool:
            try:
                vdiskinfo = self.storagedriver_client.info_volume(
                    str(self.volume_id))
            except:
                vdiskinfo = StorageDriverClient().empty_info()
        else:
            vdiskinfo = StorageDriverClient().empty_info()

        vdiskinfodict = {}
        for key, value in vdiskinfo.__class__.__dict__.items():
            if type(value) is property:
                vdiskinfodict[key] = getattr(vdiskinfo, key)
                if key == 'object_type':
                    vdiskinfodict[key] = str(vdiskinfodict[key])
        return vdiskinfodict
Beispiel #5
0
 def _statistics(self):
     """
     Aggregates the Statistics (IOPS, Bandwidth, ...) of each vDisk served by the vPool.
     """
     client = StorageDriverClient()
     vdiskstatsdict = {}
     for key in client.stat_keys:
         vdiskstatsdict[key] = 0
         vdiskstatsdict['{0}_ps'.format(key)] = 0
     for vdisk in self.vdisks:
         for key, value in vdisk.statistics.iteritems():
             if key != 'timestamp':
                 vdiskstatsdict[key] += value
     vdiskstatsdict['timestamp'] = time.time()
     return vdiskstatsdict
 def _statistics(self):
     """
     Aggregates the Statistics (IOPS, Bandwidth, ...) of the vDisks connected to the Storage Driver.
     """
     client = StorageDriverClient()
     vdiskstatsdict = {}
     for key in client.stat_keys:
         vdiskstatsdict[key] = 0
         vdiskstatsdict['{0}_ps'.format(key)] = 0
     if self.vpool is not None:
         for disk in self.vpool.vdisks:
             if disk.storagedriver_id == self.storagedriver_id:
                 for key, value in disk.statistics.iteritems():
                     if key != 'timestamp':
                         vdiskstatsdict[key] += value
     vdiskstatsdict['timestamp'] = time.time()
     return vdiskstatsdict
Beispiel #7
0
 def _statistics(self, dynamic):
     """
     Fetches the Statistics for the vDisk.
     """
     client = StorageDriverClient()
     volatile = VolatileFactory.get_client()
     prev_key = '{0}_{1}'.format(self._key, 'statistics_previous')
     # Load data from volumedriver
     if self.volume_id and self.vpool:
         try:
             vdiskstats = self.storagedriver_client.statistics_volume(
                 str(self.volume_id))
         except:
             vdiskstats = client.empty_statistics()
     else:
         vdiskstats = client.empty_statistics()
     # Load volumedriver data in dictionary
     vdiskstatsdict = {}
     for key, value in vdiskstats.__class__.__dict__.items():
         if type(value) is property and key in client.stat_counters:
             vdiskstatsdict[key] = getattr(vdiskstats, key)
     # Precalculate sums
     for key, items in client.stat_sums.iteritems():
         vdiskstatsdict[key] = 0
         for item in items:
             vdiskstatsdict[key] += vdiskstatsdict[item]
     vdiskstatsdict['timestamp'] = time.time()
     # Calculate delta's based on previously loaded dictionary
     previousdict = volatile.get(prev_key, default={})
     for key in vdiskstatsdict.keys():
         if key in client.stat_keys:
             delta = vdiskstatsdict['timestamp'] - previousdict.get(
                 'timestamp', vdiskstatsdict['timestamp'])
             if delta < 0:
                 vdiskstatsdict['{0}_ps'.format(key)] = 0
             elif delta == 0:
                 vdiskstatsdict['{0}_ps'.format(key)] = previousdict.get(
                     '{0}_ps'.format(key), 0)
             else:
                 vdiskstatsdict['{0}_ps'.format(key)] = max(
                     0, (vdiskstatsdict[key] - previousdict[key]) / delta)
     volatile.set(prev_key, vdiskstatsdict, dynamic.timeout * 10)
     # Returning the dictionary
     return vdiskstatsdict
Beispiel #8
0
 def update_status(storagedriver_id):
     """
     Sets Storage Driver offline in case hypervisor management Center
     reports the hypervisor pmachine related to this Storage Driver
     as unavailable.
     """
     pmachine = PMachineList.get_by_storagedriver_id(storagedriver_id)
     if pmachine.mgmtcenter:
         # Update status
         pmachine.invalidate_dynamics(['host_status'])
         host_status = pmachine.host_status
         if host_status != 'RUNNING':
             # Host is stopped
             storagedriver = StorageDriverList.get_by_storagedriver_id(
                 storagedriver_id)
             storagedriver_client = StorageDriverClient().load(
                 storagedriver.vpool)
             storagedriver_client.mark_node_offline(
                 str(storagedriver.storagedriver_id))
     else:
         # No management Center, cannot update status via api
         #TODO: should we try manually (ping, ssh)?
         pass