Esempio n. 1
0
    def create(self, req, body):
        """Creates a new share."""
        context = req.environ["manila.context"]

        if not self.is_valid_body(body, "share"):
            raise exc.HTTPUnprocessableEntity()

        share = body["share"]

        # NOTE(rushiagr): v2 API allows name instead of display_name
        if share.get("name"):
            share["display_name"] = share.get("name")
            del share["name"]

        # NOTE(rushiagr): v2 API allows description instead of
        #                display_description
        if share.get("description"):
            share["display_description"] = share.get("description")
            del share["description"]

        size = share["size"]
        share_proto = share["share_proto"].upper()

        msg = _("Create %(share_proto)s share of %(size)s GB") % {"share_proto": share_proto, "size": size}
        LOG.audit(msg, context=context)

        kwargs = {}
        kwargs["availability_zone"] = share.get("availability_zone")

        kwargs["metadata"] = share.get("metadata", None)

        snapshot_id = share.get("snapshot_id")
        if snapshot_id:
            kwargs["snapshot"] = self.share_api.get_snapshot(context, snapshot_id)
        else:
            kwargs["snapshot"] = None

        share_network_id = share.get("share_network_id")
        if share_network_id:
            try:
                share_network = self.share_api.db.share_network_get(context, share_network_id)
            except exception.ShareNetworkNotFound as e:
                msg = "%s" % e
                raise exc.HTTPNotFound(explanation=msg)
            if share_network["status"] != constants.STATUS_ACTIVE:
                msg = _("Share network '%s' is not in 'ACTIVE' state.")
                msg = msg % share_network["id"]
                raise exc.HTTPBadRequest(explanation=msg)
            else:
                kwargs["share_network_id"] = share_network_id

        display_name = share.get("display_name")
        display_description = share.get("display_description")

        req_volume_type = share.get("volume_type", None)
        if req_volume_type:
            try:
                if not uuidutils.is_uuid_like(req_volume_type):
                    kwargs["volume_type"] = volume_types.get_volume_type_by_name(context, req_volume_type)
                else:
                    kwargs["volume_type"] = volume_types.get_volume_type(context, req_volume_type)
            except exception.VolumeTypeNotFound:
                msg = _("Volume type not found.")
                raise exc.HTTPNotFound(explanation=msg)

        new_share = self.share_api.create(context, share_proto, size, display_name, display_description, **kwargs)

        # TODO(vish): Instance should be None at db layer instead of
        #             trying to lazy load, but for now we turn it into
        #             a dict to avoid an error.
        return self._view_builder.summary(req, dict(new_share.iteritems()))
Esempio n. 2
0
    def create(self, req, body):
        """Creates a new share."""
        context = req.environ['manila.context']

        if not self.is_valid_body(body, 'share'):
            raise exc.HTTPUnprocessableEntity()

        share = body['share']

        # NOTE(rushiagr): v2 API allows name instead of display_name
        if share.get('name'):
            share['display_name'] = share.get('name')
            del share['name']

        # NOTE(rushiagr): v2 API allows description instead of
        #                display_description
        if share.get('description'):
            share['display_description'] = share.get('description')
            del share['description']

        size = share['size']
        share_proto = share['share_proto'].upper()

        msg = (_("Create %(share_proto)s share of %(size)s GB") %
               {'share_proto': share_proto, 'size': size})
        LOG.info(msg, context=context)

        kwargs = {}
        kwargs['availability_zone'] = share.get('availability_zone')

        kwargs['metadata'] = share.get('metadata', None)

        snapshot_id = share.get('snapshot_id')
        if snapshot_id:
            snapshot = self.share_api.get_snapshot(context, snapshot_id)
        else:
            snapshot = None

        kwargs['snapshot'] = snapshot

        share_network_id = share.get('share_network_id')

        if snapshot:
            # Need to check that share_network_id from snapshot's
            # parents share equals to share_network_id from args.
            # If share_network_id is empty than update it with
            # share_network_id of parent share.
            parent_share = self.share_api.get(context, snapshot['share_id'])
            parent_share_net_id = parent_share['share_network_id']
            if share_network_id:
                if share_network_id != parent_share_net_id:
                    msg = "Share network ID should be the same as snapshot's" \
                          " parent share's or empty"
                    raise exc.HTTPBadRequest(explanation=msg)
            elif parent_share_net_id:
                share_network_id = parent_share_net_id

        if share_network_id:
            try:
                self.share_api.get_share_network(
                    context,
                    share_network_id)
            except exception.ShareNetworkNotFound as e:
                raise exc.HTTPNotFound(explanation=six.text_type(e))
            kwargs['share_network_id'] = share_network_id

        display_name = share.get('display_name')
        display_description = share.get('display_description')

        req_volume_type = share.get('volume_type', None)
        if req_volume_type:
            try:
                if not uuidutils.is_uuid_like(req_volume_type):
                    kwargs['volume_type'] = \
                        volume_types.get_volume_type_by_name(
                            context, req_volume_type)
                else:
                    kwargs['volume_type'] = volume_types.get_volume_type(
                        context, req_volume_type)
            except exception.VolumeTypeNotFound:
                msg = _("Volume type not found.")
                raise exc.HTTPNotFound(explanation=msg)

        new_share = self.share_api.create(context,
                                          share_proto,
                                          size,
                                          display_name,
                                          display_description,
                                          **kwargs)

        return self._view_builder.detail(req, dict(six.iteritems(new_share)))
Esempio n. 3
0
    def create(self, req, body):
        """Creates a new share."""
        context = req.environ['manila.context']

        if not self.is_valid_body(body, 'share'):
            raise exc.HTTPUnprocessableEntity()

        share = body['share']

        # NOTE(rushiagr): v2 API allows name instead of display_name
        if share.get('name'):
            share['display_name'] = share.get('name')
            del share['name']

        # NOTE(rushiagr): v2 API allows description instead of
        #                display_description
        if share.get('description'):
            share['display_description'] = share.get('description')
            del share['description']

        size = share['size']
        share_proto = share['share_proto'].upper()

        msg = (_("Create %(share_proto)s share of %(size)s GB") % {
            'share_proto': share_proto,
            'size': size
        })
        LOG.info(msg, context=context)

        kwargs = {}
        kwargs['availability_zone'] = share.get('availability_zone')

        kwargs['metadata'] = share.get('metadata', None)

        snapshot_id = share.get('snapshot_id')
        if snapshot_id:
            snapshot = self.share_api.get_snapshot(context, snapshot_id)
        else:
            snapshot = None

        kwargs['snapshot'] = snapshot

        share_network_id = share.get('share_network_id')

        if snapshot:
            # Need to check that share_network_id from snapshot's
            # parents share equals to share_network_id from args.
            # If share_network_id is empty than update it with
            # share_network_id of parent share.
            parent_share = self.share_api.get(context, snapshot['share_id'])
            parent_share_net_id = parent_share['share_network_id']
            if share_network_id:
                if share_network_id != parent_share_net_id:
                    msg = "Share network ID should be the same as snapshot's" \
                          " parent share's or empty"
                    raise exc.HTTPBadRequest(explanation=msg)
            elif parent_share_net_id:
                share_network_id = parent_share_net_id

        if share_network_id:
            try:
                self.share_api.get_share_network(context, share_network_id)
            except exception.ShareNetworkNotFound as e:
                msg = "%s" % e
                raise exc.HTTPNotFound(explanation=msg)
            kwargs['share_network_id'] = share_network_id

        display_name = share.get('display_name')
        display_description = share.get('display_description')

        req_volume_type = share.get('volume_type', None)
        if req_volume_type:
            try:
                if not uuidutils.is_uuid_like(req_volume_type):
                    kwargs['volume_type'] = \
                        volume_types.get_volume_type_by_name(
                            context, req_volume_type)
                else:
                    kwargs['volume_type'] = volume_types.get_volume_type(
                        context, req_volume_type)
            except exception.VolumeTypeNotFound:
                msg = _("Volume type not found.")
                raise exc.HTTPNotFound(explanation=msg)

        new_share = self.share_api.create(context, share_proto, size,
                                          display_name, display_description,
                                          **kwargs)

        # TODO(vish): Instance should be None at db layer instead of
        #             trying to lazy load, but for now we turn it into
        #             a dict to avoid an error.
        return self._view_builder.summary(req, dict(six.iteritems(new_share)))
Esempio n. 4
0
    def create(self, req, body):
        """Creates a new share."""
        context = req.environ["manila.context"]

        if not self.is_valid_body(body, "share"):
            raise exc.HTTPUnprocessableEntity()

        share = body["share"]

        # NOTE(rushiagr): v2 API allows name instead of display_name
        if share.get("name"):
            share["display_name"] = share.get("name")
            del share["name"]

        # NOTE(rushiagr): v2 API allows description instead of
        #                display_description
        if share.get("description"):
            share["display_description"] = share.get("description")
            del share["description"]

        size = share["size"]
        share_proto = share["share_proto"].upper()

        msg = _("Create %(share_proto)s share of %(size)s GB") % {"share_proto": share_proto, "size": size}
        LOG.audit(msg, context=context)

        kwargs = {}
        kwargs["availability_zone"] = share.get("availability_zone")

        kwargs["metadata"] = share.get("metadata", None)

        snapshot_id = share.get("snapshot_id")
        if snapshot_id:
            snapshot = self.share_api.get_snapshot(context, snapshot_id)
        else:
            snapshot = None

        kwargs["snapshot"] = snapshot

        share_network_id = share.get("share_network_id")

        if snapshot:
            # Need to check that share_network_id from snapshot's
            # parents share equals to share_network_id from args.
            # If share_network_id is empty than update it with
            # share_network_id of parent share.
            parent_share = self.share_api.get(context, snapshot["share_id"])
            parent_share_net_id = parent_share["share_network_id"]
            if share_network_id:
                if share_network_id != parent_share_net_id:
                    msg = "Share network ID should be the same as snapshot's" " parent share's or empty"
                    raise exc.HTTPBadRequest(explanation=msg)
            elif parent_share_net_id:
                share_network_id = parent_share_net_id

        if share_network_id:
            try:
                self.share_api.get_share_network(context, share_network_id)
            except exception.ShareNetworkNotFound as e:
                msg = "%s" % e
                raise exc.HTTPNotFound(explanation=msg)
            kwargs["share_network_id"] = share_network_id

        display_name = share.get("display_name")
        display_description = share.get("display_description")

        req_volume_type = share.get("volume_type", None)
        if req_volume_type:
            try:
                if not uuidutils.is_uuid_like(req_volume_type):
                    kwargs["volume_type"] = volume_types.get_volume_type_by_name(context, req_volume_type)
                else:
                    kwargs["volume_type"] = volume_types.get_volume_type(context, req_volume_type)
            except exception.VolumeTypeNotFound:
                msg = _("Volume type not found.")
                raise exc.HTTPNotFound(explanation=msg)

        new_share = self.share_api.create(context, share_proto, size, display_name, display_description, **kwargs)

        # TODO(vish): Instance should be None at db layer instead of
        #             trying to lazy load, but for now we turn it into
        #             a dict to avoid an error.
        return self._view_builder.summary(req, dict(new_share.iteritems()))
Esempio n. 5
0
    def create(self, req, body):
        """Creates a new share."""
        context = req.environ['manila.context']

        if not self.is_valid_body(body, 'share'):
            raise exc.HTTPUnprocessableEntity()

        share = body['share']

        # NOTE(rushiagr): v2 API allows name instead of display_name
        if share.get('name'):
            share['display_name'] = share.get('name')
            del share['name']

        # NOTE(rushiagr): v2 API allows description instead of
        #                display_description
        if share.get('description'):
            share['display_description'] = share.get('description')
            del share['description']

        size = share['size']
        share_proto = share['share_proto'].upper()

        msg = (_("Create %(share_proto)s share of %(size)s GB") %
               {'share_proto': share_proto, 'size': size})
        LOG.audit(msg, context=context)

        kwargs = {}
        kwargs['availability_zone'] = share.get('availability_zone')

        kwargs['metadata'] = share.get('metadata', None)

        snapshot_id = share.get('snapshot_id')
        if snapshot_id:
            kwargs['snapshot'] = self.share_api.get_snapshot(context,
                                                             snapshot_id)
        else:
            kwargs['snapshot'] = None

        share_network_id = share.get('share_network_id')
        if share_network_id:
            try:
                share_network = self.share_api.db.share_network_get(
                                context,
                                share_network_id)
            except exception.ShareNetworkNotFound as e:
                msg = "%s" % e
                raise exc.HTTPNotFound(explanation=msg)
            kwargs['share_network_id'] = share_network_id

        display_name = share.get('display_name')
        display_description = share.get('display_description')

        req_volume_type = share.get('volume_type', None)
        if req_volume_type:
            try:
                if not uuidutils.is_uuid_like(req_volume_type):
                    kwargs['volume_type'] = \
                        volume_types.get_volume_type_by_name(
                            context, req_volume_type)
                else:
                    kwargs['volume_type'] = volume_types.get_volume_type(
                        context, req_volume_type)
            except exception.VolumeTypeNotFound:
                msg = _("Volume type not found.")
                raise exc.HTTPNotFound(explanation=msg)

        new_share = self.share_api.create(context,
                                          share_proto,
                                          size,
                                          display_name,
                                          display_description,
                                          **kwargs)

        # TODO(vish): Instance should be None at db layer instead of
        #             trying to lazy load, but for now we turn it into
        #             a dict to avoid an error.
        return self._view_builder.summary(req, dict(new_share.iteritems()))