コード例 #1
0
    def test_share_create(self, sg_id, is_public):
        kwargs = {
            "share_network": "fake_sn",
            "snapshot_id": "fake_snapshot_id",
            "metadata": {"k1": "v1", "k2": "v2"},
            "share_type": "fake_st",
            "is_public": is_public,
            "availability_zone": "fake_az",
            "share_group_id": sg_id,
        }
        size = 5
        name = "fake_name"
        desc = "fake_description"
        proto = "fake_share_protocol"

        api.share_create(self.request, size, name, desc, proto, **kwargs)

        self.manilaclient.shares.create.assert_called_once_with(
            proto, size, name=name, description=desc, **kwargs)
コード例 #2
0
ファイル: test_manila.py プロジェクト: openstack/manila-ui
    def test_share_create(self, sg_id, is_public):
        kwargs = {
            "share_network": "fake_sn",
            "snapshot_id": "fake_snapshot_id",
            "metadata": {"k1": "v1", "k2": "v2"},
            "share_type": "fake_st",
            "is_public": is_public,
            "availability_zone": "fake_az",
            "share_group_id": sg_id,
        }
        size = 5
        name = "fake_name"
        desc = "fake_description"
        proto = "fake_share_protocol"

        api.share_create(self.request, size, name, desc, proto, **kwargs)

        self.manilaclient.shares.create.assert_called_once_with(
            proto, size, name=name, description=desc, **kwargs)
コード例 #3
0
ファイル: forms.py プロジェクト: openstack/manila-ui
    def handle(self, request, data):
        try:
            snapshot_id = None
            source_type = data.get('share_source_type', None)
            share_network = data.get('share_network', None)
            if (data.get("snapshot", None) and
                    source_type in [None, 'snapshot']):
                # Create from Snapshot
                snapshot = self.get_snapshot(request,
                                             data["snapshot"])
                snapshot_id = snapshot.id
                if (data['size'] < snapshot.size):
                    error_message = _('The share size cannot be less than the '
                                      'snapshot size (%sGiB)') % snapshot.size
                    raise ValidationError(error_message)
            else:
                data['size'] = int(data['size'])

            metadata = {}
            try:
                set_dict, unset_list = utils.parse_str_meta(data['metadata'])
                if unset_list:
                    msg = _("Expected only pairs of key=value.")
                    raise ValidationError(message=msg)
                metadata = set_dict
            except ValidationError as e:
                self.api_error(e.messages[0])
                return False
            is_public = self.enable_public_shares and data['is_public']
            share = manila.share_create(
                request,
                size=data['size'],
                name=data['name'],
                description=data['description'],
                proto=data['share_proto'],
                share_network=share_network,
                snapshot_id=snapshot_id,
                share_type=data['share_type'],
                is_public=is_public,
                metadata=metadata,
                availability_zone=data['availability_zone'],
                share_group_id=data.get('sg') or None,
            )
            message = _('Creating share "%s"') % data['name']
            messages.success(request, message)
            return share
        except ValidationError as e:
            self.api_error(e.messages[0])
        except m_exceptions.BadRequest as e:
            self.api_error(_("Unable to create share. %s") % e.message)
        except Exception:
            exceptions.handle(request, ignore=True)
            self.api_error(_("Unable to create share."))
        return False
コード例 #4
0
    def handle(self, request, data):
        try:
            snapshot_id = None
            source_type = data.get('share_source_type', None)
            share_network = data.get('share_network', None)
            if (data.get("snapshot", None) and
                    source_type in [None, 'snapshot']):
                # Create from Snapshot
                snapshot = self.get_snapshot(request,
                                             data["snapshot"])
                snapshot_id = snapshot.id
                if (data['size'] < snapshot.size):
                    error_message = _('The share size cannot be less than the '
                                      'snapshot size (%sGiB)') % snapshot.size
                    raise ValidationError(error_message)
            else:
                data['size'] = int(data['size'])

            metadata = {}
            try:
                set_dict, unset_list = utils.parse_str_meta(data['metadata'])
                if unset_list:
                    msg = _("Expected only pairs of key=value.")
                    raise ValidationError(message=msg)
                metadata = set_dict
            except ValidationError as e:
                self.api_error(e.messages[0])
                return False
            is_public = self.enable_public_shares and data['is_public']
            share = manila.share_create(
                request,
                size=data['size'],
                name=data['name'],
                description=data['description'],
                proto=data['share_proto'],
                share_network=share_network,
                snapshot_id=snapshot_id,
                share_type=data['share_type'],
                is_public=is_public,
                metadata=metadata,
                availability_zone=data['availability_zone'],
                share_group_id=data.get('sg') or None,
            )
            message = _('Creating share "%s"') % data['name']
            messages.success(request, message)
            return share
        except ValidationError as e:
            self.api_error(e.messages[0])
        except m_exceptions.BadRequest as e:
            self.api_error(_("Unable to create share. %s") % e.message)
        except Exception:
            exceptions.handle(request, ignore=True)
            self.api_error(_("Unable to create share."))
        return False
コード例 #5
0
ファイル: forms.py プロジェクト: ajarr/manila-ui
    def handle(self, request, data):
        try:
            # usages = quotas.tenant_limit_usages(self.request)
            # availableGB = usages['maxTotalShareGigabytes'] - \
            #    usages['gigabytesUsed']
            # availableVol = usages['maxTotalShares'] - usages['sharesUsed']

            snapshot_id = None
            source_type = data.get('share_source_type', None)
            share_network = data.get('share_network', None)
            if (data.get("snapshot", None) and
                    source_type in [None, 'snapshot']):
                # Create from Snapshot
                snapshot = self.get_snapshot(request,
                                             data["snapshot"])
                snapshot_id = snapshot.id
                if (data['size'] < snapshot.size):
                    error_message = _('The share size cannot be less than the '
                                      'snapshot size (%sGiB)') % snapshot.size
                    raise ValidationError(error_message)
            else:
                if type(data['size']) is str:
                    data['size'] = int(data['size'])
            #
            # if availableGB < data['size']:
            #    error_message = _('A share of %(req)iGB cannot be created as '
            #                      'you only have %(avail)iGB of your quota '
            #                      'available.')
            #    params = {'req': data['size'],
            #              'avail': availableGB}
            #    raise ValidationError(error_message % params)
            # elif availableVol <= 0:
            #    error_message = _('You are already using all of your '
            #                      'available'
            #                      ' shares.')
            #    raise ValidationError(error_message)

            metadata = {}
            try:
                set_dict, unset_list = utils.parse_str_meta(data['metadata'])
                if unset_list:
                    msg = _("Expected only pairs of key=value.")
                    raise ValidationError(message=msg)
                metadata = set_dict
            except ValidationError as e:
                self.api_error(e.messages[0])
                return False
            share = manila.share_create(
                request,
                size=data['size'],
                name=data['name'],
                description=data['description'],
                proto=data['share_proto'],
                share_network=share_network,
                snapshot_id=snapshot_id,
                share_type=data['share_type'],
                is_public=data['is_public'],
                metadata=metadata,
                availability_zone=data['availability_zone'])
            message = _('Creating share "%s"') % data['name']
            messages.success(request, message)
            return share
        except ValidationError as e:
            self.api_error(e.messages[0])
            return False
        except Exception:
            exceptions.handle(request, ignore=True)
            self.api_error(_("Unable to create share."))
            return False
コード例 #6
0
    def handle(self, request, data):
        try:
            # usages = quotas.tenant_limit_usages(self.request)
            # availableGB = usages['maxTotalShareGigabytes'] - \
            #    usages['gigabytesUsed']
            # availableVol = usages['maxTotalShares'] - usages['sharesUsed']

            snapshot_id = None
            source_type = data.get('share_source_type', None)
            share_network = data.get('share_network', None)
            if (data.get("snapshot", None)
                    and source_type in [None, 'snapshot']):
                # Create from Snapshot
                snapshot = self.get_snapshot(request, data["snapshot"])
                snapshot_id = snapshot.id
                if (data['size'] < snapshot.size):
                    error_message = _('The share size cannot be less than the '
                                      'snapshot size (%sGiB)') % snapshot.size
                    raise ValidationError(error_message)
            else:
                if type(data['size']) is str:
                    data['size'] = int(data['size'])
            #
            # if availableGB < data['size']:
            #    error_message = _('A share of %(req)iGB cannot be created as '
            #                      'you only have %(avail)iGB of your quota '
            #                      'available.')
            #    params = {'req': data['size'],
            #              'avail': availableGB}
            #    raise ValidationError(error_message % params)
            # elif availableVol <= 0:
            #    error_message = _('You are already using all of your '
            #                      'available'
            #                      ' shares.')
            #    raise ValidationError(error_message)

            metadata = {}
            try:
                set_dict, unset_list = utils.parse_str_meta(data['metadata'])
                if unset_list:
                    msg = _("Expected only pairs of key=value.")
                    raise ValidationError(message=msg)
                metadata = set_dict
            except ValidationError as e:
                self.api_error(e.messages[0])
                return False
            share = manila.share_create(
                request,
                size=data['size'],
                name=data['name'],
                description=data['description'],
                proto=data['share_proto'],
                share_network=share_network,
                snapshot_id=snapshot_id,
                share_type=data['share_type'],
                is_public=data['is_public'],
                metadata=metadata,
                availability_zone=data['availability_zone'])
            message = _('Creating share "%s"') % data['name']
            messages.success(request, message)
            return share
        except ValidationError as e:
            self.api_error(e.messages[0])
            return False
        except Exception:
            exceptions.handle(request, ignore=True)
            self.api_error(_("Unable to create share."))
            return False