Bug #8769
closed
Unable to build new VM in openstack with API
Added by Brian Lee almost 10 years ago.
Updated almost 10 years ago.
Description
I am using json to create a new VM in a openstack Icehouse environment. I get this error as a response from the json request:
{
"host": {
"id": null,
"errors": {
"base": [
"Failed to create a compute Openstack-Quicksand-SE (OpenStack) instance se-test-api.vm.<domain>.com: undefined method `delete_if' for nil:NilClass\n "
]
},
"full_messages": [
"Failed to create a compute Openstack-Quicksand-SE (OpenStack) instance se-test-api.vm.<domain>.com: undefined method `delete_if' for nil:NilClass\n "
]
}
}
Paste bin of the error in the production.log: http://pastebin.com/8F0a8AkR
Try passing an empty array in for compute_attributes[nics]
so it can iterate over something at least, though you probably need to add some info about network interfaces.
I am back to working on this. How do I add a empty array to it? This is my current json:
{"host":{"name":"se-test-api",
"environment_id":"1",
"hostgroup_id":"6",
"architecture_id":1,
"operatingsystem_id":"1",
"provision_method":"image",
"compute_resource_id":1,
"compute_attributes":{"flavor_ref":3,
"image_ref":"0937879c-c44a-42b9-b3f5-f03c1928bf39",
"tenant_id":"b9241c2ab4884ef7911b13e4cd26aa44",
"security_groups":"default",
"network":"nova"}
}
}
I have tried adding "nics": , "nics":{}, "nics":[] to the compute_attrubutes section and it does not seem to help.
When I do "nics":{}, I am getting this error: undefined method `map!' for {}:ActiveSupport::HashWithIndifferentAccess
What else can I try?
I'd try:
{"host":{"name":"se-test-api",
"environment_id":"1",
"hostgroup_id":"6",
"architecture_id":1,
"operatingsystem_id":"1",
"provision_method":"image",
"compute_resource_id":1,
"compute_attributes":{"flavor_ref":3,
"image_ref":"0937879c-c44a-42b9-b3f5-f03c1928bf39",
"tenant_id":"b9241c2ab4884ef7911b13e4cd26aa44",
"security_groups":"default",
"network":"nova",
"nics":[]}
}
}
Can you check the exact error when you try it?
It throws the same error as above. From the log:
Processing by Api::V1::HostsController#create as JSON
Parameters: {"host"=>{"name"=>"se-test-api", "environment_id"=>"1", "hostgroup_id"=>"6", "architecture_id"=>1, "operatingsystem_id"=>"1", "provision_method"=>"image", "compute_resource_id"=>1, "compute_attributes"=>{"flavor_ref"=>3, "image_ref"=>"0937879c-c44a-42b9-b3f5-f03c1928bf39", "tenant_id"=>"b9241c2ab4884ef7911b13e4cd26aa44", "security_groups"=>"default", "network"=>"nova", "nics"=>nil}}, "apiv"=>"v1"}
Authorized user blee(Brian Lee)
Adding Compute instance for se-test-api.<domain>.com
failed to create vm: undefined method `delete_if' for nil:NilClass
"nics"=>nil
looks odd, it's not an empty array as I'd expect if you're doing "nics": []
.
Looking at the log its erroring in the /usr/share/foreman/app/models/compute_resources/foreman/model/openstack.rb. This is the section:
def create_vm(args = {})
network = args.delete(:network)
# fix internal network format for fog.
args[:nics].delete_if(&:blank?)
args[:nics].map! {|nic| { 'net_id' => nic } }
vm = super(args)
if network.present?
address = allocate_address(network)
assign_floating_ip(address, vm)
end
vm
rescue => e
message = JSON.parse(e.response.body)['badRequest']['message'] rescue (e.to_s)
logger.warn "failed to create vm: #{message}"
destroy_vm vm.id if vm
raise message
end
Its complaining about the delete_if function. Is there a missing class for it? I don't know Ruby very well so I am just guessing.
args[:nic] inside compute_attributes is nil (aka null), when it expects an array of NICs. "delete_if" is only valid on arrays, not nil. I thought "nics": [] should pass in an empty array, but the params log you pasted shows it's nil still.
So what else can I do? This is a major blocker on my project. Is there some sort of a a hack workaround I can put in until it is resolved?
I did a little hacking on that part of the code and I am now able to spin up a openstack VM with the API call:
def create_vm(args = {})
network = args.delete(:network)
# fix internal network format for fog.
#args[:nics].delete_if(&:blank?)
args.delete(:nics)
#args[:nics].map! {|nic| { 'net_id' => nic } }
vm = super(args)
if network.present?
address = allocate_address(network)
assign_floating_ip(address, vm)
end
vm
rescue => e
message = JSON.parse(e.response.body)['badRequest']['message'] rescue (e.to_s)
logger.warn "failed to create vm: #{message}"
destroy_vm vm.id if vm
raise message
end
I am sure this is not ideal, but it is working for me.
I upgraded to foreman 1.7.2 and now when you pass "nics":[""] into the JSON request you do not get the error. I would say it is fixed in 1.7.2 now.
- Status changed from New to Resolved
That's good news, thanks for confirming Brian.
- Pull request https://github.com/Katello/katello-installer/pull/176 added
- Pull request deleted (
)
- Pull request added
- Pull request deleted (
https://github.com/Katello/katello-installer/pull/176)
- Related to Bug #12320: Hammer CLI : Failed to create a new VM on OpenStack - undefined method `delete_if' for nil:NilClass added
Also available in: Atom
PDF