diff --git a/cmd/export.go b/cmd/export.go index dc06d794f..7f70858b4 100644 --- a/cmd/export.go +++ b/cmd/export.go @@ -2,85 +2,160 @@ package cmd import ( "archive/tar" - "fmt" + "bytes" "io" + "io/ioutil" "os" + "path/filepath" + "github.com/Sirupsen/logrus" + "github.com/rancher/go-rancher/v2" "github.com/urfave/cli" ) func ExportCommand() cli.Command { return cli.Command{ - Name: "export", - Usage: "Export configuration yml for a stack as a tar archive", - Description: "\nExports the docker-compose.yml and rancher-compose.yml for the specified stack as a tar archive.\n\nExample:\n\t$ rancher export mystack > files.tar\n\t$ rancher export -o files.tar mystack\n", - ArgsUsage: "[STACKNAME STACKID...]", - Action: exportService, + Name: "export", + Usage: "Export configuration yml for a stack as a tar archive or to local files", + Description: ` +Exports the docker-compose.yml and rancher-compose.yml for the specified stack as a tar archive. + +Example: + $ rancher export mystack + $ rancher export -f files.tar mystack + # Export the entire environment, including system stacks + $ rancher export --system mystack +`, + ArgsUsage: "[STACKNAME STACKID...]", + Action: exportService, Flags: []cli.Flag{ cli.StringFlag{ - Name: "output,o", - Usage: "Write to a file, instead of STDOUT", + Name: "file,f", + Usage: "Write to a file, instead of local files, use - to write to STDOUT", + }, + cli.BoolFlag{ + Name: "system", + Usage: "If exporting the entire environment, include system", }, }, } } func getOutput(ctx *cli.Context) (io.WriteCloser, error) { - output := ctx.String("output") + output := ctx.String("file") if output == "" { + return nil, nil + } else if output == "-" { return os.Stdout, nil } return os.Create(output) } -func exportService(ctx *cli.Context) error { - c, err := GetClient(ctx) +func getStackNames(ctx *cli.Context, c *client.RancherClient) ([]string, error) { + stacks, err := c.Stack.List(defaultListOpts(ctx)) if err != nil { - return err + return nil, err } - if len(ctx.Args()) != 1 { - return fmt.Errorf("One stack name or ID is required as an argument") + result := []string{} + for _, stack := range stacks.Data { + result = append(result, stack.Name) } - resource, err := Lookup(c, ctx.Args()[0], "environment") - if err != nil { - return err - } + return result, nil +} - env, err := c.Stack.ById(resource.Id) +func exportService(ctx *cli.Context) error { + var err error + c, err := GetClient(ctx) if err != nil { return err } - config, err := c.Stack.ActionExportconfig(env, nil) - if err != nil { - return err + names := ctx.Args() + if len(names) == 0 { + names, err = getStackNames(ctx, c) + if err != nil { + return err + } } + var archive *tar.Writer output, err := getOutput(ctx) if err != nil { return err } - defer output.Close() + if output != nil { + defer output.Close() + archive = tar.NewWriter(output) + defer archive.Close() + } - archive := tar.NewWriter(output) - defer archive.Close() + for _, name := range names { + resource, err := Lookup(c, name, "stack") + if err != nil { + return err + } - if err := addToTar(archive, "docker-compose.yml", config.DockerComposeConfig); err != nil { - return err + stack, err := c.Stack.ById(resource.Id) + if err != nil { + return err + } + + if _, ok := stack.Actions["exportconfig"]; !ok { + continue + } + + config, err := c.Stack.ActionExportconfig(stack, nil) + if err != nil { + return err + } + + if err := addToTar(archive, stack.Name, "docker-compose.yml", config.DockerComposeConfig); err != nil { + return err + } + if err := addToTar(archive, stack.Name, "rancher-compose.yml", config.RancherComposeConfig); err != nil { + return err + } + if len(config.Actions) > 0 { + if err := addToTar(archive, stack.Name, "answers", marshalAnswers(config.Actions)); err != nil { + return err + } + } } - return addToTar(archive, "rancher-compose.yml", config.RancherComposeConfig) + + return nil +} + +func marshalAnswers(answers map[string]string) string { + buf := &bytes.Buffer{} + for k, v := range answers { + buf.WriteString(k) + buf.WriteString("=") + buf.WriteString(v) + buf.WriteString("\n") + } + return buf.String() } -func addToTar(archive *tar.Writer, name string, stringContent string) error { +func addToTar(archive *tar.Writer, stackName, name string, stringContent string) error { if len(stringContent) == 0 { return nil } + f := filepath.Join(stackName, name) + if archive == nil { + err := os.MkdirAll(stackName, 0755) + if err != nil { + return err + } + logrus.Infof("Creating %s", f) + return ioutil.WriteFile(f, []byte(stringContent), 0600) + } + content := []byte(stringContent) err := archive.WriteHeader(&tar.Header{ - Name: name, + Name: f, Size: int64(len(content)), Mode: 0644, Uname: "root", diff --git a/cmd/host_create.go b/cmd/host_create.go index fb7be9921..469a2076b 100644 --- a/cmd/host_create.go +++ b/cmd/host_create.go @@ -92,7 +92,7 @@ func buildFlag(name string, field client.Field) cli.Flag { func buildFlags(prefix string, schema client.Schema, schemas *client.Schemas) []cli.Flag { flags := []cli.Flag{} for name, field := range schema.ResourceFields { - if !field.Create || name == "name" { + if !field.Create || name == "hostname" { continue } @@ -280,9 +280,9 @@ func hostCreateRun(ctx *cli.Context, c *client.RancherClient, machineSchema clie var lastErr error for _, name := range names { - args["name"] = name + args["hostname"] = name var machine client.Machine - if err := c.Create("machine", args, &machine); err != nil { + if err := c.Create("host", args, &machine); err != nil { lastErr = err logrus.Error(err) } else { diff --git a/cmd/ps.go b/cmd/ps.go index 8454d839e..20636e422 100644 --- a/cmd/ps.go +++ b/cmd/ps.go @@ -4,7 +4,6 @@ import ( "fmt" "strings" - "github.com/mitchellh/mapstructure" "github.com/pkg/errors" "github.com/rancher/go-rancher/v2" "github.com/urfave/cli" @@ -19,6 +18,7 @@ func PsCommand() cli.Command { Action: servicePs, Flags: []cli.Flag{ listAllFlag(), + listSystemFlag(), cli.BoolFlag{ Name: "containers,c", Usage: "Display containers", @@ -37,7 +37,7 @@ func PsCommand() cli.Command { func GetStackMap(c *client.RancherClient) map[string]client.Stack { result := map[string]client.Stack{} - stacks, err := c.Stack.List(defaultListOpts(nil)) + stacks, err := c.Stack.List(baseListOpts()) if err != nil { return result } @@ -52,7 +52,7 @@ func GetStackMap(c *client.RancherClient) map[string]client.Stack { type PsData struct { Service client.Service Name string - LaunchConfig client.LaunchConfig + LaunchConfig interface{} Stack client.Stack CombinedState string ID string @@ -93,6 +93,7 @@ func servicePs(ctx *cli.Context) error { {"IMAGE", "LaunchConfig.ImageUuid"}, {"STATE", "CombinedState"}, {"SCALE", "{{len .Service.InstanceIds}}/{{.Service.Scale}}"}, + {"SYSTEM", "Service.System"}, {"ENDPOINTS", "{{endpoint .Service.PublicEndpoints}}"}, {"DETAIL", "Service.TransitioningMessage"}, }, ctx) @@ -120,22 +121,14 @@ func servicePs(ctx *cli.Context) error { CombinedState: combined, }) for _, sidekick := range item.SecondaryLaunchConfigs { - var sidekickLaunchConfig client.LaunchConfig - var sidekickSecondaryLaunchConfig client.SecondaryLaunchConfig - if err := mapstructure.Decode(sidekick, &sidekickLaunchConfig); err != nil { - return err - } - if err := mapstructure.Decode(sidekick, &sidekickSecondaryLaunchConfig); err != nil { - return err - } - sidekickLaunchConfig.ImageUuid = strings.TrimPrefix(sidekickLaunchConfig.ImageUuid, "docker:") + sidekick.ImageUuid = strings.TrimPrefix(sidekick.ImageUuid, "docker:") item.Type = "sidekick" writer.Write(PsData{ ID: item.Id, Service: item, Name: fmt.Sprintf("%s/%s/%s", stackMap[item.StackId].Name, item.Name, - sidekickSecondaryLaunchConfig.Name), - LaunchConfig: sidekickLaunchConfig, + sidekick.Name), + LaunchConfig: sidekick, Stack: stackMap[item.StackId], CombinedState: combined, }) diff --git a/cmd/run.go b/cmd/run.go index 483c276af..779211485 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -176,6 +176,18 @@ func RunCommand() cli.Command { Usage: "Number of containers to run", Value: 1, }, + cli.BoolFlag{ + Name: "schedule-global", + Usage: "Run 1 container per host", + }, + cli.StringSliceFlag{ + Name: "label,l", + Usage: "Add label in the form of key=value", + }, + cli.BoolFlag{ + Name: "pull", + Usage: "Always pull image on container start", + }, }, } } @@ -225,9 +237,8 @@ func serviceRun(ctx *cli.Context) error { Expose: ctx.StringSlice("expose"), Hostname: ctx.String("hostname"), ImageUuid: "docker:" + ctx.Args()[0], - //Labels: + Labels: map[string]interface{}{}, //LogConfig: - //Lxc: Memory: ctx.Int64("memory"), MemorySwap: ctx.Int64("memory-swap"), //NetworkIds: ctx.StringSlice("networkids"), @@ -260,6 +271,23 @@ func serviceRun(ctx *cli.Context) error { } } + for _, label := range ctx.StringSlice("label") { + parts := strings.SplitN(label, "=", 1) + value := "" + if len(parts) > 1 { + value = parts[1] + } + launchConfig.Labels[parts[0]] = value + } + + if ctx.Bool("schedule-global") { + launchConfig.Labels["io.rancher.scheduler.global"] = "true" + } + + if ctx.Bool("pull") { + launchConfig.Labels["io.rancher.container.pull_image"] = "always" + } + args := ctx.Args()[1:] if len(args) > 0 { diff --git a/cmd/stack.go b/cmd/stack.go index f6e2753dd..26f52f88e 100644 --- a/cmd/stack.go +++ b/cmd/stack.go @@ -14,6 +14,7 @@ import ( func StackCommand() cli.Command { stackLsFlags := []cli.Flag{ + listSystemFlag(), cli.BoolFlag{ Name: "quiet,q", Usage: "Only display IDs", @@ -54,6 +55,10 @@ func StackCommand() cli.Command { Name: "system", Usage: "Create a system stack", }, + cli.BoolFlag{ + Name: "empty,e", + Usage: "Create an empty stack", + }, cli.BoolFlag{ Name: "quiet,q", Usage: "Only display IDs", @@ -68,11 +73,11 @@ func StackCommand() cli.Command { Usage: "Rancher Compose file", Value: "rancher-compose.yml", }, - cli.StringFlag{ - Name: "answers,a", - Usage: "Answers files", - Value: "answers", - }, + //cli.StringFlag{ + // Name: "answers,a", + // Usage: "Answers files", + // Value: "answers", + //}, }, }, }, @@ -80,11 +85,11 @@ func StackCommand() cli.Command { } type StackData struct { - ID string - Catalog string - Stack client.Stack - State string - System bool + ID string + Catalog string + Stack client.Stack + State string + ServiceCount int } func stackLs(ctx *cli.Context) error { @@ -93,7 +98,7 @@ func stackLs(ctx *cli.Context) error { return err } - collection, err := c.Stack.List(defaultListOpts(nil)) + collection, err := c.Stack.List(defaultListOpts(ctx)) if err != nil { return err } @@ -103,30 +108,24 @@ func stackLs(ctx *cli.Context) error { {"NAME", "Stack.Name"}, {"STATE", "State"}, {"CATALOG", "Catalog"}, - {"SYSTEM", "System"}, + {"SERVICES", "ServiceCount"}, + {"SYSTEM", "Stack.System"}, {"DETAIL", "Stack.TransitioningMessage"}, }, ctx) defer writer.Close() for _, item := range collection.Data { - system := strings.HasPrefix(item.ExternalId, "system://") - if !system { - system = strings.HasPrefix(item.ExternalId, "system-catalog://") - } - if !system { - system = strings.HasPrefix(item.ExternalId, "kubernetes") - } combined := item.HealthState if item.State != "active" || combined == "" { combined = item.State } writer.Write(&StackData{ - ID: item.Id, - Stack: item, - State: combined, - System: system, - Catalog: item.ExternalId, + ID: item.Id, + Stack: item, + State: combined, + Catalog: item.ExternalId, + ServiceCount: len(item.ServiceIds), }) } @@ -138,7 +137,7 @@ func getFile(name string) (string, error) { return "", nil } bytes, err := ioutil.ReadFile(name) - if err == os.ErrNotExist { + if os.IsNotExist(err) { return "", nil } @@ -172,40 +171,56 @@ func parseAnswers(ctx *cli.Context) (map[string]interface{}, error) { func stackCreate(ctx *cli.Context) error { c, err := GetClient(ctx) - dockerCompose, err := getFile(ctx.String("docker-compose")) - if err != nil { - return err - } - if dockerCompose == "" { - return errors.New("docker-compose.yml files is required") + names := []string{RandomName()} + if len(ctx.Args()) > 0 { + names = ctx.Args() } - rancherCompose, err := getFile(ctx.String("rancher-compose")) + w, err := NewWaiter(ctx) if err != nil { return err } - answers, err := parseAnswers(ctx) - if err != nil { - return errors.Wrap(err, "reading answers") - } + var lastErr error + for _, name := range names { + stack := &client.Stack{ + Name: name, + System: ctx.Bool("system"), + StartOnCreate: ctx.Bool("start"), + } - name := RandomName() - if len(ctx.Args()) > 0 { - name = ctx.Args()[0] + if !ctx.Bool("empty") { + var err error + stack.DockerCompose, err = getFile(ctx.String("docker-compose")) + if err != nil { + return err + } + if stack.DockerCompose == "" { + return errors.New("docker-compose.yml files is required") + } + + stack.RancherCompose, err = getFile(ctx.String("rancher-compose")) + if err != nil { + return errors.Wrap(err, "reading "+ctx.String("rancher-compose")) + } + + //stack.Answers, err = parseAnswers(ctx) + //if err != nil { + //return errors.Wrap(err, "reading answers") + //} + } + + stack, err = c.Stack.Create(stack) + if err != nil { + lastErr = err + } + + w.Add(stack.Id) } - stack, err := c.Stack.Create(&client.Stack{ - Name: name, - DockerCompose: dockerCompose, - RancherCompose: rancherCompose, - Environment: answers, - System: ctx.Bool("system"), - StartOnCreate: ctx.Bool("startOnCreate"), - }) - if err != nil { - return err + if lastErr != nil { + return lastErr } - return WaitFor(ctx, stack.Id) + return w.Wait() } diff --git a/cmd/start.go b/cmd/start.go index 0bceb2754..56c4c3ff7 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -8,7 +8,7 @@ import ( ) var ( - startTypes = []string{"service", "container", "host"} + startTypes = []string{"service", "container", "host", "stack"} ) func StartCommand() cli.Command { @@ -27,7 +27,7 @@ func StartCommand() cli.Command { func startResources(ctx *cli.Context) error { return forEachResource(ctx, startTypes, func(c *client.RancherClient, resource *client.Resource) (string, error) { - action, err := pickAction(resource, "start", "activate") + action, err := pickAction(resource, "start", "activate", "activateservices") if err != nil { return "", err } diff --git a/cmd/stop.go b/cmd/stop.go index 65a2dc804..6c29f303d 100644 --- a/cmd/stop.go +++ b/cmd/stop.go @@ -8,7 +8,7 @@ import ( ) var ( - stopTypes = []string{"service", "container", "host"} + stopTypes = []string{"service", "container", "host", "stack"} ) func StopCommand() cli.Command { @@ -27,7 +27,7 @@ func StopCommand() cli.Command { func stopResources(ctx *cli.Context) error { return forEachResource(ctx, stopTypes, func(c *client.RancherClient, resource *client.Resource) (string, error) { - action, err := pickAction(resource, "stop", "deactivate") + action, err := pickAction(resource, "stop", "deactivate", "deactivateservices") if err != nil { return "", err } diff --git a/cmd/util_ls.go b/cmd/util_ls.go index 84c5e21c1..e1bcd4fa0 100644 --- a/cmd/util_ls.go +++ b/cmd/util_ls.go @@ -12,13 +12,24 @@ func listAllFlag() cli.BoolFlag { } } -func defaultListOpts(ctx *cli.Context) *client.ListOpts { - listOpts := &client.ListOpts{ +func listSystemFlag() cli.BoolFlag { + return cli.BoolFlag{ + Name: "system", + Usage: "Show system resources", + } +} + +func baseListOpts() *client.ListOpts { + return &client.ListOpts{ Filters: map[string]interface{}{ "limit": -2, "all": true, }, } +} + +func defaultListOpts(ctx *cli.Context) *client.ListOpts { + listOpts := baseListOpts() if ctx != nil && !ctx.Bool("all") { listOpts.Filters["removed_null"] = "1" listOpts.Filters["state_ne"] = []string{ @@ -28,5 +39,10 @@ func defaultListOpts(ctx *cli.Context) *client.ListOpts { } delete(listOpts.Filters, "all") } + if ctx != nil && ctx.Bool("system") { + delete(listOpts.Filters, "system") + } else { + listOpts.Filters["system"] = "false" + } return listOpts } diff --git a/trash.conf b/trash.conf index fcc02dd10..bad13929b 100644 --- a/trash.conf +++ b/trash.conf @@ -16,9 +16,9 @@ github.com/mitchellh/mapstructure ca63d7c062ee3c9f34db231e352b60012b4fd0c1 github.com/opencontainers/runc cc29e3dded8e27ba8f65738f40d251c885030a28 github.com/patrickmn/go-cache 1881a9bccb818787f68c52bfba648c6cf34c34fa github.com/pkg/errors 1d2e60385a13aaa66134984235061c2f9302520e -github.com/rancher/go-rancher f0378de1178a553cfb64666c0281486f593f0f05 +github.com/rancher/go-rancher a6ce74c723ea86532e25619cf2e72c23eb7914e9 github.com/rancher/rancher-catalog-service a3a8b500adceb82b3a0387b2c7b06a60e7eeee9a -github.com/rancher/rancher-compose cb5784e5d75067ae1ef997036d4bc3c8ee242dae +github.com/rancher/rancher-compose v0.11.0-rc3 github.com/rancher/rancher-docker-api-proxy 461b5e7022698283030495cf5693680699ce9c28 github.com/Sirupsen/logrus 26709e2714106fb8ad40b773b711ebce25b78914 github.com/spf13/pflag cb88ea77998c3f024757528e3305022ab50b43be diff --git a/vendor/github.com/rancher/go-rancher/catalog/client.go b/vendor/github.com/rancher/go-rancher/catalog/client.go index d585ef53c..b3cfd42fc 100644 --- a/vendor/github.com/rancher/go-rancher/catalog/client.go +++ b/vendor/github.com/rancher/go-rancher/catalog/client.go @@ -23,6 +23,9 @@ type RancherBaseClient interface { Delete(*Resource) error Reload(*Resource, interface{}) error Action(string, string, *Resource, interface{}, interface{}) error + GetOpts() *ClientOpts + GetSchemas() *Schemas + GetTypes() map[string]Schema doGet(string, *ListOpts, interface{}) error doList(string, *ListOpts, interface{}) error diff --git a/vendor/github.com/rancher/go-rancher/catalog/common.go b/vendor/github.com/rancher/go-rancher/catalog/common.go index fa8aa8e62..122d7d7ac 100644 --- a/vendor/github.com/rancher/go-rancher/catalog/common.go +++ b/vendor/github.com/rancher/go-rancher/catalog/common.go @@ -135,7 +135,9 @@ func setupRancherBaseClient(rancherClient *RancherBaseClientImpl, opts *ClientOp return err } - if u.Path == "/v1" || strings.HasPrefix(u.Path, "/v1/") { + if u.Path == "" || u.Path == "/" { + u.Path = "v2-beta" + } else if u.Path == "/v1" || strings.HasPrefix(u.Path, "/v1/") { u.Path = strings.Replace(u.Path, "/v1", "/v2-beta", 1) } opts.Url = u.String() @@ -358,7 +360,6 @@ func (rancherClient *RancherBaseClientImpl) doModify(method string, url string, rancherClient.setupRequest(req) req.Header.Set("Content-Type", "application/json") - req.Header.Set("Content-Length", string(len(bodyContent))) resp, err := client.Do(req) if err != nil { @@ -578,6 +579,18 @@ func (rancherClient *RancherBaseClientImpl) doAction(schemaType string, action s return json.Unmarshal(byteContent, respObject) } +func (rancherClient *RancherBaseClientImpl) GetOpts() *ClientOpts { + return rancherClient.Opts +} + +func (rancherClient *RancherBaseClientImpl) GetSchemas() *Schemas { + return rancherClient.Schemas +} + +func (rancherClient *RancherBaseClientImpl) GetTypes() map[string]Schema { + return rancherClient.Types +} + func init() { debug = os.Getenv("RANCHER_CLIENT_DEBUG") == "true" if debug { diff --git a/vendor/github.com/rancher/go-rancher/catalog/generated_template.go b/vendor/github.com/rancher/go-rancher/catalog/generated_template.go index fe1bf2fb2..3d7b87ca6 100644 --- a/vendor/github.com/rancher/go-rancher/catalog/generated_template.go +++ b/vendor/github.com/rancher/go-rancher/catalog/generated_template.go @@ -31,6 +31,8 @@ type Template struct { Maintainer string `json:"maintainer,omitempty" yaml:"maintainer,omitempty"` + MaximumRancherVersion string `json:"maximumRancherVersion,omitempty" yaml:"maximum_rancher_version,omitempty"` + MinimumRancherVersion string `json:"minimumRancherVersion,omitempty" yaml:"minimum_rancher_version,omitempty"` Name string `json:"name,omitempty" yaml:"name,omitempty"` @@ -41,6 +43,8 @@ type Template struct { TemplateVersionRancherVersion map[string]interface{} `json:"templateVersionRancherVersion,omitempty" yaml:"template_version_rancher_version,omitempty"` + TemplateVersionRancherVersionGte map[string]interface{} `json:"templateVersionRancherVersionGte,omitempty" yaml:"template_version_rancher_version_gte,omitempty"` + Type string `json:"type,omitempty" yaml:"type,omitempty"` UpgradeFrom string `json:"upgradeFrom,omitempty" yaml:"upgrade_from,omitempty"` diff --git a/vendor/github.com/rancher/go-rancher/catalog/generated_template_version.go b/vendor/github.com/rancher/go-rancher/catalog/generated_template_version.go index 55ef3d857..e40c45216 100644 --- a/vendor/github.com/rancher/go-rancher/catalog/generated_template_version.go +++ b/vendor/github.com/rancher/go-rancher/catalog/generated_template_version.go @@ -33,6 +33,8 @@ type TemplateVersion struct { Maintainer string `json:"maintainer,omitempty" yaml:"maintainer,omitempty"` + MaximumRancherVersion string `json:"maximumRancherVersion,omitempty" yaml:"maximum_rancher_version,omitempty"` + MinimumRancherVersion string `json:"minimumRancherVersion,omitempty" yaml:"minimum_rancher_version,omitempty"` Name string `json:"name,omitempty" yaml:"name,omitempty"` @@ -49,6 +51,8 @@ type TemplateVersion struct { TemplateVersionRancherVersion map[string]interface{} `json:"templateVersionRancherVersion,omitempty" yaml:"template_version_rancher_version,omitempty"` + TemplateVersionRancherVersionGte map[string]interface{} `json:"templateVersionRancherVersionGte,omitempty" yaml:"template_version_rancher_version_gte,omitempty"` + Type string `json:"type,omitempty" yaml:"type,omitempty"` UpgradeFrom string `json:"upgradeFrom,omitempty" yaml:"upgrade_from,omitempty"` diff --git a/vendor/github.com/rancher/go-rancher/client/common.go b/vendor/github.com/rancher/go-rancher/client/common.go index 62e363da2..e74145c5a 100644 --- a/vendor/github.com/rancher/go-rancher/client/common.go +++ b/vendor/github.com/rancher/go-rancher/client/common.go @@ -347,7 +347,6 @@ func (rancherClient *RancherBaseClientImpl) doModify(method string, url string, rancherClient.setupRequest(req) req.Header.Set("Content-Type", "application/json") - req.Header.Set("Content-Length", string(len(bodyContent))) resp, err := client.Do(req) if err != nil { diff --git a/vendor/github.com/rancher/go-rancher/v2/common.go b/vendor/github.com/rancher/go-rancher/v2/common.go index 7663cc67c..0061bf8a7 100644 --- a/vendor/github.com/rancher/go-rancher/v2/common.go +++ b/vendor/github.com/rancher/go-rancher/v2/common.go @@ -360,7 +360,6 @@ func (rancherClient *RancherBaseClientImpl) doModify(method string, url string, rancherClient.setupRequest(req) req.Header.Set("Content-Type", "application/json") - req.Header.Set("Content-Length", string(len(bodyContent))) resp, err := client.Do(req) if err != nil { diff --git a/vendor/github.com/rancher/go-rancher/v2/generated_azure_config.go b/vendor/github.com/rancher/go-rancher/v2/generated_azure_config.go index 4647a1d8f..14868d7e5 100644 --- a/vendor/github.com/rancher/go-rancher/v2/generated_azure_config.go +++ b/vendor/github.com/rancher/go-rancher/v2/generated_azure_config.go @@ -7,27 +7,47 @@ const ( type AzureConfig struct { Resource + AvailabilitySet string `json:"availabilitySet,omitempty" yaml:"availability_set,omitempty"` + + ClientId string `json:"clientId,omitempty" yaml:"client_id,omitempty"` + + ClientSecret string `json:"clientSecret,omitempty" yaml:"client_secret,omitempty"` + + CustomData string `json:"customData,omitempty" yaml:"custom_data,omitempty"` + DockerPort string `json:"dockerPort,omitempty" yaml:"docker_port,omitempty"` - DockerSwarmMasterPort string `json:"dockerSwarmMasterPort,omitempty" yaml:"docker_swarm_master_port,omitempty"` + Environment string `json:"environment,omitempty" yaml:"environment,omitempty"` Image string `json:"image,omitempty" yaml:"image,omitempty"` Location string `json:"location,omitempty" yaml:"location,omitempty"` - Password string `json:"password,omitempty" yaml:"password,omitempty"` + NoPublicIp bool `json:"noPublicIp,omitempty" yaml:"no_public_ip,omitempty"` + + OpenPort []string `json:"openPort,omitempty" yaml:"open_port,omitempty"` - PublishSettingsFile string `json:"publishSettingsFile,omitempty" yaml:"publish_settings_file,omitempty"` + PrivateIpAddress string `json:"privateIpAddress,omitempty" yaml:"private_ip_address,omitempty"` + + ResourceGroup string `json:"resourceGroup,omitempty" yaml:"resource_group,omitempty"` Size string `json:"size,omitempty" yaml:"size,omitempty"` - SshPort string `json:"sshPort,omitempty" yaml:"ssh_port,omitempty"` + SshUser string `json:"sshUser,omitempty" yaml:"ssh_user,omitempty"` + + StaticPublicIp bool `json:"staticPublicIp,omitempty" yaml:"static_public_ip,omitempty"` + + StorageType string `json:"storageType,omitempty" yaml:"storage_type,omitempty"` - SubscriptionCert string `json:"subscriptionCert,omitempty" yaml:"subscription_cert,omitempty"` + Subnet string `json:"subnet,omitempty" yaml:"subnet,omitempty"` + + SubnetPrefix string `json:"subnetPrefix,omitempty" yaml:"subnet_prefix,omitempty"` SubscriptionId string `json:"subscriptionId,omitempty" yaml:"subscription_id,omitempty"` - Username string `json:"username,omitempty" yaml:"username,omitempty"` + UsePrivateIp bool `json:"usePrivateIp,omitempty" yaml:"use_private_ip,omitempty"` + + Vnet string `json:"vnet,omitempty" yaml:"vnet,omitempty"` } type AzureConfigCollection struct { diff --git a/vendor/github.com/rancher/go-rancher/v2/generated_compose_service.go b/vendor/github.com/rancher/go-rancher/v2/generated_compose_service.go index 99d01d78d..ca7a297f4 100644 --- a/vendor/github.com/rancher/go-rancher/v2/generated_compose_service.go +++ b/vendor/github.com/rancher/go-rancher/v2/generated_compose_service.go @@ -9,10 +9,6 @@ type ComposeService struct { AccountId string `json:"accountId,omitempty" yaml:"account_id,omitempty"` - ConsumedByServiceIds []string `json:"consumedByServiceIds,omitempty" yaml:"consumed_by_service_ids,omitempty"` - - ConsumedServiceIds []string `json:"consumedServiceIds,omitempty" yaml:"consumed_service_ids,omitempty"` - Created string `json:"created,omitempty" yaml:"created,omitempty"` CurrentScale int64 `json:"currentScale,omitempty" yaml:"current_scale,omitempty"` @@ -33,6 +29,8 @@ type ComposeService struct { LaunchConfig *LaunchConfig `json:"launchConfig,omitempty" yaml:"launch_config,omitempty"` + LinkedServices map[string]interface{} `json:"linkedServices,omitempty" yaml:"linked_services,omitempty"` + Name string `json:"name,omitempty" yaml:"name,omitempty"` PublicEndpoints []PublicEndpoint `json:"publicEndpoints,omitempty" yaml:"public_endpoints,omitempty"` diff --git a/vendor/github.com/rancher/go-rancher/v2/generated_container.go b/vendor/github.com/rancher/go-rancher/v2/generated_container.go index 0549c8d9d..ba743120c 100644 --- a/vendor/github.com/rancher/go-rancher/v2/generated_container.go +++ b/vendor/github.com/rancher/go-rancher/v2/generated_container.go @@ -87,8 +87,12 @@ type Container struct { Memory int64 `json:"memory,omitempty" yaml:"memory,omitempty"` + MemoryReservation int64 `json:"memoryReservation,omitempty" yaml:"memory_reservation,omitempty"` + MemorySwap int64 `json:"memorySwap,omitempty" yaml:"memory_swap,omitempty"` + MilliCpuReservation int64 `json:"milliCpuReservation,omitempty" yaml:"milli_cpu_reservation,omitempty"` + Name string `json:"name,omitempty" yaml:"name,omitempty"` NativeContainer bool `json:"nativeContainer,omitempty" yaml:"native_container,omitempty"` diff --git a/vendor/github.com/rancher/go-rancher/v2/generated_digitalocean_config.go b/vendor/github.com/rancher/go-rancher/v2/generated_digitalocean_config.go index e39ef4ed4..64597575e 100644 --- a/vendor/github.com/rancher/go-rancher/v2/generated_digitalocean_config.go +++ b/vendor/github.com/rancher/go-rancher/v2/generated_digitalocean_config.go @@ -21,6 +21,8 @@ type DigitaloceanConfig struct { Size string `json:"size,omitempty" yaml:"size,omitempty"` + SshKeyFingerprint string `json:"sshKeyFingerprint,omitempty" yaml:"ssh_key_fingerprint,omitempty"` + SshPort string `json:"sshPort,omitempty" yaml:"ssh_port,omitempty"` SshUser string `json:"sshUser,omitempty" yaml:"ssh_user,omitempty"` diff --git a/vendor/github.com/rancher/go-rancher/v2/generated_dns_service.go b/vendor/github.com/rancher/go-rancher/v2/generated_dns_service.go index f385ccd4f..d554562aa 100644 --- a/vendor/github.com/rancher/go-rancher/v2/generated_dns_service.go +++ b/vendor/github.com/rancher/go-rancher/v2/generated_dns_service.go @@ -11,10 +11,6 @@ type DnsService struct { AssignServiceIpAddress bool `json:"assignServiceIpAddress,omitempty" yaml:"assign_service_ip_address,omitempty"` - ConsumedByServiceIds []string `json:"consumedByServiceIds,omitempty" yaml:"consumed_by_service_ids,omitempty"` - - ConsumedServiceIds []string `json:"consumedServiceIds,omitempty" yaml:"consumed_service_ids,omitempty"` - Created string `json:"created,omitempty" yaml:"created,omitempty"` Data map[string]interface{} `json:"data,omitempty" yaml:"data,omitempty"` @@ -33,6 +29,8 @@ type DnsService struct { LaunchConfig *LaunchConfig `json:"launchConfig,omitempty" yaml:"launch_config,omitempty"` + LinkedServices map[string]interface{} `json:"linkedServices,omitempty" yaml:"linked_services,omitempty"` + Metadata map[string]interface{} `json:"metadata,omitempty" yaml:"metadata,omitempty"` Name string `json:"name,omitempty" yaml:"name,omitempty"` diff --git a/vendor/github.com/rancher/go-rancher/v2/generated_external_service.go b/vendor/github.com/rancher/go-rancher/v2/generated_external_service.go index 088e02cde..cc9cf4f31 100644 --- a/vendor/github.com/rancher/go-rancher/v2/generated_external_service.go +++ b/vendor/github.com/rancher/go-rancher/v2/generated_external_service.go @@ -9,10 +9,6 @@ type ExternalService struct { AccountId string `json:"accountId,omitempty" yaml:"account_id,omitempty"` - ConsumedByServiceIds []string `json:"consumedByServiceIds,omitempty" yaml:"consumed_by_service_ids,omitempty"` - - ConsumedServiceIds []string `json:"consumedServiceIds,omitempty" yaml:"consumed_service_ids,omitempty"` - Created string `json:"created,omitempty" yaml:"created,omitempty"` Data map[string]interface{} `json:"data,omitempty" yaml:"data,omitempty"` @@ -37,6 +33,8 @@ type ExternalService struct { LaunchConfig *LaunchConfig `json:"launchConfig,omitempty" yaml:"launch_config,omitempty"` + LinkedServices map[string]interface{} `json:"linkedServices,omitempty" yaml:"linked_services,omitempty"` + Metadata map[string]interface{} `json:"metadata,omitempty" yaml:"metadata,omitempty"` Name string `json:"name,omitempty" yaml:"name,omitempty"` diff --git a/vendor/github.com/rancher/go-rancher/v2/generated_host.go b/vendor/github.com/rancher/go-rancher/v2/generated_host.go index bb9ebf156..5fd3625ab 100644 --- a/vendor/github.com/rancher/go-rancher/v2/generated_host.go +++ b/vendor/github.com/rancher/go-rancher/v2/generated_host.go @@ -65,6 +65,12 @@ type Host struct { Labels map[string]interface{} `json:"labels,omitempty" yaml:"labels,omitempty"` + LocalStorageMb int64 `json:"localStorageMb,omitempty" yaml:"local_storage_mb,omitempty"` + + Memory int64 `json:"memory,omitempty" yaml:"memory,omitempty"` + + MilliCpu int64 `json:"milliCpu,omitempty" yaml:"milli_cpu,omitempty"` + Name string `json:"name,omitempty" yaml:"name,omitempty"` PacketConfig *PacketConfig `json:"packetConfig,omitempty" yaml:"packet_config,omitempty"` diff --git a/vendor/github.com/rancher/go-rancher/v2/generated_kubernetes_service.go b/vendor/github.com/rancher/go-rancher/v2/generated_kubernetes_service.go index ea1f48fff..15fa37804 100644 --- a/vendor/github.com/rancher/go-rancher/v2/generated_kubernetes_service.go +++ b/vendor/github.com/rancher/go-rancher/v2/generated_kubernetes_service.go @@ -9,10 +9,6 @@ type KubernetesService struct { AccountId string `json:"accountId,omitempty" yaml:"account_id,omitempty"` - ConsumedByServiceIds []string `json:"consumedByServiceIds,omitempty" yaml:"consumed_by_service_ids,omitempty"` - - ConsumedServiceIds []string `json:"consumedServiceIds,omitempty" yaml:"consumed_service_ids,omitempty"` - Created string `json:"created,omitempty" yaml:"created,omitempty"` Data map[string]interface{} `json:"data,omitempty" yaml:"data,omitempty"` @@ -27,6 +23,8 @@ type KubernetesService struct { Kind string `json:"kind,omitempty" yaml:"kind,omitempty"` + LinkedServices map[string]interface{} `json:"linkedServices,omitempty" yaml:"linked_services,omitempty"` + Name string `json:"name,omitempty" yaml:"name,omitempty"` RemoveTime string `json:"removeTime,omitempty" yaml:"remove_time,omitempty"` diff --git a/vendor/github.com/rancher/go-rancher/v2/generated_launch_config.go b/vendor/github.com/rancher/go-rancher/v2/generated_launch_config.go index b03ba22a6..a7af9617b 100644 --- a/vendor/github.com/rancher/go-rancher/v2/generated_launch_config.go +++ b/vendor/github.com/rancher/go-rancher/v2/generated_launch_config.go @@ -93,8 +93,12 @@ type LaunchConfig struct { MemoryMb int64 `json:"memoryMb,omitempty" yaml:"memory_mb,omitempty"` + MemoryReservation int64 `json:"memoryReservation,omitempty" yaml:"memory_reservation,omitempty"` + MemorySwap int64 `json:"memorySwap,omitempty" yaml:"memory_swap,omitempty"` + MilliCpuReservation int64 `json:"milliCpuReservation,omitempty" yaml:"milli_cpu_reservation,omitempty"` + NativeContainer bool `json:"nativeContainer,omitempty" yaml:"native_container,omitempty"` NetworkContainerId string `json:"networkContainerId,omitempty" yaml:"network_container_id,omitempty"` diff --git a/vendor/github.com/rancher/go-rancher/v2/generated_load_balancer_service.go b/vendor/github.com/rancher/go-rancher/v2/generated_load_balancer_service.go index 8d3ab4578..b3ec22f40 100644 --- a/vendor/github.com/rancher/go-rancher/v2/generated_load_balancer_service.go +++ b/vendor/github.com/rancher/go-rancher/v2/generated_load_balancer_service.go @@ -13,10 +13,6 @@ type LoadBalancerService struct { CertificateIds []string `json:"certificateIds,omitempty" yaml:"certificate_ids,omitempty"` - ConsumedByServiceIds []string `json:"consumedByServiceIds,omitempty" yaml:"consumed_by_service_ids,omitempty"` - - ConsumedServiceIds []string `json:"consumedServiceIds,omitempty" yaml:"consumed_service_ids,omitempty"` - Created string `json:"created,omitempty" yaml:"created,omitempty"` CurrentScale int64 `json:"currentScale,omitempty" yaml:"current_scale,omitempty"` @@ -39,6 +35,8 @@ type LoadBalancerService struct { LaunchConfig *LaunchConfig `json:"launchConfig,omitempty" yaml:"launch_config,omitempty"` + LinkedServices map[string]interface{} `json:"linkedServices,omitempty" yaml:"linked_services,omitempty"` + LoadBalancerConfig *LoadBalancerConfig `json:"loadBalancerConfig,omitempty" yaml:"load_balancer_config,omitempty"` Metadata map[string]interface{} `json:"metadata,omitempty" yaml:"metadata,omitempty"` diff --git a/vendor/github.com/rancher/go-rancher/v2/generated_secondary_launch_config.go b/vendor/github.com/rancher/go-rancher/v2/generated_secondary_launch_config.go index 958e3eb23..257676b4a 100644 --- a/vendor/github.com/rancher/go-rancher/v2/generated_secondary_launch_config.go +++ b/vendor/github.com/rancher/go-rancher/v2/generated_secondary_launch_config.go @@ -93,8 +93,12 @@ type SecondaryLaunchConfig struct { MemoryMb int64 `json:"memoryMb,omitempty" yaml:"memory_mb,omitempty"` + MemoryReservation int64 `json:"memoryReservation,omitempty" yaml:"memory_reservation,omitempty"` + MemorySwap int64 `json:"memorySwap,omitempty" yaml:"memory_swap,omitempty"` + MilliCpuReservation int64 `json:"milliCpuReservation,omitempty" yaml:"milli_cpu_reservation,omitempty"` + Name string `json:"name,omitempty" yaml:"name,omitempty"` NativeContainer bool `json:"nativeContainer,omitempty" yaml:"native_container,omitempty"` diff --git a/vendor/github.com/rancher/go-rancher/v2/generated_service.go b/vendor/github.com/rancher/go-rancher/v2/generated_service.go index d575ed758..a4984b37a 100644 --- a/vendor/github.com/rancher/go-rancher/v2/generated_service.go +++ b/vendor/github.com/rancher/go-rancher/v2/generated_service.go @@ -11,10 +11,6 @@ type Service struct { AssignServiceIpAddress bool `json:"assignServiceIpAddress,omitempty" yaml:"assign_service_ip_address,omitempty"` - ConsumedByServiceIds []string `json:"consumedByServiceIds,omitempty" yaml:"consumed_by_service_ids,omitempty"` - - ConsumedServiceIds []string `json:"consumedServiceIds,omitempty" yaml:"consumed_service_ids,omitempty"` - CreateIndex int64 `json:"createIndex,omitempty" yaml:"create_index,omitempty"` Created string `json:"created,omitempty" yaml:"created,omitempty"` @@ -37,6 +33,8 @@ type Service struct { LaunchConfig *LaunchConfig `json:"launchConfig,omitempty" yaml:"launch_config,omitempty"` + LinkedServices map[string]interface{} `json:"linkedServices,omitempty" yaml:"linked_services,omitempty"` + Metadata map[string]interface{} `json:"metadata,omitempty" yaml:"metadata,omitempty"` Name string `json:"name,omitempty" yaml:"name,omitempty"` diff --git a/vendor/github.com/rancher/go-rancher/v2/generated_storage_pool.go b/vendor/github.com/rancher/go-rancher/v2/generated_storage_pool.go index d68575236..90c8153e2 100644 --- a/vendor/github.com/rancher/go-rancher/v2/generated_storage_pool.go +++ b/vendor/github.com/rancher/go-rancher/v2/generated_storage_pool.go @@ -21,6 +21,8 @@ type StoragePool struct { ExternalId string `json:"externalId,omitempty" yaml:"external_id,omitempty"` + HostIds []string `json:"hostIds,omitempty" yaml:"host_ids,omitempty"` + Kind string `json:"kind,omitempty" yaml:"kind,omitempty"` Name string `json:"name,omitempty" yaml:"name,omitempty"` diff --git a/vendor/github.com/rancher/go-rancher/v2/generated_virtual_machine.go b/vendor/github.com/rancher/go-rancher/v2/generated_virtual_machine.go index f22b93cde..0a6d855a0 100644 --- a/vendor/github.com/rancher/go-rancher/v2/generated_virtual_machine.go +++ b/vendor/github.com/rancher/go-rancher/v2/generated_virtual_machine.go @@ -71,8 +71,12 @@ type VirtualMachine struct { MemoryMb int64 `json:"memoryMb,omitempty" yaml:"memory_mb,omitempty"` + MemoryReservation int64 `json:"memoryReservation,omitempty" yaml:"memory_reservation,omitempty"` + MemorySwap int64 `json:"memorySwap,omitempty" yaml:"memory_swap,omitempty"` + MilliCpuReservation int64 `json:"milliCpuReservation,omitempty" yaml:"milli_cpu_reservation,omitempty"` + Name string `json:"name,omitempty" yaml:"name,omitempty"` NativeContainer bool `json:"nativeContainer,omitempty" yaml:"native_container,omitempty"` diff --git a/vendor/github.com/rancher/go-rancher/v2/generated_volume.go b/vendor/github.com/rancher/go-rancher/v2/generated_volume.go index 640e4f8b0..d1d67df8d 100644 --- a/vendor/github.com/rancher/go-rancher/v2/generated_volume.go +++ b/vendor/github.com/rancher/go-rancher/v2/generated_volume.go @@ -39,6 +39,8 @@ type Volume struct { Removed string `json:"removed,omitempty" yaml:"removed,omitempty"` + SizeMb int64 `json:"sizeMb,omitempty" yaml:"size_mb,omitempty"` + StackId string `json:"stackId,omitempty" yaml:"stack_id,omitempty"` State string `json:"state,omitempty" yaml:"state,omitempty"` diff --git a/vendor/github.com/rancher/rancher-compose/lookup/questions.go b/vendor/github.com/rancher/rancher-compose/lookup/questions.go index cb5d8f73f..c9841ee20 100644 --- a/vendor/github.com/rancher/rancher-compose/lookup/questions.go +++ b/vendor/github.com/rancher/rancher-compose/lookup/questions.go @@ -11,7 +11,6 @@ import ( "github.com/docker/libcompose/utils" "github.com/rancher/rancher-catalog-service/model" "github.com/rancher/rancher-compose/rancher" - "gopkg.in/yaml.v2" ) type questionWrapper struct { @@ -47,10 +46,11 @@ func (q *QuestionLookup) parse(file string) error { return err } - data := map[string]map[string]interface{}{} - if err := yaml.Unmarshal(contents, &data); err != nil { + config, err := config.CreateConfig(contents) + if err != nil { return err } + data := config.Services rawQuestions := data[".catalog"] if rawQuestions != nil { diff --git a/vendor/github.com/rancher/rancher-compose/rancher/context.go b/vendor/github.com/rancher/rancher-compose/rancher/context.go index ca9f94a96..081cb6ebf 100644 --- a/vendor/github.com/rancher/rancher-compose/rancher/context.go +++ b/vendor/github.com/rancher/rancher-compose/rancher/context.go @@ -9,8 +9,6 @@ import ( "regexp" "strings" - "gopkg.in/yaml.v2" - "github.com/Sirupsen/logrus" "github.com/docker/libcompose/config" "github.com/docker/libcompose/project" @@ -126,27 +124,21 @@ func (c *Context) readRancherConfig() error { func (c *Context) unmarshalBytes(composeBytes, bytes []byte) error { rawServiceMap := config.RawServiceMap{} if composeBytes != nil { - var config config.Config - if err := yaml.Unmarshal(composeBytes, &config); err != nil { + config, err := config.CreateConfig(composeBytes) + if err != nil { return err } - - if config.Version == "2" { - rawServiceMap = config.Services - } else { - if err := yaml.Unmarshal(composeBytes, &rawServiceMap); err != nil { - return err - } - } - + rawServiceMap = config.Services for key := range rawServiceMap { delete(rawServiceMap[key], "hostname") } } if bytes != nil && len(bytes) > 0 { - if err := yaml.Unmarshal(bytes, &rawServiceMap); err != nil { + config, err := config.CreateConfig(bytes) + if err != nil { return err } + rawServiceMap = config.Services } return c.fillInRancherConfig(rawServiceMap) } diff --git a/vendor/github.com/rancher/rancher-compose/rancher/service.go b/vendor/github.com/rancher/rancher-compose/rancher/service.go index f73ebef86..c4e967a1e 100644 --- a/vendor/github.com/rancher/rancher-compose/rancher/service.go +++ b/vendor/github.com/rancher/rancher-compose/rancher/service.go @@ -18,6 +18,7 @@ import ( "github.com/docker/libcompose/project/events" "github.com/docker/libcompose/project/options" "github.com/gorilla/websocket" + "github.com/rancher/go-rancher/hostaccess" "github.com/rancher/go-rancher/v2" rUtils "github.com/rancher/rancher-compose/utils" ) @@ -534,16 +535,16 @@ func (r *RancherService) Log(ctx context.Context, follow bool) error { return err } - _ = containers - /*for _, container := range containers { - conn, err := (*hostaccess.RancherWebsocketClient)(r.context.Client).GetHostAccess(container.Resource, "logs", nil) + for _, container := range containers { + websocketClient := (*hostaccess.RancherWebsocketClient)(r.context.Client) + conn, err := websocketClient.GetHostAccess(container.Resource, "logs", nil) if err != nil { logrus.Errorf("Failed to get logs for %s: %v", container.Name, err) continue } go r.pipeLogs(&container, conn) - }*/ + } return nil }