Example #1
0
    def _populate_disk_choices(self, exclude=None):

        diskchoices = dict()

        qs = models.iSCSITargetExtent.objects.filter(
            iscsi_target_extent_type='Disk')
        if exclude:
            qs = qs.exclude(id=exclude.id)
        diskids = [i[0] for i in qs.values_list('iscsi_target_extent_path')]
        used_disks = [d.disk_name for d in Disk.objects.filter(id__in=diskids)]

        qs = models.iSCSITargetExtent.objects.filter(
            iscsi_target_extent_type='ZVOL')
        if exclude:
            qs = qs.exclude(id=exclude.id)
        used_zvol = [i[0] for i in qs.values_list('iscsi_target_extent_path')]

        for v in models.Volume.objects.all():
            used_disks.extend(v.get_disks())

        for volume in Volume.objects.filter(vol_fstype__exact='ZFS'):
            zvols = notifier().list_zfs_vols(volume.vol_name)
            for zvol, attrs in zvols.items():
                if "zvol/" + zvol not in used_zvol:
                    diskchoices["zvol/" +
                                zvol] = "%s (%s)" % (zvol, attrs['volsize'])

        # Grab partition list
        # NOTE: This approach may fail if device nodes are not accessible.
        disks = notifier().get_disks()
        for name, disk in disks.items():
            if name in used_disks:
                continue
            capacity = humanize_size(disk['capacity'])
            diskchoices[name] = "%s (%s)" % (name, capacity)

        # HAST Devices through GEOM GATE
        gate_pipe = os.popen(
            """/usr/sbin/diskinfo `/sbin/geom gate status -s"""
            """| /usr/bin/cut -d" " -f1` | /usr/bin/cut -f1,3""")
        gate_diskinfo = gate_pipe.read().strip().split('\n')
        for disk in gate_diskinfo:
            if disk:
                devname, capacity = disk.split('\t')
                capacity = humanize_size(capacity)
                diskchoices[devname] = "%s (%s)" % (devname, capacity)

        return diskchoices.items()
Example #2
0
def volume_detach(request, vid):

    volume = models.Volume.objects.get(pk=vid)
    usedbytes = sum(
        [mp._get_used_bytes() for mp in volume.mountpoint_set.all()])
    usedsize = humanize_size(usedbytes)
    services = volume.has_attachments()
    if request.method == "POST":
        form = forms.VolumeExport(request.POST,
                                  instance=volume,
                                  services=services)
        if form.is_valid():
            try:
                volume.delete(destroy=form.cleaned_data['mark_new'],
                              cascade=form.cleaned_data.get('cascade', True))
                return JsonResponse(
                    message=_("The volume has been successfully detached"))
            except ServiceFailed, e:
                return JsonResponse(error=True, message=unicode(e))
Example #3
0
def volume_detach(request, vid):

    volume = models.Volume.objects.get(pk=vid)
    usedbytes = sum(
        [mp._get_used_bytes() for mp in volume.mountpoint_set.all()]
        )
    usedsize = humanize_size(usedbytes)
    services = volume.has_attachments()
    if request.method == "POST":
        form = forms.VolumeExport(request.POST,
            instance=volume,
            services=services)
        if form.is_valid():
            try:
                volume.delete(destroy=form.cleaned_data['mark_new'],
                    cascade=form.cleaned_data.get('cascade', True))
                return JsonResponse(
                    message=_("The volume has been successfully detached")
                    )
            except ServiceFailed, e:
                return JsonResponse(error=True, message=unicode(e))
Example #4
0
 def _get_used_si(self):
     try:
         usedbytes = self._get_used_bytes()
         return u"%s" % (humanize_size(usedbytes))
     except:
         return _(u"Error getting used space")
Example #5
0
 def _get_avail_si(self):
     try:
         availbytes = self._vfs.f_bavail * self._vfs.f_frsize
         return u"%s" % (humanize_size(availbytes))
     except:
         return _(u"Error getting available space")
Example #6
0
 def _get_total_si(self):
     try:
         totalbytes = self._vfs.f_blocks * self._vfs.f_frsize
         return u"%s" % (humanize_size(totalbytes))
     except:
         return _(u"Error getting total space")
Example #7
0
 def _get_used_si(self):
     try:
         usedbytes = self._get_used_bytes()
         return u"%s" % (humanize_size(usedbytes))
     except:
         return _(u"Error getting used space")
Example #8
0
 def _get_avail_si(self):
     try:
         availbytes = self._vfs.f_bavail * self._vfs.f_frsize
         return u"%s" % (humanize_size(availbytes))
     except:
         return _(u"Error getting available space")
Example #9
0
 def _get_total_si(self):
     try:
         totalbytes = self._vfs.f_blocks * self._vfs.f_frsize
         return u"%s" % (humanize_size(totalbytes))
     except:
         return _(u"Error getting total space")