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


Golang APIProject.CreateService方法代碼示例

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


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

示例1: upgradeInfo

func upgradeInfo(up bool, p project.APIProject, from, to string, opts UpgradeOpts) (*client.Service, *client.Service, *client.RancherClient, error) {
	fromService, err := p.CreateService(from)
	if err != nil {
		return nil, nil, nil, err
	}

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

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

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

	if up {
		if err := rToService.Up(context.Background(), options.Up{}); err != nil {
			return nil, nil, nil, err
		}
	}

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

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

	return source, dest, rFromService.Client(), nil
}
開發者ID:vdemeester,項目名稱:rancher-compose,代碼行數:39,代碼來源:upgrade.go

示例2: Upgrade

func Upgrade(p project.APIProject, 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)
	}

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

	if source == nil {
		return fmt.Errorf("Failed to find service %s", from)
	}

	if source.LaunchConfig.Labels["io.rancher.scheduler.global"] == "true" {
		return fmt.Errorf("Upgrade is not supported for global services")
	}

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

	if service, err := rToService.RancherService(); err != nil {
		return err
	} else if service == nil {
		if err := rToService.Create(context.Background(), options.Create{}); err != nil {
			return err
		}

		// TODO timeout shouldn't really be an argument here
		// it's ignored in our implementation anyways
		if err := rToService.Scale(context.Background(), 0, -1); err != nil {
			return err
		}
	}

	if err := rToService.Up(context.Background(), options.Up{}); err != nil {
		return err
	}

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

	if dest == nil {
		return fmt.Errorf("Failed to find service %s", to)
	}

	if dest.LaunchConfig.Labels["io.rancher.scheduler.global"] == "true" {
		return fmt.Errorf("Upgrade is not supported for global services")
	}

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

	client := rFromService.Client()

	if opts.Pull {
		if err := rToService.Pull(context.Background()); err != nil {
			return err
		}
	}

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

	if opts.Wait || opts.CleanUp {
		if err := rFromService.Wait(service); err != nil {
			return err
		}
	}

	if opts.CleanUp {
		// Reload source to check scale
//.........這裏部分代碼省略.........
開發者ID:vdemeester,項目名稱:rancher-compose,代碼行數:101,代碼來源:upgrade.go


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