当前位置: 首页>>代码示例>>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;未经允许,请勿转载。