コード例 #1
0
ファイル: libvirt.go プロジェクト: ericcapricorn/flynn
func (c *VirConnection) GetHostname() (string, error) {
	str := C.virConnectGetHostname(c.ptr)
	if str == nil {
		return "", GetLastError()
	}
	hostname := C.GoString(str)
	C.free(unsafe.Pointer(str))
	return hostname, nil
}
コード例 #2
0
ファイル: hypervisor.go プロジェクト: hooklift/golibvirt
func (h *Hypervisor) GetHostname() (string, error) {
	result := C.virConnectGetHostname(h.cptr)
	if result == nil {
		return "", GetLastError()
	}

	hostname := C.GoString(result)
	defer C.free(unsafe.Pointer(result))

	return hostname, nil
}
コード例 #3
0
// Hostname returns a system hostname on which the hypervisor is running
// (based on the result of the gethostname system call, but possibly expanded
// to a fully-qualified domain name via getaddrinfo). If we are connected to a
// remote system, then this returns the hostname of the remote system.
func (conn Connection) Hostname() (string, error) {
	conn.log.Println("reading system hostname...")
	cHostname := C.virConnectGetHostname(conn.virConnect)
	if cHostname == nil {
		err := LastError()
		conn.log.Printf("an error occurred: %v\n", err)
		return "", err
	}
	defer C.free(unsafe.Pointer(cHostname))

	hostname := C.GoString(cHostname)
	conn.log.Printf("system hostname: %v\n", hostname)

	return hostname, nil
}