-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
providers/applehv: Add Apple Hypervisor
* Add applehv platform * Ignintion read from vsock connection with the host See coreos/fedora-coreos-tracker#1533 and coreos/fedora-coreos-tracker#1548 Signed-off-by: Brent Baude <[email protected]>
- Loading branch information
Showing
41 changed files
with
3,880 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,11 @@ nav_order: 9 | |
|
||
|
||
### Features | ||
- Support the native Apple Hypervisor | ||
|
||
|
||
### Changes | ||
|
||
|
||
### Bug fixes | ||
|
||
|
||
|
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,90 @@ | ||
// 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 applehv | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"net" | ||
"net/http" | ||
"os/exec" | ||
|
||
|
||
"github.com/coreos/ignition/v2/internal/distro" | ||
"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" | ||
"github.com/mdlayher/vsock" | ||
) | ||
|
||
func init() { | ||
platform.Register(platform.Provider{ | ||
Name: "applehv", | ||
Fetch: fetchConfig, | ||
}) | ||
} | ||
|
||
func fetchConfig(f *resource.Fetcher) (types.Config, report.Report, error) { | ||
_, err := f.Logger.LogCmd(exec.Command(distro.ModprobeCmd(), "vsock"), "Loading vsock kernel module") | ||
if err != nil { | ||
f.Logger.Err("Failed to install vsocker kernel module: %v", err) | ||
errors := fmt.Errorf("Failed to install vsock kernel module: %v", err) | ||
return types.Config{}, report.Report{}, errors | ||
} | ||
conn, err := vsock.Dial(2, 1024, &vsock.Config{}) | ||
if err != nil { | ||
return types.Config{}, report.Report{}, err | ||
} | ||
defer func() { | ||
if err := conn.Close(); err != nil { | ||
f.Logger.Err("unable to close vsock connection: %v", err) | ||
} | ||
}() | ||
|
||
req, err := http.NewRequest(http.MethodGet, "http://d/", nil) | ||
if err != nil { | ||
return types.Config{}, report.Report{}, err | ||
} | ||
req.Header.Set("Accept", "application/json") | ||
|
||
client := http.Client{ | ||
Transport: &http.Transport{ | ||
DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) { | ||
return conn, nil | ||
}, | ||
}, | ||
} | ||
|
||
resp, err := client.Do(req) | ||
if err != nil { | ||
return types.Config{}, report.Report{}, err | ||
} | ||
|
||
defer func() { | ||
if err := resp.Body.Close(); err != nil { | ||
f.Logger.Err("unable to close response body: %v", err) | ||
} | ||
}() | ||
|
||
b, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
return types.Config{}, report.Report{}, err | ||
} | ||
|
||
return util.ParseConfig(f.Logger, b) | ||
} |
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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.