
This is first step in refactoring remote package to support future inventory interface, also relates to remote-direct executor, as it simplifies usage of Host objects Relates-To: #362 Change-Id: Ief2fece134a465916ce461960cd7d16c9e237eb7 Relates-To: #362
107 lines
2.7 KiB
Go
107 lines
2.7 KiB
Go
/*
|
|
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
|
|
|
|
https://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 remote
|
|
|
|
import (
|
|
"context"
|
|
|
|
api "opendev.org/airship/airshipctl/pkg/api/v1alpha1"
|
|
"opendev.org/airship/airshipctl/pkg/config"
|
|
"opendev.org/airship/airshipctl/pkg/document"
|
|
"opendev.org/airship/airshipctl/pkg/log"
|
|
"opendev.org/airship/airshipctl/pkg/phase"
|
|
"opendev.org/airship/airshipctl/pkg/phase/ifc"
|
|
"opendev.org/airship/airshipctl/pkg/remote/power"
|
|
)
|
|
|
|
// DoRemoteDirect bootstraps the ephemeral node.
|
|
func (b baremetalHost) DoRemoteDirect(cfg *config.Config) error {
|
|
helper, err := phase.NewHelper(cfg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
phaseClient := phase.NewClient(helper)
|
|
phase, err := phaseClient.PhaseByID(ifc.ID{Name: config.BootstrapPhase})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
docRoot, err := phase.DocumentRoot()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
docBundle, err := document.NewBundleByPath(docRoot)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
remoteDirectConfiguration := &api.RemoteDirectConfiguration{}
|
|
selector, err := document.NewSelector().ByObject(remoteDirectConfiguration, api.Scheme)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
doc, err := docBundle.SelectOne(selector)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = doc.ToAPIObject(remoteDirectConfiguration, api.Scheme)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Debugf("Bootstrapping ephemeral host '%s' with ID '%s' and BMC Address '%s'.", b.HostName, b.NodeID(),
|
|
b.BMCAddress)
|
|
|
|
powerStatus, err := b.SystemPowerStatus(context.Background())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Power on node if it is off
|
|
if powerStatus != power.StatusOn {
|
|
log.Debugf("Ephemeral node has power status '%s'. Attempting to power on.", powerStatus.String())
|
|
if err = b.SystemPowerOn(context.Background()); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
// Perform remote direct operations
|
|
if remoteDirectConfiguration.IsoURL == "" {
|
|
return ErrMissingOption{What: "isoURL"}
|
|
}
|
|
|
|
err = b.SetVirtualMedia(context.Background(), remoteDirectConfiguration.IsoURL)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = b.SetBootSourceByType(context.Background())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = b.RebootSystem(context.Background())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Printf("Successfully bootstrapped ephemeral host '%s'.", b.HostName)
|
|
|
|
return nil
|
|
}
|