Accessing foreman variables from fog_extension

I'm currently trying to
modify /usr/share/foreman/app/models/concerns/fog_extensions/vsphere/server.rb
to also try and match network card based on network id (to try and fix
#10186 <http://projects.theforeman.org/issues/10186>).
I need to get the datacenter variable used
in /usr/share/foreman/app/models/compute_resources/foreman/model/vmware.rb
Is this possible? If so how do I reference it in the fog extension?

Thanks
Francois

Just to provide a bit more info, here's the function:

  def get_network_id(network)
    datacenter = &quot;Datacenter Name&quot;
    network=service.get_network(network, datacenter)
    network[:id]
  end

I'm currently hard coding the datacenter name, but ideally this would be
retrieved from the foreman configuration.

> Just to provide a bit more info, here's the function:
>
> def get_network_id(network)
> datacenter = "Datacenter Name"
> network=service.get_network(network, datacenter)
> network[:id]
> end
>
> I'm currently hard coding the datacenter name, but ideally this would be
> retrieved from the foreman configuration.

fog_extensions are simply extensions made to the fog library that we use
in Foreman, so they would be added at runtime to fog classes. Normally
you would just call the method from the Compute Resource with the
appropriate variables (including datacenter). In this case, I'd say look
into app/models/compute_resources/foreman/model/vmware.rb

Hope this helps

··· On 04/19, Francois Herbert wrote: > > -- > You received this message because you are subscribed to the Google Groups "foreman-dev" group. > To unsubscribe from this group and stop receiving emails from it, send an email to foreman-dev+unsubscribe@googlegroups.com. > For more options, visit https://groups.google.com/d/optout.


Daniel Lobato Garcia

@eLobatoss
blog.daniellobato.me
daniellobato.me

GPG: http://keys.gnupg.net/pks/lookup?op=get&search=0x7A92D6DD38D6DE30
Keybase: https://keybase.io/elobato

Hi Daniel

Thanks for the reply. I'm trying to extend the select_nic function to also
try and match on the network id (since this is what fog returns when
vsphere is using portgroups). So I've tried to extend this as follows:

def select_nic(fog_nics, nic)
nic_attrs = nic.compute_attributes
match = fog_nics.detect { |fn| fn.network == nic_attrs['network']
} # grab any nic on the same network
match ||= fog_nics.detect { |fn| fn.network ==
get_network_id(nic_attrs['network']) } # no network? try the portgroup
match
end

But this select_nic function is called by the
generic app/models/concerns/orchestration/compute.rb in the
function match_macs_to_nics. So I can't see an easy way to send the
datacenter variable through compute.rb.

Is there another way I can get this variable to the select_nic function? -
I'm aware it's available in
app/models/compute_resources/foreman/model/vmware.rb

Thanks
Francois

Inside server.rb you're in an instance of a Fog server, so you might
just be able to call "datacenter" and it will resolve the DC that the
Fog server (VM) is assigned to - the equivalent of "vm.datacenter" outside.

··· On 20/04/15 09:37, Francois Herbert wrote: > Hi Daniel > > Thanks for the reply. I'm trying to extend the select_nic function to > also try and match on the network id (since this is what fog returns > when vsphere is using portgroups). So I've tried to extend this as follows: > > > > def select_nic(fog_nics, nic) > nic_attrs = nic.compute_attributes > match = fog_nics.detect { |fn| fn.network == > nic_attrs['network'] } # grab any nic on the same network > match ||= fog_nics.detect { |fn| fn.network == > get_network_id(nic_attrs['network']) } # no network? try the portgroup > match > end > > > > But this select_nic function is called by the > generic app/models/concerns/orchestration/compute.rb in the > function match_macs_to_nics. So I can't see an easy way to send the > datacenter variable through compute.rb. > > Is there another way I can get this variable to the select_nic function?


Dominic Cleal
Red Hat Engineering