Adding subcommands to knife, how can ChefDK use them in a recipe?

82 Views Asked by At

Extending a knife plugin because a particular service has some predefined and optimized database servers with an API to spin them up, add users, etc. and I started wondering:

If I do add more subcommands to the knife such as 'database instance create' to create an instance of a particular pre-configured DB server appliance, how do I write provisioning recipes in ChefDK that will invoke those commands?

And while I'd like answers to that question, if it turns out you're more interested in warning me about damaging the portability of a recipe/cookbook if I do, also tell me an alternative way to take advantage of pre-built, optimized, special purpose appliances offered by a cloud provider that you would approve of. ("You're doing it wrong" is a useless answer unless it contains an explanation of / pointer to how to do it right.)

(Trying to work totally inside ChefDK using "chef provision" for the moment; want to get the simple stuff ironed out before I start expanding this.)

Expansion:

Clearly I didn't express the question well, probably an indication of my own ignorance on the topic. So let me expand on it a bit and see if that helps.

Working within ChefDK, expecting to use 'chef provision' (which passes to chef-provisioning, yes) to create a web app involving at minimum a web server instance, db server instance (other bits and pieces needed by specific apps, but they'll all use at least these components).

I modified a knife plugin to enable it to create instances of a db server offered by the cloud service vendor, rather than create and optimize one myself with this script. After doing so, it occurred to me I didn't see how I would be using it from the chefDK provision cookbook I was setting up for the app.

A "thank you" to @tensibai for asking for the recipe pseudo-code, because as I sit down to add it here, I realize I've no idea even what the pseudo-code would look like to create the instance. The knife plugin I modified can also create db's and users on the server, and that pseudo-code is clear, but instantiating the server itself isn't, so I'm clearly more completely ignorant on that score than I first thought (always both useful and humbling to realize you know even less than the little you thought you knew).

While the pseudo-code after instantiation is clear, the mechanism isn't, as the db server isn't directly visible from my chefdk system, so the only way the db, users, etc., can be created from it is via the vendor's API, which the knife plugin knows how to use. (Yes, another way would be to have a chef server in the same cloud directly manipulate the db for this, but for the moment, that server doesn't exist.) It would go along the lines of:

using a given set of attributes: create the named database assign the users listed for that database set the schema for the db load any required initialization data repeat if necessary -- if, for example, the particular app the attributes described accesses more than one db

Does that help? Or do the constraints I've set render it impossible?

0

There are 0 best solutions below