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


Golang Client.Init方法代码示例

本文整理汇总了Golang中github.com/lxc/lxd.Client.Init方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.Init方法的具体用法?Golang Client.Init怎么用?Golang Client.Init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/lxc/lxd.Client的用法示例。


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

示例1: spawnContainers


//.........这里部分代码省略.........

		_, err = c.GetImageInfo(fingerprint)
		if err != nil {
			logf("Importing image into local store: %s", fingerprint)
			err := d.CopyImage(fingerprint, c, false, nil, false, false, nil)
			if err != nil {
				return err
			}
		} else {
			logf("Found image in local store: %s", fingerprint)
		}
	} else {
		fingerprint = image
		logf("Found image in local store: %s", fingerprint)
	}

	// Start the containers
	spawnedCount := 0
	nameFormat := "benchmark-%." + fmt.Sprintf("%d", len(fmt.Sprintf("%d", count))) + "d"
	wgBatch := sync.WaitGroup{}
	nextStat := batch

	startContainer := func(name string) {
		defer wgBatch.Done()

		// Configure
		config := map[string]string{}
		if privileged {
			config["security.privileged"] = "true"
		}
		config["user.lxd-benchmark"] = "true"

		// Create
		resp, err := c.Init(name, "local", fingerprint, nil, config, nil, false)
		if err != nil {
			logf(fmt.Sprintf("Failed to spawn container '%s': %s", name, err))
			return
		}

		err = c.WaitForSuccess(resp.Operation)
		if err != nil {
			logf(fmt.Sprintf("Failed to spawn container '%s': %s", name, err))
			return
		}

		// Start
		resp, err = c.Action(name, "start", -1, false, false)
		if err != nil {
			logf(fmt.Sprintf("Failed to spawn container '%s': %s", name, err))
			return
		}

		err = c.WaitForSuccess(resp.Operation)
		if err != nil {
			logf(fmt.Sprintf("Failed to spawn container '%s': %s", name, err))
			return
		}

		// Freeze
		if *argFreeze {
			resp, err = c.Action(name, "freeze", -1, false, false)
			if err != nil {
				logf(fmt.Sprintf("Failed to spawn container '%s': %s", name, err))
				return
			}
开发者ID:ccsblueboy,项目名称:lxd,代码行数:66,代码来源:main.go

示例2: cmdCreate


//.........这里部分代码省略.........
				for _, p := range router.Peers {
					if p.ASN != 0 {
						bgpd += fmt.Sprintf("  neighbor %s activate\n", p.Remote)
					}
				}
			}

			bgpd += `  redistribute connected
  redistribute kernel
 exit-address-family
`

			config["user.internet.config.interfaces"] = interfaces
			config["user.internet.config.bgpd"] = bgpd
		}

		// Config-only containers
		if router.Tier > 3 {
			ct, err := c.ContainerInfo(router.Name)
			if err != nil {
				logf("Failed to configure container '%s': %s", router.Name, err)
				return
			}

			for k, _ := range ct.Config {
				if strings.HasPrefix(k, "user.internet.") {
					delete(ct.Config, k)
				}
			}

			for k, v := range config {
				ct.Config[k] = v
			}

			err = c.UpdateContainerConfig(router.Name, ct.Writable())
			if err != nil {
				logf("Failed to configure container '%s': %s", router.Name, err)
				return
			}

			return
		}

		// Create the container
		resp, err := c.Init(router.Name, "local", "internet-router", &[]string{"internet-base"}, config, nil, false)
		if err != nil {
			logf("Failed to create container '%s': %s", router.Name, err)
			return
		}

		err = c.WaitForSuccess(resp.Operation)
		if err != nil {
			logf("Failed to create container '%s': %s", router.Name, err)
			return
		}

		// Setup the devices
		ct, err := c.ContainerInfo(router.Name)
		if err != nil {
			logf("Failed to configure container '%s': %s", router.Name, err)
			return
		}

		for k, v := range devices {
			ct.Devices[k] = v
		}

		err = c.UpdateContainerConfig(router.Name, ct.Writable())
		if err != nil {
			logf("Failed to configure container '%s': %s", router.Name, err)
			return
		}
	}

	// Create the containers
	batch := 8
	batches := len(routers) / batch
	remainder := len(routers) % batch

	logf("Creating the containers")
	current := 0
	for i := 0; i < batches; i++ {
		for j := 0; j < batch; j++ {
			wgBatch.Add(1)
			go createContainer(routers[current])
			current += 1
		}
		wgBatch.Wait()
	}

	for k := 0; k < remainder; k++ {
		wgBatch.Add(1)
		go createContainer(routers[current])
		current += 1
	}
	wgBatch.Wait()
	logf("%d containers created", len(routers))

	return nil
}
开发者ID:nsec,项目名称:the-internet,代码行数:101,代码来源:cmd_create.go


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