Sha256: 8e6797f0973d5ab1743a904c931fd2eb64bdf6e3e6ec2fa2a100f38af9caa2b7

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

require 'chef/knife/cloud/openstack_service_options'

class Chef
  class Knife
    class Cloud
      module OpenstackHelpers
        def primary_private_ip_address(addresses)
          primary_network_ip_address(addresses, 'private')
        end

        def primary_public_ip_address(addresses)
          primary_network_ip_address(addresses, 'public')
        end

        def primary_network_ip_address(addresses, network_name)
          addresses[network_name].last['addr'] if addresses[network_name] && !addresses[network_name].empty?
        end

        def create_service_instance
          OpenstackService.new
        end

        def validate!
          super(:openstack_username, :openstack_password, :openstack_auth_url)
        end

        def instance_addresses(addresses)
          info = []
          if addresses[addresses.keys[0]] && addresses[addresses.keys[0]].size > 0
            ips = addresses[addresses.keys[0]]
            ips.each do |ip|
              version = 'IPv6' if ip['version'] == 6
              version = 'IPv4' if ip['version'] == 4
              info << "#{addresses.keys[0]}:#{version}: #{ip['addr']}"
            end
          end
          info.join(' ')
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
knife-openstack-1.3.2 lib/chef/knife/openstack_helpers.rb
knife-openstack-1.3.2.rc1 lib/chef/knife/openstack_helpers.rb
knife-openstack-1.3.2.pre.1 lib/chef/knife/openstack_helpers.rb