-
Notifications
You must be signed in to change notification settings - Fork 247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
providers: add initial zVM hypervisor support #865
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// Copyright 2019 Red Hat, Inc. | ||
// | ||
// 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. | ||
|
||
// The zVM provider fetches a local configuration from the virtual unit | ||
// record devices. | ||
|
||
package zvm | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io/ioutil" | ||
"os/exec" | ||
"strings" | ||
|
||
"github.com/coreos/ignition/v2/config/shared/errors" | ||
"github.com/coreos/ignition/v2/config/v3_1_experimental/types" | ||
"github.com/coreos/ignition/v2/internal/distro" | ||
"github.com/coreos/ignition/v2/internal/log" | ||
"github.com/coreos/ignition/v2/internal/providers/util" | ||
"github.com/coreos/ignition/v2/internal/resource" | ||
"github.com/coreos/vcontext/report" | ||
) | ||
|
||
const readerDevice string = "000c" | ||
|
||
func FetchConfig(f *resource.Fetcher) (types.Config, report.Report, error) { | ||
// Fetch config files directly from reader device. | ||
_, err := f.Logger.LogCmd(exec.Command(distro.ModprobeCmd(), "vmur"), "Loading zVM control program module") | ||
if err != nil { | ||
f.Logger.Err("Couldn't install vmur module: %v", err) | ||
errors := fmt.Errorf("Couldn't install vmur module: %v", err) | ||
return types.Config{}, report.Report{}, errors | ||
} | ||
// Online the reader device. | ||
logger := f.Logger | ||
err = onlineDevice(logger) | ||
if err != nil { | ||
return types.Config{}, report.Report{}, err | ||
zhengxiaomei123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
// Read files from the z/VM reader queue. | ||
readerInfo, err := exec.Command(distro.VmurCmd(), "li").CombinedOutput() | ||
if err != nil { | ||
f.Logger.Err("Can not get reader device: %v", err) | ||
errors := fmt.Errorf("Can not get reader device: %v", err) | ||
return types.Config{}, report.Report{}, errors | ||
} | ||
for _, records := range strings.Split(string(readerInfo), "\n") { | ||
record := strings.Fields(records) | ||
// The records format: ORIGINID FILE CLASSA CLASSB RECORDS CPY HOLD DATE TIME NAME TYPE DIST | ||
if len(record) <= 1 { | ||
zhengxiaomei123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
break | ||
} | ||
if len(record) < 11 { | ||
zhengxiaomei123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
continue | ||
} | ||
spoolid := record[1] | ||
ftype := record[10] | ||
zhengxiaomei123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
file := record[9] + "." + ftype | ||
// Receive the spool file. | ||
if ftype == "ign" { | ||
_, err := f.Logger.LogCmd(exec.Command(distro.VmurCmd(), "re", "-f", spoolid, file), "Receive the spool file") | ||
if err != nil { | ||
return types.Config{}, report.Report{}, err | ||
} | ||
f.Logger.Info("using config file at %q", file) | ||
rawConfig, err := ioutil.ReadFile(file) | ||
if err != nil { | ||
f.Logger.Err("Couldn't read config from configFile %q: %v", file, err) | ||
break | ||
} | ||
jsonConfig := bytes.Trim(rawConfig, string(byte(0))) | ||
return util.ParseConfig(f.Logger, jsonConfig) | ||
} | ||
} | ||
return types.Config{}, report.Report{}, errors.ErrEmpty | ||
} | ||
|
||
func onlineDevice(logger *log.Logger) error { | ||
_, err := logger.LogCmd(exec.Command(distro.ChccwdevCmd(), "-e", readerDevice), "Brings a Linux device online") | ||
if err != nil { | ||
ajeddeloh marked this conversation as resolved.
Show resolved
Hide resolved
zhengxiaomei123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// If online failed, expose the device firstly. | ||
_, err = logger.LogCmd(exec.Command(distro.CioIgnoreCmd(), "-r", readerDevice), "Expose reader device") | ||
if err != nil { | ||
logger.Err("Couldn't expose reader device %q: %v", readerDevice, err) | ||
errors := fmt.Errorf("Couldn't expose reader device %q: %v", readerDevice, err) | ||
return errors | ||
} | ||
_, err = logger.LogCmd(exec.Command(distro.ChccwdevCmd(), "-e", readerDevice), "Brings a Linux device online") | ||
if err != nil { | ||
logger.Err("Couldn't online reader device") | ||
errors := fmt.Errorf("Couldn't online reader device") | ||
return errors | ||
} | ||
} | ||
_, err = logger.LogCmd(exec.Command(distro.UdevadmCmd(), "settle"), "Settle udev device") | ||
return err | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: can probably dedupe these by assigning to a var first?
Edit: and same in other spots below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean a function like printError() to do f.loggr.Err? I don't think printError should replace f.logger.Err to involve the context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just mean something like: