本文整理汇总了Golang中github.com/docker/libcompose/project.Project类的典型用法代码示例。如果您正苦于以下问题:Golang Project类的具体用法?Golang Project怎么用?Golang Project使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Project类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: upgradeInfo
func upgradeInfo(up bool, p *project.Project, from, to string, opts UpgradeOpts) (*rancherClient.Service, *rancherClient.Service, *rancherClient.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(); 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:feelobot,项目名称:rancher-compose,代码行数:39,代码来源:upgrade.go
示例17: LoadService
func LoadService(p *project.Project, cfg *config.CloudConfig, useNetwork bool, service string) error {
bytes, err := network.LoadServiceResource(service, useNetwork, cfg)
if err != nil {
return err
}
m := map[interface{}]interface{}{}
if err = yaml.Unmarshal(bytes, &m); err != nil {
return fmt.Errorf("Failed to parse YAML configuration for %s: %v", service, err)
}
m = adjustContainerNames(m)
bytes, err = yaml.Marshal(m)
if err != nil {
return fmt.Errorf("Failed to marshal YAML configuration for %s: %v", service, err)
}
if err = p.Load(bytes); err != nil {
return fmt.Errorf("Failed to load %s: %v", service, err)
}
return nil
}
开发者ID:coderjoe,项目名称:os,代码行数:24,代码来源:reload.go
示例18: getPid
func getPid(service string, project *project.Project) (int, error) {
s, err := project.CreateService(service)
if err != nil {
return 0, err
}
containers, err := s.Containers(context.Background())
if err != nil {
return 0, err
}
if len(containers) == 0 {
return 0, nil
}
client, err := composeClient.Create(composeClient.Options{
Host: config.DOCKER_SYSTEM_HOST,
})
if err != nil {
return 0, err
}
id, err := containers[0].ID()
if err != nil {
return 0, err
}
info, err := client.ContainerInspect(context.Background(), id)
if err != nil || info.ID == "" {
return 0, err
}
if info.State.Running {
return info.State.Pid, nil
}
return 0, nil
}
开发者ID:coderjoe,项目名称:os,代码行数:38,代码来源:main.go
示例19: getPid
func getPid(service string, project *project.Project) (int, error) {
s, err := project.CreateService(service)
if err != nil {
return 0, err
}
containers, err := s.Containers()
if err != nil {
return 0, err
}
if len(containers) == 0 {
return 0, nil
}
client, err := docker.CreateClient(docker.ClientOpts{
Host: config.DOCKER_SYSTEM_HOST,
})
if err != nil {
return 0, err
}
id, err := containers[0].Id()
if err != nil {
return 0, err
}
info, err := client.InspectContainer(id)
if err != nil || info == nil {
return 0, err
}
if info.State.Running {
return info.State.Pid, nil
}
return 0, nil
}
开发者ID:Jdesk,项目名称:os,代码行数:38,代码来源:main.go
示例20: 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)
}
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(); err != nil {
return err
}
if err := rToService.Scale(0); err != nil {
return err
}
}
if err := rToService.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 := &rancherClient.ServiceUpgrade{
ToServiceStrategy: &rancherClient.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(); 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
source, err = rFromService.RancherService()
if err != nil {
//.........这里部分代码省略.........
开发者ID:xaka,项目名称:rancher-compose,代码行数:101,代码来源:upgrade.go
注:本文中的github.com/docker/libcompose/project.Project类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论