Ejemplo n.º 1
0
	_ "net/http/pprof"
	"os"
	"os/signal"

	"github.com/Sirupsen/logrus"
	engineapi "github.com/docker/engine-api/client"
	"github.com/docker/swarmkit/agent"
	"github.com/docker/swarmkit/agent/exec/container"
	"github.com/docker/swarmkit/cli"
	"github.com/docker/swarmkit/log"
	"github.com/docker/swarmkit/version"
	"github.com/spf13/cobra"
	"golang.org/x/net/context"
)

var externalCAOpt cli.ExternalCAOpt

func main() {
	if err := mainCmd.Execute(); err != nil {
		log.L.Fatal(err)
	}
}

var (
	mainCmd = &cobra.Command{
		Use:          os.Args[0],
		Short:        "Run a swarm control process",
		SilenceUsage: true,
		PersistentPreRun: func(cmd *cobra.Command, _ []string) {
			logrus.SetOutput(os.Stderr)
			flag, err := cmd.Flags().GetString("log-level")
Ejemplo n.º 2
0
var (
	externalCAOpt cli.ExternalCAOpt

	updateCmd = &cobra.Command{
		Use:   "update <cluster name>",
		Short: "Update a cluster",
		RunE: func(cmd *cobra.Command, args []string) error {
			if len(args) == 0 {
				return errors.New("cluster name missing")
			}

			if len(args) > 1 {
				return errors.New("update command takes exactly 1 argument")
			}

			c, err := common.Dial(cmd)
			if err != nil {
				return err
			}

			cluster, err := getCluster(common.Context(cmd), c, args[0])
			if err != nil {
				return err
			}

			flags := cmd.Flags()
			spec := &cluster.Spec
			var rotation api.KeyRotation

			if flags.Changed("certexpiry") {
				cePeriod, err := flags.GetDuration("certexpiry")
				if err != nil {
					return err
				}
				ceProtoPeriod := ptypes.DurationProto(cePeriod)
				spec.CAConfig.NodeCertExpiry = ceProtoPeriod
			}
			if flags.Changed("external-ca") {
				spec.CAConfig.ExternalCAs = externalCAOpt.Value()
			}
			if flags.Changed("taskhistory") {
				taskHistory, err := flags.GetInt64("taskhistory")
				if err != nil {
					return err
				}
				spec.Orchestration.TaskHistoryRetentionLimit = taskHistory
			}
			if flags.Changed("heartbeatperiod") {
				hbPeriod, err := flags.GetDuration("heartbeatperiod")
				if err != nil {
					return err
				}
				spec.Dispatcher.HeartbeatPeriod = ptypes.DurationProto(hbPeriod)
			}
			if flags.Changed("rotate-join-token") {
				rotateJoinToken, err := flags.GetString("rotate-join-token")
				if err != nil {
					return err
				}
				rotateJoinToken = strings.ToLower(rotateJoinToken)

				switch rotateJoinToken {
				case "worker":
					rotation.WorkerJoinToken = true
				case "manager":
					rotation.ManagerJoinToken = true
				default:
					return errors.New("--rotate-join-token flag must be followed by 'worker' or 'manager'")
				}
			}
			if flags.Changed("autolock") {
				spec.EncryptionConfig.AutoLockManagers, err = flags.GetBool("autolock")
				if err != nil {
					return err
				}
			}
			rotateUnlockKey, err := flags.GetBool("rotate-unlock-key")
			if err != nil {
				return err
			}
			rotation.ManagerUnlockKey = rotateUnlockKey

			driver, err := common.ParseLogDriverFlags(flags)
			if err != nil {
				return err
			}
			spec.TaskDefaults.LogDriver = driver

			r, err := c.UpdateCluster(common.Context(cmd), &api.UpdateClusterRequest{
				ClusterID:      cluster.ID,
				ClusterVersion: &cluster.Meta.Version,
				Spec:           spec,
				Rotation:       rotation,
			})
			if err != nil {
				return err
			}
			fmt.Println(r.Cluster.ID)

			if rotation.ManagerUnlockKey {
				return displayUnlockKey(cmd)
			}
			return nil
		},
	}
)