-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
providers: add initial zVM hypervisor support
- Loading branch information
1 parent
641ec6a
commit 8e21c66
Showing
4 changed files
with
124 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// 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 ( | ||
"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" | ||
const configFile string = "config.ign" | ||
|
||
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) | ||
return types.Config{}, report.Report{}, err | ||
} | ||
// Online the reader device. | ||
logger := f.Logger | ||
err = onlineDevice(logger) | ||
if err != nil { | ||
return types.Config{}, report.Report{}, err | ||
} | ||
// 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) | ||
return types.Config{}, report.Report{}, err | ||
} | ||
items := strings.Split(string(readerInfo), "\n") | ||
for _, records := range items { | ||
record := strings.Fields(records) | ||
if len(record) <= 1 { | ||
break | ||
} | ||
spoolid := record[1] | ||
file := record[9] | ||
ftype := record[10] | ||
// Receive the spool file. | ||
if file == "ignition" { | ||
if ftype != "" { | ||
file = record[9] + "." + ftype | ||
} | ||
_, err := f.Logger.LogCmd(exec.Command(distro.VmurCmd(), "re", "-f", spoolid, file), "Receive the spool file") | ||
if err == nil { | ||
f.Logger.Info("using config file at %q", file) | ||
_, err := f.Logger.LogCmd(exec.Command(distro.TarCmd(), "-xzvf", file), "Extract the spool file") | ||
rawConfig, err := ioutil.ReadFile(configFile) | ||
if err != nil { | ||
f.Logger.Err("Couldn't read config %q: %v", file, err) | ||
break | ||
} | ||
return util.ParseConfig(f.Logger, rawConfig) | ||
} else { | ||
return types.Config{}, report.Report{}, err | ||
} | ||
} | ||
} | ||
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 { | ||
// 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) | ||
return err | ||
} | ||
_, err = logger.LogCmd(exec.Command(distro.ChccwdevCmd(), "-e", readerDevice), "Brings a Linux device online") | ||
if err != nil { | ||
logger.Err("Couldn't online reader device") | ||
return err | ||
} | ||
} | ||
_, err = logger.LogCmd(exec.Command("udevadm", "settle", "||", "udevsettle"), "Settle udev device") | ||
return err | ||
} |