Skip to content
This repository has been archived by the owner on Jul 6, 2018. It is now read-only.

search(:node) does not contain the ipaddress #65

Open
yazgoo opened this issue Sep 17, 2015 · 2 comments
Open

search(:node) does not contain the ipaddress #65

yazgoo opened this issue Sep 17, 2015 · 2 comments

Comments

@yazgoo
Copy link

yazgoo commented Sep 17, 2015

Here are two scripts.
One creates a machine:

require 'chef/provisioning/docker_driver'
machine "dummy" do
    tag "dummy"
    converge true
    machine_options({ docker_options: {
        base_image: { name: 'baseimage', repository: 'phusion/baseimage', tag: '0.9.17' },
        command: '/sbin/my_init'} })
end

The other searches for it:

require 'chef/provisioning/docker_driver'
search(:node, "tags:*dummy*").map do |node|
    p node.ipaddress
end

When I run these scripts with bundle and this Gemfile:

gem 'chef-provisioning-docker'

The second script works fine.

When I try and run against the master git HEAD version :

gem 'chef-provisioning-docker', :path => '../chef-provisioning-docker' 

I get the following error:

ERROR: Undefined method or attribute `ipaddress' on `node'
@yazgoo
Copy link
Author

yazgoo commented Sep 28, 2015

Here is a bypass which uses docker inspect to get the ipaddress if it is not set:

class Chef::Resource::Machine
    def running_on? kind
        kind == ENV['CHEF_DRIVER'].sub(/::.*$/, "").to_sym
    end
    def get_docker_ip_address name
        JSON.parse(`docker inspect #{name}`).first["NetworkSettings"]["IPAddress"]
    end
    alias :old_search :search
    def search what, query
        result = old_search what, query
        if what == :node and running_on? :docker
            result.map! do |node|
                node.default["ipaddress"] = get_docker_ip_address(node.name) if node["ipaddress"] == nil
                node
            end
        end
        return result
    end
end

@marc-
Copy link
Contributor

marc- commented Sep 28, 2015

Hm, there are no much changes between 0.7 and master.
I personally have ipaddress among node attributes when running CPD. Though, I use forked version of my own without changes introduced by 07753c4 .

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants