Skip to content

Commit

Permalink
Merge pull request #17 from ibuildthecloud/random
Browse files Browse the repository at this point in the history
Random
  • Loading branch information
ibuildthecloud authored Sep 13, 2016
2 parents 0a41c17 + d351715 commit e3ea48b
Show file tree
Hide file tree
Showing 343 changed files with 22,213 additions and 43,224 deletions.
13 changes: 9 additions & 4 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
image: rancher/dind:v1.10.0-rancher1
script:
- wrapdocker
- make ci
---
pipeline:
build:
privileged: true
image: rancher/dapper:1.10.3
volumes:
- /var/run/docker.sock:/var/run/docker.sock
commands:
- dapper ci
14 changes: 7 additions & 7 deletions cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"fmt"
"github.com/rancher/go-rancher/v2"
"io"
"os"
"os/exec"
Expand All @@ -12,7 +13,6 @@ import (
"text/template"

"github.com/docker/docker/pkg/namesgenerator"
"github.com/rancher/go-rancher/client"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -129,12 +129,12 @@ func LookupEnvironment(c *client.RancherClient, name string) (*client.Project, e
return c.Project.ById(env.Id)
}

func GetOrCreateDefaultStack(c *client.RancherClient, name string) (*client.Environment, error) {
func GetOrCreateDefaultStack(c *client.RancherClient, name string) (*client.Stack, error) {
if name == "" {
name = "Default"
}

resp, err := c.Environment.List(&client.ListOpts{
resp, err := c.Stack.List(&client.ListOpts{
Filters: map[string]interface{}{
"name": name,
"removed_null": 1,
Expand All @@ -148,7 +148,7 @@ func GetOrCreateDefaultStack(c *client.RancherClient, name string) (*client.Envi
return &resp.Data[0], nil
}

return c.Environment.Create(&client.Environment{
return c.Stack.Create(&client.Stack{
Name: name,
})
}
Expand All @@ -175,12 +175,12 @@ func RandomName() string {

func getServiceByName(c *client.RancherClient, name string) (client.ResourceCollection, error) {
var result client.ResourceCollection
env, serviceName, err := ParseName(c, name)
stack, serviceName, err := ParseName(c, name)

services, err := c.Service.List(&client.ListOpts{
Filters: map[string]interface{}{
"environmentId": env.Id,
"name": serviceName,
"stackId": stack.Id,
"name": serviceName,
},
})
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (
"path"
"strings"

"github.com/rancher/go-rancher/v2"

"github.com/Sirupsen/logrus"
"github.com/rancher/go-rancher/client"
"github.com/urfave/cli"
)

Expand All @@ -24,7 +25,7 @@ type Config struct {
}

func baseURL(fullURL string) (string, error) {
idx := strings.LastIndex(fullURL, "/v1")
idx := strings.LastIndex(fullURL, "/v2-beta")
if idx == -1 {
u, err := url.Parse(fullURL)
if err != nil {
Expand Down Expand Up @@ -61,7 +62,7 @@ func (c Config) EnvironmentURL() (string, error) {
if err != nil {
return "", err
}
url = url + "/v1/projects/" + projectID + "/schemas"
url = url + "/v2-beta/projects/" + projectID + "/schemas"
return url, nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"strings"

"github.com/Sirupsen/logrus"
"github.com/rancher/go-rancher/client"
"github.com/rancher/go-rancher/v2"
"github.com/rancher/rancher-docker-api-proxy"
"github.com/urfave/cli"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strings"

"github.com/rancher/go-rancher/client"
"github.com/rancher/go-rancher/v2"
"github.com/urfave/cli"
)

Expand Down
84 changes: 54 additions & 30 deletions cmd/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/Sirupsen/logrus"
"github.com/rancher/cli/monitor"
"github.com/rancher/go-rancher/v2"
"github.com/urfave/cli"
)

Expand All @@ -17,10 +18,10 @@ func EventsCommand() cli.Command {
ArgsUsage: "None",
Action: events,
Flags: []cli.Flag{
//cli.StringFlag{
// Name: "format",
// Usage: "'json' or Custom format: {{.Id}} {{.Name}}",
//},
cli.StringFlag{
Name: "format",
Usage: "'json' or Custom format: {{.Id}} {{.Name}}",
},
cli.BoolFlag{
Name: "reconnect,r",
Usage: "Reconnect on error",
Expand All @@ -29,40 +30,63 @@ func EventsCommand() cli.Command {
}
}

func events(ctx *cli.Context) error {
c, err := GetClient(ctx)
if err != nil {
return err
func getClientForSubscribe(ctx *cli.Context) (*client.RancherClient, error) {
if ctx.Bool("all") {
return GetRawClient(ctx)
}
return GetClient(ctx)
}

m := monitor.New(c)
sub := m.Subscribe()
go func() {
if ctx.Bool("reconnect") {
for {
if err := m.Start(); err != nil {
logrus.Error(err)
}
func events(ctx *cli.Context) error {
reconnect := ctx.Bool("reconnect")

for {
c, err := getClientForSubscribe(ctx)
if err != nil {
if reconnect {
logrus.Error(err)
time.Sleep(time.Second)
continue
} else {
return err
}
} else {
logrus.Fatal(m.Start())
}
}()

for event := range sub.C {
resource, _ := event.Data["resource"].(map[string]interface{})
state, _ := resource["state"].(string)
name, _ := resource["name"].(string)
m := monitor.New(c)
sub := m.Subscribe()
go func() {
if ctx.Bool("reconnect") {
for {
if err := m.Start(); err != nil {
logrus.Error(err)
}
time.Sleep(time.Second)
}
} else {
logrus.Fatal(m.Start())
}
}()

format := ctx.String("format")
for event := range sub.C {
if format == "" {
resource, _ := event.Data["resource"].(map[string]interface{})
name, _ := resource["name"].(string)
state, _ := resource["state"].(string)

if name == "ping" {
continue
}

if len(state) > 0 {
message := resource["transitioningMessage"]
if message == nil {
message = ""
message, _ := resource["transitioningMessage"].(string)
fmt.Printf("%s %s %s [%s] %v\n", event.ResourceType, event.ResourceID, state, name, message)
} else {
writer := NewTableWriter(nil, ctx)
writer.Write(event)
if err := writer.Err(); err != nil {
logrus.Error(err)
}
}
fmt.Printf("%s %s %s [%s] %v\n", event.ResourceType, event.ResourceID, state, name, message)
}
}

return nil
}
2 changes: 1 addition & 1 deletion cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strconv"
"strings"

"github.com/rancher/go-rancher/client"
"github.com/rancher/go-rancher/v2"
"github.com/urfave/cli"
)

Expand Down
4 changes: 2 additions & 2 deletions cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ func exportService(ctx *cli.Context) error {
return err
}

env, err := c.Environment.ById(resource.Id)
env, err := c.Stack.ById(resource.Id)
if err != nil {
return err
}

config, err := c.Environment.ActionExportconfig(env, nil)
config, err := c.Stack.ActionExportconfig(env, nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"strings"

"github.com/rancher/go-rancher/client"
"github.com/rancher/go-rancher/v2"
)

func FormatEndpoint(data interface{}) string {
Expand Down
2 changes: 1 addition & 1 deletion cmd/host.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cmd

import (
"github.com/rancher/go-rancher/client"
"github.com/rancher/go-rancher/v2"
"github.com/urfave/cli"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/host_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"

"github.com/Sirupsen/logrus"
"github.com/rancher/go-rancher/client"
"github.com/rancher/go-rancher/v2"
"github.com/urfave/cli"
)

Expand Down
8 changes: 4 additions & 4 deletions cmd/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package cmd
import (
"strings"

"github.com/rancher/go-rancher/client"
"github.com/rancher/go-rancher/v2"
"github.com/urfave/cli"
)

var (
inspectTypes = []string{"service", "container", "host", "project", "environment"}
inspectTypes = []string{"service", "container", "host", "project", "stack"}
)

func InspectCommand() cli.Command {
Expand Down Expand Up @@ -44,14 +44,14 @@ func inspectResources(ctx *cli.Context) error {
mapResource := map[string]interface{}{}
err := c.ById(resource.Type, resource.Id, &mapResource)
if err != nil {
return "", err
return "-", err
}
if !ctx.Bool("links") {
delete(mapResource, "links")
delete(mapResource, "actions")
}
writer.Write(mapResource)
return "", nil
return "-", nil
})
return writer.Err()
}
Loading

0 comments on commit e3ea48b

Please sign in to comment.