Example #1
0
func (d *VirDomain) SetMetadata(metaDataType int, metaDataCont, uriKey, uri string, flags uint32) error {
	var cMetaDataCont *C.char
	var cUriKey *C.char
	var cUri *C.char

	cMetaDataCont = C.CString(metaDataCont)
	defer C.free(unsafe.Pointer(cMetaDataCont))

	if metaDataType == VIR_DOMAIN_METADATA_ELEMENT {
		cUriKey = C.CString(uriKey)
		defer C.free(unsafe.Pointer(cUriKey))
		cUri = C.CString(uri)
		defer C.free(unsafe.Pointer(cUri))
	}
	result := C.virDomainSetMetadata(d.ptr, C.int(metaDataType), cMetaDataCont, cUriKey, cUri, C.uint(flags))
	if result == -1 {
		return GetLastError()
	}
	return nil
}
Example #2
0
// SetMetadata sets the appropriate domain element given by "type" to the value
// of "description". A "type" of DomMetaDescription is free-form text;
// DomMetaTitle is free-form, but no newlines are permitted, and should be
// short (although the length is not enforced). For these two options "key" and
// "uri" are irrelevant and must be set to NULL.
func (dom Domain) SetMetadata(typ DomainMetadataType, metadata string, key string, uri string, impact DomainModificationImpact) error {
	cMetadata := C.CString(metadata)
	defer C.free(unsafe.Pointer(cMetadata))

	cKey := C.CString(key)
	defer C.free(unsafe.Pointer(cKey))

	cURI := C.CString(uri)
	defer C.free(unsafe.Pointer(cURI))

	dom.log.Printf("changing domain metadata key '<%v:%v>' (type = %v, impact = %v)...\n", key, uri, typ, impact)
	cRet := C.virDomainSetMetadata(dom.virDomain, C.int(typ), cMetadata, cKey, cURI, C.uint(impact))
	ret := int32(cRet)

	if ret == -1 {
		err := LastError()
		dom.log.Printf("an error occurred: %v\n", err)
		return err
	}

	dom.log.Println("metadata changed")

	return nil
}