-
Notifications
You must be signed in to change notification settings - Fork 2k
Make libmachine consumable by outside world #1729
Make libmachine consumable by outside world #1729
Conversation
644edfe
to
2584280
Compare
@@ -12,22 +12,8 @@ func cmdActive(c *cli.Context) { | |||
log.Fatal("Error: Too many arguments given.") | |||
} | |||
|
|||
certInfo := getCertPathInfo(c) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pattern is / was all over the place, and it's super repetitive, so it's been replaced by a call to getStore
which is a helper function that performs this logic.
Huge +1 to this! Great work! I think this is a great start. 👍 for the deletes! This. Is. Awesome (to be said in a Spartan voice). :) |
8fc990d
to
7dbd979
Compare
So, the tests are hella broken, BUT! I finally have a working POC standalone usage of |
My general thinking is, now that something relatively working-ish is put together, we can iterate on the design of the API and talk about next steps. There's still a lot of work left to go, mostly converting existing drivers over to the new method, and discussing how to handle the change, but this script works out of the box now! package main
import (
"fmt"
"log"
"github.com/docker/machine/libmachine"
"github.com/docker/machine/libmachine/drivers/virtualbox"
)
func main() {
libmachine.SetDebug(true)
// returns the familiar store at $HOME/.docker/machine
store := libmachine.GetDefaultStore()
// over-ride this for now (don't want to muck with my default store)
store.Path = "/tmp/automatic"
hostName := "myfunhost"
// Set some options on the provider...
driver := virtualbox.NewDriver(hostName, "/tmp/automatic")
driver.CPU = 2
driver.Memory = 2048
h, err := store.NewHost(driver)
if err != nil {
log.Fatal(err)
}
h.HostOptions.EngineOptions.StorageDriver = "overlay"
if err := libmachine.Create(store, h); err != nil {
log.Fatal(err)
}
out, err := h.RunSSHCommand("df -h")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Results of your disk space query:\n%s\n", out)
fmt.Println("Powering down machine now...")
if err := h.Stop(); err != nil {
log.Fatal(err)
}
} |
My thinking around people wanting to create REST APIs and such with this is, you can unmarshal the |
Looks good! Could we get a list of remaining items so we could help knock those out? |
Definitely! I intend to squash down to a single commit as well soon (it will help with rebase hell down the line). Here's my list so far: Must haves
UPDATE: I have updated the drivers partially to the new
UPDATE: I've factored out a lot of the offending code into
Nice to haves
Side note: I've been thinking about how to integrate this with plugins and wondering, maybe we should just have one |
There seems to be a bug persisting EDIT: |
No one's said anything at : #1730 so I'm just going to go ahead and remove the useless coverage check for Travis here. |
a8d63f3
to
83d3f60
Compare
Still a long way to go but all the unit tests are passing again :) |
dac03dd
to
36de55f
Compare
80e97a4
to
79da42f
Compare
I feel confident about merging this very soon -- currently I am running through the integration tests to check up, but all new development work on this branch is completed, the unit tests are passing, and I'm really keen to move this upstream ASAP and get started PRing the plugin work. I do want to make a followup PR to add some documentation and more examples, though. Additionally, there seems to be at least one issue with cert placement when using the standalone program. |
The |
79da42f
to
4095f02
Compare
So I'm ready to merge this whenever comfortable, but first there are a few things I want to merge upstream and rebase to. |
It should be noted, though, that while this is a backwards-compatible change, it is not necessarily forwards-compatible (due to a config migration) -- so, it is a little dangerous to use older versions of Machine after using this on hosts you have created. |
4095f02
to
6a50dd1
Compare
probably out of scope for this PR, but I wonder if we should prompt before migration so users are duly warned... |
Or at least make a backup copy of their old config before attempting migration, etc.? I'm more concerned about users (not neccesarily intentionally) switching back and forth between old versions of Machine (currently it will FUBAR your config to do so if it has been migrated) than issues with the migration itself. |
c84605e
to
fe0ae54
Compare
- Clear out some cruft tightly coupling libmachine to filestore - Comment out drivers other than virtualbox for now - Change way too many things - Mostly, break out the code to be more modular. - Destroy all traces of "provider" in its current form. It will be brought back as something more sensible, instead of something which overlaps in function with both Host and Store. - Fix mis-managed config passthru - Remove a few instances of state stored in env vars - This should be explicitly communicated in Go-land, not through the shell. - Rename "store" module to "persist" - This is done mostly to avoid confusion about the fact that a concrete instance of a "Store" interface is oftentimes referred to as "store" in the code. - Rip out repetitive antipattern for getting store - This replaces the previous repetive idiom for getting the cert info, and consequently the store, with a much less repetitive idiom. - Also, some redundant methods in commands.go for accessing hosts have either been simplified or removed entirely. - First steps towards fixing up tests - Test progress continues - Replace unit tests with integration tests - MAKE ALL UNIT TESTS PASS YAY - Add helper test files - Don't write to disk in libmachine/host - Heh.. coverage check strikes again - Fix remove code - Move cert code around - Continued progress: simplify Driver - Fixups and make creation work with new model - Move drivers module inside of libmachine - Move ssh module inside of libmachine - Move state module to libmachine - Move utils module to libmachine - Move version module to libmachine - Move log module to libmachine - Modify some constructor methods around - Change Travis build dep structure - Boring gofmt fix - Add version module - Move NewHost to store - Update some boring cert path infos to make API easier to use - Fix up some issues around the new model - Clean up some cert path stuff - Don't use shady functions to get store path :D - Continue artifact work - Fix silly machines dir bug - Continue fixing silly path issues - Change up output of vbm a bit - Continue work to make example go - Change output a little more - Last changes needed to make create finish properly - Fix config.go to use libmachine - Cut down code duplication and make both methods work with libmachine - Add pluggable logging implementation - Return error when machine already in desired state - Update example to show log method - Fix file:// bug - Fix Swarm defaults - Remove unused TLS settings from Engine and Swarm options - Remove spurious error - Correct bug detecting if migration was performed - Fix compilation errors from tests - Fix most of remaining test issues - Fix final silly bug in tests - Remove extraneous debug code - Add -race to test command - Appease the gofmt - Appease the generate coverage - Making executive decision to remove Travis coverage check In the early days I thought this would be a good idea because it would encourage people to write tests in case they added a new module. Well, in fact it has just turned into a giant nuisance and made refactoring work like this even more difficult. - Move Get to Load - Move HostListItem code to CLI Signed-off-by: Nathan LeClaire <nathan.leclaire@gmail.com>
fe0ae54
to
b5927f1
Compare
I've added a |
I know of at least one issue using this lib independently but I will make a followup issue for it this PR LGTM |
Make libmachine consumable by outside world
@nathanleclaire Awesome 🎉 |
👍 |
👍 awesome! also, yay for merge! :D |
@nathanleclaire curios here -- does the merging of libmachine mean we'll be able to interface with machines from the Thanks! |
@briceburg Not exactly -- |
+1 on the branch name |
Alright, I'm hesitant to turn this in incomplete (which it is so far-- probably about 60-70% done), but better early than never, and I'd prefer to iterate on something crude and incomplete rather than toil away and learn that others have some fundamental disagreements on my approach.
Sorry for the size of the patch, but you'll notice (in the current state at least) there are about 2x as many deletions as additions, and a chunk of it is now-or-never cleanup work to make the API more sane.
I'll annotate the code a little to guide since the patch is so large.
Design Principles:
host
module. That's thepersist
module's job. To that end, it would be good to get anotherStore
implementation to prove viability outside ofFilestore
, and automatically test it. To that extent, ideallyStore
needs some more re-working so it can keep track of artifacts (secrets such as certs and mundane artifacts like ISOs) instead of having everybody write them to the filesystem willy-nilly.Provider
in its current form is completely gone as its role conflicted heavily withhost.Host
. Later, I want to bring backProvider
as a notion of something which "provides" host creation and management and provides the things needed to bootstrap control of them, such as API tokens.Something like the following code is my rough roadmap for where I'm working towards with the
libmachine
module. I'm not really sure how to best handle the awkwardDriverOptions
bit.interface{}
seems wrong, but we don't have strongly typedProvider
s to give usHost
s (like alluded to above).Thoughts:
host
module to something a bit less confusing, to avoid collision with the instantiatedHost
struct. To that extent, I really am wondering if we should just moveHost
to beMachine
, as it islibmachine
after all.store
is now in its own module, as are most of thelibmachine
-related functions. The corelibmachine
namespace will be reserved for very high-level functions meant for calling from the outside world, and/orcommands
.libmachine
depends on other things such asgit.luolix.top/docker/machine/log
, do those go inlibmachine
as well? How does that all work? Logging etc. since I'm sure consumers of the API won't want us logging to terminal all over the place implicitly. Guess we should pass in anio.Writer
as a "config" property of... something?libmachine
client struct that you should be instantiating before doing anything.cc @ehazlett @ibuildthecloud @hairyhenderson @SvenDowideit @tianon @bfirsh 🎵 MACHINE PARTY 🎉 🎈 🎊