fog / fog-core

fog's core, shared behaviors without API and provider specifics
MIT License
45 stars 95 forks source link

Attribute aliases work only partially #237

Open Temikus opened 6 years ago

Temikus commented 6 years ago

For example, we create a model with those attributes:

(#<Fog::Compute::Google::Network>)> attributes
=> {:name=>"fog-test-networkscol-9ca8d6cc-4686-4d3f-9cd2-8d28a9383154", :ipv4_range=>"10.240.133.0/24"}

When created actually turns into proper model fields:

=> {:name=>"fog-test-networkscol-9ca8d6cc-4686-4d3f-9cd2-8d28a9383154", :ipv4_range=>"10.240.133.0/24"}
my_network
=>   <Fog::Compute::Google::Network
    name="fog-test-networkscol-9ca8d6cc-4686-4d3f-9cd2-8d28a9383154",
    auto_create_subnetworks=nil,
    creation_timestamp="2018-04-12T22:59:17.787-07:00",
    description=nil,
    gateway_i_pv4="10.240.0.1",
    i_pv4_range="10.240.0.0/16",
    id=REDACTED,
    kind="compute#network",
    peerings=nil,
    routing_config={:routing_mode=>"REGIONAL"},
    self_link="https://www.googleapis.com/compute/v1/projects/REDACTED/global/networks/fog-test-networkscol-9ca8d6cc-4686-4d3f-9cd2-8d28a9383154",
    subnetworks=nil

But when I try to call it:

NoMethodError: undefined method `ipv4_range' for #<Fog::Compute::Google::Network:0x00007fe5221bae40>
Did you mean?  i_pv4_range
               i_pv4_range=
from (pry):3:in `test_network_workflow'```

It seems there is a bug - the alias mapping is only being done when doing a plain new object or reloading:

https://github.com/fog/fog-core/blob/7865ef77ea990fd0d085e49c28e15957b7ce0d2b/lib/fog/core/attributes.rb#L119

But the actual method setters don't: https://github.com/fog/fog-core/tree/master/lib/fog/core/attributes

Maybe we should move that alias code to inside the setter definition or do an alias automatically?

Temikus commented 6 years ago

This is a result of my chat with @plribeiro3000 earlier. Didn't have much time to look into it deeply to actually fix, but I feel this needs to at least be documented.

plribeiro3000 commented 6 years ago

I'm ok with doing a setter for the alias.

This is something i struggled myself in the past when working on fog-xenserver.

@geemus any thoughts?

geemus commented 6 years ago

Sounds reasonable to me, thanks!

stale[bot] commented 6 years ago

This issue has been automatically marked stale due to inactivity. It will be closed if no further activity occurs. Thank you for your contributions.

plribeiro3000 commented 6 years ago

Leave it open!

Em sex, 21 de set de 2018 15:37, stale[bot] notifications@github.com escreveu:

This issue has been automatically marked stale due to inactivity. It will be closed if no further activity occurs. Thank you for your contributions.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/fog/fog-core/issues/237#issuecomment-423633101, or mute the thread https://github.com/notifications/unsubscribe-auth/AApEuIhSnLO_3iVTdnCafIHBodh2ybLbks5udTHdgaJpZM4VQquE .

stale[bot] commented 5 years ago

This issue has been automatically marked stale due to inactivity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 5 years ago

This issue has been automatically marked stale due to inactivity. It will be closed if no further activity occurs. Thank you for your contributions.

Temikus commented 5 years ago

Reopening and pinning to deactivate stalebot as this looks like something @plribeiro3000 is working on.

If not - no worries, just close out.

geemus commented 5 years ago

Sounds good, thanks!

plribeiro3000 commented 5 years ago

@Temikus Not really working on this now but i would leave it open since it looks like something we should tackle.

plribeiro3000 commented 4 years ago

@Temikus Is this something you guys still need?

I will try to find some spare time to tackle this.