当前位置: 首页>>代码示例>>Golang>>正文


Golang client.NewManager函数代码示例

本文整理汇总了Golang中github.com/shipyard/shipyard/client.NewManager函数的典型用法代码示例。如果您正苦于以下问题:Golang NewManager函数的具体用法?Golang NewManager怎么用?Golang NewManager使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewManager函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: stopAction

func stopAction(c *cli.Context) {
	cfg, err := loadConfig()
	if err != nil {
		logger.Fatal(err)
	}
	m := client.NewManager(cfg)
	containers, err := m.Containers()
	if err != nil {
		logger.Fatalf("error getting container info: %s", err)
	}
	ids := c.Args()
	if len(ids) == 0 {
		logger.Fatalf("you must specify at least one id")
	}
	for _, cnt := range containers {
		// this can probably be more efficient
		for _, i := range ids {
			if strings.HasPrefix(cnt.ID, i) {
				if err := m.Stop(cnt); err != nil {
					logger.Fatalf("error stopping container: %s\n", err)
				}
				fmt.Printf("stopped %s\n", cnt.ID[:12])
			}
		}
	}
}
开发者ID:vyctorbh,项目名称:kurumin,代码行数:26,代码来源:stop.go

示例2: infoAction

func infoAction(c *cli.Context) {
	cfg, err := loadConfig(c)
	if err != nil {
		logger.Fatal(err)
	}
	m := client.NewManager(cfg)
	info, err := m.Info()
	if err != nil {
		logger.Fatalf("error getting cluster info: %s", err)
	}
	cpuPercentage := 0.0
	memPercentage := 0.0
	if info.ReservedCpus > 0.0 && info.Cpus > 0.0 {
		cpuPercentage = (info.ReservedCpus / info.Cpus) * 100
	}
	if info.ReservedMemory > 0.0 && info.Memory > 0.0 {
		memPercentage = (info.ReservedMemory / info.Memory) * 100
	}

	w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
	fmt.Fprintf(w, "Controller Version: %s\n", info.Version)
	fmt.Fprintf(w, "Cpus: %.2f\n", info.Cpus)
	fmt.Fprintf(w, "Memory: %.2f MB\n", info.Memory)
	fmt.Fprintf(w, "Containers: %d\n", info.ContainerCount)
	fmt.Fprintf(w, "Images: %d\n", info.ImageCount)
	fmt.Fprintf(w, "Engines: %d\n", info.EngineCount)
	fmt.Fprintf(w, "Reserved Cpus: %.2f%% (%.2f)\n", cpuPercentage, info.ReservedCpus)
	fmt.Fprintf(w, "Reserved Memory: %.2f%% (%.2f MB)\n", memPercentage, info.ReservedMemory)
	w.Flush()
}
开发者ID:bradbann,项目名称:shipyard,代码行数:30,代码来源:info.go

示例3: loginAction

func loginAction(c *cli.Context) {
	reader := bufio.NewReader(os.Stdin)
	fmt.Printf("URL: ")
	ur, err := reader.ReadString('\n')
	if err != nil {
		logger.Fatal(err)
	}
	fmt.Printf("Username: ")
	u, err := reader.ReadString('\n')
	if err != nil {
		logger.Fatal(err)
	}
	fmt.Printf("Password: ")
	p := gopass.GetPasswd()
	sUrl := strings.TrimSpace(string(ur[:]))
	username := strings.TrimSpace(string(u[:]))
	pass := strings.TrimSpace(string(p[:]))

	cfg := &client.ShipyardConfig{
		Url:      sUrl,
		Username: username,
	}
	m := client.NewManager(cfg)
	token, err := m.Login(username, pass)
	if err != nil {
		logger.Fatal(err)
	}
	cfg.Token = token.Token
	if err := saveConfig(cfg); err != nil {
		logger.Fatal(err)
	}
}
开发者ID:atassumer,项目名称:shipyard,代码行数:32,代码来源:login.go

示例4: containersAction

func containersAction(c *cli.Context) {
	cfg, err := loadConfig()
	if err != nil {
		logger.Fatal(err)
	}
	m := client.NewManager(cfg)
	containers, err := m.Containers()
	if err != nil {
		logger.Fatalf("error getting containers: %s", err)
	}
	if len(containers) == 0 {
		return
	}
	w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
	fmt.Fprintln(w, "ID\tName\tHost\tState\tPorts")
	for _, c := range containers {
		portDefs := []string{}
		for _, port := range c.Ports {
			p := fmt.Sprintf("%s/%d:%d", port.Proto, port.Port, port.ContainerPort)
			portDefs = append(portDefs, p)
		}
		ports := strings.Join(portDefs, ", ")
		state := "unknown"
		switch c.State.Running {
		case true:
			state = "running"
		case false:
			state = "stopped"
		}
		fmt.Fprintf(w, fmt.Sprintf("%s\t%s\t%s\t%v\t%s\n", c.ID[:12], c.Image.Name, c.Engine.ID, state, ports))
	}
	w.Flush()
}
开发者ID:atassumer,项目名称:shipyard,代码行数:33,代码来源:containers.go

示例5: init

func (m *Manager) init() error {
	var engines []*citadel.Engine
	if m.config.ShipyardUrl != "" {
		cfg := &client.ShipyardConfig{
			Url:        m.config.ShipyardUrl,
			ServiceKey: m.config.ShipyardServiceKey,
		}
		mgr := client.NewManager(cfg)
		eng, err := mgr.Engines()
		if err != nil {
			return err
		}
		for _, e := range eng {
			engines = append(engines, e.Engine)
		}
	} else {
		engines = m.engines
	}
	for _, e := range engines {
		if err := e.Connect(nil); err != nil {
			return err
		}
		logger.Infof("loaded engine: %s", e.ID)
	}
	c, err := cluster.New(scheduler.NewResourceManager(), engines...)
	if err != nil {
		return err
	}
	m.cluster = c
	// register handler
	if err := m.cluster.Events(&EventHandler{Manager: m}); err != nil {
		return err
	}
	return nil
}
开发者ID:deckapp,项目名称:interlock,代码行数:35,代码来源:manager.go

示例6: eventsAction

func eventsAction(c *cli.Context) {
	cfg, err := loadConfig()
	if err != nil {
		logger.Fatal(err)
	}
	m := client.NewManager(cfg)
	events, err := m.Events()
	if err != nil {
		logger.Fatalf("error getting events: %s", err)
	}
	if len(events) == 0 {
		return
	}
	w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
	fmt.Fprintln(w, "Time\tMessage\tEngine\tType\tTags")
	for _, e := range events {
		tags := strings.Join(e.Tags, ",")
		message := e.Message
		engine := ""
		if e.Container != nil {
			cntId := e.Container.ID[:12]
			message = fmt.Sprintf("container:%s %s", cntId, e.Message)
		}
		if e.Engine != nil {
			engine = e.Engine.ID
		}
		fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", e.Time.Format(time.RubyDate), message, engine, e.Type, tags)
	}
	w.Flush()
}
开发者ID:atassumer,项目名称:shipyard,代码行数:30,代码来源:events.go

示例7: runAction

func runAction(c *cli.Context) {
	cfg, err := loadConfig()
	if err != nil {
		logger.Fatal(err)
	}
	m := client.NewManager(cfg)
	if c.String("name") == "" {
		logger.Fatal("you must specify an image name")
	}
	env := parseEnvironmentVariables(c.StringSlice("env"))
	ports := parsePorts(c.StringSlice("port"))
	image := &citadel.Image{
		Name:        c.String("name"),
		Cpus:        c.Float64("cpus"),
		Memory:      c.Float64("memory"),
		Hostname:    c.String("hostname"),
		Domainname:  c.String("domain"),
		Labels:      c.StringSlice("label"),
		Args:        c.StringSlice("arg"),
		Environment: env,
		BindPorts:   ports,
		Type:        c.String("type"),
	}
	containers, err := m.Run(image, c.Int("count"), c.Bool("pull"))
	if err != nil {
		logger.Fatalf("error running container: %s\n", err)
	}
	for _, c := range containers {
		fmt.Printf("started %s on %s\n", c.ID[:12], c.Engine.ID)
	}
}
开发者ID:atassumer,项目名称:shipyard,代码行数:31,代码来源:run.go

示例8: logsAction

func logsAction(c *cli.Context) {
	cfg, err := loadConfig()
	if err != nil {
		logger.Fatal(err)
	}

	m := client.NewManager(cfg)
	ids := c.Args()
	if len(ids) == 0 {
		logger.Fatal("you must specify an id")
	}
	id := ids[0]

	container, err := m.Container(id)
	stdout := c.Bool("stdout")
	stderr := c.Bool("stderr")

	// if output not specified, use both
	if stdout == false && stderr == false {
		stdout = true
		stderr = true
	}

	data, err := m.Logs(container, stdout, stderr)
	if err != nil {
		logger.Fatalf("error reading logs: %s", err)
	}

	buf := new(bytes.Buffer)
	buf.ReadFrom(data)

	io.Copy(os.Stdout, buf)
}
开发者ID:vyctorbh,项目名称:kurumin,代码行数:33,代码来源:logs.go

示例9: webhookKeyCreateAction

func webhookKeyCreateAction(c *cli.Context) {
	cfg, err := loadConfig()
	if err != nil {
		logger.Fatal(err)
	}
	m := client.NewManager(cfg)
	key, err := m.NewWebhookKey(c.String("image"))
	if err != nil {
		logger.Fatalf("error generating webhook key: %s\n", err)
	}
	fmt.Printf("created key: %s\n", key.Key)
}
开发者ID:vyctorbh,项目名称:kurumin,代码行数:12,代码来源:webhookkeys.go

示例10: serviceKeyCreateAction

func serviceKeyCreateAction(c *cli.Context) {
	cfg, err := loadConfig()
	if err != nil {
		logger.Fatal(err)
	}
	m := client.NewManager(cfg)
	key, err := m.NewServiceKey(c.String("description"))
	if err != nil {
		logger.Fatalf("error generating service key: %s\n", err)
	}
	fmt.Printf("created key: %s\n", key.Key)
}
开发者ID:atassumer,项目名称:shipyard,代码行数:12,代码来源:servicekeys.go

示例11: addExtensionAction

func addExtensionAction(c *cli.Context) {
	cfg, err := loadConfig(c)
	if err != nil {
		logger.Fatal(err)
	}
	m := client.NewManager(cfg)
	extUrl := c.String("url")
	if extUrl == "" {
		logger.Fatalf("you must specify an extension config url")
	}
	env := parseEnvironmentVariables(c.StringSlice("env"))
	args := c.StringSlice("arg")
	resp, err := http.Get(extUrl)
	if err != nil {
		logger.Fatalf("unable to get extension config: %s", err)
	}
	var ext *shipyard.Extension
	if err := json.NewDecoder(resp.Body).Decode(&ext); err != nil {
		logger.Fatalf("error parsing extension config: %s", err, err)
	}
	fmt.Printf("configuring %s (%s for more info)\n", ext.Name, ext.Url)
	// check for configuration
	for _, pe := range ext.Config.PromptEnvironment {
		fmt.Printf("enter value for container environment variable %s: ", pe)
		b := bufio.NewReader(os.Stdin)
		r, _, err := b.ReadLine()
		if err != nil {
			logger.Fatalf("unable to parse input: %s", err)
		}
		env[pe] = string(r)
	}
	for _, pa := range ext.Config.PromptArgs {
		fmt.Printf("enter value for container argument %s: ", pa)
		b := bufio.NewReader(os.Stdin)
		r, _, err := b.ReadLine()
		if err != nil {
			logger.Fatalf("unable to parse input: %s", err)
		}
		arg := string(r)
		if pa != "" {
			arg = fmt.Sprintf("%s=%s", pa, r)
		}
		args = append(args, arg)
	}
	ext.Config.Environment = env
	ext.Config.Args = args
	if err := m.AddExtension(ext); err != nil {
		logger.Fatalf("error adding extension: %s", err)
	}
	fmt.Printf("added extension name=%s version=%s\n", ext.Name, ext.Version)
}
开发者ID:bradbann,项目名称:shipyard,代码行数:51,代码来源:extensions.go

示例12: webhookKeyRemoveAction

func webhookKeyRemoveAction(c *cli.Context) {
	cfg, err := loadConfig()
	if err != nil {
		logger.Fatal(err)
	}
	m := client.NewManager(cfg)
	removeKeys := c.Args()
	for _, key := range removeKeys {
		if err := m.RemoveWebhookKey(key); err != nil {
			logger.Fatalf("error removing webhook key: %s", err)
		}
		fmt.Printf("removed %s\n", key)
	}
}
开发者ID:vyctorbh,项目名称:kurumin,代码行数:14,代码来源:webhookkeys.go

示例13: runAction

func runAction(c *cli.Context) {
	cfg, err := loadConfig(c)
	if err != nil {
		logger.Fatal(err)
	}
	m := client.NewManager(cfg)
	if c.String("name") == "" {
		logger.Fatal("you must specify an image name")
	}
	vols := c.StringSlice("vol")
	env := parseEnvironmentVariables(c.StringSlice("env"))
	ports := parsePorts(c.StringSlice("port"))
	links := parseContainerLinks(c.StringSlice("link"))
	policy, maxRetries, err := parseRestartPolicy(c.String("restart"))
	if err != nil {
		logger.Fatalf("error parsing restart policy: %s", err)
	}
	rp := citadel.RestartPolicy{
		Name:              policy,
		MaximumRetryCount: maxRetries,
	}
	image := &citadel.Image{
		Name:          c.String("name"),
		ContainerName: c.String("container-name"),
		Cpus:          c.Float64("cpus"),
		Cpuset:        c.String("cpuset"),
		Memory:        c.Float64("memory"),
		Hostname:      c.String("hostname"),
		Domainname:    c.String("domain"),
		NetworkMode:   c.String("network"),
		Labels:        c.StringSlice("label"),
		Args:          c.StringSlice("arg"),
		Environment:   env,
		Links:         links,
		Publish:       c.Bool("publish"),
		Volumes:       vols,
		BindPorts:     ports,
		RestartPolicy: rp,
		Type:          c.String("type"),
	}
	containers, err := m.Run(image, c.Int("count"), c.Bool("pull"))
	if err != nil {
		logger.Fatalf("error running container: %s\n", err)
	}
	for _, c := range containers {
		fmt.Printf("started %s on %s\n", c.ID[:12], c.Engine.ID)
	}
}
开发者ID:bradbann,项目名称:shipyard,代码行数:48,代码来源:run.go

示例14: removeExtensionAction

func removeExtensionAction(c *cli.Context) {
	cfg, err := loadConfig(c)
	if err != nil {
		logger.Fatal(err)
	}
	m := client.NewManager(cfg)
	extIds := c.Args()
	if len(extIds) == 0 {
		return
	}
	for _, id := range extIds {
		if err := m.RemoveExtension(id); err != nil {
			logger.Fatalf("error removing extension: %s", err)
		}
	}
}
开发者ID:bradbann,项目名称:shipyard,代码行数:16,代码来源:extensions.go

示例15: engineInspectAction

func engineInspectAction(c *cli.Context) {
	cfg, err := loadConfig(c)
	if err != nil {
		logger.Fatal(err)
	}
	m := client.NewManager(cfg)
	if len(c.Args()) == 0 {
		logger.Fatal("you must specify an id")
	}
	id := c.Args()[0]
	eng, err := m.GetEngine(id)
	if err != nil {
		logger.Fatalf("error inspecting engine: %s", err)
	}
	b, err := json.MarshalIndent(eng, "", "    ")
	fmt.Println(string(b))
}
开发者ID:bradbann,项目名称:shipyard,代码行数:17,代码来源:engine.go


注:本文中的github.com/shipyard/shipyard/client.NewManager函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。