Exemplo n.º 1
0
    def delete(self, req, id):
        """Delete specified share network."""
        context = req.environ['manila.context']
        policy.check_policy(context, RESOURCE_NAME, 'delete')

        try:
            share_network = db_api.share_network_get(context, id)
        except exception.ShareNetworkNotFound as e:
            raise exc.HTTPNotFound(explanation=six.text_type(e))

        shares = db_api.share_get_all_by_share_network(context, id)
        if shares:
            msg = _("Can not delete share network %(id)s, it has "
                    "%(len)s share(s).") % {'id': id, 'len': len(shares)}
            LOG.error(msg)
            raise exc.HTTPConflict(explanation=msg)
        for share_server in share_network['share_servers']:
            self.share_rpcapi.delete_share_server(context, share_server)
        db_api.share_network_delete(context, id)

        try:
            reservations = QUOTAS.reserve(
                context, project_id=share_network['project_id'],
                share_networks=-1)
        except Exception:
            LOG.exception(_LE("Failed to update usages deleting "
                              "share-network."))
        else:
            QUOTAS.commit(context, reservations,
                          project_id=share_network['project_id'])
        return webob.Response(status_int=202)
Exemplo n.º 2
0
    def delete(self, req, id):
        """Delete specified share network."""
        context = req.environ['manila.context']
        policy.check_policy(context, RESOURCE_NAME, 'delete')

        try:
            share_network = db_api.share_network_get(context, id)
        except exception.ShareNetworkNotFound as e:
            msg = "%s" % e
            raise exc.HTTPNotFound(explanation=msg)
        if share_network['share_servers']:
            msg = _("Cannot delete share network %s. "
                    "There are share servers using it") % id
            raise exc.HTTPForbidden(explanation=msg)
        db_api.share_network_delete(context, id)

        try:
            reservations = QUOTAS.reserve(
                context, project_id=share_network['project_id'],
                share_networks=-1)
        except Exception:
            msg = _("Failed to update usages deleting share-network.")
            LOG.exception(msg)
        else:
            QUOTAS.commit(context, reservations,
                          project_id=share_network['project_id'])
        return webob.Response(status_int=202)
Exemplo n.º 3
0
    def test_delete(self):
        db_api.share_network_create(self.fake_context, self.share_nw_dict)
        db_api.share_network_delete(self.fake_context, self.share_nw_dict["id"])

        self.assertRaises(
            exception.ShareNetworkNotFound, db_api.share_network_get, self.fake_context, self.share_nw_dict["id"]
        )
Exemplo n.º 4
0
    def delete(self, req, id):
        """Delete specified share network."""
        context = req.environ['manila.context']
        policy.check_policy(context, RESOURCE_NAME, 'delete')

        try:
            share_network = db_api.share_network_get(context, id)
        except exception.ShareNetworkNotFound as e:
            msg = "%s" % e
            raise exc.HTTPNotFound(explanation=msg)
        if share_network['share_servers']:
            msg = _("Cannot delete share network %s. "
                    "There are share servers using it") % id
            raise exc.HTTPForbidden(explanation=msg)
        db_api.share_network_delete(context, id)

        try:
            reservations = QUOTAS.reserve(
                context, project_id=share_network['project_id'],
                share_networks=-1)
        except Exception:
            msg = _("Failed to update usages deleting share-network.")
            LOG.exception(msg)
        else:
            QUOTAS.commit(context, reservations,
                          project_id=share_network['project_id'])
        return webob.Response(status_int=202)
Exemplo n.º 5
0
    def test_delete(self):
        db_api.share_network_create(self.fake_context, self.share_nw_dict)
        db_api.share_network_delete(self.fake_context,
                                    self.share_nw_dict['id'])

        self.assertRaises(exception.ShareNetworkNotFound,
                          db_api.share_network_get, self.fake_context,
                          self.share_nw_dict['id'])
Exemplo n.º 6
0
    def delete(self, req, id):
        """Delete specified share network."""
        context = req.environ['manila.context']
        policy.check_policy(context, RESOURCE_NAME, 'delete')

        try:
            share_network = db_api.share_network_get(context, id)
        except exception.ShareNetworkNotFound as e:
            raise exc.HTTPNotFound(explanation=six.text_type(e))

        share_instances = (
            db_api.share_instances_get_all_by_share_network(context, id)
        )
        if share_instances:
            msg = _("Can not delete share network %(id)s, it has "
                    "%(len)s share(s).") % {'id': id,
                                            'len': len(share_instances)}
            LOG.error(msg)
            raise exc.HTTPConflict(explanation=msg)

        # NOTE(ameade): Do not allow deletion of share network used by share
        # group
        sg_count = db_api.count_share_groups_in_share_network(context, id)
        if sg_count:
            msg = _("Can not delete share network %(id)s, it has %(len)s "
                    "share group(s).") % {'id': id, 'len': sg_count}
            LOG.error(msg)
            raise exc.HTTPConflict(explanation=msg)

        # NOTE(silvacarlose): Do not allow the deletion of any share server
        # if one of them has the flag is_auto_deletable = False
        if not self._all_share_servers_are_auto_deletable(share_network):
            msg = _("The service cannot determine if there are any "
                    "non-managed shares on the share network %(id)s, so it "
                    "cannot be deleted. Please contact the cloud "
                    "administrator to rectify.") % {'id': id}
            LOG.error(msg)
            raise exc.HTTPConflict(explanation=msg)

        for share_server in share_network['share_servers']:
            self.share_rpcapi.delete_share_server(context, share_server)
        db_api.share_network_delete(context, id)

        try:
            reservations = QUOTAS.reserve(
                context, project_id=share_network['project_id'],
                share_networks=-1, user_id=share_network['user_id'])
        except Exception:
            LOG.exception("Failed to update usages deleting "
                          "share-network.")
        else:
            QUOTAS.commit(context, reservations,
                          project_id=share_network['project_id'],
                          user_id=share_network['user_id'])
        return webob.Response(status_int=http_client.ACCEPTED)
Exemplo n.º 7
0
    def delete(self, req, id):
        """Delete specified share network."""
        context = req.environ['manila.context']
        policy.check_policy(context, RESOURCE_NAME, 'delete')

        try:
            share_network = db_api.share_network_get(context, id)
        except exception.ShareNetworkNotFound as e:
            raise exc.HTTPNotFound(explanation=six.text_type(e))

        share_instances = (db_api.share_instances_get_all_by_share_network(
            context, id))
        if share_instances:
            msg = _("Can not delete share network %(id)s, it has "
                    "%(len)s share(s).") % {
                        'id': id,
                        'len': len(share_instances)
                    }
            LOG.error(msg)
            raise exc.HTTPConflict(explanation=msg)

        # NOTE(ameade): Do not allow deletion of share network used by share
        # group
        sg_count = db_api.count_share_groups_in_share_network(context, id)
        if sg_count:
            msg = _("Can not delete share network %(id)s, it has %(len)s "
                    "share group(s).") % {
                        'id': id,
                        'len': sg_count
                    }
            LOG.error(msg)
            raise exc.HTTPConflict(explanation=msg)

        for share_server in share_network['share_servers']:
            self.share_rpcapi.delete_share_server(context, share_server)
        db_api.share_network_delete(context, id)

        try:
            reservations = QUOTAS.reserve(
                context,
                project_id=share_network['project_id'],
                share_networks=-1,
                user_id=share_network['user_id'])
        except Exception:
            LOG.exception(
                _LE("Failed to update usages deleting "
                    "share-network."))
        else:
            QUOTAS.commit(context,
                          reservations,
                          project_id=share_network['project_id'],
                          user_id=share_network['user_id'])
        return webob.Response(status_int=202)
Exemplo n.º 8
0
    def delete(self, req, id):
        """Delete specified share network."""
        context = req.environ["manila.context"]
        policy.check_policy(context, RESOURCE_NAME, "delete")

        try:
            share_network = db_api.share_network_get(context, id)
        except exception.ShareNetworkNotFound as e:
            msg = "%s" % e
            raise exc.HTTPNotFound(explanation=msg)

        if share_network["status"] == constants.STATUS_ACTIVE:
            msg = "Network %s is in use" % id
            raise exc.HTTPBadRequest(explanation=msg)

        db_api.share_network_delete(context, id)

        return webob.Response(status_int=202)
Exemplo n.º 9
0
    def delete(self, req, id):
        """Delete specified share network."""
        context = req.environ["manila.context"]
        policy.check_policy(context, RESOURCE_NAME, "delete")

        try:
            share_network = db_api.share_network_get(context, id)
        except exception.ShareNetworkNotFound as e:
            raise exc.HTTPNotFound(explanation=six.text_type(e))

        share_instances = db_api.share_instances_get_all_by_share_network(context, id)
        if share_instances:
            msg = _("Can not delete share network %(id)s, it has " "%(len)s share(s).") % {
                "id": id,
                "len": len(share_instances),
            }
            LOG.error(msg)
            raise exc.HTTPConflict(explanation=msg)

        # NOTE(ameade): Do not allow deletion of share network used by CG
        cg_count = db_api.count_consistency_groups_in_share_network(context, id)
        if cg_count:
            msg = _("Can not delete share network %(id)s, it has %(len)s " "consistency group(s).") % {
                "id": id,
                "len": cg_count,
            }
            LOG.error(msg)
            raise exc.HTTPConflict(explanation=msg)

        for share_server in share_network["share_servers"]:
            self.share_rpcapi.delete_share_server(context, share_server)
        db_api.share_network_delete(context, id)

        try:
            reservations = QUOTAS.reserve(context, project_id=share_network["project_id"], share_networks=-1)
        except Exception:
            LOG.exception(_LE("Failed to update usages deleting " "share-network."))
        else:
            QUOTAS.commit(context, reservations, project_id=share_network["project_id"])
        return webob.Response(status_int=202)
Exemplo n.º 10
0
    def delete(self, req, id):
        """Delete specified share network."""
        context = req.environ['manila.context']
        policy.check_policy(context, RESOURCE_NAME, 'delete')

        try:
            share_network = db_api.share_network_get(context, id)
        except exception.ShareNetworkNotFound as e:
            raise exc.HTTPNotFound(explanation=six.text_type(e))

        share_instances = (db_api.share_instances_get_all_by_share_network(
            context, id))
        if share_instances:
            msg = _("Can not delete share network %(id)s, it has "
                    "%(len)s share(s).") % {
                        'id': id,
                        'len': len(share_instances)
                    }
            LOG.error(msg)
            raise exc.HTTPConflict(explanation=msg)

        # NOTE(ameade): Do not allow deletion of share network used by share
        # group
        sg_count = db_api.count_share_groups_in_share_network(context, id)
        if sg_count:
            msg = _("Can not delete share network %(id)s, it has %(len)s "
                    "share group(s).") % {
                        'id': id,
                        'len': sg_count
                    }
            LOG.error(msg)
            raise exc.HTTPConflict(explanation=msg)

        # NOTE(silvacarlose): Do not allow the deletion of share networks
        # if it still contains two or more subnets
        if self._share_network_contains_subnets(share_network):
            msg = _("The share network %(id)s has more than one subnet "
                    "attached. Please remove the subnets untill you have one "
                    "or no subnets remaining.") % {
                        'id': id
                    }
            LOG.error(msg)
            raise exc.HTTPConflict(explanation=msg)

        for subnet in share_network['share_network_subnets']:
            if not self._all_share_servers_are_auto_deletable(subnet):
                msg = _("The service cannot determine if there are any "
                        "non-managed shares on the share network subnet "
                        "%(id)s, so it cannot be deleted. Please contact the "
                        "cloud administrator to rectify.") % {
                            'id': subnet['id']
                        }
                LOG.error(msg)
                raise exc.HTTPConflict(explanation=msg)

        for subnet in share_network['share_network_subnets']:
            for share_server in subnet['share_servers']:
                self.share_rpcapi.delete_share_server(context, share_server)

        db_api.share_network_delete(context, id)

        try:
            reservations = QUOTAS.reserve(
                context,
                project_id=share_network['project_id'],
                share_networks=-1,
                user_id=share_network['user_id'])
        except Exception:
            LOG.exception("Failed to update usages deleting " "share-network.")
        else:
            QUOTAS.commit(context,
                          reservations,
                          project_id=share_network['project_id'],
                          user_id=share_network['user_id'])
        return webob.Response(status_int=http_client.ACCEPTED)
Exemplo n.º 11
0
    def create(self, req, body):
        """Creates a new share network."""
        context = req.environ['manila.context']
        policy.check_policy(context, RESOURCE_NAME, 'create')

        if not body or RESOURCE_NAME not in body:
            raise exc.HTTPUnprocessableEntity()

        share_network_values = body[RESOURCE_NAME]
        share_network_subnet_values = copy.deepcopy(share_network_values)
        share_network_values['project_id'] = context.project_id
        share_network_values['user_id'] = context.user_id

        if 'nova_net_id' in share_network_values:
            msg = _("nova networking is not supported starting in Ocata.")
            raise exc.HTTPBadRequest(explanation=msg)

        share_network_values.pop('availability_zone', None)
        share_network_values.pop('neutron_net_id', None)
        share_network_values.pop('neutron_subnet_id', None)

        if req.api_version_request >= api_version.APIVersionRequest("2.51"):
            if 'availability_zone' in share_network_subnet_values:
                try:
                    az = db_api.availability_zone_get(
                        context,
                        share_network_subnet_values['availability_zone'])
                    share_network_subnet_values['availability_zone_id'] = (
                        az['id'])
                    share_network_subnet_values.pop('availability_zone')
                except exception.AvailabilityZoneNotFound:
                    msg = (_("The provided availability zone %s does not "
                             "exist.") %
                           share_network_subnet_values['availability_zone'])
                    raise exc.HTTPBadRequest(explanation=msg)

        common.check_net_id_and_subnet_id(share_network_subnet_values)

        try:
            reservations = QUOTAS.reserve(context, share_networks=1)
        except exception.OverQuota as e:
            overs = e.kwargs['overs']
            usages = e.kwargs['usages']
            quotas = e.kwargs['quotas']

            def _consumed(name):
                return (usages[name]['reserved'] + usages[name]['in_use'])

            if 'share_networks' in overs:
                LOG.warning(
                    "Quota exceeded for %(s_pid)s, "
                    "tried to create "
                    "share-network (%(d_consumed)d of %(d_quota)d "
                    "already consumed).", {
                        's_pid': context.project_id,
                        'd_consumed': _consumed('share_networks'),
                        'd_quota': quotas['share_networks']
                    })
                raise exception.ShareNetworksLimitExceeded(
                    allowed=quotas['share_networks'])
        else:
            # Tries to create the new share network
            try:
                share_network = db_api.share_network_create(
                    context, share_network_values)
            except db_exception.DBError as e:
                LOG.exception(e)
                msg = "Could not create share network."
                raise exc.HTTPInternalServerError(explanation=msg)

            share_network_subnet_values['share_network_id'] = (
                share_network['id'])
            share_network_subnet_values.pop('id', None)

            # Try to create the share network subnet. If it fails, the service
            # must rollback the share network creation.
            try:
                db_api.share_network_subnet_create(
                    context, share_network_subnet_values)
            except db_exception.DBError:
                db_api.share_network_delete(context, share_network['id'])
                msg = _('Could not create share network.')
                raise exc.HTTPInternalServerError(explanation=msg)

            QUOTAS.commit(context, reservations)
            share_network = db_api.share_network_get(context,
                                                     share_network['id'])
            return self._view_builder.build_share_network(req, share_network)