Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get and put only certain fields from node #203

Closed
RejoOommen opened this issue May 18, 2020 · 8 comments
Closed

Get and put only certain fields from node #203

RejoOommen opened this issue May 18, 2020 · 8 comments

Comments

@RejoOommen
Copy link

Currently the get node(Nodes.Get) / put node(Nodes.Put) call gets and puts the complete node struct in json format from and to the chef server.

I have noticed that the get node brings in a lot of data, around 4000+ lines for my environment for me to update just one field. Was looking at an efficient way of doing it by getting only specific data.

Example Use Case:
Is there a something where I could get only certain field like name and RunList only and update only the RunList field and put it back to the chef server

I looked up, but wasnt able to find something to do this, if already present. Would appreciate help on this.

@MarkGibbons
Copy link
Member

@rejo-oommen

There's nothing in go-chef/chef that allows for retrieving partial information from a node.
https://docs.chef.io/api_chef_server/#get-38 shows the doc for the underlying Chef Server API get call. The GET named node endpoint doesn't take any parameters or any json body. There's nothing documented that would allow retrieval of specific database fields. Being able to get node information without the automatic data would likely cut the size down to something reasonable. This api client isn't the place to initiate that change though. The Chef Server API would need to allow a request like that.

I looked through the er-chef API code. I'm pretty sure no option exists there to get the node data without the automatic attributes.

Sorry that's not more help,
Mark

@RejoOommen
Copy link
Author

Thank You for the response @MarkGibbons . I don't see the option in the chef server api too.
Is there a possibility in the PUT call to ignore the automatic attributes received from GET and update only the rest?

@MarkGibbons
Copy link
Member

You can set:
node1.AutomaticAttributes = map[string]interface{}{}
Where node1 is a chef Node struct.

The json generated and sent with the PUT request to the api ignores the empty AutomaticAttributes field. The Chef Server however sets the automatic attributes for the node to nil in this case. So, you can do that if you don't mind wiping out the values. The next chef-client run will repopulate the values.

@RejoOommen
Copy link
Author

Ok. I would need to evaluate if I can afford making it nil. Was basically looking at skipping that attribute in PUT. Anyways thanks for clarifying.

@MarkGibbons
Copy link
Member

good luck.

@MarkGibbons
Copy link
Member

Hi @RejoOommen
Did you have more questions?

@RejoOommen
Copy link
Author

RejoOommen commented May 19, 2020

@MarkGibbons Yes, wanted to check if I could do something similar to the example given below(using knife ) which I believe will avoid the node PUT call thereby not touching the other parameters for my current use case.

Add a role to a node runlist
knife node run_list add xyz.com "role[maintain_23]"

Remove a role from a node runlist
knife node run_list remove xyz.com "role[maintain_15]"

@MarkGibbons
Copy link
Member

knife node add and remove do a get and put under the covers.
For instance see /opt/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.8.23/lib/chef/node.rb and the save method.

When you make a change to the run_list knife first loads the node then does a node.save which is in essence a put. If you want to use the API.

get the node and populate a node strucuture
update the node structure
put the node.

Set the automatic attributes to nil first if you want to eliminate some of the data transfer back. I don't see any other options in the server api. That's what knife does too.

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

No branches or pull requests

2 participants