WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@nofaralfasi
Copy link
Contributor

No description provided.

@Loumy
Copy link

Loumy commented Sep 29, 2025

Hello,
doesn't work for me : Path applied on foreman-openstack-3.16.0-1.el9.noarch
I add a logger here a363023#diff-87c1d0cf83bae98b382f8bffe3d2e4542d688420c88641bc482ef370f297e02aR168
and the value is : [{"net_id"=>"9cd70c0c-c8d0-4b13-8643-a40a2f0563c5"}]
The value of interface was : {"0"=>{"ip"=>"172.22.1.50", "ip6"=>""}}

@nofaralfasi
Copy link
Contributor Author

Hello, doesn't work for me

Thanks for sharing! I’ll take a look and work on fixing it.

@nofaralfasi
Copy link
Contributor Author

Hi @Loumy, could you give it another round of testing?

@Loumy
Copy link

Loumy commented Oct 1, 2025

Thanks @nofaralfasi but still not working.

2025-10-01T07:27:28 [W|app|9f130a36] value nics : [{"net_id"=>"9cd70c0c-c8d0-4b13-8643-a40a2f0563c5"}]
2025-10-01T07:27:28 [W|app|9f130a36] value interface: {"0"=>{"ip"=>"172.22.1.50", "ip6"=>""}}
2025-10-01T07:27:28 [W|app|9f130a36] value nics after process: [{"net_id"=>"9cd70c0c-c8d0-4b13-8643-a40a2f0563c5", "fixed_ip"=>"172.22.1.50"}]

But on the json sent to Openstack, I have only the network ID :

{    
  "server": {
    "flavorRef": "1",
    "name": "jaime-goodrick.novalocal",
    "imageRef": "f8fe0725-8155-46ba-86fc-3d22bdcc1a62",
    "metadata": {},                                                                                                                                                                                                    "availability_zone": "nova",                                                                                                                                                                                       "user_data": "[...]"
    "key_name": "foreman-2013a8523-6359-4b92-818f-7ad6c181533d",
    "security_groups": [
      {
        "name": "default"
      }
    ],
    "networks": [
      {
        "uuid": "9cd70c0c-c8d0-4b13-8643-a40a2f0563c5"
      }
    ]
  }
}

@Loumy
Copy link

Loumy commented Oct 1, 2025

I tried to reproduce with FOG and it works with this

class OpenStackVMManager
  def initialize(auth_params)
    @compute = Fog::Compute.new(auth_params.merge(provider: 'OpenStack'))
    @network = Fog::Network.new(auth_params.merge(provider: 'OpenStack'))
  end

  def create_vm_with_ip(name, image_id, flavor_id, network_id, ip_address)
    begin
      # check if already used IP
      existing_ports = @network.ports.all(fixed_ips: "ip_address=#{ip_address}")
      if existing_ports.any?
        raise "IP #{ip_address} already used"
      end

      # createport
      port = @network.ports.create(
        name: "#{name}-port",
        network_id: network_id,
        fixed_ips: [{ ip_address: ip_address }]
      )

      # Créer la VM
      server = @compute.servers.create(
        name: name,
        image_ref: image_id,
        flavor_ref: flavor_id,
        nics: [{ port_id: port.id }]
      )
[...]

I hope it help, I'm not so skilled in ruby to propose a path, I may try with an AI
fog-openstack (1.1.5)
ruby 3.0.7p220 (2024-04-23 revision 724a071175) [x86_64-linux]

@Loumy
Copy link

Loumy commented Oct 1, 2025

I made it work finally @nofaralfasi , from [1] the param is supposed v4_fixed_ip here [2] and not fixed_ip
[1] https://github.com/fog/fog-openstack/blob/master/lib/fog/openstack/compute/requests/create_server.rb#L50C42-L50C53
[2]

@nofaralfasi
Copy link
Contributor Author

Hi @Loumy, thanks for your review and comments. I was on PTO but will go through your feedback and update the PR ASAP.

@nofaralfasi nofaralfasi force-pushed the 38742 branch 3 times, most recently from 4827e2d to 4fc5eec Compare October 19, 2025 15:10
@nofaralfasi
Copy link
Contributor Author

Hi @Loumy,

Two things:

  1. Could you please confirm that my latest update (based on your most recent comment) works as expected?
  2. Regarding your comment here - I just want to confirm that the additional code you mentioned isn’t needed anymore, and that my recent changes resolve the issue on their own. If that’s not the case, could you share a bit more context about the code you added?

Thanks!

@clopnis
Copy link

clopnis commented Oct 20, 2025

@nofaralfasi I tested it on version 3.16.0 and it works like a charm great jobs.

  1. it was just a reproducer to test if was on FOG or not and not, you can forget this snippet

Many thanks !

@nofaralfasi
Copy link
Contributor Author

Thanks a lot @clopnis! 😊
Glad to hear it’s working well.
And thanks for clarifying about the snippet - I’ll leave it out then.

args[:nics].map! { |nic| nic.is_a?(String) ? { 'net_id' => nic } : nic }

# Process interface attributes to add fixed IP addresses
process_fixed_ips(args) if args[:interfaces_attributes].present?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
process_fixed_ips(args) if args[:interfaces_attributes].present?
process_fixed_ips(args)

There is another return unless interfaces_attrs&.any? check in the method itself

next unless interface_attrs.is_a?(Hash)

ip = interface_attrs[:ip] || interface_attrs['ip']
if ip.present?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about IPv6?


# Update nics with fixed IPs based on position
args[:nics].each_with_index do |nic, index|
next unless nic.is_a?(Hash) && nic['net_id']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be filtered out at the begining of the method so we can skip the ordering and everything:

nics = args[:nics].reject_if ....
return if nics.empty?

return unless interfaces_attrs&.any?

# Sort interface attributes by index to match nics order
sorted_interfaces = interfaces_attrs.sort_by { |index, _| index.to_i }.map(&:last)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you skip the sorting and just call interfaces_attrs[index.to_s] later on?

@clopnis
Copy link

clopnis commented Dec 2, 2025

tested and works on 3.16 with Openstack Epoxy

@stejskalleos stejskalleos merged commit a48be3b into theforeman:develop Dec 10, 2025
35 checks passed
@stejskalleos
Copy link
Contributor

Thanks @nofaralfasi @clopnis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants