# Help with vagrant-butcher and the Chef API

**URL:** <https://discourse.chef.io/t/help-with-vagrant-butcher-and-the-chef-api/3441>\
**Category:** Chef Infra (archive)\
**Created:** [December 26, 2012, 6:41pm UTC](https://discourse.chef.io/t/help-with-vagrant-butcher-and-the-chef-api/3441 "2012-12-26T18:41:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cassiano\_Leal](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/cassiano_leal/32/86_2.png) [@Cassiano\_Leal](https://discourse.chef.io/u/Cassiano_Leal)\
**Post date:** [December 26, 2012, 6:41pm UTC](https://discourse.chef.io/t/help-with-vagrant-butcher-and-the-chef-api/3441/1 "2012-12-26T18:41:39Z")

</div>

Ohai Chefs,

I’m struggling to get vagrant-butcher [0] to work in my current setup. I’m not sure what has changed since last time, but it used to work just fine. (And I know that this last sentence isn’t very helpful, but it’s what I’ve got 🙂

I’m using the methods Chef::Node.load and Chef::ApiClient.load, with a subsequent destroy on the object [1].

Digging into the Chef source code, I found out that I can call Chef::Node.build [2] and then destroy, and it works fine.

The same cannot be said about ApiClient, which doesn’t have a build method. For that, load should work, except it doesn’t. The problem seems to be that it’s trying to reference the client by a key ‘clientname’ [3], whereas I get a hash with a ‘name’ key instead [4].

Any clues as to what I’m doing wrong here, or if I should file bugs for Chef?

Also, if anyone had any success or failures in using the gem, I’d like to know as much as possible so that I can pinpoint where the issue might lie as well.

Thanks!

[0] [https://github.com/cassianoleal/vagrant-butcher](https://github.com/cassianoleal/vagrant-butcher)  
[1] [https://github.com/cassianoleal/vagrant-butcher/blob/master/lib/vagrant-butcher/cleanup.rb#L13-L14](https://github.com/cassianoleal/vagrant-butcher/blob/master/lib/vagrant-butcher/cleanup.rb#L13-L14)  
[2] [https://github.com/opscode/chef/blob/10.16.4/chef/lib/chef/node.rb#L595-L600](https://github.com/opscode/chef/blob/10.16.4/chef/lib/chef/node.rb#L595-L600)  
[3] [https://github.com/opscode/chef/blob/10.16.4/chef/lib/chef/api\_client.rb#L211](https://github.com/opscode/chef/blob/10.16.4/chef/lib/chef/api_client.rb#L211)  
[4] [https://gist.github.com/4381943](https://gist.github.com/4381943)

–  
Cassiano Leal

---

<div class="post-metadata">

**Author:** ![kallistec](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/kallistec/32/23_2.png) [@kallistec](https://discourse.chef.io/u/kallistec)\
**Post date:** [December 28, 2012, 7:23pm UTC](https://discourse.chef.io/t/help-with-vagrant-butcher-and-the-chef-api/3441/2 "2012-12-28T19:23:50Z")

</div>

On Wednesday, December 26, 2012 at 10:41 AM, Cassiano Leal wrote:

> Ohai Chefs,
> 
> I'm struggling to get vagrant-butcher [0] to work in my current setup. I'm not sure what has changed since last time, but it used to work just fine. (And I know that this last sentence isn't very helpful, but it's what I've got 🙂
> 
> I'm using the methods Chef::Node.load and Chef::ApiClient.load, with a subsequent destroy on the object [1].
> 
> Digging into the Chef source code, I found out that I can call Chef::Node.build [2] and then destroy, and it works fine.
> 
> The same cannot be said about ApiClient, which doesn't have a build method. For that, load should work, except it doesn't. The problem seems to be that it's trying to reference the client by a key 'clientname' [3], whereas I get a hash with a 'name' key instead [4].
> 
> Any clues as to what I'm doing wrong here, or if I should file bugs for Chef?
> 
> Also, if anyone had any success or failures in using the gem, I'd like to know as much as possible so that I can pinpoint where the issue might lie as well.
> 
> Thanks!
> 
> [0] [GitHub - c10l/vagrant-butcher: Delete Chef client and node when destroying Vagrant VM](https://github.com/cassianoleal/vagrant-butcher)  
> [1] [https://github.com/cassianoleal/vagrant-butcher/blob/master/lib/vagrant-butcher/cleanup.rb#L13-L14](https://github.com/cassianoleal/vagrant-butcher/blob/master/lib/vagrant-butcher/cleanup.rb#L13-L14)  
> [2] [chef/chef/lib/chef/node.rb at 10.16.4 · chef/chef · GitHub](https://github.com/opscode/chef/blob/10.16.4/chef/lib/chef/node.rb#L595-L600)  
> [3] [chef/chef/lib/chef/api\_client.rb at 10.16.4 · chef/chef · GitHub](https://github.com/opscode/chef/blob/10.16.4/chef/lib/chef/api_client.rb#L211)  
> [4] [https://gist.github.com/4381943](https://gist.github.com/4381943)
> 
> --  
> Cassiano Leal

Chef is relying on the json gem to "inflate" the response into an ApiClient object. Normally, the json gem looks at the "json\_class" key and if that exists, will lookup the matching class and then call class\_name.json\_create(data) to return an object of the matching class. The json gem supports changing the magic key name via (e.g.) JSON.create\_id = "not\_json\_class". If neither Node.load nor ApiClient.load are working correctly, then I'd try grepping the relevant source code for 'create\_id=', to see if that's being disabled somewhere (maybe by vagrant?).

If you can't re-enable the 'json\_class' stuff, then you can pass the hash responses you get into Node.json\_create() and ApiClient.json\_create() manually. Alternatively, you can just make a HTTP DELETE call to $base\_url/clients/$name (and similar for nodes).

As I mentioned in a previous thread, we'd like to eliminate our reliance on the 'json\_class' stuff, but it'll take a fair bit of work so it's not going to happen soon.

--  
Daniel DeLeo

---

<div class="post-metadata">

**Author:** ![Cassiano\_Leal](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/cassiano_leal/32/86_2.png) [@Cassiano\_Leal](https://discourse.chef.io/u/Cassiano_Leal)\
**Post date:** [January 1, 2013, 7:53pm UTC](https://discourse.chef.io/t/help-with-vagrant-butcher-and-the-chef-api/3441/3 "2013-01-01T19:53:34Z")

</div>

On Friday, December 28, 2012 at 17:23, Daniel DeLeo wrote:

> On Wednesday, December 26, 2012 at 10:41 AM, Cassiano Leal wrote:
> 
> > Ohai Chefs,
> > 
> > I'm struggling to get vagrant-butcher [0] to work in my current setup. I'm not sure what has changed since last time, but it used to work just fine. (And I know that this last sentence isn't very helpful, but it's what I've got 🙂
> > 
> > I'm using the methods Chef::Node.load and Chef::ApiClient.load, with a subsequent destroy on the object [1].
> > 
> > Digging into the Chef source code, I found out that I can call Chef::Node.build [2] and then destroy, and it works fine.
> > 
> > The same cannot be said about ApiClient, which doesn't have a build method. For that, load should work, except it doesn't. The problem seems to be that it's trying to reference the client by a key 'clientname' [3], whereas I get a hash with a 'name' key instead [4].
> > 
> > Any clues as to what I'm doing wrong here, or if I should file bugs for Chef?
> > 
> > Also, if anyone had any success or failures in using the gem, I'd like to know as much as possible so that I can pinpoint where the issue might lie as well.
> > 
> > Thanks!
> > 
> > [0] [GitHub - c10l/vagrant-butcher: Delete Chef client and node when destroying Vagrant VM](https://github.com/cassianoleal/vagrant-butcher)  
> > [1] [https://github.com/cassianoleal/vagrant-butcher/blob/master/lib/vagrant-butcher/cleanup.rb#L13-L14](https://github.com/cassianoleal/vagrant-butcher/blob/master/lib/vagrant-butcher/cleanup.rb#L13-L14)  
> > [2] [chef/chef/lib/chef/node.rb at 10.16.4 · chef/chef · GitHub](https://github.com/opscode/chef/blob/10.16.4/chef/lib/chef/node.rb#L595-L600)  
> > [3] [chef/chef/lib/chef/api\_client.rb at 10.16.4 · chef/chef · GitHub](https://github.com/opscode/chef/blob/10.16.4/chef/lib/chef/api_client.rb#L211)  
> > [4] [https://gist.github.com/4381943](https://gist.github.com/4381943)
> > 
> > --  
> > Cassiano Leal
> 
> Chef is relying on the json gem to "inflate" the response into an ApiClient object. Normally, the json gem looks at the "json\_class" key and if that exists, will lookup the matching class and then call class\_name.json\_create(data) to return an object of the matching class. The json gem supports changing the magic key name via (e.g.) JSON.create\_id = "not\_json\_class". If neither Node.load nor ApiClient.load are working correctly, then I'd try grepping the relevant source code for 'create\_id=', to see if that's being disabled somewhere (maybe by vagrant?).
> 
> If you can't re-enable the 'json\_class' stuff, then you can pass the hash responses you get into Node.json\_create() and ApiClient.json\_create() manually. Alternatively, you can just make a HTTP DELETE call to $base\_url/clients/$name (and similar for nodes).
> 
> As I mentioned in a previous thread, we'd like to eliminate our reliance on the 'json\_class' stuff, but it'll take a fair bit of work so it's not going to happen soon.
> 
> --  
> Daniel DeLeo

I've reverted to using the REST API for now (via Chef::REST). Thanks for the explanation and suggestions, I'll look more deeply into them later!

Cheers,

--  
Cassiano Leal
