This is used by the Minishift project.
A Copr project is available. Installation can be done as follows:
$ yum install yum-plugin-copr
$ yum copr enable gbraad/go-hvkvp
$ yum install go-hvkp
$ dnf copr enable gbraad/go-hvkvp
$ dnf install go-hvkvp
repo --name=base --baseurl=http://mirror.centos.org/centos/7/os/x86_64/
repo --name=updates --baseurl=http://mirror.centos.org/centos/7/updates/x86_64/
repo --name=hvkvp --baseurl=https://copr-be.cloud.fedoraproject.org/results/gbraad/go-hvkvp/epel-7-x86_64/
%packages
@core
go-hvkvp
$ git clone https://github.com/gbraad/go-hvkvp.git
$ cd go-hvkvp
$ go install -v ./cmd/hvkvp
$ dnf install -y rpm-build go-compilers-golang-compiler
$ rpmbuild -ba hvkvp.spec
$VmMgmt = Get-WmiObject -Namespace root\virtualization\v2 -Class Msvm_VirtualSystemManagementService
$vm = Get-WmiObject -Namespace root\virtualization\v2 -Class Msvm_ComputerSystem -Filter {ElementName = 'MyVM'}
$kvpDataItem = ([WMIClass][String]::Format("\\{0}\{1}:{2}", $VmMgmt.ClassPath.Server, $VmMgmt.ClassPath.NamespacePath, "Msvm_KvpExchangeDataItem")).CreateInstance()
$kvpDataItem.Name = "IpAddress"
$kvpDataItem.Data = "10.0.75.128"
$kvpDataItem.Source = 0
$VmMgmt.AddKvpItems($Vm, $kvpDataItem.PSBase.GetText(1))
With $kvpDataItem.Source = 0
the KVP gets stored as /var/lib/hyperv/.kvp_pool_0
.
$ ./hvkvp
Key: IpAddress, Value: 10.0.75.128
$ ./hvkvp --key Hostname
fedora-vm%
When dealing with special characters, consider using base64 encoding.
For example, the value of the message might contain:
REVWSUNFPWV0aDAKVVNFREhDUD15Cg==
This can be received on the host as:
$ hvkvp -key PROVISION_NETWORKING | base64 --decode > /var/lib/minishift/networking
$ cat /var/lib/minishift/networking
DEVICE=eth0
USEDHCP=y