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


Golang Devices.Update方法代碼示例

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


在下文中一共展示了Devices.Update方法的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.Update方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。