theforeman / foreman_fog_proxmox

Foreman plugin to add Proxmox compute resource based on fog-proxmox gem
GNU General Public License v3.0
106 stars 33 forks source link

Create host does not work with 0.8.0: private method `select' called for nil:NilClass #89

Closed hlawatschek closed 5 years ago

hlawatschek commented 5 years ago

Describe the bug Create host does not work and the following error ist shown:

2019-06-26T10:39:53 [I|app|a134af24] Adding Compute instance for doyle-nicklos.proxmox.test 2019-06-26T10:39:53 [W|app|a134af24] Failed to create a compute Proxmox (Proxmox) instance doyle-nicklos.proxmox.test: private method `select' called for nil:NilClass

NoMethodError: private method select' called for nil:NilClass /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_fog_proxmox-0.8.0/app/models/foreman_fog_proxmox/proxmox.rb:148:inblock in host_interfaces_attrs' /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_fog_proxmox-0.8.0/app/models/foreman_fog_proxmox/proxmox.rb:136:in each' /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_fog_proxmox-0.8.0/app/models/foreman_fog_proxmox/proxmox.rb:136:inwith_index' /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_fog_proxmox-0.8.0/app/models/foreman_fog_proxmox/proxmox.rb:136:in each' /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_fog_proxmox-0.8.0/app/models/foreman_fog_proxmox/proxmox.rb:136:inreduce' /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_fog_proxmox-0.8.0/app/models/foreman_fog_proxmox/proxmox.rb:136:in host_interfaces_attrs' /usr/share/foreman/app/models/compute_resource.rb:143:inhost_compute_attrs' /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_fog_proxmox-0.8.0/app/models/foreman_fog_proxmox/proxmox.rb:123:in host_compute_attrs' /usr/share/foreman/app/models/concerns/orchestration/compute.rb:90:insetCompute' /usr/share/foreman/app/models/concerns/orchestration.rb:222:in execute' /usr/share/foreman/app/models/concerns/orchestration.rb:145:inblock in process' /usr/share/foreman/app/models/concerns/orchestration.rb:137:in each' /usr/share/foreman/app/models/concerns/orchestration.rb:137:inprocess' /usr/share/foreman/app/models/concerns/orchestration.rb:44:in around_save_orchestration' /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:118:inblock in run_callbacks' ...

it seems, that in foreman_fog_proxmox-0.8.0/app/models/foreman_fog_proxmox/proxmox.rb:host_interfaces_attrs(host) the call to host.compute_attributes['interfaces_attributes'] returns nil.

To Reproduce create host

pdzionek commented 5 years ago

I can confirm this error. I have the same one with version 0.8 and with Proxmox 5.3 and 5.4

MarvinMedia commented 5 years ago

I have the same error. With Proxmox 5.4 and 6 Everyone fixed?

MarvinMedia commented 5 years ago

and under Proxmox 5.1 the same problem.

tedkozma commented 5 years ago

any workaround yet, anyone?

workshopit commented 5 years ago

same problem 5.3 and 6.0

hlawatschek commented 5 years ago

you might want to try this "workaround"

diff --git a/app/models/foreman_fog_proxmox/proxmox.rb b/app/models/foreman_fog_proxmox/proxmox.rb
index d428ba9..223a259 100644
--- a/app/models/foreman_fog_proxmox/proxmox.rb
+++ b/app/models/foreman_fog_proxmox/proxmox.rb
@@ -145,8 +145,9 @@ module ForemanFogProxmox
         mac = nic.mac
         mac = nic.attributes['mac'] unless mac
         nic_compute_attributes.store(:macaddr, mac) if (mac && !mac.empty?)
-        interface_compute_attributes = host.compute_attributes['interfaces_attributes'].select { |_k,v| v['id'] == nic.identifier }
-        nic_compute_attributes.store(:_delete, interface_compute_attributes[interface_compute_attributes.keys[0]]['_delete']) unless interface_compute_attributes.empty?
+   #Workaround? for #89
+        #interface_compute_attributes = host.compute_attributes['interfaces_attributes'].select { |_k,v| v['id'] == nic.identifier }
+        #nic_compute_attributes.store(:_delete, interface_compute_attributes[interface_compute_attributes.keys[0]]['_delete']) unless interface_compute_attributes.empty?
         nic_compute_attributes.store(:ip, nic.ip) if (nic.ip && !nic.ip.empty?)
         nic_compute_attributes.store(:ip6, nic.ip6) if (nic.ip6 && !nic.ip6.empty?)
         hash.merge(index.to_s => nic_compute_attributes)
-- 
2.20.1
MarvinMedia commented 5 years ago

you might want to try this "workaround"

diff --git a/app/models/foreman_fog_proxmox/proxmox.rb b/app/models/foreman_fog_proxmox/proxmox.rb
index d428ba9..223a259 100644
--- a/app/models/foreman_fog_proxmox/proxmox.rb
+++ b/app/models/foreman_fog_proxmox/proxmox.rb
@@ -145,8 +145,9 @@ module ForemanFogProxmox
         mac = nic.mac
         mac = nic.attributes['mac'] unless mac
         nic_compute_attributes.store(:macaddr, mac) if (mac && !mac.empty?)
-        interface_compute_attributes = host.compute_attributes['interfaces_attributes'].select { |_k,v| v['id'] == nic.identifier }
-        nic_compute_attributes.store(:_delete, interface_compute_attributes[interface_compute_attributes.keys[0]]['_delete']) unless interface_compute_attributes.empty?
+ #Workaround? for #89
+        #interface_compute_attributes = host.compute_attributes['interfaces_attributes'].select { |_k,v| v['id'] == nic.identifier }
+        #nic_compute_attributes.store(:_delete, interface_compute_attributes[interface_compute_attributes.keys[0]]['_delete']) unless interface_compute_attributes.empty?
         nic_compute_attributes.store(:ip, nic.ip) if (nic.ip && !nic.ip.empty?)
         nic_compute_attributes.store(:ip6, nic.ip6) if (nic.ip6 && !nic.ip6.empty?)
         hash.merge(index.to_s => nic_compute_attributes)
-- 
2.20.1

diff: Unbekannte Option »--git« diff: »diff --help« gibt Ihnen mehr Informationen.

i have an error by use:

diff --git a/app/models/foreman_fog_proxmox/proxmox.rb b/app/models/foreman_fog_proxmox/proxmox.rb

hlawatschek commented 5 years ago

You can just comment out the two lines in app/models/foreman_fog_proxmox/proxmox.rb should be around line 148.

#interface_compute_attributes = host.compute_attributes['interfaces_attributes'].select { |_k,v| v['id'] == nic.identifier }
#nic_compute_attributes.store(:_delete, interface_compute_attributes[interface_compute_attributes.keys[0]]['_delete']) unless interface_compute_attributes.empty?
MarvinMedia commented 5 years ago

where do I have to do that? I have the plugin installed. where can i find this file?

app/models/foreman_fog_proxmox/proxmox.rb

MarvinMedia commented 5 years ago

where do I have to do that? I have the plugin installed. where can i find this file?

app/models/foreman_fog_proxmox/proxmox.rb

there or?

/usr/share/foreman/vendor/ruby/2.3.0/gems/fog-proxmox-0.8.0/lib/fog

tedkozma commented 5 years ago

@hlawatschek confirmed, the workaround works, thanks!

At least it works with VMs (not LXCs)

MarvinMedia commented 5 years ago

can you explain how you did it exactly please?

tedkozma commented 5 years ago

@MarvinMedia just like @hlawatschek suggested: comment out 2 lines in proxmox.rb: the one that resides under app/models/foreman_fog_proxmox. Not sure about your OS and ruby version, but if you're in Ubuntu then it's, most likely: /usr/share/foreman/vendor/ruby/2.5.0/gems/foreman_fog_proxmox-0.8.0/app/models/foreman_fog_proxmox/proxmox.rb

and if you're on CentOS (and the likes), then it's: /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_fog_proxmox-0.8.0/app/models/foreman_fog_proxmox/proxmox.rb

Now, this "workaround" does appear to allow provisioning VMs, but there might be some other issues down the line.

MarvinMedia commented 5 years ago

@MarvinMedia just like @hlawatschek suggested: comment out 2 lines in proxmox.rb: the one that resides under app/models/foreman_fog_proxmox. Not sure about your OS and ruby version, but if you're in Ubuntu than it's: /usr/share/foreman/vendor/ruby/2.5.0/gems/foreman_fog_proxmox-0.8.0/app/models/foreman_fog_proxmox/proxmox.rb

and if you're on CentOS (and the likes), then it's /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_fog_proxmox-0.8.0/app/models/foreman_fog_proxmox/proxmox.rb

Now, this "workaround" does appear to allow provisioning VMs, but there might be some other issues down the line.

thank you very much.

MarvinMedia commented 5 years ago

you might want to try this "workaround"

diff --git a/app/models/foreman_fog_proxmox/proxmox.rb b/app/models/foreman_fog_proxmox/proxmox.rb
index d428ba9..223a259 100644
--- a/app/models/foreman_fog_proxmox/proxmox.rb
+++ b/app/models/foreman_fog_proxmox/proxmox.rb
@@ -145,8 +145,9 @@ module ForemanFogProxmox
         mac = nic.mac
         mac = nic.attributes['mac'] unless mac
         nic_compute_attributes.store(:macaddr, mac) if (mac && !mac.empty?)
-        interface_compute_attributes = host.compute_attributes['interfaces_attributes'].select { |_k,v| v['id'] == nic.identifier }
-        nic_compute_attributes.store(:_delete, interface_compute_attributes[interface_compute_attributes.keys[0]]['_delete']) unless interface_compute_attributes.empty?
+ #Workaround? for #89
+        #interface_compute_attributes = host.compute_attributes['interfaces_attributes'].select { |_k,v| v['id'] == nic.identifier }
+        #nic_compute_attributes.store(:_delete, interface_compute_attributes[interface_compute_attributes.keys[0]]['_delete']) unless interface_compute_attributes.empty?
         nic_compute_attributes.store(:ip, nic.ip) if (nic.ip && !nic.ip.empty?)
         nic_compute_attributes.store(:ip6, nic.ip6) if (nic.ip6 && !nic.ip6.empty?)
         hash.merge(index.to_s => nic_compute_attributes)
-- 
2.20.1

At least it works with VMs

pdzionek commented 5 years ago

I can also confirm that the workaround works.

workshopit commented 5 years ago

Confirmed also. Would be nice to have v6 support ;)

On Mon, 19 Aug 2019 at 10:06, pdzionek notifications@github.com wrote:

I can also confirm that the workaround works.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/theforeman/foreman_fog_proxmox/issues/89?email_source=notifications&email_token=AI4SYBMENECY76AHE3QDBH3QFJPALA5CNFSM4H3V5242YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4SG5JA#issuecomment-522481316, or mute the thread https://github.com/notifications/unsubscribe-auth/AI4SYBOSYLGZ2ASSNW425RTQFJPALANCNFSM4H3V524Q .

jacac commented 5 years ago

The workaround does not work for LXC.

tedkozma commented 5 years ago

@jacac actually, i was able to provision some LXCs using this.

jacac commented 5 years ago

@tedkozma Thanks for the reply. Got it working by linking a smart proxy to the organization. Apparently you get the same error if the organization does not have any smart proxies associated. Just to clarify: I had to link smart proxy to the organization + comment those two lines + #86 to get it working.

tedkozma commented 5 years ago

@jacac one thing I don't understand is how to make those containers get puppet client set. Aside from trying to package another container template, which I also have little idea how to do.

jacac commented 5 years ago

Cloud-init is not supported on Proxmox for LXC. LXD added support through profiles (https://lxd.readthedocs.io/en/stable-3.0/cloud-init/ & https://blog.simos.info/how-to-preconfigure-lxd-containers-with-cloud-init/ ). I was playing with a default Centos template installing Cloud-Init manually and get it to run locally. Next step would be to have the configuration on the network and foreman pushing it. Not sure if I can get it to run though. We should create another issue and talk about integrating foreman+proxmox lxc+cloud-init.

jacac commented 5 years ago

@tristanrobert Thank you for fixing this. Would it be possible to reference your commits to the issue so that we can see how this issue is fixed and learn. I would like to contribute but don't know Ruby and seeing those commits really helps me to learn how this plugin works.