Vhost limits commands

This commit is contained in:
Daniil Fedotov 2016-11-07 14:08:26 +00:00
parent 0bee160c59
commit 08e263ab2a
5 changed files with 103 additions and 10 deletions

View File

@ -0,0 +1,47 @@
## The contents of this file are subject to the Mozilla Public License
## Version 1.1 (the "License"); you may not use this file except in
## compliance with the License. You may obtain a copy of the License
## at http://www.mozilla.org/MPL/
##
## Software distributed under the License is distributed on an "AS IS"
## basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
## the License for the specific language governing rights and
## limitations under the License.
##
## The Original Code is RabbitMQ.
##
## The Initial Developer of the Original Code is GoPivotal, Inc.
## Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved.
defmodule RabbitMQ.CLI.Ctl.Commands.ClearVhostLimitsCommand do
@behaviour RabbitMQ.CLI.CommandBehaviour
use RabbitMQ.CLI.DefaultOutput
def switches(), do: []
def aliases(), do: []
def merge_defaults(args, opts) do
{args, Map.merge(%{vhost: "/"}, opts)}
end
def validate([], _) do
:ok
end
def validate([_|_] = args, _) when length(args) > 1 do
{:validation_failure, :too_many_args}
end
def run([], %{node: node_name, vhost: vhost}) do
:rabbit_misc.rpc_call(node_name, :rabbit_vhost_limit, :clear, [vhost])
end
def usage, do: "clear_vhost_limits [-p <vhost>]"
def flags, do: [:vhost]
def banner([], %{vhost: vhost}) do
"Clearing vhost \"#{vhost}\" limits ..."
end
end

View File

@ -43,7 +43,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.SetOperatorPolicyCommand do
vhost: vhost,
priority: priority,
apply_to: apply_to}) do
res = :rabbit_misc.rpc_call(node_name,
:rabbit_misc.rpc_call(node_name,
:rabbit_policy,
:parse_set_op,
[vhost,
@ -52,10 +52,6 @@ defmodule RabbitMQ.CLI.Ctl.Commands.SetOperatorPolicyCommand do
to_char_list(definition),
to_char_list(priority),
apply_to])
case res do
{:error, format, args} -> {:error, :rabbit_misc.format(format, args)};
_ -> res
end
end
def usage, do: "set_operator_policy [-p <vhost>] [--priority <priority>] [--apply-to <apply-to>] <name> <pattern> <definition>"

View File

@ -43,7 +43,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.SetPolicyCommand do
vhost: vhost,
priority: priority,
apply_to: apply_to}) do
res = :rabbit_misc.rpc_call(node_name,
:rabbit_misc.rpc_call(node_name,
:rabbit_policy,
:parse_set,
[vhost,
@ -52,10 +52,6 @@ defmodule RabbitMQ.CLI.Ctl.Commands.SetPolicyCommand do
to_char_list(definition),
to_char_list(priority),
apply_to])
case res do
{:error, format, args} -> {:error, :rabbit_misc.format(format, args)};
_ -> res
end
end
def usage, do: "set_policy [-p <vhost>] [--priority <priority>] [--apply-to <apply-to>] <name> <pattern> <definition>"

View File

@ -0,0 +1,50 @@
## The contents of this file are subject to the Mozilla Public License
## Version 1.1 (the "License"); you may not use this file except in
## compliance with the License. You may obtain a copy of the License
## at http://www.mozilla.org/MPL/
##
## Software distributed under the License is distributed on an "AS IS"
## basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
## the License for the specific language governing rights and
## limitations under the License.
##
## The Original Code is RabbitMQ.
##
## The Initial Developer of the Original Code is GoPivotal, Inc.
## Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved.
defmodule RabbitMQ.CLI.Ctl.Commands.SetVhostLimitsCommand do
@behaviour RabbitMQ.CLI.CommandBehaviour
use RabbitMQ.CLI.DefaultOutput
def switches(), do: []
def aliases(), do: []
def merge_defaults(args, opts) do
{args, Map.merge(%{vhost: "/"}, opts)}
end
def validate([], _) do
{:validation_failure, :not_enough_args}
end
def validate([_|_] = args, _) when length(args) > 1 do
{:validation_failure, :too_many_args}
end
def validate(_, _), do: :ok
def run([definition], %{node: node_name, vhost: vhost}) do
:rabbit_misc.rpc_call(node_name,
:rabbit_vhost_limit, :parse_set, [vhost, definition])
end
def usage, do: "set_vhost_limits [-p <vhost>] <definition>"
def flags, do: [:vhost]
def banner([definition], %{vhost: vhost}) do
"Setting vhost limits to \"#{definition}\" for vhost \"#{vhost}\" ..."
end
end

View File

@ -42,6 +42,10 @@ defmodule RabbitMQ.CLI.DefaultOutput do
defp normalize_output({:ok, _} = input), do: input
defp normalize_output({:badrpc, :nodedown} = input), do: input
defp normalize_output({:badrpc, :timeout} = input), do: input
defp normalize_output({:error, format, args})
when (is_list(format) or is_binary(format)) and is_list(args) do
{:error, :rabbit_misc.format(format, args)}
end
defp normalize_output({:error, _} = input), do: input
defp normalize_output({:error_string, _} = input), do: input
defp normalize_output(unknown) when is_atom(unknown), do: {:error, unknown}