コード例 #1
0
ファイル: forms.py プロジェクト: openstack/manila-ui
    def handle(self, request, data):
        try:
            source_type = data.get('source_type')
            if (data.get("snapshot") and source_type in (None, 'snapshot')):
                snapshot = self.get_share_group_snapshot(
                    request, data["snapshot"])
                snapshot_id = snapshot.id
                source_sg = manila.share_group_get(
                    request, snapshot.share_group_id)
                data['sgt'] = source_sg.share_group_type_id
            else:
                snapshot_id = None

            share_group = manila.share_group_create(
                request,
                name=data['name'],
                description=data['description'],
                share_group_type=data['sgt'],
                share_types=None if snapshot_id else data.get('share_types'),
                share_network=(
                    None if snapshot_id else data.get('share_network')),
                source_share_group_snapshot=snapshot_id,
                availability_zone=None if snapshot_id else data['az'])

            message = _('Creating share group "%s"') % data['name']
            messages.success(request, message)
            return share_group
        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 group."))
            return False
コード例 #2
0
    def handle(self, request, data):
        try:
            source_type = data.get('source_type')
            if (data.get("snapshot") and source_type in (None, 'snapshot')):
                snapshot = self.get_share_group_snapshot(
                    request, data["snapshot"])
                snapshot_id = snapshot.id
                source_sg = manila.share_group_get(request,
                                                   snapshot.share_group_id)
                data['sgt'] = source_sg.share_group_type_id
            else:
                snapshot_id = None

            share_group = manila.share_group_create(
                request,
                name=data['name'],
                description=data['description'],
                share_group_type=utils.transform_dashed_name(data['sgt']),
                share_types=None if snapshot_id else data.get('share_types'),
                share_network=(None
                               if snapshot_id else data.get('share_network')),
                source_share_group_snapshot=snapshot_id,
                availability_zone=None if snapshot_id else data['az'])

            message = _('Creating share group "%s"') % data['name']
            messages.success(request, message)
            return share_group
        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 group."))
            return False
コード例 #3
0
    def test_share_group_create(self):
        name = "fake_sg_name"
        kwargs = {
            "description": "fake_desc",
            "share_group_type": "fake_sg_type",
            "share_types": ["fake", "list", "of", "fake", "share", "types"],
            "share_network": "fake_sn",
            "source_share_group_snapshot": "fake_source_share_group_snapshot",
            "availability_zone": "fake_az",
        }

        result = api.share_group_create(self.request, name, **kwargs)

        self.assertEqual(self.manilaclient.share_groups.create.return_value,
                         result)
        self.manilaclient.share_groups.create.assert_called_once_with(
            name=name, **kwargs)
コード例 #4
0
ファイル: test_manila.py プロジェクト: openstack/manila-ui
    def test_share_group_create(self):
        name = "fake_sg_name"
        kwargs = {
            "description": "fake_desc",
            "share_group_type": "fake_sg_type",
            "share_types": ["fake", "list", "of", "fake", "share", "types"],
            "share_network": "fake_sn",
            "source_share_group_snapshot": "fake_source_share_group_snapshot",
            "availability_zone": "fake_az",
        }

        result = api.share_group_create(self.request, name, **kwargs)

        self.assertEqual(
            self.manilaclient.share_groups.create.return_value, result)
        self.manilaclient.share_groups.create.assert_called_once_with(
            name=name, **kwargs)