Project

General

Profile

Actions

Bug #6998

closed

Cannot rename host by API due to DHCP conflict - cannot set 'overwrite' flag

Added by Aaron Stone over 10 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
API
Target version:
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

Description

Steps in UI:
In the Foreman UI, rename a host.
Foreman shows a DHCP conflict for the MAC Address to the old name.
Click the Overwrite button.

Steps in API:
Submit form to /api/hosts/hostid with content {"name": "newname"} and an APIv2 header version
Receive error message {"error"=>{"full_messages"=>["Conflict DHCP records spare-12345-macaddr/ipaddr and spare-12345-macaddr/ipaddr already exists"] ... }
Try again with {"name": "newname", "overwrite": true}
Receive same error.

Expected:
I should be able to overwrite from the API.

This is with Foreman 1.5.1.

Actions #1

Updated by Aaron Stone over 10 years ago

Does this commit for Foreman 1.6.0 implement overwrite? @isratrade
https://github.com/theforeman/foreman/commit/c980e9a8917cc9fdee5835732428462e22fa3f5b

Actions #2

Updated by Dominic Cleal over 10 years ago

  • Category set to API

That commit will help if you're using an unwrapped set of JSON, i.e. it'll make {"overwrite":true, ...} work. Before it, only the wrapped version {"host":{"overwrite":true, ...}} will work.

Actions #3

Updated by Aaron Stone over 10 years ago

Actually, I found that I had to set {"overwrite":"true"} in quotes, because of this:

https://github.com/theforeman/foreman/blob/develop/app/models/host/managed.rb#L611-614

  # We have to coerce the value back to boolean. It is not done for us by the framework.
  def overwrite=(value)
    @overwrite = value == "true" 
  end

Is there some way to put a flexible truthiness test into the API or Controller, rather than in the model?

Actions #4

Updated by Dominic Cleal over 10 years ago

Ah. It could be at the controller level, but it'd be much less duplication in the model - you could simply use value.to_s == "true" instead. Generally Rails does string/bool stuff at the ActiveRecord layer, which isn't applicable for a setter.

Actions #5

Updated by Aaron Stone over 10 years ago

I will submit a PR shortly!

Actions #6

Updated by The Foreman Bot over 10 years ago

  • Status changed from New to Ready For Testing
  • Target version set to 1.7.5
  • Pull request https://github.com/theforeman/foreman/pull/1677 added
  • Pull request deleted ()
Actions #7

Updated by Dominic Cleal over 10 years ago

  • Assignee set to Aaron Stone
Actions #8

Updated by Dominic Cleal about 10 years ago

  • Translation missing: en.field_release set to 10
Actions #9

Updated by Aaron Stone about 10 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100
Actions

Also available in: Atom PDF