Skip to content

Commit

Permalink
Initial development
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Jul 28, 2016
1 parent d31b799 commit cc95326
Show file tree
Hide file tree
Showing 38 changed files with 3,885 additions and 22 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
./bin
./build
./.dapper
./dist
./.trash-cache
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/.dapper
/bin
/build
/dist
*.swp
/.trash-cache
8 changes: 5 additions & 3 deletions Dockerfile.dapper
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
FROM golang:1.6
FROM golang:1.6.2
RUN apt-get update && \
apt-get install -y xz-utils zip rsync
RUN go get github.com/rancher/trash
RUN go get github.com/golang/lint/golint
RUN curl -sL https://get.docker.com/builds/Linux/x86_64/docker-1.9.1 > /usr/bin/docker && \
chmod +x /usr/bin/docker
ENV PATH /go/bin:$PATH
ENV DAPPER_SOURCE /go/src/github.com/rancher/cli
ENV DAPPER_OUTPUT bin
ENV DAPPER_OUTPUT bin build/bin dist
ENV DAPPER_DOCKER_SOCKET true
ENV DAPPER_ENV TAG REPO
ENV DAPPER_ENV TAG REPO GOOS CROSS
ENV GO15VENDOREXPERIMENT 1
ENV TRASH_CACHE ${DAPPER_SOURCE}/.trash-cache
WORKDIR ${DAPPER_SOURCE}
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
cli
========
Rancher CLI
===========

A microservice that does micro things.
It takes arguments and outputs text. Trust me, this is going to be great!

Coming Summer of '16

## Building

Expand All @@ -10,7 +12,7 @@ A microservice that does micro things.

## Running

`./bin/cli`
`./bin/rancher`

## License
Copyright (c) 2014-2016 [Rancher Labs, Inc.](http://rancher.com)
Expand Down
121 changes: 121 additions & 0 deletions cmd/catalog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package cmd

import (
"fmt"
"strings"

"github.com/rancher/go-rancher/catalog"
"github.com/urfave/cli"
)

func CatalogCommand() cli.Command {
return cli.Command{
Name: "catalog",
Usage: "Operations with catalogs",
Action: catalogLs,
Flags: []cli.Flag{},
}
}

type CatalogData struct {
ID string
Template catalog.Template
}

func catalogLs(ctx *cli.Context) error {
config, err := lookupConfig(ctx)
if err != nil {
return err
}

c, err := GetClient(ctx)
if err != nil {
return err
}

proj, err := GetEnvironment(config.Environment, c)
if err != nil {
return err
}

cc, err := GetCatalogClient(ctx)
if err != nil {
return err
}

envData := NewEnvData(*proj)
envFilter := ""
switch envData.Orchestration {
case "Kubernetes":
envFilter = "kubernetes"
case "Swarm":
envFilter = "swarm"
case "Mesos":
envFilter = "mesos"
}

collection, err := cc.Template.List(nil)
if err != nil {
return err
}

writer := NewTableWriter([][]string{
{"NAME", "Template.Name"},
{"CATEGORY", "Template.Category"},
{"ID", "ID"},
}, ctx)
defer writer.Close()

for _, item := range collection.Data {
if item.TemplateBase != envFilter {
continue
}
if item.Category == "System" {
continue
}
writer.Write(CatalogData{
ID: templateID(item),
Template: item,
})
}

return writer.Err()
}

func templateID(template catalog.Template) string {
parts := strings.SplitN(template.Path, "/", 2)
if len(parts) != 2 {
return template.Name
}

first := parts[0]
second := parts[1]
version := template.DefaultVersion

parts = strings.SplitN(parts[1], "*", 2)
if len(parts) == 2 {
second = parts[1]
}

if version == "" {
return fmt.Sprintf("%s/%s", first, second)
}
return fmt.Sprintf("%s/%s:%s", first, second, version)
}

func GetCatalogClient(ctx *cli.Context) (*catalog.RancherClient, error) {
config, err := lookupConfig(ctx)
if err != nil {
return nil, err
}

idx := strings.LastIndex(config.URL, "/v1")
if idx == -1 {
return nil, fmt.Errorf("Invalid URL %s, must contain /v1", config.URL)
}

url := config.URL[:idx] + "/v1-catalog/schemas"
return catalog.NewRancherClient(&catalog.ClientOpts{
Url: url,
})
}
Loading

0 comments on commit cc95326

Please sign in to comment.