• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang shared.Devices类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: devicesApplyDeltaLive

/*
 * Given a running container and a list of devices before and after a
 * config change, update the devices in the container.
 *
 * Currently we only support nics.  Disks will be supported once we
 * decide how best to insert them.
 */
func devicesApplyDeltaLive(tx *sql.Tx, c *lxdContainer, preDevList shared.Devices, postDevList shared.Devices) error {
	rmList, addList := preDevList.Update(postDevList)
	var err error

	// note - currently Devices.Update() only returns nics
	for key, nic := range rmList {
		if nic["name"] == "" {
			return fmt.Errorf("Do not know a name for the nic for device %s\n", key)
		}
		if err := detachInterface(c, nic["name"]); err != nil {
			return fmt.Errorf("Error removing device %s (nic %s) from container %s: %s", key, nic["name"], c.name, err)
		}
	}

	for key, nic := range addList {
		var tmpName string
		if tmpName, err = setupNic(c, nic); err != nil {
			return fmt.Errorf("Unable to create nic %s for container %s: %s", nic["name"], c.name, err)
		}
		if err := c.c.AttachInterface(tmpName, nic["name"]); err != nil {
			RemoveInterface(tmpName)
			return fmt.Errorf("Unable to move nic %s into container %s as %s: %s", tmpName, c.name, nic["name"], err)
		}
		// Now we need to add the name to the database
		if err := txUpdateNic(tx, c.id, key, nic["name"]); err != nil {
			shared.Debugf("Warning: failed to update database entry for new nic %s: %s\n", key, err)
		}
	}

	return nil
}
开发者ID:timwukp,项目名称:lxd,代码行数:38,代码来源:devices.go


示例2: devicesApplyDeltaLive

/*
 * Given a running container and a list of devices before and after a
 * config change, update the devices in the container.
 *
 * Currently we only support nics.  Disks will be supported once we
 * decide how best to insert them.
 */
func devicesApplyDeltaLive(tx *sql.Tx, c container, preDevList shared.Devices, postDevList shared.Devices) error {
	rmList, addList := preDevList.Update(postDevList)
	var err error

	for key, dev := range rmList {
		switch dev["type"] {
		case "nic":
			if dev["name"] == "" {
				return fmt.Errorf("Do not know a name for the nic for device %s", key)
			}
			if err := detachInterface(c, dev["name"]); err != nil {
				return fmt.Errorf("Error removing device %s (nic %s) from container %s: %s", key, dev["name"], c.Name(), err)
			}
		case "disk":
			return c.DetachMount(dev)
		case "unix-block":
			return c.DetachUnixDev(dev)
		case "unix-char":
			return c.DetachUnixDev(dev)
		}
	}

	lxContainer := c.LXContainerGet()

	for key, dev := range addList {
		switch dev["type"] {
		case "nic":
			var tmpName string
			if tmpName, err = setupNic(tx, c, key, dev); err != nil {
				return fmt.Errorf("Unable to create nic %s for container %s: %s", dev["name"], c.Name(), err)
			}
			if err := lxContainer.AttachInterface(tmpName, dev["name"]); err != nil {
				removeInterface(tmpName)
				return fmt.Errorf("Unable to move nic %s into container %s as %s: %s", tmpName, c.Name(), dev["name"], err)
			}

			if err := txUpdateNic(tx, c.ID(), key, dev["name"]); err != nil {
				shared.Debugf("Warning: failed to update database entry for new nic %s: %s", key, err)
				return err
			}
		case "disk":
			if dev["source"] == "" || dev["path"] == "" {
				return fmt.Errorf("no source or destination given")
			}
			return c.AttachMount(dev)
		case "unix-block":
			return c.AttachUnixDev(dev)
		case "unix-char":
			return c.AttachUnixDev(dev)
		}
	}

	return nil
}
开发者ID:xnox,项目名称:lxd,代码行数:61,代码来源:devices.go


示例3: devicesApplyDeltaLive

/*
 * Given a running container and a list of devices before and after a
 * config change, update the devices in the container.
 *
 * Currently we only support nics.  Disks will be supported once we
 * decide how best to insert them.
 */
func devicesApplyDeltaLive(tx *sql.Tx, c *lxdContainer, preDevList shared.Devices, postDevList shared.Devices) error {
	rmList, addList := preDevList.Update(postDevList)
	var err error

	// note - currently Devices.Update() only returns nics
	for key, dev := range rmList {
		switch dev["type"] {
		case "nic":
			if dev["name"] == "" {
				return fmt.Errorf("Do not know a name for the nic for device %s\n", key)
			}
			if err := detachInterface(c, dev["name"]); err != nil {
				return fmt.Errorf("Error removing device %s (nic %s) from container %s: %s", key, dev["name"], c.name, err)
			}
		case "disk":
			return c.detachMount(dev)
		}
	}

	for key, dev := range addList {
		switch dev["type"] {
		case "nic":
			var tmpName string
			if tmpName, err = setupNic(c, dev); err != nil {
				return fmt.Errorf("Unable to create nic %s for container %s: %s", dev["name"], c.name, err)
			}
			if err := c.c.AttachInterface(tmpName, dev["name"]); err != nil {
				RemoveInterface(tmpName)
				return fmt.Errorf("Unable to move nic %s into container %s as %s: %s", tmpName, c.name, dev["name"], err)
			}
			// Now we need to add the name to the database
			if err := txUpdateNic(tx, c.id, key, dev["name"]); err != nil {
				shared.Debugf("Warning: failed to update database entry for new nic %s: %s\n", key, err)
			}
		case "disk":
			if dev["source"] == "" || dev["path"] == "" {
				return fmt.Errorf("no source or destination given")
			}
			return c.attachMount(dev)
		}
	}

	return nil
}
开发者ID:RuneTM,项目名称:lxd,代码行数:51,代码来源:devices.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang shared.IdmapSet类代码示例发布时间:2022-05-23
下一篇:
Golang shared.ContainerStatus类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap