コード例 #1
0
ファイル: libvirt.go プロジェクト: hopkings2008/catkeeper
/* 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
}
コード例 #2
0
ファイル: hypervisor.go プロジェクト: hooklift/golibvirt
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
}
コード例 #3
0
ファイル: libvirt.go プロジェクト: ericcapricorn/flynn
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
}
コード例 #4
0
ファイル: libvirt.go プロジェクト: redrampage/libvirt-go
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
}
コード例 #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
}