config-host-update and config-command-update can update their name

Change-Id: Iec7ec4c10866242d8dcc0368392c9f88a65d7b89
This commit is contained in:
flavien peyre 2015-07-06 14:38:26 -04:00
parent 6a53712b11
commit fb3a3570c1
5 changed files with 18 additions and 24 deletions

View File

@ -84,13 +84,12 @@ class TestCommands(clienttest.ClientTest):
self.client.config.commands.update(
command_name="command_to_update",
command_line="updated command_line"
command={'command_line': "updated command_line"}
)
self.assertEqual(
json.loads(httpretty.last_request().body.decode()),
{
"command_name": "command_to_update",
"command_line": "updated command_line"
}
)

View File

@ -81,16 +81,16 @@ class TestHosts(clienttest.ClientTest):
)
self.client.config.hosts.update(
"host_name_to_update",
address="192.168.0.1",
check_period="24x7"
host_name="host_name_to_update",
host={'address': "192.168.0.1",
'check_period': "24x7"
}
)
self.assertEqual(
json.loads(httpretty.last_request().body.decode()),
{
"check_period": u"24x7",
"host_name": u"host_name_to_update",
"address": u"192.168.0.1"
}
)

View File

@ -41,11 +41,11 @@ class CommandsManager(surveil_manager.SurveilManager):
)
return body
def update(self, **kwargs):
def update(self, command_name, command):
"""Update a command."""
resp, body = self.http_client.json_request(
CommandsManager.base_url + '/' + kwargs['command_name'], 'PUT',
body=kwargs
CommandsManager.base_url + '/' + command_name, 'PUT',
body=command
)
return body

View File

@ -41,13 +41,11 @@ class HostsManager(surveil_manager.SurveilManager):
)
return body
def update(self, host_name, **kwargs):
def update(self, host_name, host):
"""Update a host."""
kwargs['host_name'] = host_name
resp, body = self.http_client.json_request(
HostsManager.base_url + '/' + host_name, 'PUT',
body=kwargs
body=host
)
return body

View File

@ -47,7 +47,8 @@ def do_config_host_list(sc, args):
utils.print_list(hosts, cols, formatters=formatters)
@cliutils.arg("--host_name", help="Name of the host")
@cliutils.arg("original_host_name", help="Original name of the host")
@cliutils.arg("--host_name", help="New name of the host")
@cliutils.arg("--address", help="Address of the host")
@cliutils.arg("--max_check_attempts")
@cliutils.arg("--check_period")
@ -59,7 +60,8 @@ def do_config_host_list(sc, args):
@cliutils.arg("--use")
def do_config_host_update(sc, args):
"""Create a config host."""
arg_names = ['address',
arg_names = ['host_name',
'address',
'max_check_attempts',
'check_period',
'contacts',
@ -69,13 +71,7 @@ def do_config_host_update(sc, args):
'notification_period',
'use']
host = _dict_from_args(args, arg_names)
host["host_name"] = args.host_name
if "custom_fields" in host:
host["custom_fields"] = json.loads(host["custom_fields"])
sc.config.hosts.update(args.host_name, **host)
sc.config.hosts.update(args.original_host_name, host)
@cliutils.arg("--host_name", help="Name of the host")
@ -285,14 +281,15 @@ def do_config_command_show(sc, args):
utils.print_item(command, command_properties)
@cliutils.arg("--command_name", help="Name of the command")
@cliutils.arg("original_command_name", help="Original name of the command")
@cliutils.arg("--command_name", help="New name of the command")
@cliutils.arg("--command_line", help="Address of the command")
def do_config_command_update(sc, args):
"""Update a config command."""
arg_names = ['command_name',
'command_line']
command = _dict_from_args(args, arg_names)
sc.config.commands.update(**command)
sc.config.commands.update(args.original_command_name, command)
def do_config_reload(sc, args):