Beispiel #1
0
func (c *VirConnection) DomainCreateXML(xmlConfig string, flags uint32) (VirDomain, error) {
	cXml := C.CString(string(xmlConfig))
	defer C.free(unsafe.Pointer(cXml))
	ptr := C.virDomainCreateXML(c.ptr, cXml, C.uint(flags))
	if ptr == nil {
		return VirDomain{}, GetLastError()
	}
	return VirDomain{ptr: ptr}, nil
}
Beispiel #2
0
func (c *VirConnection) CreateXML(xml string) (VirDomain, error) {
	cXml := C.CString(xml)
	defer C.free(unsafe.Pointer(cXml))

	cDomainPtr := C.virDomainCreateXML(c.ptr, cXml, 0)
	if cDomainPtr == nil {
		return VirDomain{}, errors.New(GetLastError())

	}
	return VirDomain{ptr: cDomainPtr}, nil

}
Beispiel #3
0
//Domain factories
func (h *Hypervisor) CreateDomain(xml string, flags uint) (*Domain, error) {
	cxml := C.CString(xml)
	defer C.free(unsafe.Pointer(cxml))

	cdomain := C.virDomainCreateXML(h.cptr, cxml, C.uint(flags))
	if cdomain == nil {
		return nil, GetLastError()
	}

	domain := &Domain{cdomain}
	runtime.SetFinalizer(domain, cleanupDomain)

	return domain, nil
}
// CreateDomain launches a new guest domain, based on an XML description
// similar to the one returned by Domain.XML() This function may require
// privileged access to the hypervisor. The domain is not persistent, so its
// definition will disappear when it is destroyed, or if the host is restarted
// (see Domain.Define() to define persistent domains).
func (conn Connection) CreateDomain(xml string, flags DomainCreateFlag) (Domain, error) {
	cXML := C.CString(xml)
	defer C.free(unsafe.Pointer(cXML))

	conn.log.Printf("creating domain (flags = %v)...\n", flags)
	cDomain := C.virDomainCreateXML(conn.virConnect, cXML, C.uint(flags))
	if cDomain == nil {
		err := LastError()
		conn.log.Printf("an error occurred: %v\n", err)
		return Domain{}, err
	}

	conn.log.Println("domain created")

	dom := Domain{
		log:       conn.log,
		virDomain: cDomain,
	}

	return dom, nil
}