def do_host_update(cc, args): """Update host attributes.""" patch = utils.args_array_to_patch("replace", args.attributes[0]) host = host_utils._find_host(cc, args.hostnameorid) try: host = cc.host.update(host.id, patch) except exc.HTTPNotFound: raise exc.CommandError('host not found: %s' % args.hostnameorid) _print_host_show(host)
def do_host_power_off(cc, args): """Power off a host.""" attributes = [] attributes.append('action=power-off') patch = utils.args_array_to_patch("replace", attributes) host = host_utils._find_host(cc, args.hostnameorid) try: host = cc.host.update(host.id, patch) except exc.HTTPNotFound: raise exc.CommandError('host not found: %s' % args.hostnameorid) _print_host_show(host)
def test_args_array_to_patch_remove(self): my_args = { 'attributes': ['/foo', 'extra/bar'], 'op': 'remove', } patch = utils.args_array_to_patch(my_args['op'], my_args['attributes']) self.assertEqual(patch, [{ 'op': 'remove', 'path': '/foo' }, { 'op': 'remove', 'path': '/extra/bar' }])
def test_args_array_to_patch(self): my_args = { 'attributes': ['foo=bar', '/extra/bar=baz'], 'op': 'add', } patch = utils.args_array_to_patch(my_args['op'], my_args['attributes']) self.assertEqual(patch, [{ 'op': 'add', 'value': 'bar', 'path': '/foo' }, { 'op': 'add', 'value': 'baz', 'path': '/extra/bar' }])
def do_host_swact(cc, args): """Switch activity away from this active host.""" attributes = [] if args.force is True: # Forced swact operation attributes.append('action=force-swact') else: # Normal swact operation attributes.append('action=swact') patch = utils.args_array_to_patch("replace", attributes) host = host_utils._find_host(cc, args.hostnameorid) try: host = cc.host.update(host.id, patch) except exc.HTTPNotFound: raise exc.CommandError('host not found: %s' % args.hostnameorid) _print_host_show(host)
def do_host_unlock(cc, args): """Unlock a host.""" attributes = [] if args.force is True: # Forced unlock operation attributes.append('action=force-unlock') else: # Normal unlock operation attributes.append('action=unlock') patch = utils.args_array_to_patch("replace", attributes) host = host_utils._find_host(cc, args.hostnameorid) try: host = cc.host.update(host.id, patch) except exc.HTTPNotFound: raise exc.CommandError('host not found: %s' % args.hostnameorid) _print_host_show(host)