audiolize / vagrant-softlayer

This is a Vagrant plugin that adds a SoftLayer provider to Vagrant, allowing Vagrant to control and provision SoftLayer CCI instances.
MIT License
42 stars 15 forks source link

Proper syntax for SL's private network configuration? #40

Closed lonniev closed 9 years ago

lonniev commented 9 years ago

Probably just a failure to RTFM but I cannot get the SL provider to configure a private network with statically assigned IP addresses. I see that a private network address does get assigned to eth0 (and a public one to eth1) but the address assigned is not what I specify in the Vagrant file.

Here is the snippet from the Vagrantfile:

config.hostmanager.enabled = true
config.hostmanager.ignore_private_ip = false
config.hostmanager.include_offline = true

config.vm.define "sl-ubuntu-host1", primary: true do | vmh |

  vmh.vm.hostname = "host1"

  vmh.vm.provider :softlayer do |sl, vmh_override|
    sl.hostname                  = vmh.vm.hostname
    vmh_override.vm.network "private_network", type: "static", ip: "10.0.0.10", auto_config: true
  end if Vagrant.has_plugin?("SoftLayer")

  vmh.vm.network "public_network", bridge: 'eth1'
  vmh.hostmanager.aliases = %w(proxy.internal.net)
  vmh.vm.usable_port_range          = 2200..6000

end

The "hostmanager" lines are there for the hostmanager plugin to modify the /etc/hosts file on each of the VMs this Vagrantfile provisions. Hostmanager does update the hosts file with the IPs that I specify. However, the instance has a dhcp-assigned 10.* address which is viewable with ifconfig and that is not the one requested.

There are no other explicit vm.network statements in the file; nevertheless, something is overriding my statement and configuring the private network on eth0 with DHCP.

ju2wheels commented 9 years ago

Hi @lonniev, as far as I know SoftLayer will not honor any provided IP at time of order and its basically chosen from the available pool of IPs based on the sl.vlan_private and sl.vlan_public id values. The config.vm.network properties are not used by vagrant-softlayer and are only useful for non cloud providers or providers that do support it other than SoftLayer (although Quick start guide could have made that point clearer, ill update that next time).

If you do not specify the correct vlan id's it will randomly choose them so that might be your problem.

With regards to eth0/eth1, you cannot change these either and these are assigned by SoftLayer depending on whether the IP is public or private as described here.

lonniev commented 9 years ago

Ok, I’ll stop trying to force what cannot be accomplished. ;-)

If I follow the KnowledgeLayer advice, I should still be able to DHCP private addresses on the eth0 interfaces, I just don’t get to choose them.

I haven’t tried the following yet and don’t yet know if I will need it… if I state an additional public network within the Vagrantfile with an additional config.vm.network statement, does the vagrant softlayer api automatically allocate that additional network which the KnowledgeLayer claims is a purchasable option?

(My goal with my current task is to vagrant up a network of 4 hosts, 1 of which is public and is a reverse proxy for the 3 others which are internal and private.)

—Lonnie VanZandt

303-900-3048 Sent from Dropbox's Mailbox on Mac

On Tue, Oct 28, 2014 at 1:06 PM, Julio Lajara notifications@github.com wrote:

Hi @lonniev, as far as I know SoftLayer will not honor any provided IP at time of order and its basically chosen from the available pool of IPs based on the sl.vlan_private and sl.vlan_public id values. The config.vm.network properties are not used by vagrant-softlayer and are only useful for non cloud providers or providers that do support it other than SoftLayer (although Quick start guide could have made that point clearer, ill update that next time). If you do not specify the correct vlan id's it will randomly choose them so that might be your problem.

With regards to eth0/eth1, you cannot change these either and these are assigned by SoftLayer depending on whether the IP is public or private as described here.

Reply to this email directly or view it on GitHub: https://github.com/audiolize/vagrant-softlayer/issues/40#issuecomment-60813074

ju2wheels commented 9 years ago

Assuming if "additional public network" here means one of the pri_ip_addresses or sec_ip_addresses product categories to add additional IPs to a machine, then it is not currently an option with the existing versions of vagrant-softlayer but will be once advanced virtual server ordering is added. I just pushed a few changed up to softlayer_api this week to provide more information for the vagrant-softlayer-productpackage tool described in #31, I just havent had time to come back to add the tool and the changes.

Using the latest master branch of softlayer_api though you can run this in irb to see what will be purchasable in advanced mode once its done:

require 'softlayer_api'
sl_client = SoftLayer::Client.new(:api_key => ENV["SL_API_KEY"], :username => ENV["SL_API_USERNAME"], :timeout => 240)
pkgs = [SoftLayer::ProductPackage.bare_metal_instance_package(sl_client),SoftLayer::ProductPackage.virtual_server_package(sl_client),SoftLayer::ProductPackage.additional_products_package(sl_client)].concat(SoftLayer::ProductPackage.bare_metal_server_packages(sl_client))
fout = File.open("/tmp/catagories.txt", "w")
pkgs.each{|pkg| fout.write "================#{pkg.name}===================\n"; pkg.categories.each{|item_cat| fout.write "#{item_cat.categoryCode}\n"; item_cat.configuration_options.each{|cat_opt| fout.write "\t#{Hash[cat_opt.each_pair.to_a].inspect}\n"}; fout.puts; fout.puts }; fout.puts; fout.puts}
fout.close

If what you are looking for is not one of those product categories then it wont be supported either as it will have to be implemented as a separate product purchase functionality like we do with the Load Balancers configuration.

lonniev commented 9 years ago

Related to this, what's the vagrant-way to ask a machine for the IP address that the provider assigned for the private network? From outside the Vagrantfile, I'd run vagrant ssh target-machine-name -c "ifconfig eth0|grep inet" and then split out the IP address. Is there a provider method that will obtain that while within the running Vagrantfile but only in the outermost config scope and not within the define block of the machine?

(If I was a ruby programmer, I'd probably see how to do this looking at the get ssh info action but that is still a bit foreign to me.)

lonniev commented 9 years ago

I see in the SL Python API that there is a "private_network" action/method. How can I call that method from the vagrantfile?

Again, my goal is to ask the newly instantiated SL machine what is the IP address that SL assigned to it for private networking.

ju2wheels commented 9 years ago

The Vagrantfile is straight ruby so you could just call the SoftLayer api directly as if you were writing against the api itself (assuming you are using vagrant-softlayer v4.0 :

vm_network = [ :public_ip => nil, :private_ip => nil ]
sl_client = SoftLayer::Client.new(:api_key => ENV["SL_API_KEY"], :username => ENV["SL_API_USERNAME"])
related_machine = SoftLayer::VirtualServer.find_servers(:client=>sl_client, :hostname => "vmhostname", :domain => "vmdomain")

unless related_machine.empty?
    related_machine = related_machine.first
    related_machine['networkComponents'].each do |net_comp|
        case net_comp['port']
        when 0
            vm_network[:private_ip] = net_comp['primaryIpAddress'] if vm_network[:private_ip].nil?
        when 1
            vm_network[:public_ip] = net_comp['primaryIpAddress'] if vm_network[:public_ip].nil?
        end
    end
end

That should give you the IP's for machines. FYI, I havent actually tested the above.

lonniev commented 9 years ago

So I read that you reauthenticate and then query for all the machines that that SL user has. Can all that be skipped if one already has a machine instance in the vagrantfile scope for the particular instance? That is, can related_machine be populated with config.vm.machine or something similar?

—Lonnie VanZandt

303-900-3048 Sent from Dropbox's Mailbox on Mac

On Fri, Nov 14, 2014 at 2:07 PM, Julio Lajara notifications@github.com wrote:

The Vagrantfile is straight ruby so you could just call the SoftLayer api directly as if you were writing against the api itself (assuming you are using vagrant-softlayer v4.0 :

vm_network = [ :public_ip => nil, :private_ip => nil ]
sl_client = SoftLayer::Client.new(:api_key => ENV["SL_API_KEY"], :username => ENV["SL_API_USERNAME"])
related_machine = SoftLayer::VirtualServer.find_servers(:client=>sl_client, :hostname => "vmhostname", :domain => "vmdomain")
unless related_machine.empty?
    related_machine = related_machine.first
    related_machine['networkComponents'].each do |net_comp|
        case net_comp['port']
        when 0
            vm_network[:private] = net_comp['primaryIpAddress'] if vm_network[:private].nil?
        when 1
            vm_network[:public] = net_comp['primaryIpAddress'] if vm_network[:public].nil?
        end
    end
end

That should give you the IP's for machines. FYI, I havent actually tested the above.

Reply to this email directly or view it on GitHub: https://github.com/audiolize/vagrant-softlayer/issues/40#issuecomment-63129075

ju2wheels commented 9 years ago

You may be able to get away with not re-authenticating if you access the machine's environment variables which has a stored sl_client but im not sure how to do that off the top of my head or if its even possible/accessible.

In regards to related_machine, if this is what you mean then yes it should work as long as you only want the IP for the current machine and not another:

related_machine = SoftLayer::VirtualServer.find_servers(:client=>sl_client, :hostname => cci.vm.hostname, :domain => cci.vm.provider.domain)

Again I havent tested the above, so if the domain part doesnt work you can leave that off the find properties as long as you dont have another machine with the same hostname in different datacenters or on different domains (:datacenter is also an acceptable filter there as well).

ju2wheels commented 9 years ago

closing, assuming the above worked out ok, if not reopen or let us know.

lonniev commented 9 years ago

np. I haven't worked with the SL vagrants for a few months now. I hope to get back to them this Spring.