Git Product home page Git Product logo

collins-go-cli's Introduction

Collins CLI

Command line interface for interacting with https://tumblr.github.io/collins/


Install

Checkout the github releases page.

Config file

In order to talk to collins you will need to create a ~/.collins.yml file with the following fields.

host: http://10.0.0.5:9000
username: blake
password: test

NOTE: if you do not have the password saved in ~/.collins.yml, the client will prompt for a password at runtime. But, this will error and fail, if the collins command is being piped from one collins command to next.

Documentation

All docs can be found in markdown under collins/docs/.

Development

You can easily build this by cloning the repo and running go build -mod=vendor ./cmd/collins. Additionally the most recent tags will have binaries uploaded for most common and some uncommon platforms that you can pull down via curl/wget.

This repos supports building with bazel as well as the default go build command. If you would like to build with bazel which I use for releases now you can look at github.com/bazelbuild/bazel-gazelle/cmd/gazelle which is used to generate the build files. However it's not 100% feature complete and running it in this repo without knowing a little about bazel will likely cause some breakage. If you would like to build the world you can run the following which will pull in some git keys that are created with the setup.sh script and then build the binary.

To get a similar feature set as I have used gox in the past for you can pass the --platforms flag to bazel build. That flag can take anything that is output by bazel query 'kind(platform, @io_bazel_rules_go//go/toolchain:all)' See the following page for more info https://github.com/bazelbuild/rules_go/blob/master/go/core.rst#cross-compilation.

$ bazel build //cmd/collins:collins

Setting up collins itself for testing and populating it is beyond the scope of this readme. If you would like to do that but don't know how to get started send me a message.

collins-go-cli's People

Contributors

michaeljs1990 avatar nshalman avatar vj396 avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

nshalman

collins-go-cli's Issues

Add negative matching on State/Status

$ collins query -p DEVEL | collins query -S "~Maintenance"
400 Bad Request returned from collins: Invalid asset status specified. Valid values are Incomplete, New, Unallocated, Provisioning, Provisioned, Allocated, Cancelled, Decommissioned or Maintenance.

I think we can support this via raw CQL but I will need to look into it more.

Switch float to uint64

$ collins query --limit 100 -x disk_storage_human
panic: runtime error: index out of range [-9223372036854775808]

goroutine 1 [running]:
cgit.xrt0x.com/xrt0x/collins-go-cli/collins/commands.BytesToHumanSize(0x0, 0xc000240f66, 0x9)
	/Users/michaelschuett/gocode/src/cgit.xrt0x.com/xrt0x/collins-go-cli/collins/commands/util.go:59 +0x211
cgit.xrt0x.com/xrt0x/collins-go-cli/collins/commands.fieldToAssetStruct.func16(0x7ffeefbff9ed, 0x14763c7)
	/Users/michaelschuett/gocode/src/cgit.xrt0x.com/xrt0x/collins-go-cli/collins/commands/format.go:146 +0xd8
cgit.xrt0x.com/xrt0x/collins-go-cli/collins/commands.emptyOrValue(...)
	/Users/michaelschuett/gocode/src/cgit.xrt0x.com/xrt0x/collins-go-cli/collins/commands/format.go:31
cgit.xrt0x.com/xrt0x/collins-go-cli/collins/commands.fieldToAssetStruct(0x7ffeefbff9ed, 0x12, 0x2b, 0xc0002403a2, 0x7, 0x0, 0x0, 0x0, 0x0, 0xc0002403b3, ...)
	/Users/michaelschuett/gocode/src/cgit.xrt0x.com/xrt0x/collins-go-cli/collins/commands/format.go:140 +0x13cb
cgit.xrt0x.com/xrt0x/collins-go-cli/collins/commands.renderTable(0x147168c, 0x1, 0xc000018600, 0xc00022a7e0, 0x8, 0xe, 0xc0005b0000, 0x1f, 0x21)
	/Users/michaelschuett/gocode/src/cgit.xrt0x.com/xrt0x/collins-go-cli/collins/commands/format.go:172 +0x18b
cgit.xrt0x.com/xrt0x/collins-go-cli/collins/commands.formatAssets(0x1471f88, 0x5, 0x147168c, 0x1, 0x0, 0xc0004dcae0, 0x26, 0x0, 0xc00022a7e0, 0x8, ...)
	/Users/michaelschuett/gocode/src/cgit.xrt0x.com/xrt0x/collins-go-cli/collins/commands/format.go:17 +0x1dc
cgit.xrt0x.com/xrt0x/collins-go-cli/collins/commands.queryRunCommand(0xc000001b00, 0xc000095800, 0xc000001b00)
	/Users/michaelschuett/gocode/src/cgit.xrt0x.com/xrt0x/collins-go-cli/collins/commands/query.go:475 +0xb8f
cgit.xrt0x.com/xrt0x/collins-go-cli/vendor/github.com/urfave/cli.HandleAction(0x13eb0e0, 0x148ea88, 0xc000001b00, 0x0, 0xc000012e40)
	/Users/michaelschuett/gocode/src/cgit.xrt0x.com/xrt0x/collins-go-cli/vendor/github.com/urfave/cli/app.go:521 +0xc8
cgit.xrt0x.com/xrt0x/collins-go-cli/vendor/github.com/urfave/cli.Command.Run(0x1471f47, 0x5, 0x0, 0x0, 0xc00005ae50, 0x1, 0x1, 0x147ab94, 0x1c, 0x0, ...)
	/Users/michaelschuett/gocode/src/cgit.xrt0x.com/xrt0x/collins-go-cli/vendor/github.com/urfave/cli/command.go:167 +0x476
cgit.xrt0x.com/xrt0x/collins-go-cli/vendor/github.com/urfave/cli.(*App).Run(0xc0000ce1c0, 0xc000012240, 0x6, 0x6, 0x0, 0x0)
	/Users/michaelschuett/gocode/src/cgit.xrt0x.com/xrt0x/collins-go-cli/vendor/github.com/urfave/cli/app.go:274 +0x6c2
main.main()
	/Users/michaelschuett/gocode/src/cgit.xrt0x.com/xrt0x/collins-go-cli/cmd/collins/main.go:55 +0x2781

Better man page support

I am creating man pages for each sub command but currently since you would have to manually install them they are of little to no use. We could embed the man pages in the binary on build and then install them on the users system. Not sure how good of an idea this is though...

Fix the ability to `go get` this

$ go get github.com/michaeljs1990/collins-go-cli
package cgit.xrt0x.com/xrt0x/collins-go-cli/cmds: unrecognized import path "cgit.xrt0x.com/xrt0x/collins-go-cli/cmds" (https fetch: Get https://cgit.xrt0x.com/xrt0x/collins-go-cli/cmds?go-get=1: x509: certificate signed by unknown authority)

This should fail but the x509 error seems wrong as I have a valid cert. Will need to look into it more.

ruby symbol support

Ruby accepts both symbols and strings for the collins.yml file. We should add support for this just so it's easy to move from the ruby cli to the golang one.

Look into formatting issue

It looks like when setting the -c flag I am outputting a ton of whitespace still for fields that aren't rendered.

Support streaming output for large queries

For some queries you don't really care about the output looking pretty you just want to get some information. We should add in a flag that lets you turn on streaming for the table output format.

Hardware info flag user readable

It would be nice to have the flags for hardware info, to spit results out in human readable format.

right now, when we run a query asking for hw info, like collins find <some param> -x disk_storage_total, the column for disk_storage_total is in bytes, it would be nice to have that in human readable format like, X-KB or X-Gb/GB.

along with that, it would be nice to know the what type of drive it is, say, a micron-ssd, samsung etc.
with a flag/attr call like disk_storage_type?

Output formatting quirk

Not sure how this bug got introduced but it's pretty annoying. For whatever reason the first hostname is getting indented more than the rest. Dumping any debug information before this happens fixes the issue... :/

$ ./test query -p MESOS-PROD01 --limit 10
U0555      hostname    computeagentnode        Allocated       MESOS-PROD01    agent   
U0556 hostname    computeagentnode        Allocated       MESOS-PROD01    agent   

Power subcommand off formatting not adding new line

$ collins query -n node | collins power -p off
U005873 performing off ... SUCCESSU005866 performing off ... SUCCESSU005869 performing off ... SUCCESSU005871 performing off ... SUCCESSU005865 performing off ... SUCCESSU005870 performing off ... SUCCESSU005864 performing off ... SUCCESSU005867 performing off ... SUCCESS%                                                                                                                                                                                                           

Add debug mode env

Add debug mode environment variable so that you can have collins output things like the current CQL being sent to collins with the collins query command. Might be useful for outputting other things like the http endpoints being hit as well.

Add better hardware output support

We should support outputting these assets by default for when the user may want to query on something like base_product.

https://github.com/michaeljs1990/go-collins/blob/master/collins/asset.go#L115

diff --git a/collins/commands/format.go b/collins/commands/format.go
index 1445ee7..e00a06a 100644
--- a/collins/commands/format.go
+++ b/collins/commands/format.go
@@ -48,6 +48,8 @@ func fieldToAssetStruct(field string, asset collins.Asset) string {
                return asset.Classification.Tag
        case "ipmi_address":
                return asset.IPMI.Address
+       case "base_product":
+               return asset.Hardware.Base.Product
        case "ip_address":
                return emptyOrValue(len(asset.Addresses), func() string {
                        ips := []string{}

Example patch that I added for quickly getting this today.

Saved Query Support

Often times when I am operating on a bunch of different pools or types of machine I end up with a directory full of different dumps of assets. It would be useful to support something like --save save-name and --load save-name for writing and reading those assets again. Additionally this lets you easily watch physical assets as they go through different states.

Similar functionality could be added by letting you pipe to collins query however this ends up getting back into having tons of asset dump files in a folder.

Add GPU Support

This will require a little work since the go-collins library will need to be updated for this. However currently you can't output information about GPUs.

Allow comma delimited list for modify `-d` flag

To make the delete attribute function like all of the other query flags now we should allow users to specify multiple values to delete with -d values,i,hate instead of having to do -d values -d i -d hate which is needed right now.

This will take a little refactoring since the modify command turned into a little bit of a mess when I was throwing it together.

Make power requests concurrently

BMCs suck we should make the default to making 5 power requests at a time so that in the case that you have a bunch of flakey BMCs you don't need to wait for a large amount of time to make it through a list of 40 assets.

Broken cat to collins query

This doesn't work as one would expect. I likely botched something about reading from stdin that needs to be fixed. You can reproduce by catting any file with multiple tags in it to the command.

Collins query != support

with the -a flag you are always doing an equality match. It is in some cases useful to be able to do not equal for getting hosts.

Not sure how I want to add this yet it could be key!:value however key! may be valid in collins in which case key!!:value would have to work properly as well.

Also we could use -na for not attribute (very clever). I am more a fan of !: support though and just making sure it handles the edge case above.

Fixup limit function

Made a dump mistake since range is a copy of the value not the value we want to modify.

diff --git a/src/query.go b/src/query.go
index 159f5b8..f5c220a 100644
--- a/src/query.go
+++ b/src/query.go
@@ -416,8 +416,8 @@ func queryRunCommand(c *cli.Context) error {
                size = c.Int("limit")
        }
 
-       for _, opt := range opts {
-               opt.PageOpts = collins.PageOpts{
+       for i, _ := range opts {
+               opts[i].PageOpts = collins.PageOpts{
                        Size: size,
                }
        }

Should add a unit test for this as well.

Possible custom column collisions

Just realized when adding another custom column "asset_type" that in some very rare cases we could be stopping some values from being returned that has been set on the asset themselves.

The only way I can think to sanely solve this is by requiring that all columns that we compute client side to have an ~ or @ before them as both of these can't be used in a collins key. This would change the client to look like collins query -n aaanode -x @asset_type I like this as unlike ~ you don't need to quote it. I'm not going to fix this atm but if someone else sees this as a valid issue I'll add it.

Add fuzzy match on State/Status

The way we currently search for state and status using opts.Status and opts.State. We should see if we can just use raw CQL to find out this information which would allow you to not have to type out the full name "Allocated" and could instead do Allo or whatever if you are feeling lazy.

go get broken

For whatever reason go get seems to be broken. It looks like it's not properly using my fork of go-collins.

$ go get -u cgit.xrt0x.com/xrt0x/collins-go-cli/cmd/collins

# cgit.xrt0x.com/xrt0x/collins-go-cli/collins/commands
../../gocode/src/cgit.xrt0x.com/xrt0x/collins-go-cli/collins/commands/ipam.go:202:31: client.IPAM.IPMIPools undefined (type *collins.IPAMService has no field or method IPMIPools, but does have IpmiPools)
../../gocode/src/cgit.xrt0x.com/xrt0x/collins-go-cli/collins/commands/profiles.go:33:50: undefined: collins.Profile
../../gocode/src/cgit.xrt0x.com/xrt0x/collins-go-cli/collins/commands/profiles.go:62:48: undefined: collins.Profile
../../gocode/src/cgit.xrt0x.com/xrt0x/collins-go-cli/collins/commands/profiles.go:131:37: client.Management.GetProvisioningProfiles undefined (type *collins.ManagementService has no field or method GetProvisioningProfiles)
../../gocode/src/cgit.xrt0x.com/xrt0x/collins-go-cli/collins/commands/query.go:452:20: opts[i].PageOpts.SortField undefined (type collins.PageOpts has no field or method SortField)

Fix bazel build

Broke bazel when I added some new files and forgot to include them in the library.

Profiles sub command

Make a function that allows you to return the profiles currently available in collins. Possibly some other information can be output around this number of those profiles in use or pools belonging to a given profile.

Generally being able to dump the current profiles though is helpful when determining what can be cleaned up.

CLI based IPMI query

we can query for the asset, based on the IP address, but sometimes we would also need to query for the IPMI IP, say something like collins find --ipmi_ip <ipmi ip>?

Power off command broken

This currently takes the wrong action and tries to do a softoff which doesn't work in most cases. Re evaluate collins-cli to make sure we are mapping strings to the proper power actions.

Build with proper version

Grab version output from git when building to ensure users know what they have installed locally.

Documentation

The documentation can be about 80% stolen from the collins-cli repo however it would be good to document the differences between the client as well as all the additional fields that the collins query command supports as this will grow over time.

Unable to go get

I followed the instructions in the README. I am unable to go get.

martin.velez@martin-velez-7510:~$ go version
go version go1.12.10 linux/amd64
martin.velez@martin-velez-7510:~$ go get -u cgit.xrt0x.com/xrt0x/collins-go-cli/cmd/collins
# cd .; git clone https://cgit.xrt0x.com/xrt0x/collins-go-cli /home/martin.velez/gocode/src/cgit.xrt0x.com/xrt0x/collins-go-cli
Cloning into '/home/martin.velez/gocode/src/cgit.xrt0x.com/xrt0x/collins-go-cli'...
fatal: early EOF
error: Unable to find 10e9d322f3c813fdb0122cef1aa3c2f869a82d7f under https://cgit.xrt0x.com/xrt0x/collins-go-cli
Cannot obtain needed blob 10e9d322f3c813fdb0122cef1aa3c2f869a82d7f
while processing commit 1691c4bcc5a2e8fb88f7f9ca54f9107706681ac4.
error: fetch failed.
package cgit.xrt0x.com/xrt0x/collins-go-cli/cmd/collins: exit status 128

Better asset metadata support

Currently we support some metadata values in the output such as tag, asset_type, base_product and so on. All of the metadata fields should be support such as Created and Updated as well so it's easier to pull out.

diff --git a/collins/commands/format.go b/collins/commands/format.go
index 3cbe34b..c4f8cda 100644
--- a/collins/commands/format.go
+++ b/collins/commands/format.go
@@ -44,6 +44,8 @@ func fieldToAssetStruct(field string, asset collins.Asset) string {
 		return asset.Metadata.State.Name
 	case "asset_type":
 		return asset.Metadata.Type
+	case "created", "created_on":
+		return asset.Metadata.Created
 	case "classification":
 		return asset.Classification.Tag
 	case "base_product":

Add negative matching for named flags

Right now you can do a negative match on attributes with key-:value however for flags such as -n devnode and -p DEV you can't currently. I'm not sure I like the above syntax since I am using for attributes. In practice no one is using - for keys but it is possible. I should likely find some character that is not valid CQL for matching on instead and let that be passed for the key such as %key:value or -n %devnode,something.

Need to verify that characters are illegal though.

Add addresses output support

Currently in the collins ruby cli you can do this magic.

user@gentoo ~/code/collins-cli $ collins query dev -x addresses -H
tag             hostname                        nodeclass       status          pool            primary_role    secondary_role  addresses                                                                                                                                            
M0000002        dev-a7e8c3277b.pit1.terame.com  devnode         Provisioned     DEVELOPMENT     DEVELOPMENT                     Collins::Address(address = 10.0.0.102, gateway = 10.0.0.1, netmask = 255.255.255.0, is_private = true)                                               

I'm not sure that I want to add the exact same thing however something should be added that lets you get the same or similar information about the asset.

Autofix YAML config for users

I was thinking about adding symbol support to the golang collins client for reading from user, pass, and host when they are in the form of :user, :pass, and :host however go doesn't offer a nice way to do this. It might be easier to just verify the YAML config for users doesn't container them and if they do ask the user if they would like us to write out a file in the format we expect.

converting :user to user for instance will still work with collins-cli and collins-shell.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.