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


Golang VirConnection.StoragePoolLookupByName方法代码示例

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


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

示例1: createRemoteBootPool

func createRemoteBootPool(conn libvirt.VirConnection) (libvirt.VirStoragePool, error) {
	// Test volume pool
	// create vol from pool and Upload
	var pool libvirt.VirStoragePool
	pool, err := conn.StoragePoolLookupByName("boot-scratch")
	if err != nil {
		// pool not existed
		// create on pool named "boot-scrath"
		// TODO
		log.Println("pool not exist")
		//poolXML, _:= ioutil.ReadFile("./pool.xml")
		poolXML := POOXML
		pool, err = conn.StoragePoolDefineXML(string(poolXML))
		if err != nil {
			return libvirt.VirStoragePool{}, err
		}
	}
	return pool, nil
}
开发者ID:hopkings2008,项目名称:catkeeper,代码行数:19,代码来源:vminstall.go

示例2: VmInstall

func VmInstall(conn libvirt.VirConnection, vmname string, url string, autoyast string, imageSize uint64, ch chan string) {

	//check input

	if len(vmname) <= 0 {
		reportFail(ch, "Name too short")
		return
	}

	if imageSize == 0 {
		reportFail(ch, "disk size too short")
	}

	//sender close the channel
	if ch != nil {
		defer close(ch)
	}

	pool, err := createRemoteBootPool(conn)
	defer pool.Free()

	//url := "http://mirror.bej.suse.com/dist/install/SLP/SLE-12-Server-Beta10/x86_64/DVD1"
	linuxSurfix := "/boot/x86_64/loader/linux"
	initrdSurfix := "/boot/x86_64/loader/initrd"

	// Download linux and initrd image from remote
	reportStatus(ch, "Downloading linux image")
	m := DownloadManager{}
	m.Regsiter(HTTPDownloader{})
	linuxContent, err := m.Download(url + linuxSurfix)
	if err != nil {
		reportFail(ch, err.Error())
		return
	}

	reportStatus(ch, "Downloading initrd image")

	initrdContent, err := m.Download(url + initrdSurfix)
	if err != nil {
		reportFail(ch, err.Error())
		return
	}

	//prepare two temporary name for linux;initrd image
	temp := generateFourRandom()
	bootImageName := vmname + temp + ".image"
	bootInitrdName := vmname + temp + ".initrd"

	// create remote boot linux storage from temp pool
	linuxVolume, err := createVolume(pool, Storage{Name: bootImageName, Size: uint64(len(linuxContent)), Type: "raw"})
	if err != nil {
		reportFail(ch, err.Error())
		return
	}
	defer linuxVolume.Free()
	defer linuxVolume.Delete()
	linuxPath, _ := linuxVolume.GetPath()

	// create remote boot initrd storage from temp pool
	initrdVolume, err := createVolume(pool, Storage{Name: bootInitrdName, Size: uint64(len(initrdContent)), Type: "raw"})
	if err != nil {
		reportFail(ch, err.Error())
		return
	}
	defer initrdVolume.Free()
	defer initrdVolume.Delete()
	initrdPath, _ := initrdVolume.GetPath()

	var stream libvirt.VirStream
	stream, err = conn.StreamNew()
	if err != nil {
		reportFail(ch, err.Error())
		return
	}
	defer stream.Free()

	//Upload to remote
	reportStatus(ch, "sending linuxVolume")
	if err := SendLocalToRemote(stream, linuxVolume, linuxContent); err != nil {
		reportFail(ch, err.Error())
		return
	}

	reportStatus(ch, "sending initrd")
	if err := SendLocalToRemote(stream, initrdVolume, initrdContent); err != nil {
		reportFail(ch, err.Error())
		return
	}

	// create image
	reportStatus(ch, "creating remote imaging...")
	dataPool, err := conn.StoragePoolLookupByName("default")
	if err != nil {
		reportFail(ch, err.Error())
		return
	}
	defer dataPool.Free()

	//var imageSize uint64 = 8589934592 //8G

//.........这里部分代码省略.........
开发者ID:hopkings2008,项目名称:catkeeper,代码行数:101,代码来源:vminstall.go


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