Project

General

Profile

Actions

Bug #14179

closed

Interface/NIC compute attributes in API host creation overwritten with compute profile attributes

Added by Dominic Cleal about 8 years ago. Updated over 5 years ago.

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

Description

Since #6342, compute attributes specified inside a NIC/interface via the host create API are overwritten with compute attributes from associated compute profiles. This has the same symptoms as ticket #11124, which fixed it before #6342 reintroduced it.

POST to /api/v2/hosts with the following parameters:

{
    "host": {
        "name": "niccrattrs",
        "hostgroup_name": "libvirt",
        "compute_resource_name": "localhost",
        "compute_attributes": {
            "cpus": 3
        },
        "interfaces_attributes": {
            "0": {
                "primary": "true",
                "compute_attributes": {
                    "model": "e1000" 
                }
            }
        }
    }
}

... results in a VM with the NIC model set in the compute profile assigned to the host group, rather than e1000 as per the NIC compute attributes.

In HostsController#create, the host compute attrs after ComputeAttributeMerge contains the nic_attributes from the profile:

[1] pry(#<Api::V2::HostsController>)> @host.compute_attributes
=> {"cpus"=>3,
 "memory"=>"1073741824",
 "nics_attributes"=>{"0"=>{"type"=>"network", "network"=>"default", "model"=>"virtio"}},
 "volumes_attributes"=>{"0"=>{"pool_name"=>"default", "capacity"=>"10G", "allocation"=>"0G", "format_type"=>"qcow2"}}}

Prior to #6342, these compute attributes wouldn't have been filled in - it changed the API behaviour to merge compute profile attributes into host.compute_attributes.

But the NIC's compute_attributes does contain the merged compute attributes from the compute profile plus the user's parameters, due to InterfaceMerge and #11124:

[2] pry(#<Api::V2::HostsController>)> @host.interfaces
=> [#<Nic::Managed id: nil, mac: nil, ip: nil, type: "Nic::Managed", name: "test13982a", host_id: nil, subnet_id: nil, domain_id: nil, attrs: {}, created_at: nil, updated_at: nil, provider: nil, username: nil, password: nil, virtual: false, link: true, identifier: nil, tag: "", attached_to: "", managed: true, mode: "balance-rr", attached_devices: "", bond_options: "", primary: true, provision: true, compute_attributes: {"type"=>"network", "network"=>"default", "model"=>"e1000", "from_profile"=>"libvirt"}>]

Later in Orchestration::Compute#add_interfaces_to_compute_attrs, the per-NIC compute attributes should be merged back into the host compute attributes, but the step is skipped (the return unless in this method) as the host compute attributes already contains nics_attributes:

[1] pry(#<Host::Managed>)> compute_attributes[attrs_name]
=> {"0"=>{"type"=>"network", "network"=>"default", "model"=>"virtio"}}
[2] pry(#<Host::Managed>)> compute_attributes
=> {"cpus"=>3,
 "memory"=>"1073741824",
 "nics_attributes"=>{"0"=>{"type"=>"network", "network"=>"default", "model"=>"virtio"}},
 "volumes_attributes"=>{"0"=>{"pool_name"=>"default", "capacity"=>"10G", "allocation"=>"0G", "format_type"=>"qcow2"}}}

Related issues 2 (0 open2 closed)

Related to Foreman - Bug #6342: Compute profile should be used when empty volumes and interfaces passed in compute_attributesClosedTomáš Strachota06/23/2014Actions
Related to Foreman - Bug #11124: Interface compute attributes not merged from API request over compute profileClosedTimo Goebel07/15/2015Actions
Actions #1

Updated by Dominic Cleal about 8 years ago

  • Related to Bug #6342: Compute profile should be used when empty volumes and interfaces passed in compute_attributes added
Actions #2

Updated by Dominic Cleal about 8 years ago

  • Related to Bug #11124: Interface compute attributes not merged from API request over compute profile added
Actions #3

Updated by Dominic Cleal about 8 years ago

  • Status changed from New to Assigned
  • Assignee set to Dominic Cleal
Actions #4

Updated by The Foreman Bot about 8 years ago

  • Status changed from Assigned to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/3316 added
Actions #5

Updated by Dominic Cleal about 8 years ago

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

Also available in: Atom PDF