Bug #6998
closedCannot rename host by API due to DHCP conflict - cannot set 'overwrite' flag
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.
Updated by Aaron Stone about 9 years ago
Does this commit for Foreman 1.6.0 implement overwrite? @isratrade
https://github.com/theforeman/foreman/commit/c980e9a8917cc9fdee5835732428462e22fa3f5b
Updated by Dominic Cleal about 9 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.
Updated by Aaron Stone about 9 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?
Updated by Dominic Cleal about 9 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.
Updated by The Foreman Bot about 9 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 (
)
Updated by Dominic Cleal about 9 years ago
- translation missing: en.field_release set to 10
Updated by Aaron Stone about 9 years ago
- Status changed from Ready For Testing to Closed
- % Done changed from 0 to 100
Applied in changeset a0d231daf018694a4aec708c2d8e32e69492a84a.