Exemplo n.º 1
0
/* virtual connection */
func NewVirConnection(uri string) (VirConnection, error) {
	cUri := C.CString(uri)
	defer C.free(unsafe.Pointer(cUri))
	ptr := C.virConnectOpen(cUri)
	if ptr == nil {
		return VirConnection{}, errors.New(GetLastError())
	}
	obj := VirConnection{ptr: ptr}
	return obj, nil
}
Exemplo n.º 2
0
func NewHypervisor(uri string) (*Hypervisor, error) {
	cUri := C.CString(uri)
	defer C.free(unsafe.Pointer(cUri))

	cptr := C.virConnectOpen(cUri)
	if cptr == nil {
		return &Hypervisor{}, GetLastError()
	}
	return &Hypervisor{cptr}, nil
}
Exemplo n.º 3
0
func NewVirConnection(uri string) (VirConnection, error) {
	var cUri *C.char
	if uri != "" {
		cUri = C.CString(uri)
		defer C.free(unsafe.Pointer(cUri))
	}
	ptr := C.virConnectOpen(cUri)
	if ptr == nil {
		return VirConnection{}, GetLastError()
	}
	obj := VirConnection{ptr: ptr}
	return obj, nil
}
Exemplo n.º 4
0
func NewVirConnection(uri string) (VirConnection, error) {
	var cUri *C.char
	if uri != "" {
		cUri = C.CString(uri)
		defer C.free(unsafe.Pointer(cUri))
	}
	ptr := C.virConnectOpen(cUri)
	if ptr == nil {
		return VirConnection{}, GetLastError()
	}
	obj := VirConnection{ptr: ptr, event_cbs: make(map[int]*domainCallbackContext)}
	return obj, nil
}
Exemplo n.º 5
0
// Open creates a new libvirt connection to the Hypervisor. The
// connection mode specifies whether the connection will be read-write
// or read-only. The URIs are documented at http://libvirt.org/uri.html.
func Open(uri string, mode ConnectionMode, logOutput io.Writer) (Connection, error) {
	cUri := C.CString(uri)
	defer C.free(unsafe.Pointer(cUri))

	logger := newLogger(logOutput)

	if uri == DefaultURI {
		logger.Printf("opening connection (mode = %v) to the default URI...\n", mode)
	} else {
		logger.Printf("opening connection (mode = %v) to %v...\n", mode, uri)
	}

	var cConn C.virConnectPtr
	switch mode {
	case ReadWrite:
		cConn = C.virConnectOpen(cUri)
	case ReadOnly:
		cConn = C.virConnectOpenReadOnly(cUri)
	default:
		return Connection{}, ErrInvalidConnectionMode
	}

	if cConn == nil {
		err := LastError()
		logger.Printf("an error occurred: %v\n", err)
		return Connection{}, err
	}

	logger.Println("connection established")

	conn := Connection{
		log:        logger,
		virConnect: cConn,
	}

	return conn, nil
}