當前位置: 首頁>>代碼示例>>Golang>>正文


Golang project.Project類代碼示例

本文整理匯總了Golang中github.com/docker/libcompose/project.Project的典型用法代碼示例。如果您正苦於以下問題:Golang Project類的具體用法?Golang Project怎麽用?Golang Project使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Project類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: ProjectPort

func ProjectPort(p *project.Project, c *cli.Context) {
	if len(c.Args()) != 2 {
		logrus.Fatalf("Please pass arguments in the form: SERVICE PORT")
	}

	index := c.Int("index")
	protocol := c.String("protocol")

	service, err := p.CreateService(c.Args()[0])
	if err != nil {
		logrus.Fatal(err)
	}

	containers, err := service.Containers()
	if err != nil {
		logrus.Fatal(err)
	}

	if index < 1 || index > len(containers) {
		logrus.Fatalf("Invalid index %d", index)
	}

	output, err := containers[index-1].Port(fmt.Sprintf("%s/%s", c.Args()[1], protocol))
	if err != nil {
		logrus.Fatal(err)
	}
	fmt.Println(output)
}
開發者ID:aduermael,項目名稱:libcompose,代碼行數:28,代碼來源:app.go

示例2: Upgrade

func Upgrade(p *project.Project, from, to string, opts UpgradeOpts) error {
	fromService, err := p.CreateService(from)
	if err != nil {
		return err
	}

	toService, err := p.CreateService(to)
	if err != nil {
		return err
	}

	rFromService, ok := fromService.(*rancher.RancherService)
	if !ok {
		return fmt.Errorf("%s is not a Rancher service", from)
	}

	rToService, ok := toService.(*rancher.RancherService)
	if !ok {
		return fmt.Errorf("%s is not a Rancher service", to)
	}

	if err := rToService.Up(); err != nil {
		return err
	}

	source, err := rFromService.RancherService()
	if err != nil {
		return err
	}

	dest, err := rToService.RancherService()
	if err != nil {
		return err
	}

	upgradeOpts := &rancherClient.ServiceUpgrade{
		UpdateLinks:    opts.UpdateLinks,
		FinalScale:     int64(opts.FinalScale),
		BatchSize:      int64(opts.BatchSize),
		IntervalMillis: int64(opts.IntervalMillis),
		ToServiceId:    dest.Id,
	}
	if upgradeOpts.FinalScale == -1 {
		upgradeOpts.FinalScale = source.Scale
	}

	client := rFromService.Client()

	logrus.Infof("Upgrading %s to %s, scale=%d", from, to, upgradeOpts.FinalScale)
	service, err := client.Service.ActionUpgrade(source, upgradeOpts)
	if err != nil {
		return err
	}

	if opts.Wait {
		return rFromService.Wait(service)
	}

	return nil
}
開發者ID:feelobot,項目名稱:rancher-compose,代碼行數:60,代碼來源:upgrade.go

示例3: ProjectDelete

// ProjectDelete deletes services.
func ProjectDelete(p *project.Project, c *cli.Context) {
	stoppedContainers, err := p.ListStoppedContainers(c.Args()...)
	if err != nil {
		logrus.Fatal(err)
	}
	if len(stoppedContainers) == 0 {
		fmt.Println("No stopped containers")
		return
	}
	if !c.Bool("force") {
		fmt.Printf("Going to remove %v\nAre you sure? [yN]\n", strings.Join(stoppedContainers, ", "))
		var answer string
		_, err := fmt.Scanln(&answer)
		if err != nil {
			logrus.Fatal(err)
		}
		if answer != "y" && answer != "Y" {
			return
		}
	}
	err = p.Delete(c.Args()...)
	if err != nil {
		logrus.Fatal(err)
	}
}
開發者ID:kunalkushwaha,項目名稱:libcompose,代碼行數:26,代碼來源:app.go

示例4: addServices

func addServices(p *project.Project, enabled map[interface{}]interface{}, configs map[string]*composeConfig.ServiceConfigV1) map[interface{}]interface{} {
	serviceConfigsV2, _ := composeConfig.ConvertServices(configs)

	// Note: we ignore errors while loading services
	unchanged := true
	for name, serviceConfig := range serviceConfigsV2 {
		hash := composeConfig.GetServiceHash(name, serviceConfig)

		if enabled[name] == hash {
			continue
		}

		if err := p.AddConfig(name, serviceConfig); err != nil {
			log.Infof("Failed loading service %s", name)
			continue
		}

		if unchanged {
			enabled = util.MapCopy(enabled)
			unchanged = false
		}
		enabled[name] = hash
	}
	return enabled
}
開發者ID:coderjoe,項目名稱:os,代碼行數:25,代碼來源:project.go

示例5: ProjectLog

func ProjectLog(p *project.Project, c *cli.Context) {
	err := p.Log(c.Args()...)
	if err != nil {
		logrus.Fatal(err)
	}
	wait()
}
開發者ID:sonchang,項目名稱:rancher-compose,代碼行數:7,代碼來源:app.go

示例6: ProjectDelete

func ProjectDelete(p *project.Project, c *cli.Context) {
	if !c.Bool("force") && len(c.Args()) == 0 {
		logrus.Fatal("Will not remove all services with out --force")
	}
	err := p.Delete(c.Args()...)
	if err != nil {
		logrus.Fatal(err)
	}
}
開發者ID:sonchang,項目名稱:rancher-compose,代碼行數:9,代碼來源:app.go

示例7: ProjectLog

// ProjectLog gets services logs.
func ProjectLog(p *project.Project, c *cli.Context) {
	err := p.Log(c.Args()...)
	if err != nil {
		logrus.Fatal(err)
	}
	if c.Bool("follow") {
		wait()
	}
}
開發者ID:kunalkushwaha,項目名稱:libcompose,代碼行數:10,代碼來源:app.go

示例8: ProjectUp

func ProjectUp(p *project.Project, c *cli.Context) {
	err := p.Up(c.Args()...)
	if err != nil {
		logrus.Fatal(err)
	}

	if !c.Bool("d") {
		wait()
	}
}
開發者ID:sonchang,項目名稱:rancher-compose,代碼行數:10,代碼來源:app.go

示例9: ProjectCreate

func ProjectCreate(p *project.Project, c *cli.Context) {
	if err := p.Create(c.Args()...); err != nil {
		logrus.Fatal(err)
	}

	// This is to fix circular links... What!? It works.
	if err := p.Create(c.Args()...); err != nil {
		logrus.Fatal(err)
	}
}
開發者ID:xaka,項目名稱:rancher-compose,代碼行數:10,代碼來源:app.go

示例10: ProjectUp

func ProjectUp(p *project.Project, c *cli.Context) {
	if err := p.Create(c.Args()...); err != nil {
		logrus.Fatal(err)
	}

	if err := p.Up(c.Args()...); err != nil {
		logrus.Fatal(err)
	}

	if !c.Bool("d") {
		// wait forever
		<-make(chan interface{})
	}
}
開發者ID:xaka,項目名稱:rancher-compose,代碼行數:14,代碼來源:app.go

示例11: addServices

func addServices(p *project.Project, cfg *config.CloudConfig, enabled map[string]string, configs map[string]*project.ServiceConfig) {
	// Note: we ignore errors while loading services
	for name, serviceConfig := range configs {
		hash := project.GetServiceHash(name, *serviceConfig)

		if enabled[name] == hash {
			continue
		}

		if err := p.AddConfig(name, serviceConfig); err != nil {
			log.Infof("Failed loading service %s", name)
			continue
		}

		enabled[name] = hash
	}
}
開發者ID:clhudson2,項目名稱:os,代碼行數:17,代碼來源:project.go

示例12: ProjectPs

func ProjectPs(p *project.Project, c *cli.Context) {
	allInfo := project.InfoSet{}
	for name := range p.Configs {
		service, err := p.CreateService(name)
		if err != nil {
			logrus.Fatal(err)
		}

		info, err := service.Info()
		if err != nil {
			logrus.Fatal(err)
		}

		allInfo = append(allInfo, info...)
	}

	os.Stdout.WriteString(allInfo.String())
}
開發者ID:aduermael,項目名稱:libcompose,代碼行數:18,代碼來源:app.go

示例13: ProjectPs

// ProjectPs lists the containers.
func ProjectPs(p *project.Project, c *cli.Context) {
	allInfo := project.InfoSet{}
	qFlag := c.Bool("q")
	for _, name := range p.Configs.Keys() {
		service, err := p.CreateService(name)
		if err != nil {
			logrus.Fatal(err)
		}

		info, err := service.Info(qFlag)
		if err != nil {
			logrus.Fatal(err)
		}

		allInfo = append(allInfo, info...)
	}

	os.Stdout.WriteString(allInfo.String(!qFlag))
}
開發者ID:kunalkushwaha,項目名稱:libcompose,代碼行數:20,代碼來源:app.go

示例14: ProjectRun

// ProjectRun runs a given command within a service's container.
func ProjectRun(p *project.Project, c *cli.Context) {
	if len(c.Args()) == 1 {
		logrus.Fatal("No service specified")
	}

	serviceName := c.Args()[0]
	commandParts := c.Args()[1:]

	if !p.Configs.Has(serviceName) {
		logrus.Fatalf("%s is not defined in the template", serviceName)
	}

	exitCode, err := p.Run(serviceName, commandParts)
	if err != nil {
		logrus.Fatal(err)
	}

	os.Exit(exitCode)
}
開發者ID:kunalkushwaha,項目名稱:libcompose,代碼行數:20,代碼來源:app.go

示例15: ProjectScale

func ProjectScale(p *project.Project, c *cli.Context) {
	// This code is a bit verbose but I wanted to parse everything up front
	order := make([]string, 0, 0)
	serviceScale := make(map[string]int)
	services := make(map[string]project.Service)

	for _, arg := range c.Args() {
		kv := strings.SplitN(arg, "=", 2)
		if len(kv) != 2 {
			logrus.Fatalf("Invalid scale parameter: %s", arg)
		}

		name := kv[0]

		count, err := strconv.Atoi(kv[1])
		if err != nil {
			logrus.Fatalf("Invalid scale parameter: %v", err)
		}

		if _, ok := p.Configs[name]; !ok {
			logrus.Fatalf("% is not defined in the template", name)
		}

		service, err := p.CreateService(name)
		if err != nil {
			logrus.Fatalf("Failed to lookup service: %s: %v", service, err)
		}

		order = append(order, name)
		serviceScale[name] = count
		services[name] = service
	}

	for _, name := range order {
		scale := serviceScale[name]
		logrus.Infof("Setting scale %s=%d...", name, scale)
		err := services[name].Scale(scale)
		if err != nil {
			logrus.Fatalf("Failed to set the scale %s=%d: %v", name, scale, err)
		}
	}
}
開發者ID:sonchang,項目名稱:rancher-compose,代碼行數:42,代碼來源:app.go


注:本文中的github.com/docker/libcompose/project.Project類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。