forked from coreos/ignition
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR adds initial support for the Microsoft HyperV platform. It uses HyperV and MS WMI to read key/value pairs as provided by the Windows host. Because the size allocation of the value is quite small, the ignition values will likely be split into at least 2 and more like more parts which must be read and reassembled in ignition. Supports: * coreos/fedora-coreos-tracker#1411 * coreos/fedora-coreos-tracker#1424 Signed-off-by: Brent Baude <[email protected]>
- Loading branch information
Showing
11 changed files
with
586 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright 2023 Red Hat | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package hyperv | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"path/filepath" | ||
|
||
"github.com/containers/libhvee/pkg/kvp" | ||
"github.com/coreos/ignition/v2/config/v3_5_experimental/types" | ||
"github.com/coreos/ignition/v2/internal/platform" | ||
"github.com/coreos/ignition/v2/internal/providers/util" | ||
"github.com/coreos/ignition/v2/internal/resource" | ||
"github.com/coreos/vcontext/report" | ||
) | ||
|
||
// key represents the prefix key name for finding kvp file parts | ||
// in the key value pairs. it normally will have an integer added to the | ||
// end when looking up keys sequentially | ||
const key = "ignition.config." | ||
|
||
func init() { | ||
platform.Register(platform.Provider{ | ||
Name: "hyperv", | ||
FetchWithFiles: fetchConfig, | ||
}) | ||
} | ||
|
||
func fetchConfig(f *resource.Fetcher) ([]types.File, types.Config, report.Report, error) { | ||
var ( | ||
kvpFiles []types.File | ||
) | ||
|
||
f.Logger.Info("attempting to read from kvp") | ||
|
||
// To read key-value pairs from the Windows host, the hv_util kernel module | ||
// must be loaded to create the kernel device itself. | ||
_, err := f.Logger.LogCmd(exec.Command("modprobe", "hv_utils"), "loading hyperv kernel device module") | ||
if err != nil { | ||
return nil, types.Config{}, report.Report{}, err | ||
} | ||
|
||
keyValuePairs, err := kvp.GetKeyValuePairs() | ||
if err != nil { | ||
return nil, types.Config{}, report.Report{}, err | ||
} | ||
|
||
ign, _, err := keyValuePairs.GetSplitKeyValues(key, kvp.DefaultKVPPoolID) | ||
if err != nil { | ||
return nil, types.Config{}, report.Report{}, err | ||
} | ||
|
||
// KVP files are written to the filesystem in /var/lib/hyperv by pool id. We will do the same | ||
// for the first boot as well. | ||
for poolID := range keyValuePairs { | ||
fqWritePath := filepath.Join(kvp.DefaultKVPFilePath, fmt.Sprintf("%s%d", kvp.DefaultKVPBaseName, poolID)) | ||
kvpFiles = append(kvpFiles, util.MakeProviderOutputFile(fqWritePath, kvp.DefaultKVPFileWritePermissions, keyValuePairs.EncodePoolFile(poolID))) | ||
} | ||
c, r, err := util.ParseConfig(f.Logger, []byte(ign)) | ||
return kvpFiles, c, r, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.